+ RappHandlerException exception = assertThrows(RappHandlerException.class,
+ () -> rappCsarConfigurationHandler.isFileExistsInCsar(multipartFile, "INVALID_LOCATION"));
+ assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
+ }
+
+ @Test
+ void testCsarContainsValidAsdFile() throws IOException {
+ String rappCsarPath = validCsarFileLocation + File.separator + validRappFile;
+ MultipartFile multipartFile =
+ new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(),
+ new FileInputStream(rappCsarPath));
+ assertTrue(rappCsarConfigurationHandler.containsValidArtifactDefinition(multipartFile));
+ }
+
+ @Test
+ void testCsarContainsValidAsdFileFailure() throws IOException {
+ String rappCsarPath = validCsarFileLocation + File.separator + invalidRappFile;
+ MultipartFile multipartFile =
+ new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(),
+ new FileInputStream(rappCsarPath));
+ RappHandlerException exception = assertThrows(RappHandlerException.class,
+ () -> rappCsarConfigurationHandler.containsValidArtifactDefinition(multipartFile));
+ assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
+ }
+
+ @Test
+ void testCsarNoAsdFailure() {
+ MultipartFile multipartFile = mock(MultipartFile.class);
+ RappHandlerException exception = assertThrows(RappHandlerException.class,
+ () -> rappCsarConfigurationHandler.containsValidArtifactDefinition(multipartFile));
+ assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
+ }
+
+ @Test
+ void testCsarAsdContentInvalidFailure() throws IOException {
+ String rappCsarPath = validCsarFileLocation + File.separator + validRappFile;
+ MultipartFile multipartFile =
+ new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(),
+ new FileInputStream(rappCsarPath));
+ String invalidJson = "{asasdasd";
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ byteArrayOutputStream.write(invalidJson.getBytes(), 0, invalidJson.getBytes().length);
+ doCallRealMethod().doReturn(byteArrayOutputStream).when(rappCsarConfigurationHandler)
+ .getFileFromCsar(any(MultipartFile.class), any());
+ RappHandlerException exception = assertThrows(RappHandlerException.class,
+ () -> rappCsarConfigurationHandler.containsValidArtifactDefinition(multipartFile));
+ assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
+ }
+
+ @Test
+ void testgetFileFromCsarFailure() throws IOException {
+ MultipartFile multipartFile = mock(MultipartFile.class);
+ when(multipartFile.getInputStream()).thenThrow(new IOException());
+ assertThat(rappCsarConfigurationHandler.getFileFromCsar(multipartFile, null).size()).isZero();