Skip to content

Commit

Permalink
unit test and AB2D-6043 Blank spaces if optout is null
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnovaae committed Mar 27, 2024
1 parent 57e64cd commit 7e7356c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ String getResponseLine(String currentMbi, Timestamp effectiveDate, Boolean optOu
result.append(new SimpleDateFormat(EFFECTIVE_DATE_PATTERN).format(effectiveDate));
result.append((optOutFlag) ? 'Y' : 'N');
}
return result.toString();
// Exactly 20 characters on each line.
// If the effective date and flag are null, additional spaces should be added at the end of string.
return String.format("%-20s", result);
}

public String uploadToS3(S3AsyncClient s3AsyncClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,15 @@ void copyDataToFileTest() throws IOException, SQLException {

@Test
void getResponseLineTest() {
assertEquals(MBI_1, helper.getResponseLine(MBI_1, null, null));
assertEquals(MBI_2 + "20240226N", helper.getResponseLine(MBI_2, DATE, false));
assertEquals("A 20240226Y", helper.getResponseLine("A", DATE, true));
var line1 = helper.getResponseLine(MBI_1, null, null);
var line2 = helper.getResponseLine(MBI_2, DATE, false);
var line3 = helper.getResponseLine("A", DATE, true);
assertEquals(20, line1.length());
assertEquals(20, line2.length());
assertEquals(20, line3.length());
assertEquals(MBI_1 + " ", line1);
assertEquals(MBI_2 + "20240226N", line2);
assertEquals("A 20240226Y", line3);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void beforeAll() throws SQLException {

@BeforeEach
void beforeEach() throws IOException {
S3MockAPIExtension.createFile(Files.readString(Paths.get("src/test/resources/" + TEST_FILE_NAME), StandardCharsets.UTF_8));
S3MockAPIExtension.createFile(Files.readString(Paths.get("src/test/resources/" + TEST_FILE_NAME), StandardCharsets.UTF_8), TEST_FILE_NAME);
parameterStore.when(OptOutParameterStore::getParameterStore).thenReturn(new OptOutParameterStore("", "", "", ""));
optOutProcessing = spy(new OptOutProcessor(mock(LambdaLogger.class)));
optOutProcessing.isRejected = false;
Expand All @@ -67,6 +67,15 @@ void processTest() throws URISyntaxException {
assertEquals(7, optOutProcessing.optOutInformationMap.size());
}

@Test
void processEmptyFileTest() throws IOException, URISyntaxException {
var emptyFileName = "emptyDummy.txt";
S3MockAPIExtension.createFile(Files.readString(Paths.get("src/test/resources/" + emptyFileName), StandardCharsets.UTF_8), emptyFileName);
optOutProcessing.process(emptyFileName, TEST_BFD_BUCKET_NAME, TEST_ENDPOINT);
assertEquals(0, optOutProcessing.optOutInformationMap.size());
S3MockAPIExtension.deleteFile(emptyFileName);
}

@Test
void createTrueOptOutInformationTest() {
var optOutInformation = optOutProcessing.createOptOutInformation(validLine('Y'));
Expand Down
2 changes: 1 addition & 1 deletion optout/src/test/java/gov/cms/ab2d/optout/OptOutS3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class OptOutS3Test {

@BeforeEach
public void beforeEach() throws IOException {
S3MockAPIExtension.createFile(Files.readString(Paths.get("src/test/resources/" + TEST_FILE_NAME), StandardCharsets.UTF_8));
S3MockAPIExtension.createFile(Files.readString(Paths.get("src/test/resources/" + TEST_FILE_NAME), StandardCharsets.UTF_8), TEST_FILE_NAME);
OPT_OUT_S3 = new OptOutS3(S3_CLIENT, TEST_FILE_NAME, TEST_BFD_BUCKET_NAME, mock(LambdaLogger.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ private static void createBucket() {
S3_CLIENT.createBucket(bucketRequest);
}

public static void createFile(String content) {
public static void createFile(String content, String fileName) {
var objectRequest = PutObjectRequest.builder()
.bucket(TEST_BFD_BUCKET_NAME)
.key(TEST_FILE_NAME)
.key(fileName)
.build();

S3_CLIENT.putObject(objectRequest, RequestBody.fromString(content));
Expand Down
2 changes: 2 additions & 0 deletions optout/src/test/resources/emptyDummy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
HDR_BENEDATARSP20240123
TRL_BENEDATARSP202401230000000000

0 comments on commit 7e7356c

Please sign in to comment.