Merge "Refactor, fix code formatting and add unittests"
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / core / TestComponentSpec.java
1 /**============LICENSE_START======================================================= 
2  org.onap.dcae 
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 
9  
10       http://www.apache.org/licenses/LICENSE-2.0 
11  
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========================================================= 
18  
19 */
20
21 package org.onap.blueprintgenerator.core;
22
23 import java.util.ArrayList;
24 import java.util.TreeMap;
25 import lombok.Getter;
26 import lombok.Setter;
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;
43
44 @Getter @Setter
45 public class TestComponentSpec {
46         private String componentSpecAsString = "{\r\n" +
47                         "       \"self\": {\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" + 
52                         "       },\r\n" + 
53                         "\r\n" + 
54                         "       \"service\": {\r\n" + 
55                         "               \"calls\": [],\r\n" + 
56                         "               \"provides\": []\r\n" + 
57                         "       },\r\n" + 
58                         "\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" + 
65                         "                       },\r\n" + 
66                         "                       {\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" + 
71                         "                       }\r\n" + 
72                         "               ],\r\n" + 
73                         "\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" + 
80                         "                       },\r\n" + 
81                         "                       {\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" + 
87                         "                       }               \r\n" + 
88                         "               ]\r\n" + 
89                         "       },\r\n" + 
90                         "\r\n" + 
91                         "       \"parameters\":\r\n" + 
92                         "       [\r\n" + 
93                         "               {\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" + 
103                         "               }\r\n" + 
104                         "       ],\r\n" + 
105                         "\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" + 
112                         "               },\r\n" + 
113                         "\r\n" + 
114                         "               \"databases\" : {\r\n" + 
115                         "          \"TestDB1\": \"PGaaS\",\r\n" + 
116                         "          \"TestDB2\": \"PGaaS\"\r\n" + 
117                         "        },\r\n" + 
118                         "\r\n" + 
119                         "               \"policy\": {\r\n" + 
120                         "                       \"trigger_type\": \"docker\",\r\n" + 
121                         "                       \"script_path\": \"/opt/app/manager/bin/reconfigure.sh\"\r\n" + 
122                         "               },\r\n" + 
123                         "               \"volumes\": [\r\n" + 
124                         "                       {\r\n" + 
125                         "                               \"container\": {\r\n" + 
126                         "                                       \"bind\": \"/opt/app/manager/config/hostname\"\r\n" + 
127                         "                               },\r\n" + 
128                         "                               \"host\": {\r\n" + 
129                         "                                       \"path\": \"/etc/hostname\",\r\n" + 
130                         "                                       \"mode\": \"ro\"\r\n" + 
131                         "                               }\r\n" + 
132                         "                       }\r\n" + 
133                         "\r\n" + 
134                         "               ],\r\n" + 
135                         "               \"ports\": [\r\n" + 
136                         "                       \"80:80\"\r\n" + 
137                         "               ]\r\n" + 
138                         "       },\r\n" + 
139                         "\r\n" + 
140                         "           \"artifacts\": [{\r\n" + 
141                         "               \"type\": \"docker image\",\r\n" + 
142                         "               \"uri\": \"test.tester\"\r\n" + 
143                         "       }]      \r\n" + 
144                         "\r\n" + 
145                         "}";
146         private ComponentSpec componentSpec;
147
148         public TestComponentSpec() {
149                 this.componentSpec = createComponentSpec();
150         }
151
152         private ComponentSpec createComponentSpec(){
153                 //Manually fill a component spec object with the values from the file itself
154                 ComponentSpec manualSpec = new ComponentSpec();
155
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);
162
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);
169
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");
177
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");
183                 publishes[0] = pub1;
184                 publishes[1] = pub2;
185                 streams.setPublishes(publishes);
186
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");
194
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);
204
205                 manualSpec.setStreams(streams);
206
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;
219
220                 manualSpec.setParameters(parameters);
221
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);
229
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");
236                 host1.setMode("ro");
237                 vol1.setContainer(con1);
238                 vol1.setHost(host1);
239
240                 volumes[0] = vol1;
241
242                 auxilary.setVolumes(volumes);
243
244                 ArrayList<Object> ports = new ArrayList();
245                 ports.add("80:80");
246
247                 TreeMap<String, String> dataBases = new TreeMap<>();
248                 dataBases.put("TestDB1", "PGaaS");
249                 dataBases.put("TestDB2", "PGaaS");
250                 auxilary.setDatabases(dataBases);
251
252                 Policy pol = new Policy();
253                 pol.setTrigger_type("docker");
254                 pol.setScript_path("/opt/app/manager/bin/reconfigure.sh");
255                 auxilary.setPolicy(pol);
256
257                 auxilary.setPorts(ports);
258
259                 manualSpec.setAuxilary(auxilary);
260
261                 Artifacts[] artifacts = new Artifacts[1];
262                 Artifacts art = new Artifacts();
263                 art.setType("docker image");
264                 art.setUri("test.tester");
265
266                 artifacts[0] = art;
267                 manualSpec.setArtifacts(artifacts);
268                 return manualSpec;
269         }
270 }