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;
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();
@Test
void testFileListing() {
File file = new File(validCsarFileLocation + validRappFile);
- List<String> fileListFromCsar =
- rappCsarConfigurationHandler.getFileListFromCsar(file, "Files/Sme/serviceapis/");
+ 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);
+ 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
void testListResources() {
UUID rappId = UUID.randomUUID();
RappResources rappResources = rappCsarConfigurationHandler.getRappResource(rapp);
assertThat(rappResources).isNotNull();
assertNotNull(rappResources.getAcm().getCompositionDefinitions());
- assertThat(rappResources.getAcm().getCompositionInstances()).hasSize(3);
+ 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
assertThat(rappResources).isNotNull();
assertNull(rappResources.getAcm());
assertNull(rappResources.getSme());
+ assertNull(rappResources.getDme());
}
@Test
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();
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();
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);
+ }
+
}