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);
}
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;
}
}
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;
}
}
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);
}
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);
}
Aggregations