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.junit.Assert.assertTrue;
25 import static org.mockito.Mockito.spy;
26 import static org.mockito.Mockito.when;
29 import java.util.TreeMap;
30 import org.junit.Test;
31 import org.onap.blueprintgenerator.core.TestComponentSpec;
32 import org.onap.blueprintgenerator.models.componentspec.Auxilary;
33 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
34 import org.onap.blueprintgenerator.models.componentspec.Publishes;
35 import org.onap.blueprintgenerator.models.componentspec.Streams;
36 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
38 public class DmaapNodeTest {
40 private static final String EXPECTED_DMAAP_NODE_TYPE = "dcae.nodes.ContainerizedServiceComponentUsingDmaap";
42 private static final String DATA_ROUTER_TYPE = "data_router";
43 private static final String MESSAGE_ROUTER_TYPE = "message_router";
45 private static final String CONFIG_KEY = "Configkey";
47 private static final String SAMPLE_FORMAT = "Format";
48 private static final String SAMPLE_VERSION = "1.0.0";
49 private static final String SAMPLE_ROUTE = "SampleRoute";
50 private static final String TYPE = "type";
51 private static final String TARGET = "target";
55 public void dmaapNodeShouldHaveExpectedNodeType() {
57 ComponentSpec mockedComponentSpec = getSpiedComponentSpecWithoutRelationships();
59 DmaapNode dmaapNode = new DmaapNode();
60 dmaapNode.createDmaapNode(mockedComponentSpec, new TreeMap<>(), "");
62 assertEquals(EXPECTED_DMAAP_NODE_TYPE, dmaapNode.getType());
66 public void createdDmaapNodeShouldHaveRelationshipWithTypeAndTargetForMessageRouterPublishes() {
67 ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
69 Streams streams = new Streams();
70 streams.setSubscribes(new Subscribes[0]);
71 streams.setPublishes(createSamplePublishes(MESSAGE_ROUTER_TYPE));
73 when(componentSpec.getStreams()).thenReturn(streams);
74 DmaapNode dmaapNode = new DmaapNode();
75 dmaapNode.createDmaapNode(componentSpec, new TreeMap<>(), "");
77 Map<String, String> relationship = dmaapNode.getRelationships().get(0);
79 assertNotNull(relationship.get(TYPE));
80 assertNotNull(relationship.get(TARGET));
84 public void createdDmaapNodeShouldHaveRelationshipWithTypeAndTargetForDataRouterPublishes() {
85 ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
87 Streams streams = new Streams();
88 streams.setSubscribes(new Subscribes[0]);
89 streams.setPublishes(createSamplePublishes(DATA_ROUTER_TYPE));
91 when(componentSpec.getStreams()).thenReturn(streams);
92 DmaapNode dmaapNode = new DmaapNode();
93 dmaapNode.createDmaapNode(componentSpec, new TreeMap<>(), "");
95 Map<String, String> relationship = dmaapNode.getRelationships().get(0);
97 assertNotNull(relationship.get(TYPE));
98 assertNotNull(relationship.get(TARGET));
102 public void createdDmaapNodeShouldHaveRelationshipWithTypeAndTargetForMessageRouterSubscribes() {
103 ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
105 Streams streams = new Streams();
106 streams.setSubscribes(createSampleSubscribes(MESSAGE_ROUTER_TYPE));
107 streams.setPublishes(new Publishes[0]);
109 when(componentSpec.getStreams()).thenReturn(streams);
110 DmaapNode dmaapNode = new DmaapNode();
111 dmaapNode.createDmaapNode(componentSpec, new TreeMap<>(), "");
113 Map<String, String> relationship = dmaapNode.getRelationships().get(0);
115 assertNotNull(relationship.get(TYPE));
116 assertNotNull(relationship.get(TARGET));
120 public void createdDmaapNodeShouldHaveRelationshipWithTypeAndTargetForDataRouterSubscribes() {
121 ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
123 Streams streams = new Streams();
124 streams.setSubscribes(createSampleSubscribes(DATA_ROUTER_TYPE));
125 streams.setPublishes(new Publishes[0]);
127 when(componentSpec.getStreams()).thenReturn(streams);
128 DmaapNode dmaapNode = new DmaapNode();
129 dmaapNode.createDmaapNode(componentSpec, new TreeMap<>(), "");
131 Map<String, String> relationship = dmaapNode.getRelationships().get(0);
133 assertNotNull(relationship.get(TYPE));
134 assertNotNull(relationship.get(TARGET));
138 public void createFeedNodeShouldSetFeedNodeType() {
139 ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
141 DmaapNode dmaapNode = new DmaapNode();
142 dmaapNode.createFeedNode(componentSpec, new TreeMap<>() ,"");
144 assertTrue(dmaapNode.getType().endsWith("Feed"));
148 public void createTopicNodeShouldSetTopicNodeType() {
150 ComponentSpec componentSpec = getSpiedComponentSpecWithoutRelationships();
152 DmaapNode dmaapNode = new DmaapNode();
153 dmaapNode.createTopicNode(componentSpec, new TreeMap<>() ,"");
155 assertTrue(dmaapNode.getType().endsWith("Topic"));
158 private Publishes[] createSamplePublishes(String type) {
159 Publishes publishes = new Publishes();
161 publishes.setType(type);
162 publishes.setConfig_key(CONFIG_KEY);
163 publishes.setFormat(SAMPLE_FORMAT);
164 publishes.setVersion(SAMPLE_VERSION);
165 publishes.setRoute(SAMPLE_ROUTE);
167 return new Publishes[]{publishes};
170 private Subscribes[] createSampleSubscribes(String type) {
171 Subscribes subscribes = new Subscribes();
173 subscribes.setType(type);
174 subscribes.setConfig_key(CONFIG_KEY);
175 subscribes.setFormat(SAMPLE_FORMAT);
176 subscribes.setVersion(SAMPLE_VERSION);
177 subscribes.setRoute(SAMPLE_ROUTE);
179 return new Subscribes[]{subscribes};
182 private ComponentSpec getSpiedComponentSpecWithoutRelationships() {
183 ComponentSpec baseComponentSpec = new ComponentSpec();
184 baseComponentSpec.createComponentSpecFromString(new TestComponentSpec().getComponentSpecAsString());
185 ComponentSpec componentSpec = spy(baseComponentSpec);
187 Streams streams = new Streams();
188 streams.setSubscribes(new Subscribes[0]);
189 streams.setPublishes(new Publishes[0]);
190 when(componentSpec.getStreams()).thenReturn(streams);
192 Auxilary auxilary = spy(baseComponentSpec.getAuxilary());
193 when(auxilary.getDatabases()).thenReturn(null);
195 when(componentSpec.getAuxilary()).thenReturn(auxilary);
196 when(componentSpec.getPolicyInfo()).thenReturn(null);
198 return componentSpec;