1 /*============LICENSE_START=======================================================
3 ================================================================================
4 Copyright (c) 2020 Nokia. All rights reserved.
5 ================================================================================
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ============LICENSE_END=========================================================
20 package org.onap.blueprintgenerator.models.dmaapbp;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24 import static org.mockito.Mockito.spy;
25 import static org.mockito.Mockito.when;
26 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.CONTENERIZED_SERVICE_COMPONENT_USING_DMAAP;
27 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.FEED;
28 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.SUBSCRIBE_TO_EVENTS;
29 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.SUBSCRIBE_TO_FILES;
30 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.TOPIC;
33 import java.util.TreeMap;
34 import org.junit.Test;
35 import org.onap.blueprintgenerator.core.TestComponentSpec;
36 import org.onap.blueprintgenerator.models.componentspec.Auxilary;
37 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
38 import org.onap.blueprintgenerator.models.componentspec.Publishes;
39 import org.onap.blueprintgenerator.models.componentspec.Streams;
40 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
42 public class DmaapNodeTest {
44 private static final String DATA_ROUTER_TYPE = "data_router";
45 private static final String MESSAGE_ROUTER_TYPE = "message_router";
47 private static final String CONFIG_KEY = "Configkey";
49 private static final String SAMPLE_FORMAT = "Format";
50 private static final String SAMPLE_VERSION = "1.0.0";
51 private static final String SAMPLE_ROUTE = "SampleRoute";
52 private static final String TYPE = "type";
53 private static final String TARGET = "target";
57 public void dmaapNodeShouldHaveExpectedNodeType() {
59 ComponentSpec mockedComponentSpec = getSpiedComponentSpecWithoutRelationships();
61 DmaapNode dmaapNode = new DmaapNode();
62 dmaapNode.createDmaapNode(mockedComponentSpec, new TreeMap<>(), "");
64 assertEquals(CONTENERIZED_SERVICE_COMPONENT_USING_DMAAP, dmaapNode.getType());
68 public void createdDmaapNodeShouldHaveRelationshipWithTypeAndTargetForMessageRouterPublishes() {
69 ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
71 Streams streams = new Streams();
72 streams.setSubscribes(new Subscribes[0]);
73 streams.setPublishes(createSamplePublishes(MESSAGE_ROUTER_TYPE));
75 when(componentSpec.getStreams()).thenReturn(streams);
76 DmaapNode dmaapNode = new DmaapNode();
77 dmaapNode.createDmaapNode(componentSpec, new TreeMap<>(), "");
79 Map<String, String> relationship = dmaapNode.getRelationships().get(0);
81 assertNotNull(relationship.get(TYPE));
82 assertNotNull(relationship.get(TARGET));
86 public void createdDmaapNodeShouldHaveRelationshipWithTypeAndTargetForDataRouterPublishes() {
87 ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
89 Streams streams = new Streams();
90 streams.setSubscribes(new Subscribes[0]);
91 streams.setPublishes(createSamplePublishes(DATA_ROUTER_TYPE));
93 when(componentSpec.getStreams()).thenReturn(streams);
94 DmaapNode dmaapNode = new DmaapNode();
95 dmaapNode.createDmaapNode(componentSpec, new TreeMap<>(), "");
97 Map<String, String> relationship = dmaapNode.getRelationships().get(0);
99 assertNotNull(relationship.get(TYPE));
100 assertNotNull(relationship.get(TARGET));
104 public void createdDmaapNodeShouldHaveRelationshipWithTypeAndTargetForMessageRouterSubscribes() {
105 ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
107 Streams streams = new Streams();
108 streams.setSubscribes(createSampleSubscribes(MESSAGE_ROUTER_TYPE));
109 streams.setPublishes(new Publishes[0]);
111 when(componentSpec.getStreams()).thenReturn(streams);
112 DmaapNode dmaapNode = new DmaapNode();
113 dmaapNode.createDmaapNode(componentSpec, new TreeMap<>(), "");
115 Map<String, String> relationship = dmaapNode.getRelationships().get(0);
117 assertEquals(SUBSCRIBE_TO_EVENTS, relationship.get(TYPE));
118 assertNotNull(relationship.get(TARGET));
122 public void createdDmaapNodeShouldHaveRelationshipWithTypeAndTargetForDataRouterSubscribes() {
123 ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
125 Streams streams = new Streams();
126 streams.setSubscribes(createSampleSubscribes(DATA_ROUTER_TYPE));
127 streams.setPublishes(new Publishes[0]);
129 when(componentSpec.getStreams()).thenReturn(streams);
130 DmaapNode dmaapNode = new DmaapNode();
131 dmaapNode.createDmaapNode(componentSpec, new TreeMap<>(), "");
133 Map<String, String> relationship = dmaapNode.getRelationships().get(0);
135 assertEquals(SUBSCRIBE_TO_FILES, relationship.get(TYPE));
136 assertNotNull(relationship.get(TARGET));
140 public void createFeedNodeShouldSetFeedNodeType() {
141 ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
143 DmaapNode dmaapNode = new DmaapNode();
144 dmaapNode.createFeedNode(componentSpec, new TreeMap<>(), "");
146 assertEquals(FEED, dmaapNode.getType());
150 public void createTopicNodeShouldSetTopicNodeType() {
152 ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
154 DmaapNode dmaapNode = new DmaapNode();
155 dmaapNode.createTopicNode(componentSpec, new TreeMap<>(), "");
157 assertEquals(TOPIC, dmaapNode.getType());
160 private Publishes[] createSamplePublishes(String type) {
161 Publishes publishes = new Publishes();
163 publishes.setType(type);
164 publishes.setConfig_key(CONFIG_KEY);
165 publishes.setFormat(SAMPLE_FORMAT);
166 publishes.setVersion(SAMPLE_VERSION);
167 publishes.setRoute(SAMPLE_ROUTE);
169 return new Publishes[]{publishes};
172 private Subscribes[] createSampleSubscribes(String type) {
173 Subscribes subscribes = new Subscribes();
175 subscribes.setType(type);
176 subscribes.setConfig_key(CONFIG_KEY);
177 subscribes.setFormat(SAMPLE_FORMAT);
178 subscribes.setVersion(SAMPLE_VERSION);
179 subscribes.setRoute(SAMPLE_ROUTE);
181 return new Subscribes[]{subscribes};
184 private ComponentSpec getSpiedComponentSpecWithoutRelationships() {
185 ComponentSpec baseComponentSpec = new ComponentSpec();
186 baseComponentSpec.createComponentSpecFromString(new TestComponentSpec().getComponentSpecAsString());
187 ComponentSpec componentSpec = spy(baseComponentSpec);
189 Streams streams = new Streams();
190 streams.setSubscribes(new Subscribes[0]);
191 streams.setPublishes(new Publishes[0]);
192 when(componentSpec.getStreams()).thenReturn(streams);
194 Auxilary auxilary = spy(baseComponentSpec.getAuxilary());
195 when(auxilary.getDatabases()).thenReturn(null);
197 when(componentSpec.getAuxilary()).thenReturn(auxilary);
198 when(componentSpec.getPolicyInfo()).thenReturn(null);
200 return componentSpec;