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