diff --git a/attribution-data-file-share/src/test/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareHelperTest.java b/attribution-data-file-share/src/test/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareTest.java similarity index 97% rename from attribution-data-file-share/src/test/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareHelperTest.java rename to attribution-data-file-share/src/test/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareTest.java index fa476e0..fbc85ee 100644 --- a/attribution-data-file-share/src/test/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareHelperTest.java +++ b/attribution-data-file-share/src/test/java/gov/cms/ab2d/attributionDataShare/AttributionDataShareTest.java @@ -28,7 +28,7 @@ @Testcontainers @ExtendWith({S3MockAPIExtension.class}) -public class AttributionDataShareHelperTest { +public class AttributionDataShareTest { @SuppressWarnings({"rawtypes", "unused"}) @Container private static final PostgreSQLContainer POSTGRE_SQL_CONTAINER = new AB2DPostgresqlContainer(); @@ -37,7 +37,7 @@ public class AttributionDataShareHelperTest { String FILE_NAME = FILE_PARTIAL_NAME + new SimpleDateFormat(PATTERN).format(new Date()) + FILE_FORMAT; String FILE_FULL_PATH = FILE_PATH + FILE_NAME; - String MBI = "1AA2BB3CC45"; + String MBI = "DUMMY000001"; AttributionDataShareHelper helper; @BeforeEach diff --git a/optout/src/main/java/gov/cms/ab2d/optout/OptOutHandler.java b/optout/src/main/java/gov/cms/ab2d/optout/OptOutHandler.java index ce7e10b..e5a795c 100644 --- a/optout/src/main/java/gov/cms/ab2d/optout/OptOutHandler.java +++ b/optout/src/main/java/gov/cms/ab2d/optout/OptOutHandler.java @@ -25,7 +25,7 @@ public void processSQSMessage(SQSEvent.SQSMessage msg, Context context) { try { logger.log("OptOut Lambda started. Processing message from SQS " + msg.getBody()); - var optOutProcessing = processingInit(msg.getBody(), logger); + var optOutProcessing = processorInit(msg.getBody(), logger); optOutProcessing.process(); } catch (Exception ex) { logger.log("An error occurred"); @@ -33,8 +33,8 @@ public void processSQSMessage(SQSEvent.SQSMessage msg, Context context) { } } - public OptOutProcessing processingInit(String msg, LambdaLogger logger) throws URISyntaxException { - return new OptOutProcessing(msg, ENDPOINT, logger); + public OptOutProcessor processorInit(String msg, LambdaLogger logger) throws URISyntaxException { + return new OptOutProcessor(msg, ENDPOINT, logger); //ToDo: uncomment when permanent credentials will be available // var creds = SecretManager.getS3Credentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY, ACCESS_TOKEN, logger); // if (creds.isPresent()) diff --git a/optout/src/main/java/gov/cms/ab2d/optout/OptOutProcessing.java b/optout/src/main/java/gov/cms/ab2d/optout/OptOutProcessor.java similarity index 97% rename from optout/src/main/java/gov/cms/ab2d/optout/OptOutProcessing.java rename to optout/src/main/java/gov/cms/ab2d/optout/OptOutProcessor.java index c10181a..99e876c 100644 --- a/optout/src/main/java/gov/cms/ab2d/optout/OptOutProcessing.java +++ b/optout/src/main/java/gov/cms/ab2d/optout/OptOutProcessor.java @@ -21,12 +21,12 @@ import static gov.cms.ab2d.optout.OptOutConstants.*; -public class OptOutProcessing { +public class OptOutProcessor { private final LambdaLogger logger; public SortedMap optOutResultMap; private final OptOutS3 optOutS3; - public OptOutProcessing(String fileName, String endpoint, LambdaLogger logger) throws URISyntaxException { + public OptOutProcessor(String fileName, String endpoint, LambdaLogger logger) throws URISyntaxException { this.logger = logger; this.optOutResultMap = new TreeMap<>(); var s3Client = S3Client.builder() diff --git a/optout/src/test/java/gov/cms/ab2d/optout/OptOutHandlerTest.java b/optout/src/test/java/gov/cms/ab2d/optout/OptOutHandlerTest.java index 6631df7..3d148c9 100644 --- a/optout/src/test/java/gov/cms/ab2d/optout/OptOutHandlerTest.java +++ b/optout/src/test/java/gov/cms/ab2d/optout/OptOutHandlerTest.java @@ -26,7 +26,7 @@ public class OptOutHandlerTest { @Container private static final PostgreSQLContainer POSTGRE_SQL_CONTAINER = new AB2DPostgresqlContainer(); private final static OptOutHandler handler = spy(new OptOutHandler()); - private final static OptOutProcessing optOutProcessing = mock(OptOutProcessing.class); + private final static OptOutProcessor OPT_OUT_PROCESSOR = mock(OptOutProcessor.class); private final static SQSEvent sqsEvent = mock(SQSEvent.class); private final static SQSEvent.SQSMessage sqsMessage = mock(SQSEvent.SQSMessage.class); @@ -34,7 +34,7 @@ public class OptOutHandlerTest { static void beforeAll() throws URISyntaxException { when(sqsEvent.getRecords()).thenReturn(Collections.singletonList(sqsMessage)); when(sqsMessage.getBody()).thenReturn("optOutDummy.txt"); - when(handler.processingInit(anyString(), any(LambdaLogger.class))).thenReturn(optOutProcessing); + when(handler.processorInit(anyString(), any(LambdaLogger.class))).thenReturn(OPT_OUT_PROCESSOR); } @Test @@ -48,7 +48,7 @@ void optOutHandlerInvoke() { @Test void optOutHandlerException() { - doThrow(new OptOutException("errorMessage", new AmazonS3Exception("errorMessage"))).when(optOutProcessing).process(); - assertThrows(OptOutException.class, optOutProcessing::process); + doThrow(new OptOutException("errorMessage", new AmazonS3Exception("errorMessage"))).when(OPT_OUT_PROCESSOR).process(); + assertThrows(OptOutException.class, OPT_OUT_PROCESSOR::process); } } diff --git a/optout/src/test/java/gov/cms/ab2d/optout/OptOutProcessingTest.java b/optout/src/test/java/gov/cms/ab2d/optout/OptOutProcessorTest.java similarity index 67% rename from optout/src/test/java/gov/cms/ab2d/optout/OptOutProcessingTest.java rename to optout/src/test/java/gov/cms/ab2d/optout/OptOutProcessorTest.java index 596c541..fb7477c 100644 --- a/optout/src/test/java/gov/cms/ab2d/optout/OptOutProcessingTest.java +++ b/optout/src/test/java/gov/cms/ab2d/optout/OptOutProcessorTest.java @@ -27,7 +27,7 @@ import static org.mockito.Mockito.*; @ExtendWith({S3MockAPIExtension.class}) -public class OptOutProcessingTest { +public class OptOutProcessorTest { private static final LambdaLogger logger = mock(LambdaLogger.class); private static final Connection dbConnection = mock(Connection.class); private static final PreparedStatement statement = mock(PreparedStatement.class); @@ -35,7 +35,7 @@ public class OptOutProcessingTest { private static final String VALID_LINE = MBI + " NAME LASTNAME 111 DUMMY ADDRESS TESTDATA DUMMY11DUMMY20230726202307261-800TY"; private final String INVALID_LINE = "TRL_BENEDATARSP202307260000000009"; private final String EXPECTED_ACCEPTED_LINE = VALID_LINE + " Accepted 00"; - static OptOutProcessing optOutProcessing; + static OptOutProcessor optOutProcessor; @BeforeAll static void beforeAll() throws SQLException { @@ -47,24 +47,24 @@ static void beforeAll() throws SQLException { @BeforeEach void beforeEach() throws URISyntaxException { // var creds = StaticCredentialsProvider.create(AwsSessionCredentials.create("test", "test", "")); - optOutProcessing = spy(new OptOutProcessing(TEST_FILE_NAME, TEST_ENDPOINT, logger)); + optOutProcessor = spy(new OptOutProcessor(TEST_FILE_NAME, TEST_ENDPOINT, logger)); } @Test void processTest() throws IOException { S3MockAPIExtension.createFile(Files.readString(Paths.get("src/test/resources/" + TEST_FILE_NAME), StandardCharsets.UTF_8)); - optOutProcessing.process(); - assertEquals(4, optOutProcessing.optOutResultMap.size()); - verify(optOutProcessing, times(4)).createOptOutInformation(anyString(), anyLong()); - verify(optOutProcessing, times(2)).updateOptOut(any(OptOutInformation.class), any(Connection.class)); - verify(optOutProcessing, times(1)).createResponseContent(); + optOutProcessor.process(); + assertEquals(4, optOutProcessor.optOutResultMap.size()); + verify(optOutProcessor, times(4)).createOptOutInformation(anyString(), anyLong()); + verify(optOutProcessor, times(2)).updateOptOut(any(OptOutInformation.class), any(Connection.class)); + verify(optOutProcessor, times(1)).createResponseContent(); //Because map contains records with insertion error Assertions.assertTrue(S3MockAPIExtension.isObjectExists(TEST_FILE_NAME)); } @Test void createOptOutInformationValidTest1() { - Optional optOutInformation = optOutProcessing.createOptOutInformation(VALID_LINE, 1L); + Optional optOutInformation = optOutProcessor.createOptOutInformation(VALID_LINE, 1L); assertTrue(optOutInformation.isPresent()); assertEquals(1L, optOutInformation.get().getLineNumber()); assertEquals(VALID_LINE, optOutInformation.get().getText()); @@ -74,71 +74,71 @@ void createOptOutInformationValidTest1() { @Test void createOptOutInformationValidTest2() { - Optional optOutInformation = optOutProcessing.createOptOutInformation(VALID_LINE.substring(0, VALID_LINE.length() - 1) + 'N', 1L); + Optional optOutInformation = optOutProcessor.createOptOutInformation(VALID_LINE.substring(0, VALID_LINE.length() - 1) + 'N', 1L); assertTrue(optOutInformation.isPresent()); assertFalse(optOutInformation.get().isOptOut()); } @Test void optOutResultMapValidTest() { - optOutProcessing.createOptOutInformation(VALID_LINE, 1L); - assertEquals(1, optOutProcessing.optOutResultMap.size()); - OptOutResult mapValue = optOutProcessing.optOutResultMap.get(1L); + optOutProcessor.createOptOutInformation(VALID_LINE, 1L); + assertEquals(1, optOutProcessor.optOutResultMap.size()); + OptOutResult mapValue = optOutProcessor.optOutResultMap.get(1L); assertEquals(ReasonCode.ACCEPTED, mapValue.getReasonCode()); assertEquals(RecordStatus.ACCEPTED, mapValue.getRecordStatus()); } @Test void createOptOutInformationInvalidTest() { - var optOutInformation = optOutProcessing.createOptOutInformation(INVALID_LINE, 0L); + var optOutInformation = optOutProcessor.createOptOutInformation(INVALID_LINE, 0L); assertFalse(optOutInformation.isPresent()); } @Test void optOutResultMapParseErrorTest() { - optOutProcessing.createOptOutInformation(INVALID_LINE, 0L); - assertEquals(1, optOutProcessing.optOutResultMap.size()); - var mapValue = optOutProcessing.optOutResultMap.get(0L); + optOutProcessor.createOptOutInformation(INVALID_LINE, 0L); + assertEquals(1, optOutProcessor.optOutResultMap.size()); + var mapValue = optOutProcessor.optOutResultMap.get(0L); assertEquals(ReasonCode.PARSE_ERROR, mapValue.getReasonCode()); assertEquals(RecordStatus.REJECTED, mapValue.getRecordStatus()); } @Test void createResponseOptOutContentTest() { - optOutProcessing.createOptOutInformation(VALID_LINE, 1L); - assertEquals(EXPECTED_ACCEPTED_LINE, optOutProcessing.createResponseContent()); + optOutProcessor.createOptOutInformation(VALID_LINE, 1L); + assertEquals(EXPECTED_ACCEPTED_LINE, optOutProcessor.createResponseContent()); } @Test void createMultipleResponseOptOutContentTest() throws ParseException { - optOutProcessing.optOutResultMap.put(0L, new OptOutResult(new OptOutInformation(0L, INVALID_LINE), RecordStatus.REJECTED, ReasonCode.PARSE_ERROR)); - optOutProcessing.optOutResultMap.put(1L, new OptOutResult(new OptOutInformation(MBI, getTestTimestamp(), true, 1L, VALID_LINE), RecordStatus.ACCEPTED, ReasonCode.ACCEPTED)); - optOutProcessing.optOutResultMap.put(2L, new OptOutResult(new OptOutInformation(2L, INVALID_LINE), RecordStatus.REJECTED, ReasonCode.PARSE_ERROR)); + optOutProcessor.optOutResultMap.put(0L, new OptOutResult(new OptOutInformation(0L, INVALID_LINE), RecordStatus.REJECTED, ReasonCode.PARSE_ERROR)); + optOutProcessor.optOutResultMap.put(1L, new OptOutResult(new OptOutInformation(MBI, getTestTimestamp(), true, 1L, VALID_LINE), RecordStatus.ACCEPTED, ReasonCode.ACCEPTED)); + optOutProcessor.optOutResultMap.put(2L, new OptOutResult(new OptOutInformation(2L, INVALID_LINE), RecordStatus.REJECTED, ReasonCode.PARSE_ERROR)); var expectedText = INVALID_LINE + LINE_SEPARATOR + EXPECTED_ACCEPTED_LINE + LINE_SEPARATOR + INVALID_LINE; - assertEquals(expectedText, optOutProcessing.createResponseContent()); + assertEquals(expectedText, optOutProcessor.createResponseContent()); } @Test void updateOptOutTest() { - Optional optOutInformation = optOutProcessing.createOptOutInformation(VALID_LINE, 1L); + Optional optOutInformation = optOutProcessor.createOptOutInformation(VALID_LINE, 1L); assertTrue(optOutInformation.isPresent()); - optOutProcessing.updateOptOut(optOutInformation.get(), dbConnection); - assertEquals(1, optOutProcessing.optOutResultMap.size()); - OptOutResult mapValue = optOutProcessing.optOutResultMap.get(1L); + optOutProcessor.updateOptOut(optOutInformation.get(), dbConnection); + assertEquals(1, optOutProcessor.optOutResultMap.size()); + OptOutResult mapValue = optOutProcessor.optOutResultMap.get(1L); assertEquals(ReasonCode.ACCEPTED, mapValue.getReasonCode()); assertEquals(RecordStatus.ACCEPTED, mapValue.getRecordStatus()); } @Test void updateOptOutInvalidTest() throws SQLException { - Optional optOutInformation = optOutProcessing.createOptOutInformation(VALID_LINE, 1L); + Optional optOutInformation = optOutProcessor.createOptOutInformation(VALID_LINE, 1L); when(dbConnection.prepareStatement(anyString())).thenThrow(SQLException.class); assertTrue(optOutInformation.isPresent()); - optOutProcessing.updateOptOut(optOutInformation.get(), dbConnection); - assertEquals(1, optOutProcessing.optOutResultMap.size()); - OptOutResult mapValue = optOutProcessing.optOutResultMap.get(1L); + optOutProcessor.updateOptOut(optOutInformation.get(), dbConnection); + assertEquals(1, optOutProcessor.optOutResultMap.size()); + OptOutResult mapValue = optOutProcessor.optOutResultMap.get(1L); assertEquals(ReasonCode.INSERT_ERROR, mapValue.getReasonCode()); assertEquals(RecordStatus.REJECTED, mapValue.getRecordStatus()); }