Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: class cast exception, map to list #53

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/main/java/io/diagrid/dapr/DaprContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<DaprContainer> {

Expand Down Expand Up @@ -259,10 +251,14 @@ public DaprContainer withComponent(Path path) {
Map<String, Object> spec = (Map<String, Object>) component.get("spec");
String version = (String) spec.get("version");
List<Map<String, Object>> specMetadata =
(List<Map<String, Object>>) spec.getOrDefault("metadata", Collections.emptyMap());
(List<Map<String, Object>>) spec.getOrDefault("metadata", Collections.emptyList());

ArrayList<MetadataEntry> metadataEntries = new ArrayList<>();

if (specMetadata == null) {
return withComponent(name, type, version, metadataEntries);
}

for (Map<String, Object> specMetadataItem : specMetadata) {
for (Map.Entry<String, Object> metadataItem : specMetadataItem.entrySet()) {
metadataEntries.add(new MetadataEntry(metadataItem.getKey(), metadataItem.getValue()));
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/io/diagrid/dapr/DaprComponentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Component> components = dapr.getComponents();
Assert.assertEquals(1, components.size());
final Component component = components.iterator().next();
Assert.assertEquals(true, component.getMetadata().isEmpty());
}
}
7 changes: 7 additions & 0 deletions src/test/resources/components/no-metadata-component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: statestore
spec:
type: state.redis
version: v1