2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 package org.onap.clamp.clds.it;
26 import static org.junit.Assert.assertTrue;
28 import java.util.LinkedList;
29 import java.util.List;
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.AbstractIT;
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.junit4.SpringRunner;
47 * Test DCAE API in org.onap.clamp.ClampDesigner.client package - replicate DCAE
50 @RunWith(SpringRunner.class)
52 public class SdcCatalogServicesIT extends AbstractIT {
54 private SdcCatalogServices sdcCatalogWired = new SdcCatalogServices();
57 public void removeDuplicateServicesTest() throws Exception {
59 CldsSdcServiceInfo service1a = new CldsSdcServiceInfo();
60 service1a.setName("service1");
61 service1a.setVersion("1.0");
62 service1a.setInvariantUUID("invariantUUID1.0");
64 List<CldsSdcServiceInfo> rawCldsSdcServiceList = new LinkedList<CldsSdcServiceInfo>();
65 rawCldsSdcServiceList.add(service1a);
66 rawCldsSdcServiceList.add(service1a);
68 CldsSdcServiceInfo service1b = new CldsSdcServiceInfo();
69 service1b.setName("service1");
70 service1b.setVersion("1.1");
71 service1b.setInvariantUUID("invariantUUID1.1");
72 rawCldsSdcServiceList.add(service1b);
74 CldsSdcServiceInfo service1c = new CldsSdcServiceInfo();
75 service1c.setName("service1");
76 service1c.setVersion("1.2");
77 service1c.setInvariantUUID("invariantUUID1.2");
78 rawCldsSdcServiceList.add(service1c);
80 CldsSdcServiceInfo service2 = new CldsSdcServiceInfo();
81 service2.setName("service2");
82 service2.setVersion("1.0");
83 service2.setInvariantUUID("invariantUUID2.0");
84 rawCldsSdcServiceList.add(service2);
86 SdcCatalogServices catalogServices = new SdcCatalogServices();
87 List<CldsSdcServiceInfo> resultList = catalogServices.removeDuplicateServices(rawCldsSdcServiceList);
89 assertTrue(resultList.size() == 2);
91 CldsSdcServiceInfo res1;
92 CldsSdcServiceInfo res2;
93 if ("service1".equals(resultList.get(0).getName())) {
94 res1 = resultList.get(0);
95 res2 = resultList.get(1);
97 res1 = resultList.get(1);
98 res2 = resultList.get(0);
101 assertTrue("service1".equals(res1.getName()));
102 assertTrue("1.2".equals(res1.getVersion()));
104 assertTrue("service2".equals(res2.getName()));
105 assertTrue("1.0".equals(res2.getVersion()));
110 public void removeDuplicateSdcResourceInstancesTest() {
112 List<CldsSdcResource> rawCldsSdcResourceList = new LinkedList<CldsSdcResource>();
114 CldsSdcResource sdcResource1a = new CldsSdcResource();
115 sdcResource1a.setResourceInstanceName("resource1");
116 sdcResource1a.setResourceVersion("1.0");
117 rawCldsSdcResourceList.add(sdcResource1a);
119 CldsSdcResource sdcResource1b = new CldsSdcResource();
120 sdcResource1b.setResourceInstanceName("resource1");
121 sdcResource1b.setResourceVersion("1.1");
122 rawCldsSdcResourceList.add(sdcResource1b);
124 CldsSdcResource sdcResource1c = new CldsSdcResource();
125 sdcResource1c.setResourceInstanceName("resource1");
126 sdcResource1c.setResourceVersion("1.2");
127 rawCldsSdcResourceList.add(sdcResource1c);
129 CldsSdcResource sdcResource2 = new CldsSdcResource();
130 sdcResource2.setResourceInstanceName("resource2");
131 sdcResource2.setResourceVersion("1.0");
132 rawCldsSdcResourceList.add(sdcResource2);
134 SdcCatalogServices catalogServices = new SdcCatalogServices();
135 List<CldsSdcResource> resultList = catalogServices.removeDuplicateSdcResourceInstances(rawCldsSdcResourceList);
137 CldsSdcResource res1;
138 CldsSdcResource res2;
139 if ("resource1".equals(resultList.get(0).getResourceInstanceName())) {
140 res1 = resultList.get(0);
141 res2 = resultList.get(1);
143 res1 = resultList.get(1);
144 res2 = resultList.get(0);
147 assertTrue("resource1".equals(res1.getResourceInstanceName()));
148 assertTrue("1.2".equals(res1.getResourceVersion()));
150 assertTrue("resource2".equals(res2.getResourceInstanceName()));
151 assertTrue("1.0".equals(res2.getResourceVersion()));
156 public void removeDuplicateSdcResourceBasicInfoTest() {
158 List<CldsSdcResourceBasicInfo> rawCldsSdcResourceList = new LinkedList<CldsSdcResourceBasicInfo>();
160 CldsSdcResourceBasicInfo sdcResource1a = new CldsSdcResourceBasicInfo();
161 sdcResource1a.setName("resource1");
162 sdcResource1a.setVersion("1.0");
163 rawCldsSdcResourceList.add(sdcResource1a);
165 CldsSdcResourceBasicInfo sdcResource1b = new CldsSdcResourceBasicInfo();
166 sdcResource1b.setName("resource1");
167 sdcResource1b.setVersion("1.1");
168 rawCldsSdcResourceList.add(sdcResource1b);
170 CldsSdcResourceBasicInfo sdcResource1c = new CldsSdcResourceBasicInfo();
171 sdcResource1c.setName("resource1");
172 sdcResource1c.setVersion("1.2");
173 rawCldsSdcResourceList.add(sdcResource1c);
175 CldsSdcResourceBasicInfo sdcResource2 = new CldsSdcResourceBasicInfo();
176 sdcResource2.setName("resource2");
177 sdcResource2.setVersion("1.0");
178 rawCldsSdcResourceList.add(sdcResource2);
180 SdcCatalogServices catalogServices = new SdcCatalogServices();
181 List<CldsSdcResourceBasicInfo> resultList = catalogServices
182 .removeDuplicateSdcResourceBasicInfo(rawCldsSdcResourceList);
184 CldsSdcResourceBasicInfo res1;
185 CldsSdcResourceBasicInfo res2;
186 if ("resource1".equals(resultList.get(0).getName())) {
187 res1 = resultList.get(0);
188 res2 = resultList.get(1);
190 res1 = resultList.get(1);
191 res2 = resultList.get(0);
194 assertTrue("resource1".equals(res1.getName()));
195 assertTrue("1.2".equals(res1.getVersion()));
197 assertTrue("resource2".equals(res2.getName()));
198 assertTrue("1.0".equals(res2.getVersion()));
203 public void getServiceUuidFromServiceInvariantIdTest() throws Exception {
204 SdcCatalogServices spy = Mockito.spy(sdcCatalogWired);
206 Mockito.doReturn(IOUtils.toString(
207 SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), "UTF-8"))
208 .when(spy).getSdcServicesInformation(null);
209 // Try the vcts4 version 1.0, this one should be replaced by 1.1 so it
210 // should not exist, returning empty string
211 String resUuidVcts4Null = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9b");
212 assertTrue("".equals(resUuidVcts4Null));
214 // Try the vcts4 version 1.1, this one should be there as it replaces
216 String resUuidVcts4Latest = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9c");
217 assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(resUuidVcts4Latest));
219 // Try the vcts5 version 1.0, this one should be there
220 String resUuidVcts5 = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d8c");
221 assertTrue("29018914-966c-442d-9d08-251b9dc45b7f".equals(resUuidVcts5));
223 // try one that does not exist at all
224 String resUuidUnknown = spy.getServiceUuidFromServiceInvariantId("testuuid");
225 assertTrue("".equals(resUuidUnknown));
230 public void getCldsServiceDataWithAlarmConditionsTest() throws Exception {
231 SdcCatalogServices spy = Mockito.spy(sdcCatalogWired);
233 Mockito.doReturn(IOUtils.toString(
234 SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), "UTF-8"))
235 .when(spy).getSdcServicesInformation(null);
237 // This invariant uuid is the one from vcts4 v1.1
238 String serviceResourceDetailUrl = refProp.getStringValue("sdc.serviceUrl")
239 + "/29018914-966c-442d-9d08-251b9dc45b8f/metadata";
240 Mockito.when(spy.getCldsServicesOrResourcesBasedOnURL(serviceResourceDetailUrl, false))
241 .thenReturn(IOUtils.toString(
242 SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServiceDetailsExample.json"),
245 String resourceDetailUrl = refProp.getStringValue("sdc.catalog.url")
246 + "resources/585822c7-4027-4f84-ba50-e9248606f136/metadata";
247 Mockito.when(spy.getCldsServicesOrResourcesBasedOnURL(resourceDetailUrl, false))
248 .thenReturn(IOUtils.toString(
249 SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcResourceDetailsExample.json"),
252 String securityRulesDetailUrl = refProp.getStringValue("sdc.catalog.url")
253 + "resources/d57e57d2-e3c6-470d-8d16-e6ea05f536c5/metadata";
254 Mockito.when(spy.getCldsServicesOrResourcesBasedOnURL(securityRulesDetailUrl, false)).thenReturn(
255 IOUtils.toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcSecurityRules.json"),
258 String cinderVolumeDetailUrl = refProp.getStringValue("sdc.catalog.url")
259 + "resources/b4288e07-597a-44a2-aa98-ad36e551a39d/metadata";
260 Mockito.when(spy.getCldsServicesOrResourcesBasedOnURL(cinderVolumeDetailUrl, false)).thenReturn(
261 IOUtils.toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcCinderVolume.json"),
264 String vfcGenericDetailUrl = refProp.getStringValue("sdc.catalog.url")
265 + "resources/2c8f1219-8000-4001-aa13-496a0396d40f/metadata";
266 Mockito.when(spy.getCldsServicesOrResourcesBasedOnURL(vfcGenericDetailUrl, false)).thenReturn(IOUtils.toString(
267 SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcVFCGenericWithAlarms.json"), "UTF-8"));
269 String csvDetailUrl = "/sdc/v1/catalog/resources/84855843-5247-4e97-a2bd-5395a510253b/artifacts/d57ac7ec-f3c3-4793-983a-c75ac3a43153";
270 Mockito.when(spy.getResponsesFromArtifactUrl(csvDetailUrl)).thenReturn(IOUtils.toString(
271 SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcMeasurementsList.csv"), "UTF-8"));
273 String csvAlarmsDetailUrl = "/sdc/v1/catalog/resources/2c8f1219-8000-4001-aa13-496a0396d40f/resourceInstances/virc_fe_be/artifacts/5138e316-0237-49aa-817a-b3d8eaf77392";
274 Mockito.when(spy.getResponsesFromArtifactUrl(csvAlarmsDetailUrl)).thenReturn(IOUtils
275 .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8"));
277 String allVfResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VF";
278 Mockito.when(spy.getCldsServicesOrResourcesBasedOnURL(allVfResourcesDetailUrl, false)).thenReturn(IOUtils
279 .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcVFResources.json"), "UTF-8"));
281 String allVfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VFC";
282 Mockito.when(spy.getCldsServicesOrResourcesBasedOnURL(allVfcResourcesDetailUrl, false)).thenReturn(
283 IOUtils.toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcVFCResources.json"),
286 CldsServiceData cldsServiceData = spy
287 .getCldsServiceDataWithAlarmConditions("a33ed748-3477-4434-b3f3-b5560f5e7d9c");
288 assertTrue("a33ed748-3477-4434-b3f3-b5560f5e7d9c".equals(cldsServiceData.getServiceInvariantUUID()));
289 assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(cldsServiceData.getServiceUUID()));
290 assertTrue(cldsServiceData.getCldsVfs().size() == 1);
292 List<CldsAlarmCondition> alarmsList = spy.getAllAlarmConditionsFromCldsServiceData(cldsServiceData,
294 assertTrue(alarmsList.size() == 6);