Search in sources :

Example 1 with NoFileInDatabaseException

use of gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException in project qpp-conversion-tool by CMSgov.

the class ExceptionHandlerControllerV1Test method testFileNotFoundExceptionStatusCode.

@Test
void testFileNotFoundExceptionStatusCode() {
    NoFileInDatabaseException exception = new NoFileInDatabaseException(CpcFileServiceImpl.FILE_NOT_FOUND);
    ResponseEntity<String> responseEntity = objectUnderTest.handleFileNotFoundException(exception);
    assertWithMessage("The response entity's status code must be 422.").that(responseEntity.getStatusCode()).isEquivalentAccordingToCompareTo(HttpStatus.NOT_FOUND);
}
Also used : NoFileInDatabaseException(gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException) Test(org.junit.jupiter.api.Test)

Example 2 with NoFileInDatabaseException

use of gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException in project qpp-conversion-tool by CMSgov.

the class CpcFileServiceImpl method unprocessFileById.

/**
 * Process to ensure the file is a processed cpc+ file and marks the file as unprocessed
 *
 * @param fileId Identifier of the CPC+ file
 * @return Success or failure message.
 */
@Override
public String unprocessFileById(String fileId) {
    Metadata metadata = dbService.getMetadataById(fileId);
    if (metadata == null) {
        throw new NoFileInDatabaseException(FILE_NOT_FOUND);
    } else if (metadata.getCpc() == null) {
        throw new InvalidFileTypeException(INVALID_FILE);
    } else if (!metadata.getCpcProcessed()) {
        return FILE_FOUND_UNPROCESSED;
    } else {
        metadata.setCpcProcessed(false);
        CompletableFuture<Metadata> metadataFuture = dbService.write(metadata);
        metadataFuture.join();
        return FILE_FOUND_UNPROCESSED;
    }
}
Also used : InvalidFileTypeException(gov.cms.qpp.conversion.api.exceptions.InvalidFileTypeException) Metadata(gov.cms.qpp.conversion.api.model.Metadata) NoFileInDatabaseException(gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException)

Example 3 with NoFileInDatabaseException

use of gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException in project qpp-conversion-tool by CMSgov.

the class CpcFileServiceImpl method processFileById.

/**
 * Process to ensure the file is an unprocessed cpc+ file and marks the file as processed
 *
 * @param fileId Identifier of the CPC+ file
 * @return Success or failure message.
 */
@Override
public String processFileById(String fileId) {
    Metadata metadata = dbService.getMetadataById(fileId);
    if (metadata == null) {
        throw new NoFileInDatabaseException(FILE_NOT_FOUND);
    } else if (metadata.getCpc() == null) {
        throw new InvalidFileTypeException(INVALID_FILE);
    } else if (metadata.getCpcProcessed()) {
        return FILE_FOUND_PROCESSED;
    } else {
        metadata.setCpcProcessed(true);
        CompletableFuture<Metadata> metadataFuture = dbService.write(metadata);
        metadataFuture.join();
        return FILE_FOUND_PROCESSED;
    }
}
Also used : InvalidFileTypeException(gov.cms.qpp.conversion.api.exceptions.InvalidFileTypeException) Metadata(gov.cms.qpp.conversion.api.model.Metadata) NoFileInDatabaseException(gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException)

Example 4 with NoFileInDatabaseException

use of gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException in project qpp-conversion-tool by CMSgov.

the class CpcFileServiceImplTest method testGetFileByIdNoFile.

@Test
void testGetFileByIdNoFile() {
    when(dbService.getMetadataById(anyString())).thenReturn(null);
    when(storageService.getFileByLocationId("test")).thenReturn(new ByteArrayInputStream("1337".getBytes()));
    NoFileInDatabaseException expectedException = assertThrows(NoFileInDatabaseException.class, () -> objectUnderTest.getFileById("test"));
    verify(dbService, times(1)).getMetadataById(anyString());
    assertThat(expectedException).hasMessageThat().isEqualTo(CpcFileServiceImpl.FILE_NOT_FOUND);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NoFileInDatabaseException(gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with NoFileInDatabaseException

use of gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException in project qpp-conversion-tool by CMSgov.

the class CpcFileServiceImplTest method testUnprocessFileByIdFileNotFound.

@Test
void testUnprocessFileByIdFileNotFound() {
    when(dbService.getMetadataById(anyString())).thenReturn(null);
    NoFileInDatabaseException expectedException = assertThrows(NoFileInDatabaseException.class, () -> objectUnderTest.unprocessFileById("test"));
    verify(dbService, times(1)).getMetadataById(anyString());
    assertThat(expectedException).hasMessageThat().isEqualTo(CpcFileServiceImpl.FILE_NOT_FOUND);
}
Also used : NoFileInDatabaseException(gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

NoFileInDatabaseException (gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException)10 Test (org.junit.jupiter.api.Test)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InvalidFileTypeException (gov.cms.qpp.conversion.api.exceptions.InvalidFileTypeException)2 Metadata (gov.cms.qpp.conversion.api.model.Metadata)2