summaryrefslogtreecommitdiffstats
path: root/mod/bpgenerator/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'mod/bpgenerator/src/test/java/org/onap')
-rw-r--r--mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java244
-rw-r--r--mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/ImportsTest.java52
-rw-r--r--mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/tls/ExternalCertificateParametersFactoryTest.java2
-rw-r--r--mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprintTest.java245
-rw-r--r--mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNodeTest.java224
5 files changed, 558 insertions, 209 deletions
diff --git a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java
index 1c7e592..b978701 100644
--- a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java
+++ b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java
@@ -21,15 +21,14 @@
package org.onap.blueprintgenerator.core;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.LinkedHashMap;
@@ -39,22 +38,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.onap.blueprintgenerator.models.blueprint.Blueprint;
import org.onap.blueprintgenerator.models.blueprint.GetInput;
-import org.onap.blueprintgenerator.models.componentspec.Artifacts;
-import org.onap.blueprintgenerator.models.componentspec.Auxilary;
-import org.onap.blueprintgenerator.models.componentspec.CallsObj;
import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
-import org.onap.blueprintgenerator.models.componentspec.Container;
-import org.onap.blueprintgenerator.models.componentspec.HealthCheck;
-import org.onap.blueprintgenerator.models.componentspec.Host;
-import org.onap.blueprintgenerator.models.componentspec.Parameters;
-import org.onap.blueprintgenerator.models.componentspec.Policy;
-import org.onap.blueprintgenerator.models.componentspec.ProvidesObj;
-import org.onap.blueprintgenerator.models.componentspec.Publishes;
-import org.onap.blueprintgenerator.models.componentspec.Self;
-import org.onap.blueprintgenerator.models.componentspec.Services;
-import org.onap.blueprintgenerator.models.componentspec.Streams;
-import org.onap.blueprintgenerator.models.componentspec.Subscribes;
-import org.onap.blueprintgenerator.models.componentspec.Volumes;
import org.onap.blueprintgenerator.models.dmaapbp.DmaapNode;
import org.onap.blueprintgenerator.models.onapbp.OnapNode;
import org.onap.blueprintgenerator.models.policymodel.PolicyModel;
@@ -70,146 +54,20 @@ public class BlueprintGeneratorTest {
/**
* Component spec test.
*
- * @throws JsonParseException the json parse exception
- * @throws JsonMappingException the json mapping exception
- * @throws IOException Signals that an I/O exception has occurred.
*/
-
@Test
- public void componentSpecTest() throws JsonParseException, JsonMappingException, IOException {
-
+ public void componentSpecTest() {
ComponentSpec spec = new ComponentSpec();
TestComponentSpec test = new TestComponentSpec();
- spec.createComponentSpecFromString(test.getCs());
-
- //Manually fill a component spec object with the values from the file itself
- ComponentSpec manualSpec = new ComponentSpec();
-
- Self self = new Self();
- self.setComponent_type("docker");
- self.setDescription("Test component spec");
- self.setName("test.component.spec");
- self.setVersion("1.0.1");
- manualSpec.setSelf(self);
-
- //assertEquals(manualSpec.getSelf(), spec.getSelf());
-
- Services services = new Services();
- CallsObj[] calls = new CallsObj[0];
- ProvidesObj[] provides = new ProvidesObj[0];
- services.setCalls(calls);
- services.setProvides(provides);
- manualSpec.setServices(null);
-
- //assertEquals(manualSpec.getServices(), spec.getServices());
-
- Streams streams = new Streams();
- Publishes[] publishes = new Publishes[2];
- Publishes pub1 = new Publishes();
- pub1.setConfig_key("TEST-PUB-DR");
- pub1.setFormat("dataformat_Hello_World_PM");
- pub1.setType("data_router");
- pub1.setVersion("1.0.0");
-
- Publishes pub2 = new Publishes();
- pub2.setConfig_key("TEST-PUB-MR");
- pub2.setFormat("dataformat_Hello_World_PM");
- pub2.setType("message_router");
- pub2.setVersion("1.0.0");
- publishes[0] = pub1;
- publishes[1] = pub2;
- streams.setPublishes(publishes);
-
- Subscribes[] subscribes = new Subscribes[2];
- Subscribes sub1 = new Subscribes();
- sub1.setConfig_key("TEST-SUB-MR");
- sub1.setFormat("dataformat_Hello_World_PM");
- sub1.setRoute("/TEST_HELLO_WORLD_SUB_MR");
- sub1.setType("message_router");
- sub1.setVersion("1.0.0");
-
- Subscribes sub2 = new Subscribes();
- sub2.setConfig_key("TEST-SUB-DR");
- sub2.setFormat("dataformat_Hello_World_PM");
- sub2.setRoute("/TEST-HELLO-WORLD-SUB-DR");
- sub2.setType("data_router");
- sub2.setVersion("1.0.0");
- subscribes[0] = sub1;
- subscribes[1] = sub2;
- streams.setSubscribes(subscribes);
-
- manualSpec.setStreams(streams);
-
- //assertEquals(manualSpec.getStreams(), spec.getStreams());
-
- Parameters[] parameters = new Parameters[1];
- Parameters par1 = new Parameters();
- par1.setName("testParam1");
- par1.setValue("test-param-1");
- par1.setDescription("test parameter 1");
- par1.setSourced_at_deployment(true);
- par1.setDesigner_editable(true);
- par1.setPolicy_editable(true);
- par1.setPolicy_group("Test_Parameters");
- par1.setRequired(true);
- par1.setType("string");
- parameters[0] = par1;
-
- manualSpec.setParameters(parameters);
-
- //assertEquals(manualSpec.getParameters(), spec.getParameters());
-
- Auxilary auxilary = new Auxilary();
- HealthCheck healthcheck = new HealthCheck();
- healthcheck.setInterval("300s");
- healthcheck.setTimeout("120s");
- healthcheck.setScript("/etc/init.d/nagios status");
- healthcheck.setType("docker");
- auxilary.setHealthcheck(healthcheck);
-
- Volumes[] volumes = new Volumes[1];
- Volumes vol1 = new Volumes();
- Container con1 = new Container();
- con1.setBind("/opt/app/manager/config/hostname");
- Host host1 = new Host();
- host1.setPath("/etc/hostname");
- host1.setMode("ro");
- vol1.setContainer(con1);
- vol1.setHost(host1);
-
- volumes[0] = vol1;
-
- auxilary.setVolumes(volumes);
-
- ArrayList<Object> ports = new ArrayList();
- ports.add("80:90");
- ports.add("99:99");
-
- TreeMap<String, String> dataBases = new TreeMap<String, String>();
- dataBases.put("TestDB1", "PGaaS");
- dataBases.put("TestDB2", "PGaaS");
- auxilary.setDatabases(dataBases);
-
- Policy pol = new Policy();
- pol.setTrigger_type("docker");
- pol.setScript_path("/opt/app/manager/bin/reconfigure.sh");
- auxilary.setPolicy(pol);
-
- auxilary.setPorts(ports);
-
- manualSpec.setAuxilary(auxilary);
-
- //assertEquals(manualSpec.getAuxilary(), spec.getAuxilary());
-
- Artifacts[] artifacts = new Artifacts[1];
- Artifacts art = new Artifacts();
- art.setType("docker image");
- art.setUri("test.tester");
-
- artifacts[0] = art;
- manualSpec.setArtifacts(artifacts);
-
- //assertEquals(manualSpec.getArtifacts(), spec.getArtifacts());
+ spec.createComponentSpecFromString(test.getComponentSpecAsString());
+ ComponentSpec expectedSpec = test.getComponentSpec();
+
+ assertEquals(expectedSpec.getSelf(), spec.getSelf());
+ assertEquals(expectedSpec.getServices(), spec.getServices());
+ assertEquals(expectedSpec.getStreams(), spec.getStreams());
+ assertArrayEquals(expectedSpec.getParameters(), spec.getParameters());
+ assertEquals(expectedSpec.getAuxilary(), spec.getAuxilary());
+ assertArrayEquals(expectedSpec.getArtifacts(), spec.getArtifacts());
}
/**
@@ -219,11 +77,11 @@ public class BlueprintGeneratorTest {
public void toscaDefinitionTest() {
ComponentSpec cs = new ComponentSpec();
TestComponentSpec test = new TestComponentSpec();
- cs.createComponentSpecFromString(test.getCs());
+ cs.createComponentSpecFromString(test.getComponentSpecAsString());
Blueprint bp = new Blueprint();
bp = bp.createBlueprint(cs, "", 'o', "", "");
- assertEquals(bp.getTosca_definitions_version(), "cloudify_dsl_1_3");
+ assertEquals("cloudify_dsl_1_3", bp.getTosca_definitions_version());
}
/**
@@ -233,19 +91,16 @@ public class BlueprintGeneratorTest {
public void importsTest() {
ComponentSpec cs = new ComponentSpec();
TestComponentSpec test = new TestComponentSpec();
- cs.createComponentSpecFromString(test.getCs());
+ cs.createComponentSpecFromString(test.getComponentSpecAsString());
Blueprint bp = new Blueprint();
bp = bp.createBlueprint(cs, "", 'o', "", "");
- ArrayList<String> imps = new ArrayList<String>();
-
- imps.add("http://www.getcloudify.org/spec/cloudify/3.4/types.yaml");
- imps.add(
- "https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R6/k8splugin/1.7.2/k8splugin_types.yaml");
- imps.add(
- "https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R6/dcaepolicyplugin/2.4.0/dcaepolicyplugin_types.yaml");
- assertEquals(bp.getImports(), imps);
+ ArrayList<String> imps = new ArrayList<>();
+ imps.add("https://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml");
+ imps.add("plugin:k8splugin?version=3.4.2");
+ imps.add("plugin:dcaepolicyplugin?version=2.4.0");
+ assertEquals(imps, bp.getImports());
}
@Test
@@ -256,50 +111,49 @@ public class BlueprintGeneratorTest {
Blueprint bp = new Blueprint();
bp = bp.createBlueprint(cs, "", 'o', "", "");
- TreeMap<String, LinkedHashMap<String, Object>> inputs = new TreeMap<String, LinkedHashMap<String, Object>>();
+ TreeMap<String, LinkedHashMap<String, Object>> inputs = new TreeMap<>();
//mr inputs
- LinkedHashMap<String, Object> stringType = new LinkedHashMap<String, Object>();
+ LinkedHashMap<String, Object> stringType = new LinkedHashMap<>();
stringType.put("type", "string");
//necessary inputs
- LinkedHashMap<String, Object> tag = new LinkedHashMap<String, Object>();
+ LinkedHashMap<String, Object> tag = new LinkedHashMap<>();
tag.put("type", "string");
String tester = "test.tester";
tag.put("default", '"' + tester + '"');
- String tagVersion = "tag_version";
inputs.put("tag_version", tag);
inputs.put("log_directory", stringType);
- LinkedHashMap cert = new LinkedHashMap();
+ LinkedHashMap<String, Object> cert = new LinkedHashMap<>();
cert.put("type", "string");
cert.put("default", "");
inputs.put("cert_directory", cert);
- LinkedHashMap<String, Object> env = new LinkedHashMap();
+ LinkedHashMap<String, Object> env = new LinkedHashMap<>();
env.put("default", "{}");
inputs.put("envs", env);
- LinkedHashMap port = new LinkedHashMap();
+ LinkedHashMap<String, Object> port = new LinkedHashMap<>();
port.put("type", "string");
port.put("description", "Kubernetes node port on which collector is exposed");
port.put("default", "99");
inputs.put("external_port", port);
- LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>();
+ LinkedHashMap<String, Object> rep = new LinkedHashMap<>();
rep.put("type", "integer");
rep.put("description", "number of instances");
rep.put("default", 1);
inputs.put("replicas", rep);
- LinkedHashMap<String, Object> aaf = new LinkedHashMap();
+ LinkedHashMap<String, Object> aaf = new LinkedHashMap<>();
aaf.put("type", "boolean");
aaf.put("default", false);
inputs.put("use_tls", aaf);
//parmaeter input
- LinkedHashMap<String, Object> test = new LinkedHashMap<String, Object>();
+ LinkedHashMap<String, Object> test = new LinkedHashMap<>();
test.put("type", "string");
String testParam = "test-param-1";
test.put("default", '"' + testParam + '"');
@@ -325,19 +179,17 @@ public class BlueprintGeneratorTest {
inputs.put("topic0_name", stringType);
inputs.put("topic1_name", stringType);
- LinkedHashMap<String, Object> cpu = new LinkedHashMap();
+ LinkedHashMap<String, Object> cpu = new LinkedHashMap<>();
cpu.put("type", "string");
cpu.put("default", "250m");
inputs.put("test.component.spec_cpu_limit", cpu);
inputs.put("test.component.spec_cpu_request", cpu);
- LinkedHashMap<String, Object> mem = new LinkedHashMap();
+ LinkedHashMap<String, Object> mem = new LinkedHashMap<>();
mem.put("type", "string");
mem.put("default", "128Mi");
inputs.put("test.component.spec_memory_limit", mem);
inputs.put("test.component.spec_memory_request", mem);
-
- assertEquals(true, true);
}
@Test
@@ -355,10 +207,9 @@ public class BlueprintGeneratorTest {
//set the type
testNode.setType("dcae.nodes.ContainerizedServiceComponent");
- ArrayList<String> ports = new ArrayList<String>();
+ ArrayList<String> ports = new ArrayList<>();
ports.add("concat: [\"80:\", {get_input: external_port }]");
ports.add("concat: [\"99:\", {get_input: external_port }]");
- assertEquals(true, true);
}
@Test
@@ -372,7 +223,7 @@ public class BlueprintGeneratorTest {
OnapNode node = (OnapNode) bp.getNode_templates().get("test.component.spec");
GetInput par = (GetInput) node.getProperties().getApplication_config().getParams().get("testParam1");
- assertEquals(par.getBpInputName(), "testParam1");
+ assertEquals("testParam1", par.getBpInputName());
}
@Test
@@ -385,13 +236,7 @@ public class BlueprintGeneratorTest {
OnapNode node = (OnapNode) bp.getNode_templates().get("test.component.spec");
- boolean test = false;
- if (!node.getProperties().getApplication_config().getStreams_publishes().isEmpty()) {
- test = true;
- System.out.println("tst");
- }
-
- assertEquals(true, test);
+ assertFalse(node.getProperties().getApplication_config().getStreams_publishes().isEmpty());
}
@Test
@@ -405,13 +250,8 @@ public class BlueprintGeneratorTest {
DmaapNode dmaap = (DmaapNode) bp.getNode_templates().get("test.component.spec");
//check if the stream publishes and subscribes are not null to see if the dmaap plugin was invoked properly
- boolean d = false;
-
- if (dmaap.getProperties().getStreams_publishes() != null
- || dmaap.getProperties().getStreams_subscribes() != null) {
- d = true;
- }
- assertEquals(true, d);
+ assertNotNull(dmaap.getProperties().getStreams_publishes());
+ assertNotNull(dmaap.getProperties().getStreams_subscribes());
}
@Test
@@ -442,17 +282,5 @@ public class BlueprintGeneratorTest {
PolicyModel p = new PolicyModel();
p.createPolicyModels(cs, "TestModels");
-
- assertEquals(true, true);
- }
-
- private void assertContainsInputWithDefault(Blueprint bp, String inputName, Object defaultValue) {
- LinkedHashMap<String, Object> input = bp.getInputs().get(inputName);
- assertNotNull(input);
- assertEquals(defaultValue, input.get("default"));
- }
-
- private String inQuotes(String filedName) {
- return String.format("\"%s\"", filedName);
}
}
diff --git a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/ImportsTest.java b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/ImportsTest.java
new file mode 100644
index 0000000..1ce296a
--- /dev/null
+++ b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/ImportsTest.java
@@ -0,0 +1,52 @@
+/*============LICENSE_START=======================================================
+ org.onap.dcae
+ ================================================================================
+ Copyright (c) 2020 Nokia Intellectual Property. All rights reserved.
+ ================================================================================
+ 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.
+ ============LICENSE_END=========================================================
+ */
+
+package org.onap.blueprintgenerator.models.blueprint;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Test;
+
+public class ImportsTest {
+
+ private final List<String> expectedImports = Arrays.asList(
+ "https://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml",
+ "plugin:k8splugin?version=3.4.1",
+ "plugin:pgaas?version=1.3.0",
+ "plugin:clamppolicyplugin?version=1.1.0",
+ "plugin:dmaap?version=1.5.0"
+ );
+
+ @Test
+ public void shouldReadImportsFromFile() {
+ ArrayList<String> importsFromFile = Imports.createImportsFromFile("TestCases/imports/imports.yaml");
+ assertEquals(expectedImports, importsFromFile);
+ }
+
+ @Test
+ public void shouldRemoveBlankImportsFromFile() {
+ ArrayList<String> importsFromFile =
+ Imports.createImportsFromFile("TestCases/imports/importsWithBlanks.yaml");
+ assertEquals(expectedImports, importsFromFile);
+ }
+
+}
diff --git a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/tls/ExternalCertificateParametersFactoryTest.java b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/tls/ExternalCertificateParametersFactoryTest.java
index e854b19..1cdb58b 100644
--- a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/tls/ExternalCertificateParametersFactoryTest.java
+++ b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/tls/ExternalCertificateParametersFactoryTest.java
@@ -25,7 +25,7 @@ import org.onap.blueprintgenerator.models.blueprint.tls.impl.ExternalCertificate
import java.util.LinkedHashMap;
import java.util.Map;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.COMMON_NAME_FIELD;
import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.DEFAULT_COMMON_NAME;
import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.DEFAULT_SANS;
diff --git a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprintTest.java b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprintTest.java
new file mode 100644
index 0000000..9e31002
--- /dev/null
+++ b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprintTest.java
@@ -0,0 +1,245 @@
+/*============LICENSE_START=======================================================
+ org.onap.dcae
+ ================================================================================
+ Copyright (c) 2020 Nokia. All rights reserved.
+ ================================================================================
+ 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.
+ ============LICENSE_END=========================================================
+ */
+
+
+package org.onap.blueprintgenerator.models.dmaapbp;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+import org.onap.blueprintgenerator.models.blueprint.Blueprint;
+import org.onap.blueprintgenerator.models.componentspec.Artifacts;
+import org.onap.blueprintgenerator.models.componentspec.Auxilary;
+import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
+import org.onap.blueprintgenerator.models.componentspec.Parameters;
+import org.onap.blueprintgenerator.models.componentspec.Publishes;
+import org.onap.blueprintgenerator.models.componentspec.Self;
+import org.onap.blueprintgenerator.models.componentspec.Streams;
+import org.onap.blueprintgenerator.models.componentspec.Subscribes;
+
+public class DmaapBlueprintTest {
+
+ private static final String MOCKED_NAME = "sample.name";
+ private static final String MESSAGE_ROUTER_TYPE_1 = "message_router";
+ private static final String MESSAGE_ROUTER_TYPE_2 = "message router";
+ private static final String DATA_ROUTER_TYPE_1 = "data_router";
+ private static final String DATA_ROUTER_TYPE_2 = "data router";
+ private static final String CONFIG_KEY_1 = "Configkey1";
+ private static final String CONFIG_KEY_2 = "Configkey2";
+
+ private static final String TOPIC_NODE_1 = CONFIG_KEY_1 + "_topic";
+ private static final String TOPIC_NODE_2 = CONFIG_KEY_2 + "_topic";
+ private static final String FEED_NODE_1 = CONFIG_KEY_1 + "_feed";
+ private static final String FEED_NODE_2 = CONFIG_KEY_2 + "_feed";
+
+ private static final String SAMPLE_FORMAT = "Format";
+ private static final String SAMPLE_VERSION = "1.0.0";
+ private static final String SAMPLE_ROUTE = "SampleRoute";
+ private static final String SAMPLE_DESCRIPTION = "sample description";
+ private static final String SAMPLE_PORTS = "8080:8080";
+ private static final String SAMPLE_ARTIFACT_TYPE = "test";
+ private static final String SAMPLE_ARTIFACT_URI = "test_uri";
+
+ @Test
+ public void dmaapBlueprintShouldHaveNodeTemplateWithDmaapNode() {
+
+ //given
+ ComponentSpec componentSpec = getMockedComponentSpec();
+ DmaapBlueprint dmaapBlueprint = new DmaapBlueprint();
+
+ //when
+ Blueprint resultBlueprint = dmaapBlueprint.createDmaapBlueprint(componentSpec, "", "");
+
+ //then
+ assertTrue(resultBlueprint.getNode_templates().get(MOCKED_NAME) instanceof DmaapNode);
+ }
+
+ @Test
+ public void nodeTemplateHasTopicNodeWhenAddMessageRouterAsPublishes() {
+ //given
+ ComponentSpec componentSpec = getMockedComponentSpec();
+ Streams streams = new Streams();
+ streams.setPublishes(getMessageRouterPublishes());
+ streams.setSubscribes(new Subscribes[0]);
+
+ when(componentSpec.getStreams()).thenReturn(streams);
+ DmaapBlueprint dmaapBlueprint = new DmaapBlueprint();
+
+ //when
+ Blueprint resultBlueprint = dmaapBlueprint.createDmaapBlueprint(componentSpec, "", "");
+
+ //then
+ assertNotNull(resultBlueprint.getNode_templates().get(TOPIC_NODE_1));
+ assertNotNull(resultBlueprint.getNode_templates().get(TOPIC_NODE_2));
+
+ }
+
+ @Test
+ public void nodeTemplateHasTopicNodeWhenAddMessageRouterAsSubscribes() {
+ //given
+ ComponentSpec componentSpec = getMockedComponentSpec();
+ Streams streams = new Streams();
+ streams.setPublishes(new Publishes[0]);
+ streams.setSubscribes(getMessageRouterSubscribes());
+
+ when(componentSpec.getStreams()).thenReturn(streams);
+ DmaapBlueprint dmaapBlueprint = new DmaapBlueprint();
+
+ //when
+ Blueprint resultBlueprint = dmaapBlueprint.createDmaapBlueprint(componentSpec, "", "");
+
+ //then
+ assertNotNull(resultBlueprint.getNode_templates().get(TOPIC_NODE_1));
+ assertNotNull(resultBlueprint.getNode_templates().get(TOPIC_NODE_2));
+
+ }
+
+ @Test
+ public void nodeTemplateHasFeedNodeWhenAddDataRouterAsPublishes() {
+ //given
+ ComponentSpec componentSpec = getMockedComponentSpec();
+ Streams streams = new Streams();
+ streams.setPublishes(getDataRouterPublishes());
+ streams.setSubscribes(new Subscribes[0]);
+
+ when(componentSpec.getStreams()).thenReturn(streams);
+ DmaapBlueprint dmaapBlueprint = new DmaapBlueprint();
+
+ //when
+ Blueprint resultBlueprint = dmaapBlueprint.createDmaapBlueprint(componentSpec, "", "");
+
+ //then
+ assertNotNull(resultBlueprint.getNode_templates().get(FEED_NODE_1));
+ assertNotNull(resultBlueprint.getNode_templates().get(FEED_NODE_2));
+
+ }
+
+ @Test
+ public void nodeTemplateHasFeedNodeWhenAddDataRouterAsSubscribes() {
+ //given
+ ComponentSpec componentSpec = getMockedComponentSpec();
+ Streams streams = new Streams();
+ streams.setPublishes(new Publishes[0]);
+ streams.setSubscribes(getDataRouterSubscribes());
+
+ when(componentSpec.getStreams()).thenReturn(streams);
+ DmaapBlueprint dmaapBlueprint = new DmaapBlueprint();
+
+ //when
+ Blueprint resultBlueprint = dmaapBlueprint.createDmaapBlueprint(componentSpec, "", "");
+
+ //then
+ assertNotNull(resultBlueprint.getNode_templates().get(FEED_NODE_1));
+ assertNotNull(resultBlueprint.getNode_templates().get(FEED_NODE_2));
+
+ }
+
+ private Publishes[] getMessageRouterPublishes() {
+ List<Publishes> publishesList = new ArrayList<>();
+
+ publishesList.add(createSamplePublishes(MESSAGE_ROUTER_TYPE_1, CONFIG_KEY_1));
+ publishesList.add(createSamplePublishes(MESSAGE_ROUTER_TYPE_2, CONFIG_KEY_2));
+ return publishesList.toArray(new Publishes[0]);
+ }
+
+ private Subscribes[] getMessageRouterSubscribes() {
+ List<Subscribes> subscribesList = new ArrayList<>();
+
+ subscribesList.add(createSampleSubscribes(MESSAGE_ROUTER_TYPE_1, CONFIG_KEY_1));
+ subscribesList.add(createSampleSubscribes(MESSAGE_ROUTER_TYPE_2, CONFIG_KEY_2));
+ return subscribesList.toArray(new Subscribes[0]);
+ }
+
+ private Publishes[] getDataRouterPublishes() {
+ List<Publishes> publishesList = new ArrayList<>();
+
+ publishesList.add(createSamplePublishes(DATA_ROUTER_TYPE_1, CONFIG_KEY_1));
+ publishesList.add(createSamplePublishes(DATA_ROUTER_TYPE_2, CONFIG_KEY_2));
+ return publishesList.toArray(new Publishes[0]);
+ }
+
+ private Subscribes[] getDataRouterSubscribes() {
+ List<Subscribes> subscribesList = new ArrayList<>();
+
+ subscribesList.add(createSampleSubscribes(DATA_ROUTER_TYPE_1, CONFIG_KEY_1));
+ subscribesList.add(createSampleSubscribes(DATA_ROUTER_TYPE_2, CONFIG_KEY_2));
+ return subscribesList.toArray(new Subscribes[0]);
+ }
+
+ private Publishes createSamplePublishes(String type, String key) {
+ Publishes publishes = new Publishes();
+
+ publishes.setType(type);
+ publishes.setConfig_key(key);
+ publishes.setFormat(SAMPLE_FORMAT);
+ publishes.setVersion(SAMPLE_VERSION);
+ publishes.setRoute(SAMPLE_ROUTE);
+
+ return publishes;
+ }
+
+ private Subscribes createSampleSubscribes(String type, String key) {
+ Subscribes subscribes = new Subscribes();
+
+ subscribes.setType(type);
+ subscribes.setConfig_key(key);
+ subscribes.setFormat(SAMPLE_FORMAT);
+ subscribes.setVersion(SAMPLE_FORMAT);
+ subscribes.setRoute(SAMPLE_ROUTE);
+
+ return subscribes;
+ }
+
+ private ComponentSpec getMockedComponentSpec() {
+ Self self = mock(Self.class);
+ when(self.getDescription()).thenReturn(SAMPLE_DESCRIPTION);
+ when(self.getName()).thenReturn(MOCKED_NAME);
+
+ Auxilary auxilary = mock(Auxilary.class);
+ ArrayList<Object> ports = new ArrayList<>();
+ ports.add(SAMPLE_PORTS);
+ when(auxilary.getPorts()).thenReturn(ports);
+
+ Streams streams = mock(Streams.class);
+ when(streams.getPublishes()).thenReturn(new Publishes[0]);
+ when(streams.getSubscribes()).thenReturn(new Subscribes[0]);
+
+ Artifacts artifact = new Artifacts();
+ artifact.setType(SAMPLE_ARTIFACT_TYPE);
+ artifact.setUri(SAMPLE_ARTIFACT_URI);
+
+ Artifacts[] arrayArtifacts = new Artifacts[10];
+ arrayArtifacts[0] = artifact;
+
+ ComponentSpec componentSpec = mock(ComponentSpec.class);
+ when(componentSpec.getSelf()).thenReturn(self);
+ when(componentSpec.getAuxilary()).thenReturn(auxilary);
+ when(componentSpec.getStreams()).thenReturn(streams);
+ when(componentSpec.getArtifacts()).thenReturn(arrayArtifacts);
+ when(componentSpec.getParameters()).thenReturn(new Parameters[0]);
+ when(componentSpec.getSelfName()).thenReturn(MOCKED_NAME);
+ return componentSpec;
+ }
+}
diff --git a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNodeTest.java b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNodeTest.java
new file mode 100644
index 0000000..83419e5
--- /dev/null
+++ b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNodeTest.java
@@ -0,0 +1,224 @@
+/*============LICENSE_START=======================================================
+ org.onap.dcae
+ ================================================================================
+ Copyright (c) 2020 Nokia. All rights reserved.
+ ================================================================================
+ 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.
+ ============LICENSE_END=========================================================
+ */
+
+package org.onap.blueprintgenerator.models.dmaapbp;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+import static org.onap.blueprintgenerator.models.blueprint.BpConstants.CONTENERIZED_SERVICE_COMPONENT_USING_DMAAP;
+import static org.onap.blueprintgenerator.models.blueprint.BpConstants.FEED;
+import static org.onap.blueprintgenerator.models.blueprint.BpConstants.SUBSCRIBE_TO_EVENTS;
+import static org.onap.blueprintgenerator.models.blueprint.BpConstants.SUBSCRIBE_TO_FILES;
+import static org.onap.blueprintgenerator.models.blueprint.BpConstants.TOPIC;
+
+import java.util.Map;
+import java.util.TreeMap;
+import org.junit.Test;
+import org.onap.blueprintgenerator.core.TestComponentSpec;
+import org.onap.blueprintgenerator.models.componentspec.Auxilary;
+import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
+import org.onap.blueprintgenerator.models.componentspec.Publishes;
+import org.onap.blueprintgenerator.models.componentspec.Streams;
+import org.onap.blueprintgenerator.models.componentspec.Subscribes;
+
+public class DmaapNodeTest {
+
+ private static final String DATA_ROUTER_TYPE = "data_router";
+ private static final String MESSAGE_ROUTER_TYPE = "message_router";
+
+ private static final String CONFIG_KEY = "Configkey";
+
+ private static final String SAMPLE_FORMAT = "Format";
+ private static final String SAMPLE_VERSION = "1.0.0";
+ private static final String SAMPLE_ROUTE = "SampleRoute";
+ private static final String TYPE = "type";
+ private static final String TARGET = "target";
+
+
+ @Test
+ public void dmaapNodeShouldHaveExpectedNodeType() {
+
+ ComponentSpec mockedComponentSpec = getSpiedComponentSpecWithoutRelationships();
+
+ DmaapNode dmaapNode = new DmaapNode();
+ dmaapNode.createDmaapNode(mockedComponentSpec, new TreeMap<>(), "");
+
+ assertEquals(CONTENERIZED_SERVICE_COMPONENT_USING_DMAAP, dmaapNode.getType());
+ }
+
+ @Test
+ public void createdDmaapNodeShouldHaveRelationshipWithTypeAndTargetForMessageRouterPublishes() {
+ ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
+
+ Streams streams = new Streams();
+ streams.setSubscribes(new Subscribes[0]);
+ streams.setPublishes(createSamplePublishes(MESSAGE_ROUTER_TYPE));
+
+ when(componentSpec.getStreams()).thenReturn(streams);
+ DmaapNode dmaapNode = new DmaapNode();
+ dmaapNode.createDmaapNode(componentSpec, new TreeMap<>(), "");
+
+ Map<String, String> relationship = dmaapNode.getRelationships().get(0);
+
+ assertNotNull(relationship.get(TYPE));
+ assertNotNull(relationship.get(TARGET));
+ }
+
+ @Test
+ public void createdDmaapNodeShouldHaveRelationshipWithTypeAndTargetForDataRouterPublishes() {
+ ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
+
+ Streams streams = new Streams();
+ streams.setSubscribes(new Subscribes[0]);
+ streams.setPublishes(createSamplePublishes(DATA_ROUTER_TYPE));
+
+ when(componentSpec.getStreams()).thenReturn(streams);
+ DmaapNode dmaapNode = new DmaapNode();
+ dmaapNode.createDmaapNode(componentSpec, new TreeMap<>(), "");
+
+ Map<String, String> relationship = dmaapNode.getRelationships().get(0);
+
+ assertNotNull(relationship.get(TYPE));
+ assertNotNull(relationship.get(TARGET));
+ }
+
+ @Test
+ public void createdDmaapNodeShouldHaveRelationshipWithTypeAndTargetForMessageRouterSubscribes() {
+ ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
+
+ Streams streams = new Streams();
+ streams.setSubscribes(createSampleSubscribes(MESSAGE_ROUTER_TYPE));
+ streams.setPublishes(new Publishes[0]);
+
+ when(componentSpec.getStreams()).thenReturn(streams);
+ DmaapNode dmaapNode = new DmaapNode();
+ dmaapNode.createDmaapNode(componentSpec, new TreeMap<>(), "");
+
+ Map<String, String> relationship = dmaapNode.getRelationships().get(0);
+
+ assertEquals(SUBSCRIBE_TO_EVENTS, relationship.get(TYPE));
+ assertNotNull(relationship.get(TARGET));
+ }
+
+ @Test
+ public void createdDmaapNodeShouldHaveRelationshipWithTypeAndTargetForDataRouterSubscribes() {
+ ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
+
+ Streams streams = new Streams();
+ streams.setSubscribes(createSampleSubscribes(DATA_ROUTER_TYPE));
+ streams.setPublishes(new Publishes[0]);
+
+ when(componentSpec.getStreams()).thenReturn(streams);
+ DmaapNode dmaapNode = new DmaapNode();
+ dmaapNode.createDmaapNode(componentSpec, new TreeMap<>(), "");
+
+ Map<String, String> relationship = dmaapNode.getRelationships().get(0);
+
+ assertEquals(SUBSCRIBE_TO_FILES, relationship.get(TYPE));
+ assertNotNull(relationship.get(TARGET));
+ }
+
+ @Test
+ public void createFeedNodeShouldSetFeedNodeType() {
+ ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
+
+ DmaapNode dmaapNode = new DmaapNode();
+ dmaapNode.createFeedNode(componentSpec, new TreeMap<>(), "");
+
+ assertEquals(FEED, dmaapNode.getType());
+ }
+
+ @Test
+ public void feedNodePropertiesShouldHaveUseExistingField() {
+ ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
+
+ DmaapNode dmaapNode = new DmaapNode();
+ dmaapNode.createFeedNode(componentSpec, new TreeMap<>() ,"");
+
+ assertTrue(dmaapNode.getProperties().getUseExisting());
+ }
+
+ @Test
+ public void createTopicNodeShouldSetTopicNodeType() {
+
+ ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
+
+ DmaapNode dmaapNode = new DmaapNode();
+ dmaapNode.createTopicNode(componentSpec, new TreeMap<>(), "");
+
+ assertEquals(TOPIC, dmaapNode.getType());
+ }
+
+ @Test
+ public void topicNodePropertiesShouldNotHaveUseExistingField() {
+ ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
+
+ DmaapNode dmaapNode = new DmaapNode();
+ dmaapNode.createTopicNode(componentSpec, new TreeMap<>() ,"");
+
+ assertNull(dmaapNode.getProperties().getUseExisting());
+ }
+
+ private Publishes[] createSamplePublishes(String type) {
+ Publishes publishes = new Publishes();
+
+ publishes.setType(type);
+ publishes.setConfig_key(CONFIG_KEY);
+ publishes.setFormat(SAMPLE_FORMAT);
+ publishes.setVersion(SAMPLE_VERSION);
+ publishes.setRoute(SAMPLE_ROUTE);
+
+ return new Publishes[]{publishes};
+ }
+
+ private Subscribes[] createSampleSubscribes(String type) {
+ Subscribes subscribes = new Subscribes();
+
+ subscribes.setType(type);
+ subscribes.setConfig_key(CONFIG_KEY);
+ subscribes.setFormat(SAMPLE_FORMAT);
+ subscribes.setVersion(SAMPLE_VERSION);
+ subscribes.setRoute(SAMPLE_ROUTE);
+
+ return new Subscribes[]{subscribes};
+ }
+
+ private ComponentSpec getSpiedComponentSpecWithoutRelationships() {
+ ComponentSpec baseComponentSpec = new ComponentSpec();
+ baseComponentSpec.createComponentSpecFromString(new TestComponentSpec().getComponentSpecAsString());
+ ComponentSpec componentSpec = spy(baseComponentSpec);
+
+ Streams streams = new Streams();
+ streams.setSubscribes(new Subscribes[0]);
+ streams.setPublishes(new Publishes[0]);
+ when(componentSpec.getStreams()).thenReturn(streams);
+
+ Auxilary auxilary = spy(baseComponentSpec.getAuxilary());
+ when(auxilary.getDatabases()).thenReturn(null);
+
+ when(componentSpec.getAuxilary()).thenReturn(auxilary);
+ when(componentSpec.getPolicyInfo()).thenReturn(null);
+
+ return componentSpec;
+ }
+}