Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AB2D-6043 Blank spaces if optout is null #98

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading