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 java.util.ArrayList;
24 import java.util.TreeMap;
27 import org.onap.blueprintgenerator.models.componentspec.Artifacts;
28 import org.onap.blueprintgenerator.models.componentspec.Auxilary;
29 import org.onap.blueprintgenerator.models.componentspec.CallsObj;
30 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
31 import org.onap.blueprintgenerator.models.componentspec.Container;
32 import org.onap.blueprintgenerator.models.componentspec.HealthCheck;
33 import org.onap.blueprintgenerator.models.componentspec.Host;
34 import org.onap.blueprintgenerator.models.componentspec.Parameters;
35 import org.onap.blueprintgenerator.models.componentspec.Policy;
36 import org.onap.blueprintgenerator.models.componentspec.ProvidesObj;
37 import org.onap.blueprintgenerator.models.componentspec.Publishes;
38 import org.onap.blueprintgenerator.models.componentspec.Self;
39 import org.onap.blueprintgenerator.models.componentspec.Services;
40 import org.onap.blueprintgenerator.models.componentspec.Streams;
41 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
42 import org.onap.blueprintgenerator.models.componentspec.Volumes;
45 public class TestComponentSpec {
46 private String componentSpecAsString = "{\r\n" +
48 " \"component_type\": \"docker\",\r\n" +
49 " \"description\": \"Test component spec\",\r\n" +
50 " \"name\": \"test.component.spec\",\r\n" +
51 " \"version\": \"1.0.1\"\r\n" +
54 " \"service\": {\r\n" +
55 " \"calls\": [],\r\n" +
56 " \"provides\": []\r\n" +
59 " \"streams\": {\r\n" +
60 " \"publishes\": [{\r\n" +
61 " \"config_key\": \"TEST-PUB-DR\",\r\n" +
62 " \"format\": \"dataformat_Hello_World_PM\",\r\n" +
63 " \"type\": \"data_router\",\r\n" +
64 " \"version\": \"1.0.0\"\r\n" +
67 " \"config_key\": \"TEST-PUB-MR\",\r\n" +
68 " \"format\": \"dataformat_Hello_World_PM\",\r\n" +
69 " \"type\": \"message_router\",\r\n" +
70 " \"version\": \"1.0.0\"\r\n" +
74 " \"subscribes\": [{\r\n" +
75 " \"config_key\": \"TEST-SUB-MR\",\r\n" +
76 " \"format\": \"dataformat_Hello_World_PM\",\r\n" +
77 " \"route\": \"/TEST_HELLO_WORLD_SUB_MR\",\r\n" +
78 " \"type\": \"message_router\",\r\n" +
79 " \"version\": \"1.0.0\"\r\n" +
82 " \"config_key\": \"TEST-SUB-DR\",\r\n" +
83 " \"format\": \"dataformat_Hello_World_PM\",\r\n" +
84 " \"route\": \"/TEST-HELLO-WORLD-SUB-DR\",\r\n" +
85 " \"type\": \"data_router\",\r\n" +
86 " \"version\": \"1.0.0\"\r\n" +
91 " \"parameters\":\r\n" +
94 " \"name\": \"testParam1\",\r\n" +
95 " \"description\": \"test parameter 1\",\r\n" +
96 " \"value\": \"test-param-1\",\r\n" +
97 " \"type\": \"string\",\r\n" +
98 " \"sourced_at_deployment\": true,\r\n" +
99 " \"designer_editable\": true,\r\n" +
100 " \"policy_editable\": true,\r\n" +
101 " \"policy_group\": \"Test_Parameters\",\r\n" +
102 " \"required\": true\r\n" +
106 " \"auxilary\": {\r\n" +
107 " \"healthcheck\": {\r\n" +
108 " \"type\": \"docker\",\r\n" +
109 " \"interval\": \"300s\",\r\n" +
110 " \"timeout\": \"120s\",\r\n" +
111 " \"script\": \"/etc/init.d/nagios status\"\r\n" +
114 " \"databases\" : {\r\n" +
115 " \"TestDB1\": \"PGaaS\",\r\n" +
116 " \"TestDB2\": \"PGaaS\"\r\n" +
119 " \"policy\": {\r\n" +
120 " \"trigger_type\": \"docker\",\r\n" +
121 " \"script_path\": \"/opt/app/manager/bin/reconfigure.sh\"\r\n" +
123 " \"volumes\": [\r\n" +
125 " \"container\": {\r\n" +
126 " \"bind\": \"/opt/app/manager/config/hostname\"\r\n" +
129 " \"path\": \"/etc/hostname\",\r\n" +
130 " \"mode\": \"ro\"\r\n" +
135 " \"ports\": [\r\n" +
140 " \"artifacts\": [{\r\n" +
141 " \"type\": \"docker image\",\r\n" +
142 " \"uri\": \"test.tester\"\r\n" +
146 private ComponentSpec componentSpec;
148 public TestComponentSpec() {
149 this.componentSpec = createComponentSpec();
152 private ComponentSpec createComponentSpec(){
153 //Manually fill a component spec object with the values from the file itself
154 ComponentSpec manualSpec = new ComponentSpec();
156 Self self = new Self();
157 self.setComponent_type("docker");
158 self.setDescription("Test component spec");
159 self.setName("test.component.spec");
160 self.setVersion("1.0.1");
161 manualSpec.setSelf(self);
163 Services services = new Services();
164 CallsObj[] calls = new CallsObj[0];
165 ProvidesObj[] provides = new ProvidesObj[0];
166 services.setCalls(calls);
167 services.setProvides(provides);
168 manualSpec.setServices(null);
170 Streams streams = new Streams();
171 Publishes[] publishes = new Publishes[2];
172 Publishes pub1 = new Publishes();
173 pub1.setConfig_key("TEST-PUB-DR");
174 pub1.setFormat("dataformat_Hello_World_PM");
175 pub1.setType("data_router");
176 pub1.setVersion("1.0.0");
178 Publishes pub2 = new Publishes();
179 pub2.setConfig_key("TEST-PUB-MR");
180 pub2.setFormat("dataformat_Hello_World_PM");
181 pub2.setType("message_router");
182 pub2.setVersion("1.0.0");
185 streams.setPublishes(publishes);
187 Subscribes[] subscribes = new Subscribes[2];
188 Subscribes sub1 = new Subscribes();
189 sub1.setConfig_key("TEST-SUB-MR");
190 sub1.setFormat("dataformat_Hello_World_PM");
191 sub1.setRoute("/TEST_HELLO_WORLD_SUB_MR");
192 sub1.setType("message_router");
193 sub1.setVersion("1.0.0");
195 Subscribes sub2 = new Subscribes();
196 sub2.setConfig_key("TEST-SUB-DR");
197 sub2.setFormat("dataformat_Hello_World_PM");
198 sub2.setRoute("/TEST-HELLO-WORLD-SUB-DR");
199 sub2.setType("data_router");
200 sub2.setVersion("1.0.0");
201 subscribes[0] = sub1;
202 subscribes[1] = sub2;
203 streams.setSubscribes(subscribes);
205 manualSpec.setStreams(streams);
207 Parameters[] parameters = new Parameters[1];
208 Parameters par1 = new Parameters();
209 par1.setName("testParam1");
210 par1.setValue("test-param-1");
211 par1.setDescription("test parameter 1");
212 par1.setSourced_at_deployment(true);
213 par1.setDesigner_editable(true);
214 par1.setPolicy_editable(true);
215 par1.setPolicy_group("Test_Parameters");
216 par1.setRequired(true);
217 par1.setType("string");
218 parameters[0] = par1;
220 manualSpec.setParameters(parameters);
222 Auxilary auxilary = new Auxilary();
223 HealthCheck healthcheck = new HealthCheck();
224 healthcheck.setInterval("300s");
225 healthcheck.setTimeout("120s");
226 healthcheck.setScript("/etc/init.d/nagios status");
227 healthcheck.setType("docker");
228 auxilary.setHealthcheck(healthcheck);
230 Volumes[] volumes = new Volumes[1];
231 Volumes vol1 = new Volumes();
232 Container con1 = new Container();
233 con1.setBind("/opt/app/manager/config/hostname");
234 Host host1 = new Host();
235 host1.setPath("/etc/hostname");
237 vol1.setContainer(con1);
242 auxilary.setVolumes(volumes);
244 ArrayList<Object> ports = new ArrayList();
247 TreeMap<String, String> dataBases = new TreeMap<>();
248 dataBases.put("TestDB1", "PGaaS");
249 dataBases.put("TestDB2", "PGaaS");
250 auxilary.setDatabases(dataBases);
252 Policy pol = new Policy();
253 pol.setTrigger_type("docker");
254 pol.setScript_path("/opt/app/manager/bin/reconfigure.sh");
255 auxilary.setPolicy(pol);
257 auxilary.setPorts(ports);
259 manualSpec.setAuxilary(auxilary);
261 Artifacts[] artifacts = new Artifacts[1];
262 Artifacts art = new Artifacts();
263 art.setType("docker image");
264 art.setUri("test.tester");
267 manualSpec.setArtifacts(artifacts);