Search in sources :

Example 1 with InvalidFileTypeException

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

the class ExceptionHandlerControllerV1Test method testInvalidFileTypeExceptionHeaderContentType.

@Test
void testInvalidFileTypeExceptionHeaderContentType() {
    InvalidFileTypeException exception = new InvalidFileTypeException(CpcFileServiceImpl.FILE_NOT_FOUND);
    ResponseEntity<String> responseEntity = objectUnderTest.handleInvalidFileTypeException(exception);
    assertThat(responseEntity.getHeaders().getContentType()).isEquivalentAccordingToCompareTo(MediaType.TEXT_PLAIN);
}
Also used : InvalidFileTypeException(gov.cms.qpp.conversion.api.exceptions.InvalidFileTypeException) Test(org.junit.jupiter.api.Test)

Example 2 with InvalidFileTypeException

use of gov.cms.qpp.conversion.api.exceptions.InvalidFileTypeException 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 InvalidFileTypeException

use of gov.cms.qpp.conversion.api.exceptions.InvalidFileTypeException 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 InvalidFileTypeException

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

the class CpcFileServiceImplTest method testProcessFileByIdWithMipsFile.

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

Example 5 with InvalidFileTypeException

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

the class CpcFileServiceImplTest method testUnprocessFileByIdWithMipsFile.

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

Aggregations

InvalidFileTypeException (gov.cms.qpp.conversion.api.exceptions.InvalidFileTypeException)7 Test (org.junit.jupiter.api.Test)5 NoFileInDatabaseException (gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException)2 Metadata (gov.cms.qpp.conversion.api.model.Metadata)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2