Add unit tests
[clamp.git] / src / test / java / org / onap / clamp / clds / sdc / controller / installer / CsarHandlerTest.java
index bb4fd01..e008874 100644 (file)
@@ -24,6 +24,7 @@
 package org.onap.clamp.clds.sdc.controller.installer;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -115,6 +116,13 @@ public class CsarHandlerTest {
         return resultArtifact;
     }
 
+    private IDistributionClientDownloadResult buildFakeSdcResultWithoutPolicyModel() throws IOException {
+        IDistributionClientDownloadResult resultArtifact = Mockito.mock(IDistributionClientDownloadResult.class);
+        Mockito.when(resultArtifact.getArtifactPayload()).thenReturn(
+            IOUtils.toByteArray(ResourceFileUtil.getResourceAsStream("example/sdc/service-without-policy.csar")));
+        return resultArtifact;
+    }
+
     @Test
     public void testSave()
         throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException {
@@ -147,6 +155,23 @@ public class CsarHandlerTest {
 
     }
 
+    @Test
+    public void testLoadingOfPolicyModelFromCsar()
+        throws CsarHandlerException, IOException, SdcArtifactInstallerException, SdcToscaParserException {
+        CsarHandler csar = new CsarHandler(buildFakeSdcNotification(), "test-controller", "/tmp/csar-handler-tests");
+        csar.save(buildFakeSdcResut());
+        String policyModelYaml = csar.getPolicyModelYaml().get();
+        assertTrue(policyModelYaml.contains("tosca_simple_yaml_1_0_0"));
+    }
+
+    @Test
+    public void testLoadingOfNonexistentPolicyModelFromCsar()
+        throws CsarHandlerException, IOException, SdcArtifactInstallerException, SdcToscaParserException {
+        CsarHandler csar = new CsarHandler(buildFakeSdcNotification(), "test-controller", "/tmp/csar-handler-tests");
+        csar.save(buildFakeSdcResultWithoutPolicyModel());
+        assertFalse(csar.getPolicyModelYaml().isPresent());
+    }
+
     @Test
     public void testDoubleSave()
         throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException {