diff --git a/src/main/java/io/diagrid/dapr/DaprContainer.java b/src/main/java/io/diagrid/dapr/DaprContainer.java index 11ab5f4..17f4898 100644 --- a/src/main/java/io/diagrid/dapr/DaprContainer.java +++ b/src/main/java/io/diagrid/dapr/DaprContainer.java @@ -25,15 +25,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; +import java.util.*; public class DaprContainer extends GenericContainer { @@ -259,10 +251,14 @@ public DaprContainer withComponent(Path path) { Map spec = (Map) component.get("spec"); String version = (String) spec.get("version"); List> specMetadata = - (List>) spec.getOrDefault("metadata", Collections.emptyMap()); + (List>) spec.getOrDefault("metadata", Collections.emptyList()); ArrayList metadataEntries = new ArrayList<>(); + if (specMetadata == null) { + return withComponent(name, type, version, metadataEntries); + } + for (Map specMetadataItem : specMetadata) { for (Map.Entry metadataItem : specMetadataItem.entrySet()) { metadataEntries.add(new MetadataEntry(metadataItem.getKey(), metadataItem.getValue())); diff --git a/src/test/java/io/diagrid/dapr/DaprComponentTest.java b/src/test/java/io/diagrid/dapr/DaprComponentTest.java index 0a124a3..f780a8f 100644 --- a/src/test/java/io/diagrid/dapr/DaprComponentTest.java +++ b/src/test/java/io/diagrid/dapr/DaprComponentTest.java @@ -141,4 +141,21 @@ public void withComponentFromPath() { Assert.assertEquals(expectedComponentYaml, componentYaml); } + + @Test + public void withComponentFromPathNoMetadata() { + final URL componentYaml = this.getClass().getClassLoader().getResource("components/no-metadata-component.yaml"); + final Path path = Paths.get(componentYaml.getPath()); + + final DaprContainer dapr = new DaprContainer("daprio/daprd") + .withAppName("dapr-app") + .withAppPort(8081) + .withComponent(path) + .withAppChannelAddress("host.testcontainers.internal"); + + final Set components = dapr.getComponents(); + Assert.assertEquals(1, components.size()); + final Component component = components.iterator().next(); + Assert.assertEquals(true, component.getMetadata().isEmpty()); + } } diff --git a/src/test/resources/components/no-metadata-component.yaml b/src/test/resources/components/no-metadata-component.yaml new file mode 100644 index 0000000..b7efb93 --- /dev/null +++ b/src/test/resources/components/no-metadata-component.yaml @@ -0,0 +1,7 @@ +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: statestore +spec: + type: state.redis + version: v1 \ No newline at end of file