Add info types for producer and consumer in rApp package
[nonrtric/plt/rappmanager.git] / rapp-manager-models / src / test / java / com / oransc / rappmanager / models / csar / RappCsarConfigurationHandlerTest.java
index 10f5d96..8c416ee 100755 (executable)
@@ -22,15 +22,18 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
 
 import com.oransc.rappmanager.models.rapp.Rapp;
 import com.oransc.rappmanager.models.rapp.RappResources;
 import com.oransc.rappmanager.models.rappinstance.RappACMInstance;
+import com.oransc.rappmanager.models.rappinstance.RappDMEInstance;
 import com.oransc.rappmanager.models.rappinstance.RappSMEInstance;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.util.List;
+import java.util.Set;
 import java.util.UUID;
 import org.apache.http.entity.ContentType;
 import org.json.JSONException;
@@ -44,7 +47,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 @SpringBootTest
 @ContextConfiguration(classes = RappCsarConfigurationHandler.class)
-public class RappCsarConfigurationHandlerTest {
+class RappCsarConfigurationHandlerTest {
 
     @Autowired
     RappCsarConfigurationHandler rappCsarConfigurationHandler;
@@ -74,6 +77,18 @@ public class RappCsarConfigurationHandlerTest {
         assertEquals(Boolean.FALSE, rappCsarConfigurationHandler.isValidRappPackage(multipartFile));
     }
 
+    @Test
+    void testCsarPackageValidationFailureWithoutOrginalName() throws IOException {
+        MultipartFile multipartFile = mock(MultipartFile.class);
+        assertEquals(Boolean.FALSE, rappCsarConfigurationHandler.isValidRappPackage(multipartFile));
+    }
+
+    @Test
+    void testInvalidCsarFileExist() {
+        MultipartFile multipartFile = mock(MultipartFile.class);
+        assertEquals(Boolean.FALSE, rappCsarConfigurationHandler.isFileExistsInCsar(multipartFile, "INVALID_LOCATION"));
+    }
+
     @Test
     void testCsarInstantiationPayload() throws JSONException {
         Rapp rapp = Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build();
@@ -88,16 +103,22 @@ public class RappCsarConfigurationHandlerTest {
     @Test
     void testFileListing() {
         File file = new File(validCsarFileLocation + validRappFile);
-        List<String> fileListFromCsar =
-                rappCsarConfigurationHandler.getFileListFromCsar(file, "Files/Sme/serviceapis/");
-        assertThat(fileListFromCsar.size()).isEqualTo(2);
+        Set<String> fileListFromCsar = rappCsarConfigurationHandler.getFileListFromCsar(file, "Files/Sme/serviceapis/");
+        assertThat(fileListFromCsar).hasSize(2);
     }
 
     @Test
     void testInvalidFileListing() {
         File file = new File(validCsarFileLocation);
-        List<String> fileListFromCsar = rappCsarConfigurationHandler.getFileListFromCsar(file, null);
-        assertThat(fileListFromCsar.size()).isEqualTo(0);
+        Set<String> fileListFromCsar = rappCsarConfigurationHandler.getFileListFromCsar(file, null);
+        assertThat(fileListFromCsar).isEmpty();
+    }
+
+    @Test
+    void testInvalidFileListingFromCsar() {
+        File file = new File("InvalidFile");
+        ByteArrayOutputStream fileByteArray = rappCsarConfigurationHandler.getFileFromCsar(file, null);
+        assertThat(fileByteArray.size()).isZero();
     }
 
     @Test
@@ -109,10 +130,14 @@ public class RappCsarConfigurationHandlerTest {
         RappResources rappResources = rappCsarConfigurationHandler.getRappResource(rapp);
         assertThat(rappResources).isNotNull();
         assertNotNull(rappResources.getAcm().getCompositionDefinitions());
-        assertThat(rappResources.getAcm().getCompositionInstances().size()).isEqualTo(3);
-        assertThat(rappResources.getSme().getProviderFunctions().size()).isEqualTo(4);
-        assertThat(rappResources.getSme().getServiceApis().size()).isEqualTo(2);
-        assertThat(rappResources.getSme().getInvokers().size()).isEqualTo(2);
+        assertThat(rappResources.getAcm().getCompositionInstances()).hasSize(4);
+        assertThat(rappResources.getSme().getProviderFunctions()).hasSize(4);
+        assertThat(rappResources.getSme().getServiceApis()).hasSize(2);
+        assertThat(rappResources.getSme().getInvokers()).hasSize(2);
+        assertThat(rappResources.getDme().getProducerInfoTypes()).hasSize(2);
+        assertThat(rappResources.getDme().getConsumerInfoTypes()).hasSize(2);
+        assertThat(rappResources.getDme().getInfoProducers()).hasSize(2);
+        assertThat(rappResources.getDme().getInfoConsumers()).hasSize(2);
     }
 
     @Test
@@ -123,6 +148,7 @@ public class RappCsarConfigurationHandlerTest {
         assertThat(rappResources).isNotNull();
         assertNull(rappResources.getAcm());
         assertNull(rappResources.getSme());
+        assertNull(rappResources.getDme());
     }
 
     @Test
@@ -130,7 +156,7 @@ public class RappCsarConfigurationHandlerTest {
         UUID rappId = UUID.randomUUID();
         RappResources rappResources = new RappResources();
         rappResources.setAcm(RappResources.ACMResources.builder().compositionDefinitions("compositions")
-                                     .compositionInstances(List.of()).build());
+                                     .compositionInstances(Set.of()).build());
         Rapp rapp =
                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
                         .rappResources(rappResources).build();
@@ -143,7 +169,7 @@ public class RappCsarConfigurationHandlerTest {
         UUID rappId = UUID.randomUUID();
         RappResources rappResources = new RappResources();
         rappResources.setAcm(RappResources.ACMResources.builder().compositionDefinitions("invalidcomposition")
-                                     .compositionInstances(List.of()).build());
+                                     .compositionInstances(Set.of()).build());
         Rapp rapp =
                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
                         .rappResources(rappResources).build();
@@ -188,4 +214,56 @@ public class RappCsarConfigurationHandlerTest {
         assertNotNull(smeProviderDomainPayload);
     }
 
+    @Test
+    void testGetDmeProducerInfoTypePayload() {
+        UUID rappId = UUID.randomUUID();
+        RappDMEInstance rappDMEInstance = new RappDMEInstance();
+        rappDMEInstance.setInfoTypesProducer(Set.of("json-file-data-from-filestore"));
+        Rapp rapp =
+                Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
+                        .build();
+        String dmeInfoTypePayload = rappCsarConfigurationHandler.getDmeProducerInfoTypePayload(rapp,
+                rappDMEInstance.getInfoTypesProducer().iterator().next());
+        assertNotNull(dmeInfoTypePayload);
+    }
+
+    @Test
+    void testGetDmeConsumerInfoTypePayload() {
+        UUID rappId = UUID.randomUUID();
+        RappDMEInstance rappDMEInstance = new RappDMEInstance();
+        rappDMEInstance.setInfoTypeConsumer("json-file-data-from-filestore");
+        Rapp rapp =
+                Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
+                        .build();
+        String dmeInfoTypePayload =
+                rappCsarConfigurationHandler.getDmeConsumerInfoTypePayload(rapp, rappDMEInstance.getInfoTypeConsumer());
+        assertNotNull(dmeInfoTypePayload);
+    }
+
+    @Test
+    void testGetDmeInfoProducerPayload() {
+        UUID rappId = UUID.randomUUID();
+        RappDMEInstance rappDMEInstance = new RappDMEInstance();
+        rappDMEInstance.setInfoProducer("json-file-data-producer");
+        Rapp rapp =
+                Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
+                        .build();
+        String dmeInfoProducerPayload =
+                rappCsarConfigurationHandler.getDmeInfoProducerPayload(rapp, rappDMEInstance.getInfoProducer());
+        assertNotNull(dmeInfoProducerPayload);
+    }
+
+    @Test
+    void testGetDmeInfoConsumerPayload() {
+        UUID rappId = UUID.randomUUID();
+        RappDMEInstance rappDMEInstance = new RappDMEInstance();
+        rappDMEInstance.setInfoConsumer("json-file-consumer");
+        Rapp rapp =
+                Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
+                        .build();
+        String dmeInfoConsumerPayload =
+                rappCsarConfigurationHandler.getDmeInfoConsumerPayload(rapp, rappDMEInstance.getInfoConsumer());
+        assertNotNull(dmeInfoConsumerPayload);
+    }
+
 }