2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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.AbstractItCase;
36 import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices;
37 import org.onap.clamp.clds.model.CldsAlarmCondition;
38 import org.onap.clamp.clds.model.CldsServiceData;
39 import org.onap.clamp.clds.model.sdc.SdcResource;
40 import org.onap.clamp.clds.model.sdc.SdcResourceBasicInfo;
41 import org.onap.clamp.clds.model.sdc.SdcServiceInfo;
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 SDC Catalog Service class by mocking the SDC answers.
49 @RunWith(SpringRunner.class)
51 public class SdcCatalogServicesItCase extends AbstractItCase {
54 private SdcCatalogServices sdcCatalogWired = new SdcCatalogServices();
57 public void removeDuplicateServicesTest() {
58 SdcServiceInfo service1a = new SdcServiceInfo();
59 service1a.setName("service1");
60 service1a.setVersion("1.0");
61 service1a.setInvariantUUID("invariantUUID1.0");
62 List<SdcServiceInfo> rawCldsSdcServiceList = new LinkedList<>();
63 rawCldsSdcServiceList.add(service1a);
64 rawCldsSdcServiceList.add(service1a);
65 SdcServiceInfo service1b = new SdcServiceInfo();
66 service1b.setName("service1");
67 service1b.setVersion("1.1");
68 service1b.setInvariantUUID("invariantUUID1.1");
69 rawCldsSdcServiceList.add(service1b);
70 SdcServiceInfo service1c = new SdcServiceInfo();
71 service1c.setName("service1");
72 service1c.setVersion("1.2");
73 service1c.setInvariantUUID("invariantUUID1.2");
74 rawCldsSdcServiceList.add(service1c);
75 SdcServiceInfo service2 = new SdcServiceInfo();
76 service2.setName("service2");
77 service2.setVersion("1.0");
78 service2.setInvariantUUID("invariantUUID2.0");
79 rawCldsSdcServiceList.add(service2);
80 SdcCatalogServices catalogServices = new SdcCatalogServices();
81 List<SdcServiceInfo> resultList = catalogServices.removeDuplicateServices(rawCldsSdcServiceList);
82 assertTrue(resultList.size() == 2);
85 if ("service1".equals(resultList.get(0).getName())) {
86 res1 = resultList.get(0);
87 res2 = resultList.get(1);
89 res1 = resultList.get(1);
90 res2 = resultList.get(0);
92 assertTrue("service1".equals(res1.getName()));
93 assertTrue("1.2".equals(res1.getVersion()));
94 assertTrue("service2".equals(res2.getName()));
95 assertTrue("1.0".equals(res2.getVersion()));
99 public void removeDuplicateSdcResourceInstancesTest() {
100 List<SdcResource> rawCldsSdcResourceList = new LinkedList<>();
101 SdcResource sdcResource1a = new SdcResource();
102 sdcResource1a.setResourceInstanceName("resource1");
103 sdcResource1a.setResourceVersion("1.0");
104 rawCldsSdcResourceList.add(sdcResource1a);
105 SdcResource sdcResource1b = new SdcResource();
106 sdcResource1b.setResourceInstanceName("resource1");
107 sdcResource1b.setResourceVersion("1.1");
108 rawCldsSdcResourceList.add(sdcResource1b);
109 SdcResource sdcResource1c = new SdcResource();
110 sdcResource1c.setResourceInstanceName("resource1");
111 sdcResource1c.setResourceVersion("1.2");
112 rawCldsSdcResourceList.add(sdcResource1c);
113 SdcResource sdcResource2 = new SdcResource();
114 sdcResource2.setResourceInstanceName("resource2");
115 sdcResource2.setResourceVersion("1.0");
116 rawCldsSdcResourceList.add(sdcResource2);
117 SdcCatalogServices catalogServices = new SdcCatalogServices();
118 List<SdcResource> resultList = catalogServices.removeDuplicateSdcResourceInstances(rawCldsSdcResourceList);
121 if ("resource1".equals(resultList.get(0).getResourceInstanceName())) {
122 res1 = resultList.get(0);
123 res2 = resultList.get(1);
125 res1 = resultList.get(1);
126 res2 = resultList.get(0);
128 assertTrue("resource1".equals(res1.getResourceInstanceName()));
129 assertTrue("1.2".equals(res1.getResourceVersion()));
130 assertTrue("resource2".equals(res2.getResourceInstanceName()));
131 assertTrue("1.0".equals(res2.getResourceVersion()));
135 public void removeDuplicateSdcResourceBasicInfoTest() {
136 List<SdcResourceBasicInfo> rawCldsSdcResourceList = new LinkedList<>();
137 SdcResourceBasicInfo sdcResource1a = new SdcResourceBasicInfo();
138 sdcResource1a.setName("resource1");
139 sdcResource1a.setVersion("1.0");
140 rawCldsSdcResourceList.add(sdcResource1a);
141 SdcResourceBasicInfo sdcResource1b = new SdcResourceBasicInfo();
142 sdcResource1b.setName("resource1");
143 sdcResource1b.setVersion("1.1");
144 rawCldsSdcResourceList.add(sdcResource1b);
145 SdcResourceBasicInfo sdcResource1c = new SdcResourceBasicInfo();
146 sdcResource1c.setName("resource1");
147 sdcResource1c.setVersion("1.2");
148 rawCldsSdcResourceList.add(sdcResource1c);
149 SdcResourceBasicInfo sdcResource2 = new SdcResourceBasicInfo();
150 sdcResource2.setName("resource2");
151 sdcResource2.setVersion("1.0");
152 rawCldsSdcResourceList.add(sdcResource2);
153 SdcCatalogServices catalogServices = new SdcCatalogServices();
154 List<SdcResourceBasicInfo> resultList = catalogServices
155 .removeDuplicateSdcResourceBasicInfo(rawCldsSdcResourceList);
156 SdcResourceBasicInfo res1;
157 SdcResourceBasicInfo res2;
158 if ("resource1".equals(resultList.get(0).getName())) {
159 res1 = resultList.get(0);
160 res2 = resultList.get(1);
162 res1 = resultList.get(1);
163 res2 = resultList.get(0);
165 assertTrue("resource1".equals(res1.getName()));
166 assertTrue("1.2".equals(res1.getVersion()));
167 assertTrue("resource2".equals(res2.getName()));
168 assertTrue("1.0".equals(res2.getVersion()));
172 public void getServiceUuidFromServiceInvariantIdTest() throws Exception {
173 SdcCatalogServices spy = Mockito.spy(sdcCatalogWired);
174 Mockito.doReturn(IOUtils.toString(
175 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"),
176 "UTF-8")).when(spy).getSdcServicesInformation(null);
177 // Try the vcts4 version 1.0, this one should be replaced by 1.1 so it
178 // should not exist, returning empty string
179 String resUuidVcts4Null = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9b");
180 assertTrue("".equals(resUuidVcts4Null));
181 // Try the vcts4 version 1.1, this one should be there as it replaces
183 String resUuidVcts4Latest = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9c");
184 assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(resUuidVcts4Latest));
185 // Try the vcts5 version 1.0, this one should be there
186 String resUuidVcts5 = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d8c");
187 assertTrue("29018914-966c-442d-9d08-251b9dc45b7f".equals(resUuidVcts5));
188 // try one that does not exist at all
189 String resUuidUnknown = spy.getServiceUuidFromServiceInvariantId("testuuid");
190 assertTrue("".equals(resUuidUnknown));
194 public void getCldsServiceDataWithAlarmConditionsTest() throws Exception {
195 SdcCatalogServices spy = Mockito.spy(sdcCatalogWired);
196 Mockito.doReturn(IOUtils.toString(
197 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"),
198 "UTF-8")).when(spy).getSdcServicesInformation(null);
199 // This invariant uuid is the one from vcts4 v1.1
200 String serviceResourceDetailUrl = refProp.getStringValue("sdc.serviceUrl")
201 + "/29018914-966c-442d-9d08-251b9dc45b8f/metadata";
202 Mockito.doReturn(IOUtils.toString(
203 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcServiceDetailsExample.json"),
204 "UTF-8")).when(spy).getCldsServicesOrResourcesBasedOnURL(serviceResourceDetailUrl);
205 String resourceDetailUrl = refProp.getStringValue("sdc.catalog.url")
206 + "resources/585822c7-4027-4f84-ba50-e9248606f136/metadata";
207 Mockito.doReturn(IOUtils.toString(
208 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcResourceDetailsExample.json"),
209 "UTF-8")).when(spy).getCldsServicesOrResourcesBasedOnURL(resourceDetailUrl);
210 String securityRulesDetailUrl = refProp.getStringValue("sdc.catalog.url")
211 + "resources/d57e57d2-e3c6-470d-8d16-e6ea05f536c5/metadata";
212 Mockito.doReturn(IOUtils.toString(
213 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcSecurityRules.json"), "UTF-8"))
214 .when(spy).getCldsServicesOrResourcesBasedOnURL(securityRulesDetailUrl);
215 String cinderVolumeDetailUrl = refProp.getStringValue("sdc.catalog.url")
216 + "resources/b4288e07-597a-44a2-aa98-ad36e551a39d/metadata";
217 Mockito.doReturn(IOUtils.toString(
218 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcCinderVolume.json"), "UTF-8"))
219 .when(spy).getCldsServicesOrResourcesBasedOnURL(cinderVolumeDetailUrl);
220 String vfcGenericDetailUrl = refProp.getStringValue("sdc.catalog.url")
221 + "resources/2c8f1219-8000-4001-aa13-496a0396d40f/metadata";
222 Mockito.doReturn(IOUtils.toString(
223 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFCGenericWithAlarms.json"),
224 "UTF-8")).when(spy).getCldsServicesOrResourcesBasedOnURL(vfcGenericDetailUrl);
225 String csvAlarmsDetailUrl = refProp.getStringValue("sdc.catalog.url")
226 + "resources/2c8f1219-8000-4001-aa13-496a0396d40f/resourceInstances/virc_fe_be/artifacts/5138e316-0237-49aa-817a-b3d8eaf77392";
227 Mockito.doReturn(IOUtils.toString(
228 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8"))
229 .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl);
230 Mockito.doReturn(IOUtils.toString(
231 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8"))
232 .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl);
233 String csvAlarmsDetailUrl2 = refProp.getStringValue("sdc.catalog.url")
234 + "resources/d7646638-2572-4a94-b497-c028ac15f9ca/artifacts/5138e316-0237-49aa-817a-b3d8eaf77392";
235 Mockito.doReturn(IOUtils.toString(
236 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8"))
237 .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl2);
238 String allVfResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VF";
239 Mockito.doReturn(IOUtils.toString(
240 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFResources.json"), "UTF-8"))
241 .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfResourcesDetailUrl);
242 String vfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url")
243 + "resources/a0475018-1e7e-4ddd-8bee-33cbf958c2e6/metadata";
244 Mockito.doReturn(IOUtils.toString(
245 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcCVFCResourceExample.json"),
246 "UTF-8")).when(spy).getCldsServicesOrResourcesBasedOnURL(vfcResourcesDetailUrl);
247 String allVfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VFC";
248 Mockito.doReturn(IOUtils.toString(
249 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFCResources.json"), "UTF-8"))
250 .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfcResourcesDetailUrl);
251 String allCvfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=CVFC";
252 Mockito.doReturn(IOUtils.toString(
253 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcCVFCResources.json"), "UTF-8"))
254 .when(spy).getCldsServicesOrResourcesBasedOnURL(allCvfcResourcesDetailUrl);
255 String allVfAlarms = refProp.getStringValue("sdc.catalog.url")
256 + "resources/84855843-5247-4e97-a2bd-5395a510253b/artifacts/d57ac7ec-f3c3-4793-983a-c75ac3a43153";
257 Mockito.doReturn(IOUtils.toString(
258 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcMeasurementsList.csv"), "UTF-8"))
259 .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfAlarms);
260 String vfcResourceExample = refProp.getStringValue("sdc.catalog.url")
261 + "resources/d7646638-2572-4a94-b497-c028ac15f9ca/metadata";
262 Mockito.doReturn(IOUtils.toString(
263 SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFCResourceExample.json"), "UTF-8"))
264 .when(spy).getCldsServicesOrResourcesBasedOnURL(vfcResourceExample);
265 CldsServiceData cldsServiceData = spy
266 .getCldsServiceDataWithAlarmConditions("a33ed748-3477-4434-b3f3-b5560f5e7d9c");
267 assertTrue("a33ed748-3477-4434-b3f3-b5560f5e7d9c".equals(cldsServiceData.getServiceInvariantUUID()));
268 assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(cldsServiceData.getServiceUUID()));
269 assertTrue(cldsServiceData.getCldsVfs().size() == 1);
270 List<CldsAlarmCondition> alarmsList = spy.getAllAlarmConditionsFromCldsServiceData(cldsServiceData,
272 assertTrue(alarmsList.size() == 12);