Merge "Set localhost in config"
[clamp.git] / src / test / java / org / onap / clamp / clds / it / SdcCatalogServicesIT.java
index 159e66a..dce6c90 100644 (file)
@@ -41,27 +41,28 @@ import org.onap.clamp.clds.model.CldsSdcServiceInfo;
 import org.onap.clamp.clds.model.CldsServiceData;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
 import org.springframework.test.context.junit4.SpringRunner;
 
 /**
- * Test DCAE API in org.onap.clamp.ClampDesigner.client package - replicate DCAE
- * Delegates in test.
+ * Test SDC Catalog Service class by mocking the SDC answers.
  */
 @RunWith(SpringRunner.class)
 @SpringBootTest
+@TestPropertySource(locations = "classpath:application-no-camunda.properties")
 public class SdcCatalogServicesIT extends AbstractIT {
     @Autowired
     private SdcCatalogServices sdcCatalogWired = new SdcCatalogServices();
 
     @Test
     public void removeDuplicateServicesTest() throws Exception {
-        SdcCatalogServices catalogServices = new SdcCatalogServices();
-        List<CldsSdcServiceInfo> rawCldsSdcServiceList = new LinkedList<CldsSdcServiceInfo>();
 
         CldsSdcServiceInfo service1a = new CldsSdcServiceInfo();
         service1a.setName("service1");
         service1a.setVersion("1.0");
         service1a.setInvariantUUID("invariantUUID1.0");
+
+        List<CldsSdcServiceInfo> rawCldsSdcServiceList = new LinkedList<CldsSdcServiceInfo>();
         rawCldsSdcServiceList.add(service1a);
         rawCldsSdcServiceList.add(service1a);
 
@@ -83,11 +84,13 @@ public class SdcCatalogServicesIT extends AbstractIT {
         service2.setInvariantUUID("invariantUUID2.0");
         rawCldsSdcServiceList.add(service2);
 
+        SdcCatalogServices catalogServices = new SdcCatalogServices();
         List<CldsSdcServiceInfo> resultList = catalogServices.removeDuplicateServices(rawCldsSdcServiceList);
 
         assertTrue(resultList.size() == 2);
 
-        CldsSdcServiceInfo res1, res2;
+        CldsSdcServiceInfo res1;
+        CldsSdcServiceInfo res2;
         if ("service1".equals(resultList.get(0).getName())) {
             res1 = resultList.get(0);
             res2 = resultList.get(1);
@@ -106,7 +109,7 @@ public class SdcCatalogServicesIT extends AbstractIT {
 
     @Test
     public void removeDuplicateSdcResourceInstancesTest() {
-        SdcCatalogServices catalogServices = new SdcCatalogServices();
+
         List<CldsSdcResource> rawCldsSdcResourceList = new LinkedList<CldsSdcResource>();
 
         CldsSdcResource sdcResource1a = new CldsSdcResource();
@@ -129,9 +132,11 @@ public class SdcCatalogServicesIT extends AbstractIT {
         sdcResource2.setResourceVersion("1.0");
         rawCldsSdcResourceList.add(sdcResource2);
 
+        SdcCatalogServices catalogServices = new SdcCatalogServices();
         List<CldsSdcResource> resultList = catalogServices.removeDuplicateSdcResourceInstances(rawCldsSdcResourceList);
 
-        CldsSdcResource res1, res2;
+        CldsSdcResource res1;
+        CldsSdcResource res2;
         if ("resource1".equals(resultList.get(0).getResourceInstanceName())) {
             res1 = resultList.get(0);
             res2 = resultList.get(1);
@@ -151,7 +156,6 @@ public class SdcCatalogServicesIT extends AbstractIT {
     @Test
     public void removeDuplicateSdcResourceBasicInfoTest() {
 
-        SdcCatalogServices catalogServices = new SdcCatalogServices();
         List<CldsSdcResourceBasicInfo> rawCldsSdcResourceList = new LinkedList<CldsSdcResourceBasicInfo>();
 
         CldsSdcResourceBasicInfo sdcResource1a = new CldsSdcResourceBasicInfo();
@@ -174,10 +178,12 @@ public class SdcCatalogServicesIT extends AbstractIT {
         sdcResource2.setVersion("1.0");
         rawCldsSdcResourceList.add(sdcResource2);
 
+        SdcCatalogServices catalogServices = new SdcCatalogServices();
         List<CldsSdcResourceBasicInfo> resultList = catalogServices
                 .removeDuplicateSdcResourceBasicInfo(rawCldsSdcResourceList);
 
-        CldsSdcResourceBasicInfo res1, res2;
+        CldsSdcResourceBasicInfo res1;
+        CldsSdcResourceBasicInfo res2;
         if ("resource1".equals(resultList.get(0).getName())) {
             res1 = resultList.get(0);
             res2 = resultList.get(1);
@@ -196,93 +202,123 @@ public class SdcCatalogServicesIT extends AbstractIT {
 
     @Test
     public void getServiceUuidFromServiceInvariantIdTest() throws Exception {
-        SdcCatalogServices aSpy = Mockito.spy(sdcCatalogWired);
-        Mockito.when(aSpy.getSdcServicesInformation(null)).thenReturn(IOUtils.toString(
-                SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), "UTF-8"));
+        SdcCatalogServices spy = Mockito.spy(sdcCatalogWired);
 
+        Mockito.doReturn(IOUtils.toString(
+                SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), "UTF-8"))
+                .when(spy).getSdcServicesInformation(null);
         // Try the vcts4 version 1.0, this one should be replaced by 1.1 so it
         // should not exist, returning empty string
-        String resUuidVcts4Null = aSpy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9b");
+        String resUuidVcts4Null = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9b");
         assertTrue("".equals(resUuidVcts4Null));
 
         // Try the vcts4 version 1.1, this one should be there as it replaces
         // the vcts4 v1.0
-        String resUuidVcts4Latest = aSpy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9c");
+        String resUuidVcts4Latest = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9c");
         assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(resUuidVcts4Latest));
 
         // Try the vcts5 version 1.0, this one should be there
-        String resUuidVcts5 = aSpy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d8c");
+        String resUuidVcts5 = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d8c");
         assertTrue("29018914-966c-442d-9d08-251b9dc45b7f".equals(resUuidVcts5));
 
         // try one that does not exist at all
-        String resUuidUnknown = aSpy.getServiceUuidFromServiceInvariantId("testuuid");
+        String resUuidUnknown = spy.getServiceUuidFromServiceInvariantId("testuuid");
         assertTrue("".equals(resUuidUnknown));
 
     }
 
     @Test
     public void getCldsServiceDataWithAlarmConditionsTest() throws Exception {
-        SdcCatalogServices aSpy = Mockito.spy(sdcCatalogWired);
-        Mockito.when(aSpy.getSdcServicesInformation(null)).thenReturn(IOUtils.toString(
-                SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), "UTF-8"));
+        SdcCatalogServices spy = Mockito.spy(sdcCatalogWired);
+
+        Mockito.doReturn(IOUtils.toString(
+                SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), "UTF-8"))
+                .when(spy).getSdcServicesInformation(null);
 
         // This invariant uuid is the one from vcts4 v1.1
         String serviceResourceDetailUrl = refProp.getStringValue("sdc.serviceUrl")
                 + "/29018914-966c-442d-9d08-251b9dc45b8f/metadata";
-        Mockito.when(aSpy.getCldsServicesOrResourcesBasedOnURL(serviceResourceDetailUrl, false))
-                .thenReturn(IOUtils.toString(
-                        SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServiceDetailsExample.json"),
-                        "UTF-8"));
+        Mockito.doReturn(IOUtils.toString(
+                SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServiceDetailsExample.json"), "UTF-8"))
+                .when(spy).getCldsServicesOrResourcesBasedOnURL(serviceResourceDetailUrl, false);
 
         String resourceDetailUrl = refProp.getStringValue("sdc.catalog.url")
                 + "resources/585822c7-4027-4f84-ba50-e9248606f136/metadata";
-        Mockito.when(aSpy.getCldsServicesOrResourcesBasedOnURL(resourceDetailUrl, false))
-                .thenReturn(IOUtils.toString(
-                        SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcResourceDetailsExample.json"),
-                        "UTF-8"));
+        Mockito.doReturn(IOUtils.toString(
+                SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcResourceDetailsExample.json"), "UTF-8"))
+                .when(spy).getCldsServicesOrResourcesBasedOnURL(resourceDetailUrl, false);
 
         String securityRulesDetailUrl = refProp.getStringValue("sdc.catalog.url")
                 + "resources/d57e57d2-e3c6-470d-8d16-e6ea05f536c5/metadata";
-        Mockito.when(aSpy.getCldsServicesOrResourcesBasedOnURL(securityRulesDetailUrl, false)).thenReturn(
-                IOUtils.toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcSecurityRules.json"),
-                        "UTF-8"));
+        Mockito.doReturn(IOUtils.toString(
+                SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcSecurityRules.json"), "UTF-8"))
+                .when(spy).getCldsServicesOrResourcesBasedOnURL(securityRulesDetailUrl, false);
 
         String cinderVolumeDetailUrl = refProp.getStringValue("sdc.catalog.url")
                 + "resources/b4288e07-597a-44a2-aa98-ad36e551a39d/metadata";
-        Mockito.when(aSpy.getCldsServicesOrResourcesBasedOnURL(cinderVolumeDetailUrl, false)).thenReturn(
-                IOUtils.toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcCinderVolume.json"),
-                        "UTF-8"));
+        Mockito.doReturn(IOUtils
+                .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcCinderVolume.json"), "UTF-8"))
+                .when(spy).getCldsServicesOrResourcesBasedOnURL(cinderVolumeDetailUrl, false);
 
         String vfcGenericDetailUrl = refProp.getStringValue("sdc.catalog.url")
                 + "resources/2c8f1219-8000-4001-aa13-496a0396d40f/metadata";
-        Mockito.when(aSpy.getCldsServicesOrResourcesBasedOnURL(vfcGenericDetailUrl, false)).thenReturn(IOUtils.toString(
-                SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcVFCGenericWithAlarms.json"), "UTF-8"));
-
-        String csvDetailUrl = "/sdc/v1/catalog/resources/84855843-5247-4e97-a2bd-5395a510253b/artifacts/d57ac7ec-f3c3-4793-983a-c75ac3a43153";
-        Mockito.when(aSpy.getResponsesFromArtifactUrl(csvDetailUrl)).thenReturn(IOUtils.toString(
-                SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcMeasurementsList.csv"), "UTF-8"));
-
-        String csvAlarmsDetailUrl = "/sdc/v1/catalog/resources/2c8f1219-8000-4001-aa13-496a0396d40f/resourceInstances/virc_fe_be/artifacts/5138e316-0237-49aa-817a-b3d8eaf77392";
-        Mockito.when(aSpy.getResponsesFromArtifactUrl(csvAlarmsDetailUrl)).thenReturn(IOUtils
-                .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8"));
+        Mockito.doReturn(IOUtils.toString(
+                SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcVFCGenericWithAlarms.json"), "UTF-8"))
+                .when(spy).getCldsServicesOrResourcesBasedOnURL(vfcGenericDetailUrl, false);
+
+        String csvAlarmsDetailUrl = refProp.getStringValue("sdc.catalog.url")
+                + "resources/2c8f1219-8000-4001-aa13-496a0396d40f/resourceInstances/virc_fe_be/artifacts/5138e316-0237-49aa-817a-b3d8eaf77392";
+        Mockito.doReturn(IOUtils
+                .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8"))
+                .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl, false);
+
+        Mockito.doReturn(IOUtils
+                .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8"))
+                .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl, true);
+
+        String csvAlarmsDetailUrl2 = refProp.getStringValue("sdc.catalog.url")
+                + "resources/d7646638-2572-4a94-b497-c028ac15f9ca/artifacts/5138e316-0237-49aa-817a-b3d8eaf77392";
+        Mockito.doReturn(IOUtils
+                .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8"))
+                .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl2, true);
 
         String allVfResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VF";
-        Mockito.when(aSpy.getCldsServicesOrResourcesBasedOnURL(allVfResourcesDetailUrl, false)).thenReturn(IOUtils
-                .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcVFResources.json"), "UTF-8"));
+        Mockito.doReturn(IOUtils
+                .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcVFResources.json"), "UTF-8"))
+                .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfResourcesDetailUrl, false);
 
-        String allVfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VFC";
-        Mockito.when(aSpy.getCldsServicesOrResourcesBasedOnURL(allVfcResourcesDetailUrl, false)).thenReturn(
-                IOUtils.toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcVFCResources.json"),
-                        "UTF-8"));
+        String cVfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url")
+                + "resources/a0475018-1e7e-4ddd-8bee-33cbf958c2e6/metadata";
+        Mockito.doReturn(IOUtils.toString(
+                SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcCVFCResourceExample.json"), "UTF-8"))
+                .when(spy).getCldsServicesOrResourcesBasedOnURL(cVfcResourcesDetailUrl, false);
 
-        CldsServiceData cldsServiceData = aSpy
+        String allVfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VFC";
+        Mockito.doReturn(IOUtils
+                .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcVFCResources.json"), "UTF-8"))
+                .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfcResourcesDetailUrl, false);
+
+        String allVfAlarms = refProp.getStringValue("sdc.catalog.url")
+                + "resources/84855843-5247-4e97-a2bd-5395a510253b/artifacts/d57ac7ec-f3c3-4793-983a-c75ac3a43153";
+        Mockito.doReturn(IOUtils.toString(
+                SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcMeasurementsList.csv"), "UTF-8"))
+                .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfAlarms, true);
+
+        String vfcResourceExample = refProp.getStringValue("sdc.catalog.url")
+                + "resources/d7646638-2572-4a94-b497-c028ac15f9ca/metadata";
+        Mockito.doReturn(IOUtils.toString(
+                SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcVFCResourceExample.json"), "UTF-8"))
+                .when(spy).getCldsServicesOrResourcesBasedOnURL(vfcResourceExample, false);
+
+        CldsServiceData cldsServiceData = spy
                 .getCldsServiceDataWithAlarmConditions("a33ed748-3477-4434-b3f3-b5560f5e7d9c");
         assertTrue("a33ed748-3477-4434-b3f3-b5560f5e7d9c".equals(cldsServiceData.getServiceInvariantUUID()));
         assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(cldsServiceData.getServiceUUID()));
         assertTrue(cldsServiceData.getCldsVfs().size() == 1);
 
-        List<CldsAlarmCondition> alarmsList = aSpy.getAllAlarmConditionsFromCldsServiceData(cldsServiceData);
-        assertTrue(alarmsList.size() == 6);
+        List<CldsAlarmCondition> alarmsList = spy.getAllAlarmConditionsFromCldsServiceData(cldsServiceData,
+                "alarmCondition");
+        assertTrue(alarmsList.size() == 12);
 
     }