Add encryption for passwords
[clamp.git] / src / test / java / org / onap / clamp / clds / it / SdcCatalogServicesItCase.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License"); 
9  * you may not use this file except in compliance with the License. 
10  * You may obtain a copy of the License at
11  * 
12  * http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software 
15  * distributed under the License is distributed on an "AS IS" BASIS, 
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
17  * See the License for the specific language governing permissions and 
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 package org.onap.clamp.clds.it;
25
26 import static org.junit.Assert.assertTrue;
27
28 import java.util.LinkedList;
29 import java.util.List;
30
31 import org.apache.commons.io.IOUtils;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mockito;
35 import org.onap.clamp.clds.AbstractItCase;
36 import org.onap.clamp.clds.client.SdcCatalogServices;
37 import org.onap.clamp.clds.model.CldsAlarmCondition;
38 import org.onap.clamp.clds.model.CldsSdcResource;
39 import org.onap.clamp.clds.model.CldsSdcResourceBasicInfo;
40 import org.onap.clamp.clds.model.CldsSdcServiceInfo;
41 import org.onap.clamp.clds.model.CldsServiceData;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.boot.test.context.SpringBootTest;
44 import org.springframework.test.context.TestPropertySource;
45 import org.springframework.test.context.junit4.SpringRunner;
46
47 /**
48  * Test SDC Catalog Service class by mocking the SDC answers.
49  */
50 @RunWith(SpringRunner.class)
51 @SpringBootTest
52 @TestPropertySource(locations = "classpath:application-no-camunda.properties")
53 public class SdcCatalogServicesItCase extends AbstractItCase {
54     @Autowired
55     private SdcCatalogServices sdcCatalogWired = new SdcCatalogServices();
56
57     @Test
58     public void removeDuplicateServicesTest() throws Exception {
59
60         CldsSdcServiceInfo service1a = new CldsSdcServiceInfo();
61         service1a.setName("service1");
62         service1a.setVersion("1.0");
63         service1a.setInvariantUUID("invariantUUID1.0");
64
65         List<CldsSdcServiceInfo> rawCldsSdcServiceList = new LinkedList<CldsSdcServiceInfo>();
66         rawCldsSdcServiceList.add(service1a);
67         rawCldsSdcServiceList.add(service1a);
68
69         CldsSdcServiceInfo service1b = new CldsSdcServiceInfo();
70         service1b.setName("service1");
71         service1b.setVersion("1.1");
72         service1b.setInvariantUUID("invariantUUID1.1");
73         rawCldsSdcServiceList.add(service1b);
74
75         CldsSdcServiceInfo service1c = new CldsSdcServiceInfo();
76         service1c.setName("service1");
77         service1c.setVersion("1.2");
78         service1c.setInvariantUUID("invariantUUID1.2");
79         rawCldsSdcServiceList.add(service1c);
80
81         CldsSdcServiceInfo service2 = new CldsSdcServiceInfo();
82         service2.setName("service2");
83         service2.setVersion("1.0");
84         service2.setInvariantUUID("invariantUUID2.0");
85         rawCldsSdcServiceList.add(service2);
86
87         SdcCatalogServices catalogServices = new SdcCatalogServices();
88         List<CldsSdcServiceInfo> resultList = catalogServices.removeDuplicateServices(rawCldsSdcServiceList);
89
90         assertTrue(resultList.size() == 2);
91
92         CldsSdcServiceInfo res1;
93         CldsSdcServiceInfo res2;
94         if ("service1".equals(resultList.get(0).getName())) {
95             res1 = resultList.get(0);
96             res2 = resultList.get(1);
97         } else {
98             res1 = resultList.get(1);
99             res2 = resultList.get(0);
100         }
101
102         assertTrue("service1".equals(res1.getName()));
103         assertTrue("1.2".equals(res1.getVersion()));
104
105         assertTrue("service2".equals(res2.getName()));
106         assertTrue("1.0".equals(res2.getVersion()));
107
108     }
109
110     @Test
111     public void removeDuplicateSdcResourceInstancesTest() {
112
113         List<CldsSdcResource> rawCldsSdcResourceList = new LinkedList<CldsSdcResource>();
114
115         CldsSdcResource sdcResource1a = new CldsSdcResource();
116         sdcResource1a.setResourceInstanceName("resource1");
117         sdcResource1a.setResourceVersion("1.0");
118         rawCldsSdcResourceList.add(sdcResource1a);
119
120         CldsSdcResource sdcResource1b = new CldsSdcResource();
121         sdcResource1b.setResourceInstanceName("resource1");
122         sdcResource1b.setResourceVersion("1.1");
123         rawCldsSdcResourceList.add(sdcResource1b);
124
125         CldsSdcResource sdcResource1c = new CldsSdcResource();
126         sdcResource1c.setResourceInstanceName("resource1");
127         sdcResource1c.setResourceVersion("1.2");
128         rawCldsSdcResourceList.add(sdcResource1c);
129
130         CldsSdcResource sdcResource2 = new CldsSdcResource();
131         sdcResource2.setResourceInstanceName("resource2");
132         sdcResource2.setResourceVersion("1.0");
133         rawCldsSdcResourceList.add(sdcResource2);
134
135         SdcCatalogServices catalogServices = new SdcCatalogServices();
136         List<CldsSdcResource> resultList = catalogServices.removeDuplicateSdcResourceInstances(rawCldsSdcResourceList);
137
138         CldsSdcResource res1;
139         CldsSdcResource res2;
140         if ("resource1".equals(resultList.get(0).getResourceInstanceName())) {
141             res1 = resultList.get(0);
142             res2 = resultList.get(1);
143         } else {
144             res1 = resultList.get(1);
145             res2 = resultList.get(0);
146         }
147
148         assertTrue("resource1".equals(res1.getResourceInstanceName()));
149         assertTrue("1.2".equals(res1.getResourceVersion()));
150
151         assertTrue("resource2".equals(res2.getResourceInstanceName()));
152         assertTrue("1.0".equals(res2.getResourceVersion()));
153
154     }
155
156     @Test
157     public void removeDuplicateSdcResourceBasicInfoTest() {
158
159         List<CldsSdcResourceBasicInfo> rawCldsSdcResourceList = new LinkedList<CldsSdcResourceBasicInfo>();
160
161         CldsSdcResourceBasicInfo sdcResource1a = new CldsSdcResourceBasicInfo();
162         sdcResource1a.setName("resource1");
163         sdcResource1a.setVersion("1.0");
164         rawCldsSdcResourceList.add(sdcResource1a);
165
166         CldsSdcResourceBasicInfo sdcResource1b = new CldsSdcResourceBasicInfo();
167         sdcResource1b.setName("resource1");
168         sdcResource1b.setVersion("1.1");
169         rawCldsSdcResourceList.add(sdcResource1b);
170
171         CldsSdcResourceBasicInfo sdcResource1c = new CldsSdcResourceBasicInfo();
172         sdcResource1c.setName("resource1");
173         sdcResource1c.setVersion("1.2");
174         rawCldsSdcResourceList.add(sdcResource1c);
175
176         CldsSdcResourceBasicInfo sdcResource2 = new CldsSdcResourceBasicInfo();
177         sdcResource2.setName("resource2");
178         sdcResource2.setVersion("1.0");
179         rawCldsSdcResourceList.add(sdcResource2);
180
181         SdcCatalogServices catalogServices = new SdcCatalogServices();
182         List<CldsSdcResourceBasicInfo> resultList = catalogServices
183                 .removeDuplicateSdcResourceBasicInfo(rawCldsSdcResourceList);
184
185         CldsSdcResourceBasicInfo res1;
186         CldsSdcResourceBasicInfo res2;
187         if ("resource1".equals(resultList.get(0).getName())) {
188             res1 = resultList.get(0);
189             res2 = resultList.get(1);
190         } else {
191             res1 = resultList.get(1);
192             res2 = resultList.get(0);
193         }
194
195         assertTrue("resource1".equals(res1.getName()));
196         assertTrue("1.2".equals(res1.getVersion()));
197
198         assertTrue("resource2".equals(res2.getName()));
199         assertTrue("1.0".equals(res2.getVersion()));
200
201     }
202
203     @Test
204     public void getServiceUuidFromServiceInvariantIdTest() throws Exception {
205         SdcCatalogServices spy = Mockito.spy(sdcCatalogWired);
206
207         Mockito.doReturn(IOUtils.toString(
208                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"),
209                 "UTF-8")).when(spy).getSdcServicesInformation(null);
210         // Try the vcts4 version 1.0, this one should be replaced by 1.1 so it
211         // should not exist, returning empty string
212         String resUuidVcts4Null = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9b");
213         assertTrue("".equals(resUuidVcts4Null));
214
215         // Try the vcts4 version 1.1, this one should be there as it replaces
216         // the vcts4 v1.0
217         String resUuidVcts4Latest = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9c");
218         assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(resUuidVcts4Latest));
219
220         // Try the vcts5 version 1.0, this one should be there
221         String resUuidVcts5 = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d8c");
222         assertTrue("29018914-966c-442d-9d08-251b9dc45b7f".equals(resUuidVcts5));
223
224         // try one that does not exist at all
225         String resUuidUnknown = spy.getServiceUuidFromServiceInvariantId("testuuid");
226         assertTrue("".equals(resUuidUnknown));
227
228     }
229
230     @Test
231     public void getCldsServiceDataWithAlarmConditionsTest() throws Exception {
232         SdcCatalogServices spy = Mockito.spy(sdcCatalogWired);
233
234         Mockito.doReturn(IOUtils.toString(
235                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"),
236                 "UTF-8")).when(spy).getSdcServicesInformation(null);
237
238         // This invariant uuid is the one from vcts4 v1.1
239         String serviceResourceDetailUrl = refProp.getStringValue("sdc.serviceUrl")
240                 + "/29018914-966c-442d-9d08-251b9dc45b8f/metadata";
241         Mockito.doReturn(IOUtils.toString(
242                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcServiceDetailsExample.json"),
243                 "UTF-8")).when(spy).getCldsServicesOrResourcesBasedOnURL(serviceResourceDetailUrl, false);
244
245         String resourceDetailUrl = refProp.getStringValue("sdc.catalog.url")
246                 + "resources/585822c7-4027-4f84-ba50-e9248606f136/metadata";
247         Mockito.doReturn(IOUtils.toString(
248                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcResourceDetailsExample.json"),
249                 "UTF-8")).when(spy).getCldsServicesOrResourcesBasedOnURL(resourceDetailUrl, false);
250
251         String securityRulesDetailUrl = refProp.getStringValue("sdc.catalog.url")
252                 + "resources/d57e57d2-e3c6-470d-8d16-e6ea05f536c5/metadata";
253         Mockito.doReturn(IOUtils.toString(
254                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcSecurityRules.json"), "UTF-8"))
255                 .when(spy).getCldsServicesOrResourcesBasedOnURL(securityRulesDetailUrl, false);
256
257         String cinderVolumeDetailUrl = refProp.getStringValue("sdc.catalog.url")
258                 + "resources/b4288e07-597a-44a2-aa98-ad36e551a39d/metadata";
259         Mockito.doReturn(IOUtils.toString(
260                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcCinderVolume.json"), "UTF-8"))
261                 .when(spy).getCldsServicesOrResourcesBasedOnURL(cinderVolumeDetailUrl, false);
262
263         String vfcGenericDetailUrl = refProp.getStringValue("sdc.catalog.url")
264                 + "resources/2c8f1219-8000-4001-aa13-496a0396d40f/metadata";
265         Mockito.doReturn(IOUtils.toString(
266                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFCGenericWithAlarms.json"),
267                 "UTF-8")).when(spy).getCldsServicesOrResourcesBasedOnURL(vfcGenericDetailUrl, false);
268
269         String csvAlarmsDetailUrl = refProp.getStringValue("sdc.catalog.url")
270                 + "resources/2c8f1219-8000-4001-aa13-496a0396d40f/resourceInstances/virc_fe_be/artifacts/5138e316-0237-49aa-817a-b3d8eaf77392";
271         Mockito.doReturn(IOUtils.toString(
272                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8"))
273                 .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl, false);
274
275         Mockito.doReturn(IOUtils.toString(
276                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8"))
277                 .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl, true);
278
279         String csvAlarmsDetailUrl2 = refProp.getStringValue("sdc.catalog.url")
280                 + "resources/d7646638-2572-4a94-b497-c028ac15f9ca/artifacts/5138e316-0237-49aa-817a-b3d8eaf77392";
281         Mockito.doReturn(IOUtils.toString(
282                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8"))
283                 .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl2, true);
284
285         String allVfResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VF";
286         Mockito.doReturn(IOUtils.toString(
287                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFResources.json"), "UTF-8"))
288                 .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfResourcesDetailUrl, false);
289
290         String vfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url")
291                 + "resources/a0475018-1e7e-4ddd-8bee-33cbf958c2e6/metadata";
292         Mockito.doReturn(IOUtils.toString(
293                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcCVFCResourceExample.json"),
294                 "UTF-8")).when(spy).getCldsServicesOrResourcesBasedOnURL(vfcResourcesDetailUrl, false);
295
296         String allVfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VFC";
297         Mockito.doReturn(IOUtils.toString(
298                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFCResources.json"), "UTF-8"))
299                 .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfcResourcesDetailUrl, false);
300
301         String allCvfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=CVFC";
302         Mockito.doReturn(IOUtils.toString(
303                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcCVFCResources.json"), "UTF-8"))
304                 .when(spy).getCldsServicesOrResourcesBasedOnURL(allCvfcResourcesDetailUrl, false);
305
306         String allVfAlarms = refProp.getStringValue("sdc.catalog.url")
307                 + "resources/84855843-5247-4e97-a2bd-5395a510253b/artifacts/d57ac7ec-f3c3-4793-983a-c75ac3a43153";
308         Mockito.doReturn(IOUtils.toString(
309                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcMeasurementsList.csv"), "UTF-8"))
310                 .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfAlarms, true);
311
312         String vfcResourceExample = refProp.getStringValue("sdc.catalog.url")
313                 + "resources/d7646638-2572-4a94-b497-c028ac15f9ca/metadata";
314         Mockito.doReturn(IOUtils.toString(
315                 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFCResourceExample.json"), "UTF-8"))
316                 .when(spy).getCldsServicesOrResourcesBasedOnURL(vfcResourceExample, false);
317
318         CldsServiceData cldsServiceData = spy
319                 .getCldsServiceDataWithAlarmConditions("a33ed748-3477-4434-b3f3-b5560f5e7d9c");
320         assertTrue("a33ed748-3477-4434-b3f3-b5560f5e7d9c".equals(cldsServiceData.getServiceInvariantUUID()));
321         assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(cldsServiceData.getServiceUUID()));
322         assertTrue(cldsServiceData.getCldsVfs().size() == 1);
323
324         List<CldsAlarmCondition> alarmsList = spy.getAllAlarmConditionsFromCldsServiceData(cldsServiceData,
325                 "alarmCondition");
326         assertTrue(alarmsList.size() == 12);
327
328     }
329
330 }