diff --git a/testcontainers-dapr/pom.xml b/testcontainers-dapr/pom.xml index 32897991f..3df408512 100644 --- a/testcontainers-dapr/pom.xml +++ b/testcontainers-dapr/pom.xml @@ -11,6 +11,7 @@ testcontainers-dapr testcontainers-dapr Testcontainers Dapr Module + 0.12.0-SNAPSHOT jar diff --git a/testcontainers-dapr/src/main/java/io/dapr/testcontainers/Component.java b/testcontainers-dapr/src/main/java/io/dapr/testcontainers/Component.java new file mode 100644 index 000000000..9e69a9d54 --- /dev/null +++ b/testcontainers-dapr/src/main/java/io/dapr/testcontainers/Component.java @@ -0,0 +1,80 @@ +/* + * Copyright 2024 The Dapr Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and +limitations under the License. +*/ + +package io.dapr.testcontainers; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * Represents a Dapr component. + */ +public class Component { + private String name; + private String type; + private String version; + private List metadata; + + /** + * Creates a new component. + * + * @param name Component name. + * @param type Component type. + * @param version Component version. + * @param metadata Metadata. + */ + public Component(String name, String type, String version, Map metadata) { + this.name = name; + this.type = type; + this.version = version; + this.metadata = new ArrayList(); + if (!metadata.isEmpty()) { + for (Map.Entry entry : metadata.entrySet()) { + this.metadata.add(new MetadataEntry(entry.getKey(), entry.getValue())); + } + } + } + + /** + * Creates a new component. + * + * @param name Component name. + * @param type Component type. + * @param version Component version. + * @param metadataEntries Component metadata entries. + */ + public Component(String name, String type, String version, List metadataEntries) { + this.name = name; + this.type = type; + this.version = version; + metadata = Objects.requireNonNull(metadataEntries); + } + + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public List getMetadata() { + return metadata; + } + + public String getVersion() { + return version; + } +} diff --git a/testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprContainer.java b/testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprContainer.java index d8deebe17..46ee48be4 100644 --- a/testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprContainer.java +++ b/testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprContainer.java @@ -32,127 +32,10 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; public class DaprContainer extends GenericContainer { - public enum DaprLogLevel { - ERROR, - WARN, - INFO, - DEBUG - } - - public static class Subscription { - String name; - String pubsubName; - String topic; - String route; - - /** - * Creates a new subscription. - * @param name Subscription name. - * @param pubsubName PubSub name. - * @param topic Topic name. - * @param route Route. - */ - public Subscription(String name, String pubsubName, String topic, String route) { - this.name = name; - this.pubsubName = pubsubName; - this.topic = topic; - this.route = route; - } - } - - public static class MetadataEntry { - String name; - Object value; - - public MetadataEntry(String name, Object value) { - this.name = name; - this.value = value; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Object getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - } - - /** - * Represents a Dapr component. - */ - public static class Component { - String name; - - String type; - - String version; - - List metadata; - - /** - * Creates a new component. - * @param name Component name. - * @param type Component type. - * @param version Component version. - * @param metadata Metadata. - */ - public Component(String name, String type, String version, Map metadata) { - this.name = name; - this.type = type; - this.version = version; - this.metadata = new ArrayList(); - if (!metadata.isEmpty()) { - for (Map.Entry entry : metadata.entrySet()) { - this.metadata.add(new MetadataEntry(entry.getKey(), entry.getValue())); - } - } - } - - /** - * Creates a new component. - * @param name Component name. - * @param type Component type. - * @param version Component version. - * @param metadataEntries Component metadata entries. - */ - public Component(String name, String type, String version, List metadataEntries) { - this.name = name; - this.type = type; - this.version = version; - metadata = Objects.requireNonNull(metadataEntries); - } - - public String getName() { - return name; - } - - public String getType() { - return type; - } - - public List getMetadata() { - return metadata; - } - - public String getVersion() { - return version; - } - } - private static final int DAPRD_HTTP_PORT = 3500; private static final int DAPRD_GRPC_PORT = 50001; private final Set components = new HashSet<>(); @@ -304,15 +187,15 @@ public Map componentToMap(Component component) { componentProps.put("kind", "Component"); Map componentMetadata = new LinkedHashMap<>(); - componentMetadata.put("name", component.name); + componentMetadata.put("name", component.getName()); componentProps.put("metadata", componentMetadata); Map componentSpec = new HashMap<>(); - componentSpec.put("type", component.type); - componentSpec.put("version", component.version); + componentSpec.put("type", component.getType()); + componentSpec.put("version", component.getVersion()); - if (!component.metadata.isEmpty()) { - componentSpec.put("metadata", component.metadata); + if (!component.getMetadata().isEmpty()) { + componentSpec.put("metadata", component.getMetadata()); } componentProps.put("spec", componentSpec); return componentProps; @@ -329,13 +212,13 @@ public Map subscriptionToMap(Subscription subscription) { subscriptionProps.put("kind", "Subscription"); Map subscriptionMetadata = new LinkedHashMap<>(); - subscriptionMetadata.put("name", subscription.name); + subscriptionMetadata.put("name", subscription.getName()); subscriptionProps.put("metadata", subscriptionMetadata); Map subscriptionSpec = new HashMap<>(); - subscriptionSpec.put("pubsubname", subscription.pubsubName); - subscriptionSpec.put("topic", subscription.topic); - subscriptionSpec.put("route", subscription.route); + subscriptionSpec.put("pubsubname", subscription.getPubsubName()); + subscriptionSpec.put("topic", subscription.getTopic()); + subscriptionSpec.put("route", subscription.getRoute()); subscriptionProps.put("spec", subscriptionSpec); return subscriptionProps; @@ -385,12 +268,12 @@ protected void configure() { for (Component component : components) { String componentYaml = componentToYaml(component); - withCopyToContainer(Transferable.of(componentYaml), "/components/" + component.name + ".yaml"); + withCopyToContainer(Transferable.of(componentYaml), "/components/" + component.getName() + ".yaml"); } for (Subscription subscription : subscriptions) { String subscriptionYaml = subscriptionToYaml(subscription); - withCopyToContainer(Transferable.of(subscriptionYaml), "/components/" + subscription.name + ".yaml"); + withCopyToContainer(Transferable.of(subscriptionYaml), "/components/" + subscription.getName() + ".yaml"); } } diff --git a/testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprLogLevel.java b/testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprLogLevel.java new file mode 100644 index 000000000..5ccb61e6f --- /dev/null +++ b/testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprLogLevel.java @@ -0,0 +1,8 @@ +package io.dapr.testcontainers; + +public enum DaprLogLevel { + ERROR, + WARN, + INFO, + DEBUG +} diff --git a/testcontainers-dapr/src/main/java/io/dapr/testcontainers/MetadataEntry.java b/testcontainers-dapr/src/main/java/io/dapr/testcontainers/MetadataEntry.java new file mode 100644 index 000000000..d25595103 --- /dev/null +++ b/testcontainers-dapr/src/main/java/io/dapr/testcontainers/MetadataEntry.java @@ -0,0 +1,40 @@ +/* + * Copyright 2024 The Dapr Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and +limitations under the License. +*/ + +package io.dapr.testcontainers; + +public class MetadataEntry { + private String name; + private Object value; + + public MetadataEntry(String name, Object value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public Object getValue() { + return value; + } + + public void setName(String name) { + this.name = name; + } + + public void setValue(Object value) { + this.value = value; + } +} diff --git a/testcontainers-dapr/src/main/java/io/dapr/testcontainers/Subscription.java b/testcontainers-dapr/src/main/java/io/dapr/testcontainers/Subscription.java new file mode 100644 index 000000000..faa1b6916 --- /dev/null +++ b/testcontainers-dapr/src/main/java/io/dapr/testcontainers/Subscription.java @@ -0,0 +1,52 @@ +/* + * Copyright 2024 The Dapr Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and +limitations under the License. +*/ + +package io.dapr.testcontainers; + +public class Subscription { + private String name; + private String pubsubName; + private String topic; + private String route; + + /** + * Creates a new subscription. + * + * @param name Subscription name. + * @param pubsubName PubSub name. + * @param topic Topic name. + * @param route Route. + */ + public Subscription(String name, String pubsubName, String topic, String route) { + this.name = name; + this.pubsubName = pubsubName; + this.topic = topic; + this.route = route; + } + + public String getName() { + return name; + } + + public String getPubsubName() { + return pubsubName; + } + + public String getTopic() { + return topic; + } + + public String getRoute() { + return route; + } +} diff --git a/testcontainers-dapr/src/main/resources/application.properties b/testcontainers-dapr/src/main/resources/application.properties deleted file mode 100644 index 8b1378917..000000000 --- a/testcontainers-dapr/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/testcontainers-dapr/src/test/java/io/dapr/testcontainers/DaprComponentTest.java b/testcontainers-dapr/src/test/java/io/dapr/testcontainers/DaprComponentTest.java index e4b6f9c0e..9671c4bad 100644 --- a/testcontainers-dapr/src/test/java/io/dapr/testcontainers/DaprComponentTest.java +++ b/testcontainers-dapr/src/test/java/io/dapr/testcontainers/DaprComponentTest.java @@ -13,8 +13,6 @@ package io.dapr.testcontainers; -import io.dapr.testcontainers.DaprContainer.Component; -import io.dapr.testcontainers.DaprContainer.Subscription; import org.junit.Assert; import org.junit.Test;