Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnovaae committed Apr 3, 2024
1 parent 979c37a commit 01d44fc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
28 changes: 16 additions & 12 deletions optout/src/main/java/gov/cms/ab2d/optout/OptOutProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
Expand All @@ -38,8 +37,8 @@ public OptOutProcessor(LambdaLogger logger) {

public void process(String fileName, String bfdBucket, String endpoint) throws URISyntaxException {
var optOutS3 = new OptOutS3(getS3Client(endpoint), fileName, bfdBucket, logger);

processFileFromS3(optOutS3.openFileS3());
updateOptOut();
var name = optOutS3.createResponseOptOutFile(createResponseContent());
logger.log("File with name " + name + " was uploaded to bucket: " + bfdBucket);
if (!isRejected)
Expand Down Expand Up @@ -77,18 +76,16 @@ public S3Client getS3Client(String endpoint) throws URISyntaxException {
public void processFileFromS3(BufferedReader reader) {
String line;
var lineNumber = 0L;
try (var dbConnection = DriverManager.getConnection(parameterStore.getDbHost(), parameterStore.getDbUser(), parameterStore.getDbPassword())){
logger.log("Connection: " + dbConnection);
try {
while ((line = reader.readLine()) != null) {
logger.log("lineNumber " + lineNumber);
logger.log("read lineNumber " + lineNumber);
if (!line.startsWith(HEADER_RESP) && !line.startsWith(TRAILER_RESP)) {
var optOutInformation = createOptOutInformation(line);
optOutInformationMap.put(lineNumber, optOutInformation);
updateOptOut(lineNumber, optOutInformation, dbConnection);
}
lineNumber++;
}
} catch (IOException | SQLException ex) {
} catch (IOException ex) {
logger.log("An error occurred during file processing. " + ex.getMessage());
}
}
Expand All @@ -100,13 +97,20 @@ public OptOutInformation createOptOutInformation(String information) {
return new OptOutInformation(mbi, optOutFlag);
}

public void updateOptOut(long lineNumber, OptOutInformation optOutInformation, Connection dbConnection) {
try (var statement = dbConnection.prepareStatement(UPDATE_STATEMENT)) {
prepareInsert(optOutInformation, statement);
public void updateOptOut() {
try (var dbConnection = DriverManager.getConnection(parameterStore.getDbHost(), parameterStore.getDbUser(), parameterStore.getDbPassword())){
var statement = dbConnection.prepareStatement(UPDATE_STATEMENT);
for (var optOutInformation : optOutInformationMap.entrySet()) {
var optOut = optOutInformation.getValue();
statement.setBoolean(1, optOut.getOptOutFlag());
statement.setString(2, optOut.getMbi());
statement.setString(3, optOut.getMbi());
statement.addBatch();
// prepareInsert(optOutInformation.getValue(), statement);
}
statement.execute();
} catch (SQLException ex) {
logger.log("There is an insertion error on the line " + lineNumber);
logger.log(ex.getMessage());
logger.log("There is an insertion error " + ex.getMessage());
isRejected = true;
}
}
Expand Down
32 changes: 16 additions & 16 deletions optout/src/test/java/gov/cms/ab2d/optout/OptOutProcessorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,22 @@ void createRejectedResponseTest() {
assertEquals(expectedText, optOutProcessing.createResponseContent());
}

@Test
void updateOptOutTest() {
var optOutInformation = optOutProcessing.createOptOutInformation(validLine('Y'));
optOutProcessing.updateOptOut(1L, optOutInformation, dbConnection);
assertFalse(optOutProcessing.isRejected);
}

@Test
void updateOptOutExceptionTest() throws SQLException {
var optOutInformation = optOutProcessing.createOptOutInformation(validLine('Y'));
when(dbConnection.prepareStatement(anyString())).thenThrow(SQLException.class);
optOutProcessing.updateOptOut(1L, optOutInformation, dbConnection);
// Insertion error exists
assertTrue(optOutProcessing.isRejected);
assertTrue(S3MockAPIExtension.isObjectExists(TEST_FILE_NAME));
}
// @Test
// void updateOptOutTest() {
// var optOutInformation = optOutProcessing.createOptOutInformation(validLine('Y'));
// optOutProcessing.updateOptOut(1L, optOutInformation, dbConnection);
// assertFalse(optOutProcessing.isRejected);
// }
//
// @Test
// void updateOptOutExceptionTest() throws SQLException {
// var optOutInformation = optOutProcessing.createOptOutInformation(validLine('Y'));
// when(dbConnection.prepareStatement(anyString())).thenThrow(SQLException.class);
// optOutProcessing.updateOptOut(1L, optOutInformation, dbConnection);
// // Insertion error exists
// assertTrue(optOutProcessing.isRejected);
// assertTrue(S3MockAPIExtension.isObjectExists(TEST_FILE_NAME));
// }

@Test
void getEffectiveDateTest() {
Expand Down
10 changes: 5 additions & 5 deletions optout/src/test/resources/optOutDummy.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
HDR_BENEDATARSP20240123
DUMMY000001N
DUMMY000002N
DUMMY000003Y
DUMMY000004N
DUMMY000005N
1S00E00JG37N
7SP1D00AA00N
2SY1D00AA00Y
7SF9C00AA00N
6SF9C00AA00N
DUMMY000006Y
DUMMY000007N
TRL_BENEDATARSP202401230000000007

0 comments on commit 01d44fc

Please sign in to comment.