Change CsarHandler behavior
[clamp.git] / src / test / java / org / onap / clamp / clds / sdc / controller / installer / CsarHandlerTest.java
index c842068..3a37f94 100644 (file)
@@ -43,11 +43,11 @@ import org.mockito.Mockito;
 import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException;
 import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
 import org.onap.clamp.clds.util.ResourceFileUtil;
-import org.openecomp.sdc.api.notification.IArtifactInfo;
-import org.openecomp.sdc.api.notification.INotificationData;
-import org.openecomp.sdc.api.notification.IResourceInstance;
-import org.openecomp.sdc.api.results.IDistributionClientDownloadResult;
-import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.onap.sdc.api.notification.IArtifactInfo;
+import org.onap.sdc.api.notification.INotificationData;
+import org.onap.sdc.api.notification.IResourceInstance;
+import org.onap.sdc.api.results.IDistributionClientDownloadResult;
+import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
 
 public class CsarHandlerTest {
 
@@ -90,8 +90,6 @@ public class CsarHandlerTest {
         // Build what is needed for UUID
         Mockito.when(notifData.getServiceInvariantUUID()).thenReturn(SERVICE_UUID);
         // Build fake resource with one artifact BLUEPRINT
-        List<IResourceInstance> resourcesList = new ArrayList<>();
-        List<IArtifactInfo> artifactsListForResource = new ArrayList<>();
         IResourceInstance resource1 = Mockito.mock(IResourceInstance.class);
         Mockito.when(resource1.getResourceType()).thenReturn("VF");
         Mockito.when(resource1.getResourceInvariantUUID()).thenReturn(RESOURCE1_UUID);
@@ -99,8 +97,10 @@ public class CsarHandlerTest {
         IArtifactInfo blueprintArtifact = Mockito.mock(IArtifactInfo.class);
         Mockito.when(blueprintArtifact.getArtifactType()).thenReturn(CsarHandler.BLUEPRINT_TYPE);
         Mockito.when(blueprintArtifact.getArtifactName()).thenReturn(BLUEPRINT1_NAME);
+        List<IArtifactInfo> artifactsListForResource = new ArrayList<>();
         artifactsListForResource.add(blueprintArtifact);
         Mockito.when(resource1.getArtifacts()).thenReturn(artifactsListForResource);
+        List<IResourceInstance> resourcesList = new ArrayList<>();
         resourcesList.add(resource1);
         Mockito.when(notifData.getResources()).thenReturn(resourcesList);
         return notifData;
@@ -135,4 +135,29 @@ public class CsarHandlerTest {
         Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME);
         Files.deleteIfExists(path);
     }
+
+    @Test
+    public void testDoubleSave()
+            throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException {
+        CsarHandler csar = new CsarHandler(buildFakeSdcNotification(), "test-controller", "/tmp/csar-handler-tests");
+        // Test the save
+        csar.save(buildFakeSdcResut());
+        assertTrue((new File(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME)).exists());
+        assertEquals(CSAR_ARTIFACT_NAME, csar.getArtifactElement().getArtifactName());
+        assertNotNull(csar.getSdcCsarHelper());
+        // Test dcaeBlueprint
+        String blueprint = csar.getDcaeBlueprint();
+        assertNotNull(blueprint);
+        assertTrue(!blueprint.isEmpty());
+        assertTrue(blueprint.contains("DCAE-VES-PM-EVENT-v1"));
+        // Test additional properties from Sdc notif
+        assertEquals(BLUEPRINT1_NAME, csar.getBlueprintArtifactName());
+        assertEquals(RESOURCE1_UUID, csar.getBlueprintInvariantResourceUuid());
+        assertEquals(SERVICE_UUID, csar.getBlueprintInvariantServiceUuid());
+        Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME);
+        // A double save should simply overwrite the existing
+        csar.save(buildFakeSdcResut());
+        // Do some cleanup
+        Files.deleteIfExists(path);
+    }
 }