1 /**============LICENSE_START=======================================================
3 ================================================================================
4 Copyright (c) 2019 AT&T Intellectual Property. 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=========================================================
21 package org.onap.blueprintgenerator.core;
23 import static org.junit.Assert.assertEquals;
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.HashMap;
29 import java.util.LinkedHashMap;
30 import java.util.TreeMap;
32 import org.junit.Test;
33 import org.onap.blueprintgenerator.core.BlueprintGenerator;
34 import org.onap.blueprintgenerator.models.blueprint.Blueprint;
35 import org.onap.blueprintgenerator.models.blueprint.ConcatObj;
36 import org.onap.blueprintgenerator.models.blueprint.DmaapObj;
37 import org.onap.blueprintgenerator.models.blueprint.GetInput;
38 import org.onap.blueprintgenerator.models.blueprint.Interfaces;
39 import org.onap.blueprintgenerator.models.blueprint.Start;
40 import org.onap.blueprintgenerator.models.blueprint.StartInputs;
41 import org.onap.blueprintgenerator.models.componentspec.Artifacts;
42 import org.onap.blueprintgenerator.models.componentspec.Auxilary;
43 import org.onap.blueprintgenerator.models.componentspec.CallsObj;
44 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
45 import org.onap.blueprintgenerator.models.componentspec.Container;
46 import org.onap.blueprintgenerator.models.componentspec.HealthCheck;
47 import org.onap.blueprintgenerator.models.componentspec.Host;
48 import org.onap.blueprintgenerator.models.componentspec.Parameters;
49 import org.onap.blueprintgenerator.models.componentspec.Policy;
50 import org.onap.blueprintgenerator.models.componentspec.ProvidesObj;
51 import org.onap.blueprintgenerator.models.componentspec.Publishes;
52 import org.onap.blueprintgenerator.models.componentspec.Self;
53 import org.onap.blueprintgenerator.models.componentspec.Services;
54 import org.onap.blueprintgenerator.models.componentspec.Streams;
55 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
56 import org.onap.blueprintgenerator.models.componentspec.Volumes;
57 import org.onap.blueprintgenerator.models.onapbp.OnapNode;
60 import com.fasterxml.jackson.core.JsonParseException;
61 import com.fasterxml.jackson.databind.JsonMappingException;
63 import junit.framework.Assert;
66 // TODO: Auto-generated Javadoc
68 * The Class BlueprintGeneratorTest.
70 public class BlueprintGeneratorTest {
73 * Component spec test.
75 * @throws JsonParseException the json parse exception
76 * @throws JsonMappingException the json mapping exception
77 * @throws IOException Signals that an I/O exception has occurred.
81 public void componentSpecTest() throws JsonParseException, JsonMappingException, IOException {
83 ComponentSpec spec = new ComponentSpec();
84 TestComponentSpec test = new TestComponentSpec();
85 spec.createComponentSpecFromString(test.getCs());
87 //Manually fill a component spec object with the values from the file itself
88 ComponentSpec manualSpec = new ComponentSpec();
90 Self self = new Self();
91 self.setComponent_type("docker");
92 self.setDescription("Test component spec");
93 self.setName("test.component.spec");
94 self.setVersion("1.0.1");
95 manualSpec.setSelf(self);
97 //assertEquals(manualSpec.getSelf(), spec.getSelf());
99 Services services = new Services();
100 CallsObj[] calls = new CallsObj[0];
101 ProvidesObj[] provides = new ProvidesObj[0];
102 services.setCalls(calls);
103 services.setProvides(provides);
104 manualSpec.setServices(null);
106 //assertEquals(manualSpec.getServices(), spec.getServices());
108 Streams streams = new Streams();
109 Publishes[] publishes = new Publishes[2];
110 Publishes pub1 = new Publishes();
111 pub1.setConfig_key("TEST-PUB-DR");
112 pub1.setFormat("dataformat_Hello_World_PM");
113 pub1.setType("data_router");
114 pub1.setVersion("1.0.0");
116 Publishes pub2 = new Publishes();
117 pub2.setConfig_key("TEST-PUB-MR");
118 pub2.setFormat("dataformat_Hello_World_PM");
119 pub2.setType("message_router");
120 pub2.setVersion("1.0.0");
123 streams.setPublishes(publishes);
125 Subscribes[] subscribes = new Subscribes[2];
126 Subscribes sub1 = new Subscribes();
127 sub1.setConfig_key("TEST-SUB-MR");
128 sub1.setFormat("dataformat_Hello_World_PM");
129 sub1.setRoute("/TEST_HELLO_WORLD_SUB_MR");
130 sub1.setType("message_router");
131 sub1.setVersion("1.0.0");
133 Subscribes sub2 = new Subscribes();
134 sub2.setConfig_key("TEST-SUB-DR");
135 sub2.setFormat("dataformat_Hello_World_PM");
136 sub2.setRoute("/TEST-HELLO-WORLD-SUB-DR");
137 sub2.setType("data_router");
138 sub2.setVersion("1.0.0");
139 subscribes[0] = sub1;
140 subscribes[1] = sub2;
141 streams.setSubscribes(subscribes);
143 manualSpec.setStreams(streams);
145 //assertEquals(manualSpec.getStreams(), spec.getStreams());
147 Parameters[] parameters = new Parameters[1];
148 Parameters par1 = new Parameters();
149 par1.setName("testParam1");
150 par1.setValue("test-param-1");
151 par1.setDescription("test parameter 1");
152 par1.setSourced_at_deployment(true);
153 par1.setDesigner_editable(true);
154 par1.setPolicy_editable(true);
155 par1.setPolicy_group("Test_Parameters");
156 par1.setRequired(true);
157 par1.setType("string");
158 parameters[0] = par1;
160 manualSpec.setParameters(parameters);
162 //assertEquals(manualSpec.getParameters(), spec.getParameters());
164 Auxilary auxilary = new Auxilary();
165 HealthCheck healthcheck = new HealthCheck();
166 healthcheck.setInterval("300s");
167 healthcheck.setTimeout("120s");
168 healthcheck.setScript("/etc/init.d/nagios status");
169 healthcheck.setType("docker");
170 auxilary.setHealthcheck(healthcheck);
172 Volumes[] volumes = new Volumes[1];
173 Volumes vol1 = new Volumes();
174 Container con1 = new Container();
175 con1.setBind("/opt/app/manager/config/hostname");
176 Host host1 = new Host();
177 host1.setPath("/etc/hostname");
179 vol1.setContainer(con1);
185 auxilary.setVolumes(volumes);
187 String[] ports = new String[2];
191 TreeMap<String, String> dataBases = new TreeMap<String, String>();
192 dataBases.put("TestDB1", "PGaaS");
193 dataBases.put("TestDB2", "PGaaS");
194 auxilary.setDatabases(dataBases);
196 Policy pol = new Policy();
197 pol.setTrigger_type("docker");
198 pol.setScript_path("/opt/app/manager/bin/reconfigure.sh");
199 auxilary.setPolicy(pol);
201 auxilary.setPorts(ports);
203 manualSpec.setAuxilary(auxilary);
205 //assertEquals(manualSpec.getAuxilary(), spec.getAuxilary());
207 Artifacts[] artifacts = new Artifacts[1];
208 Artifacts art = new Artifacts();
209 art.setType("docker image");
210 art.setUri("test.tester");
213 manualSpec.setArtifacts(artifacts);
215 //assertEquals(manualSpec.getArtifacts(), spec.getArtifacts());
220 * Tosca definition test.
223 public void toscaDefinitionTest() {
224 ComponentSpec cs = new ComponentSpec();
225 TestComponentSpec test = new TestComponentSpec();
226 cs.createComponentSpecFromString(test.getCs());
227 Blueprint bp = new Blueprint();
228 bp = bp.createBlueprint(cs, "", 'o', "");
230 assertEquals(bp.getTosca_definitions_version(), "cloudify_dsl_1_3");
237 public void importsTest() {
238 ComponentSpec cs = new ComponentSpec();
239 TestComponentSpec test = new TestComponentSpec();
240 cs.createComponentSpecFromString(test.getCs());
242 Blueprint bp = new Blueprint();
243 bp = bp.createBlueprint(cs, "", 'o', "");
245 ArrayList<String> imps = new ArrayList<String>();
247 imps.add("http://www.getcloudify.org/spec/cloudify/3.4/types.yaml");
248 imps.add("https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/k8splugin/1.4.5/k8splugin_types.yaml");
249 imps.add("https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/dcaepolicyplugin/2.3.0/dcaepolicyplugin_types.yaml");
250 assertEquals(bp.getImports(), imps);
254 public void inputTest() {
255 ComponentSpec cs = new ComponentSpec();
256 cs.createComponentSpecFromFile("TestCases/testComponentSpec.json");
258 Blueprint bp = new Blueprint();
259 bp = bp.createBlueprint(cs, "", 'o', "");
261 TreeMap<String, LinkedHashMap<String, Object>> inputs = new TreeMap<String, LinkedHashMap<String, Object>>();
264 LinkedHashMap<String, Object> stringType = new LinkedHashMap<String, Object>();
265 stringType.put("type", "string");
266 inputs.put("TEST_PUB_MR_publish_url", stringType);
267 inputs.put("TEST_SUB_MR_subscribe_url", stringType);
270 LinkedHashMap<String, Object> tag = new LinkedHashMap<String, Object>();
271 tag.put("type", "string");
272 String tester = "test.tester";
273 tag.put("default", '"' + tester + '"');
274 String tagVersion = "tag_version";
275 inputs.put("tag_version", tag);
277 inputs.put("log_directory", stringType);
280 LinkedHashMap<String, Object> port = new LinkedHashMap<String, Object>();
281 port.put("type", "string");
282 port.put("description", "Kubernetes node port on which collector is exposed");
283 String p = "'30235'";
284 port.put("default", '"' + p + '"');
285 inputs.put("external_port", port);
287 LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>();
288 rep.put("type", "integer");
289 rep.put("description", "number of instances");
290 rep.put("default", 1);
291 inputs.put("replicas", rep);
294 LinkedHashMap<String, Object> test = new LinkedHashMap<String, Object>();
295 test.put("type", "string");
296 String testParam = "test-param-1";
297 test.put("default", '"' + testParam + '"');
298 inputs.put("testParam1", test);
301 inputs.put("TEST-PUB-DR_delivery_url", stringType);
302 inputs.put("TEST-PUB-DR_location", stringType);
303 inputs.put("TEST-PUB-DR_password", stringType);
304 inputs.put("TEST-PUB-DR_subscriber_id", stringType);
305 inputs.put("TEST-PUB-DR_username", stringType);
306 inputs.put("TEST-SUB-DR_delivery_url", stringType);
307 inputs.put("TEST-SUB-DR_location", stringType);
308 inputs.put("TEST-SUB-DR_password", stringType);
309 inputs.put("TEST-SUB-DR_subscriber_id", stringType);
310 inputs.put("TEST-SUB-DR_username", stringType);
311 inputs.put("TEST_PUB_MR_publish_url", stringType);
312 inputs.put("TEST_SUB_MR_subscribe_url", stringType);
314 assertEquals(bp.getInputs(), inputs);
318 public void interfaceTest() {
319 ComponentSpec cs = new ComponentSpec();
320 cs.createComponentSpecFromFile("TestCases/testComponentSpec.json");
322 Blueprint bp = new Blueprint();
323 bp = bp.createBlueprint(cs, "", 'o', "");
325 OnapNode node = (OnapNode) bp.getNode_templates().get("test.component.spec");
327 OnapNode testNode = new OnapNode();
330 testNode.setType("dcae.nodes.ContainerizedPlatformComponent");
332 ArrayList<String> ports = new ArrayList<String>();
333 ports.add("concat: [\"80:\", {get_input: external_port }]");
334 ports.add("concat: [\"99:\", {get_input: external_port }]");
338 assertEquals(node.getInterfaces().get("cloudify.interfaces.lifecycle").getStart().getInputs().getPorts(), ports);
342 public void parametersTest() {
343 ComponentSpec cs = new ComponentSpec();
344 cs.createComponentSpecFromFile("TestCases/testComponentSpec.json");
346 Blueprint bp = new Blueprint();
347 bp = bp.createBlueprint(cs, "", 'o', "");
349 OnapNode node = (OnapNode) bp.getNode_templates().get("test.component.spec");
351 GetInput par = (GetInput) node.getProperties().getApplication_config().getParams().get("testParam1");
352 assertEquals(par.getGet_input(), "testParam1");
356 public void streamPublishesTest() {
357 ComponentSpec cs = new ComponentSpec();
358 cs.createComponentSpecFromFile("TestCases/testComponentSpec.json");
360 Blueprint bp = new Blueprint();
361 bp = bp.createBlueprint(cs, "", 'o', "");
363 OnapNode node = (OnapNode) bp.getNode_templates().get("test.component.spec");
365 assertEquals(node.getProperties().getApplication_config().getStream_publishes().get("TEST-PUB-DR").getDmaap_info().getUsername().getGet_input(), "TEST-PUB-DR_username");