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.dmaapbp.DmaapNode;
58 import org.onap.blueprintgenerator.models.onapbp.OnapNode;
61 import com.fasterxml.jackson.core.JsonParseException;
62 import com.fasterxml.jackson.databind.JsonMappingException;
64 import junit.framework.Assert;
67 // TODO: Auto-generated Javadoc
69 * The Class BlueprintGeneratorTest.
71 public class BlueprintGeneratorTest {
74 * Component spec test.
76 * @throws JsonParseException the json parse exception
77 * @throws JsonMappingException the json mapping exception
78 * @throws IOException Signals that an I/O exception has occurred.
82 public void componentSpecTest() throws JsonParseException, JsonMappingException, IOException {
84 ComponentSpec spec = new ComponentSpec();
85 TestComponentSpec test = new TestComponentSpec();
86 spec.createComponentSpecFromString(test.getCs());
88 //Manually fill a component spec object with the values from the file itself
89 ComponentSpec manualSpec = new ComponentSpec();
91 Self self = new Self();
92 self.setComponent_type("docker");
93 self.setDescription("Test component spec");
94 self.setName("test.component.spec");
95 self.setVersion("1.0.1");
96 manualSpec.setSelf(self);
98 //assertEquals(manualSpec.getSelf(), spec.getSelf());
100 Services services = new Services();
101 CallsObj[] calls = new CallsObj[0];
102 ProvidesObj[] provides = new ProvidesObj[0];
103 services.setCalls(calls);
104 services.setProvides(provides);
105 manualSpec.setServices(null);
107 //assertEquals(manualSpec.getServices(), spec.getServices());
109 Streams streams = new Streams();
110 Publishes[] publishes = new Publishes[2];
111 Publishes pub1 = new Publishes();
112 pub1.setConfig_key("TEST-PUB-DR");
113 pub1.setFormat("dataformat_Hello_World_PM");
114 pub1.setType("data_router");
115 pub1.setVersion("1.0.0");
117 Publishes pub2 = new Publishes();
118 pub2.setConfig_key("TEST-PUB-MR");
119 pub2.setFormat("dataformat_Hello_World_PM");
120 pub2.setType("message_router");
121 pub2.setVersion("1.0.0");
124 streams.setPublishes(publishes);
126 Subscribes[] subscribes = new Subscribes[2];
127 Subscribes sub1 = new Subscribes();
128 sub1.setConfig_key("TEST-SUB-MR");
129 sub1.setFormat("dataformat_Hello_World_PM");
130 sub1.setRoute("/TEST_HELLO_WORLD_SUB_MR");
131 sub1.setType("message_router");
132 sub1.setVersion("1.0.0");
134 Subscribes sub2 = new Subscribes();
135 sub2.setConfig_key("TEST-SUB-DR");
136 sub2.setFormat("dataformat_Hello_World_PM");
137 sub2.setRoute("/TEST-HELLO-WORLD-SUB-DR");
138 sub2.setType("data_router");
139 sub2.setVersion("1.0.0");
140 subscribes[0] = sub1;
141 subscribes[1] = sub2;
142 streams.setSubscribes(subscribes);
144 manualSpec.setStreams(streams);
146 //assertEquals(manualSpec.getStreams(), spec.getStreams());
148 Parameters[] parameters = new Parameters[1];
149 Parameters par1 = new Parameters();
150 par1.setName("testParam1");
151 par1.setValue("test-param-1");
152 par1.setDescription("test parameter 1");
153 par1.setSourced_at_deployment(true);
154 par1.setDesigner_editable(true);
155 par1.setPolicy_editable(true);
156 par1.setPolicy_group("Test_Parameters");
157 par1.setRequired(true);
158 par1.setType("string");
159 parameters[0] = par1;
161 manualSpec.setParameters(parameters);
163 //assertEquals(manualSpec.getParameters(), spec.getParameters());
165 Auxilary auxilary = new Auxilary();
166 HealthCheck healthcheck = new HealthCheck();
167 healthcheck.setInterval("300s");
168 healthcheck.setTimeout("120s");
169 healthcheck.setScript("/etc/init.d/nagios status");
170 healthcheck.setType("docker");
171 auxilary.setHealthcheck(healthcheck);
173 Volumes[] volumes = new Volumes[1];
174 Volumes vol1 = new Volumes();
175 Container con1 = new Container();
176 con1.setBind("/opt/app/manager/config/hostname");
177 Host host1 = new Host();
178 host1.setPath("/etc/hostname");
180 vol1.setContainer(con1);
186 auxilary.setVolumes(volumes);
188 ArrayList<Object> ports = new ArrayList();
192 TreeMap<String, String> dataBases = new TreeMap<String, String>();
193 dataBases.put("TestDB1", "PGaaS");
194 dataBases.put("TestDB2", "PGaaS");
195 auxilary.setDatabases(dataBases);
197 Policy pol = new Policy();
198 pol.setTrigger_type("docker");
199 pol.setScript_path("/opt/app/manager/bin/reconfigure.sh");
200 auxilary.setPolicy(pol);
202 auxilary.setPorts(ports);
204 manualSpec.setAuxilary(auxilary);
206 //assertEquals(manualSpec.getAuxilary(), spec.getAuxilary());
208 Artifacts[] artifacts = new Artifacts[1];
209 Artifacts art = new Artifacts();
210 art.setType("docker image");
211 art.setUri("test.tester");
214 manualSpec.setArtifacts(artifacts);
216 //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");
269 LinkedHashMap<String, Object> tag = new LinkedHashMap<String, Object>();
270 tag.put("type", "string");
271 String tester = "test.tester";
272 tag.put("default", '"' + tester + '"');
273 String tagVersion = "tag_version";
274 inputs.put("tag_version", tag);
276 inputs.put("log_directory", stringType);
278 LinkedHashMap cert = new LinkedHashMap();
279 cert.put("type", "string");
280 cert.put("default", "");
281 inputs.put("cert_directory", cert);
283 LinkedHashMap<String, Object> env = new LinkedHashMap();
284 env.put("default", "{}");
285 inputs.put("envs", env);
287 LinkedHashMap port = new LinkedHashMap();
288 port.put("type", "string");
289 port.put("description", "Kubernetes node port on which collector is exposed");
290 port.put("default", "99");
291 inputs.put("external_port", port);
293 LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>();
294 rep.put("type", "integer");
295 rep.put("description", "number of instances");
296 rep.put("default", 1);
297 inputs.put("replicas", rep);
299 LinkedHashMap<String, Object> aaf = new LinkedHashMap();
300 aaf.put("type", "boolean");
301 aaf.put("default", false);
302 inputs.put("use_tls", aaf);
305 LinkedHashMap<String, Object> test = new LinkedHashMap<String, Object>();
306 test.put("type", "string");
307 String testParam = "test-param-1";
308 test.put("default", '"' + testParam + '"');
309 inputs.put("testParam1", test);
312 inputs.put("TEST-PUB-DR_feed0_client_role", stringType);
313 inputs.put("TEST-PUB-DR_feed0_password", stringType);
314 inputs.put("TEST-PUB-DR_feed0_username", stringType);
315 inputs.put("TEST-PUB-MR_topic1_aaf_password", stringType);
316 inputs.put("TEST-PUB-MR_topic1_aaf_username", stringType);
317 inputs.put("TEST-PUB-MR_topic1_client_role", stringType);
318 inputs.put("TEST-SUB-DR_feed1_client_role", stringType);
319 inputs.put("TEST-SUB-DR_feed1_password", stringType);
320 inputs.put("TEST-SUB-DR_feed1_username", stringType);
321 inputs.put("TEST-SUB-MR_topic0_client_role", stringType);
322 inputs.put("TEST-SUB-MR_topic2_aaf_password", stringType);
323 inputs.put("TEST-SUB-MR_topic2_aaf_username", stringType);
324 inputs.put("namespace", stringType);
325 inputs.put("idn_fqdn", cert);
326 inputs.put("feed0_name", stringType);
327 inputs.put("feed1_name", stringType);
328 inputs.put("topic0_name", stringType);
329 inputs.put("topic1_name", stringType);
331 LinkedHashMap<String, Object> cpu = new LinkedHashMap();
332 cpu.put("type", "string");
333 cpu.put("default", "250m");
334 inputs.put("test.component.spec_cpu_limit", cpu);
335 inputs.put("test.component.spec_cpu_request", cpu);
337 LinkedHashMap<String, Object> mem = new LinkedHashMap();
338 mem.put("type", "string");
339 mem.put("default", "128Mi");
340 inputs.put("test.component.spec_memory_limit", mem);
341 inputs.put("test.component.spec_memory_request", mem);
343 assertEquals(true, true);
346 public void interfaceTest() {
347 ComponentSpec cs = new ComponentSpec();
348 cs.createComponentSpecFromFile("TestCases/testComponentSpec.json");
350 Blueprint bp = new Blueprint();
351 bp = bp.createBlueprint(cs, "", 'o', "", "");
353 OnapNode node = (OnapNode) bp.getNode_templates().get("test.component.spec");
355 OnapNode testNode = new OnapNode();
358 testNode.setType("dcae.nodes.ContainerizedPlatformComponent");
360 ArrayList<String> ports = new ArrayList<String>();
361 ports.add("concat: [\"80:\", {get_input: external_port }]");
362 ports.add("concat: [\"99:\", {get_input: external_port }]");
363 assertEquals(true, true);
367 public void parametersTest() {
368 ComponentSpec cs = new ComponentSpec();
369 cs.createComponentSpecFromFile("TestCases/testComponentSpec.json");
371 Blueprint bp = new Blueprint();
372 bp = bp.createBlueprint(cs, "", 'o', "", "");
374 OnapNode node = (OnapNode) bp.getNode_templates().get("test.component.spec");
376 GetInput par = (GetInput) node.getProperties().getApplication_config().getParams().get("testParam1");
377 assertEquals(par.getGet_input(), "testParam1");
381 public void streamPublishesTest() {
382 ComponentSpec cs = new ComponentSpec();
383 cs.createComponentSpecFromFile("TestCases/testComponentSpec.json");
385 Blueprint bp = new Blueprint();
386 bp = bp.createBlueprint(cs, "", 'o', "", "");
388 OnapNode node = (OnapNode) bp.getNode_templates().get("test.component.spec");
390 boolean test = false;
391 if(!node.getProperties().getApplication_config().getStreams_publishes().isEmpty()) {
393 System.out.println("tst");
396 assertEquals(true, test);
399 public void dmaapPluginTest() {
400 ComponentSpec cs = new ComponentSpec();
401 cs.createComponentSpecFromFile("TestCases/testComponentSpec.json");
403 Blueprint bp = new Blueprint();
404 bp = bp.createBlueprint(cs, "", 'd', "", "");
406 DmaapNode dmaap = (DmaapNode) bp.getNode_templates().get("test.component.spec");
408 //check if the stream publishes and subscribes are not null to see if the dmaap plugin was invoked properly
411 if(dmaap.getProperties().getStreams_publishes() != null || dmaap.getProperties().getStreams_subscribes() != null) {
414 assertEquals(true, d);
417 public void testPrintInstructions() {
418 //check if the instructions are pritns correctly and if the print statement comes out then its correct
419 BlueprintGenerator bp = new BlueprintGenerator();
420 bp.printInstructions();
422 assertEquals(true, t);