From 55dcf3197958c76b1622a0c26489e68fe77e0314 Mon Sep 17 00:00:00 2001 From: Ravi Mantena Date: Wed, 21 Oct 2020 15:47:38 -0400 Subject: Blueprint Generator Refactored Code Issue-ID: DCAEGEN2-2472 Change-Id: I2ade7fb3b4196554eb4ecadd918fd45cb6ba8a52 Signed-off-by: Ravi Mantena --- .../models/blueprint/AppconfigTest.java | 62 ------ .../models/blueprint/ImportsTest.java | 52 ----- .../models/blueprint/ResourceConfigTest.java | 38 ---- .../ExternalCertificateParametersFactoryTest.java | 62 ------ .../models/dmaapbp/DmaapBlueprintTest.java | 245 --------------------- .../models/dmaapbp/DmaapNodeTest.java | 224 ------------------- 6 files changed, 683 deletions(-) delete mode 100644 mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/AppconfigTest.java delete mode 100644 mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/ImportsTest.java delete mode 100644 mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfigTest.java delete mode 100644 mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/tls/ExternalCertificateParametersFactoryTest.java delete mode 100644 mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprintTest.java delete mode 100644 mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNodeTest.java (limited to 'mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models') diff --git a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/AppconfigTest.java b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/AppconfigTest.java deleted file mode 100644 index 173d230..0000000 --- a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/AppconfigTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/*============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.blueprint; - -import static org.junit.Assert.assertEquals; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.LinkedHashMap; -import java.util.TreeMap; -import java.util.stream.Collectors; -import org.junit.Test; -import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; - -public class AppconfigTest { - - @Test - public void createAppconfigShouldReturnExpectedResult() throws FileNotFoundException { - TreeMap> inputs = new TreeMap>(); - ComponentSpec cs = new ComponentSpec(); - cs.createComponentSpecFromFile("TestCases/testComponentSpec.json"); - - TreeMap> result = new Appconfig().createAppconfig(inputs, cs, "", false); - - assertEquals(getExpectedStringFromFile(), result.toString()); - } - - private String getExpectedStringFromFile() throws FileNotFoundException { - File file = new File("TestCases/expects/createAppConfigResult.txt"); - InputStream inputStream = new FileInputStream(file); - return readFromInputStream(inputStream); - } - - private String readFromInputStream(InputStream inputStream) { - return new BufferedReader( - new InputStreamReader(inputStream, StandardCharsets.UTF_8)) - .lines() - .collect(Collectors.joining("")); - } -} 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 deleted file mode 100644 index 1ce296a..0000000 --- a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/ImportsTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/*============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 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 importsFromFile = Imports.createImportsFromFile("TestCases/imports/imports.yaml"); - assertEquals(expectedImports, importsFromFile); - } - - @Test - public void shouldRemoveBlankImportsFromFile() { - ArrayList importsFromFile = - Imports.createImportsFromFile("TestCases/imports/importsWithBlanks.yaml"); - assertEquals(expectedImports, importsFromFile); - } - -} diff --git a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfigTest.java b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfigTest.java deleted file mode 100644 index cf12da1..0000000 --- a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfigTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/*============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.blueprint; - -import static org.junit.Assert.assertEquals; - -import java.util.LinkedHashMap; -import java.util.TreeMap; -import org.junit.Test; - -public class ResourceConfigTest { - - @Test - public void createResourceConfig() { - TreeMap> result = new ResourceConfig() - .createResourceConfig(new TreeMap<>(), "demo"); - - String expectedResult = "{demo_cpu_limit={type=string, default=250m}, demo_cpu_request={type=string, default=250m}, demo_memory_limit={type=string, default=128Mi}, demo_memory_request={type=string, default=128Mi}}"; - assertEquals(expectedResult, result.toString()); - } -} 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 deleted file mode 100644 index 1cdb58b..0000000 --- a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/blueprint/tls/ExternalCertificateParametersFactoryTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/*============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.tls; - -import org.junit.Test; -import org.onap.blueprintgenerator.models.blueprint.tls.impl.ExternalCertificateParameters; - -import java.util.LinkedHashMap; -import java.util.Map; - -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; -import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.INPUT_PREFIX; -import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.SANS_FIELD; - -public class ExternalCertificateParametersFactoryTest { - - private static final String PREFIXED_COMMON_NAME_FIELD = INPUT_PREFIX + COMMON_NAME_FIELD; - private static final String PREFIXED_SANS_FIELD = INPUT_PREFIX + SANS_FIELD; - private static final String DEFAULT = "default"; - - @Test - public void shouldCreateExternalCertificatePropertiesObject() { - // given - ExternalCertificateParametersFactory cut = new ExternalCertificateParametersFactory(); - // when - ExternalCertificateParameters result = cut.create(); - // then - assertEquals(result.getCommonName().getBpInputName(), PREFIXED_COMMON_NAME_FIELD); - assertEquals(result.getSans().getBpInputName(), PREFIXED_SANS_FIELD); - } - - @Test - public void shouldCreateCorrectInputListWithDefaultValuesTakenFromComponentSpec() { - // given - ExternalCertificateParametersFactory cut = new ExternalCertificateParametersFactory(); - // when - Map> result = cut.createInputList(); - // then - assertEquals(DEFAULT_COMMON_NAME, result.get(PREFIXED_COMMON_NAME_FIELD).get(DEFAULT)); - assertEquals(DEFAULT_SANS, result.get(PREFIXED_SANS_FIELD).get(DEFAULT)); - } -} 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 deleted file mode 100644 index 9e31002..0000000 --- a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprintTest.java +++ /dev/null @@ -1,245 +0,0 @@ -/*============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 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 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 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 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 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 deleted file mode 100644 index 83419e5..0000000 --- a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNodeTest.java +++ /dev/null @@ -1,224 +0,0 @@ -/*============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 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 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 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 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; - } -} -- cgit 1.2.3-korg