Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnovaae committed Mar 11, 2024
1 parent 982beb2 commit e62c933
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 14 deletions.
3 changes: 0 additions & 3 deletions optout/src/main/java/gov/cms/ab2d/optout/OptOutConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

public class OptOutConstants {
public static final String ENDPOINT = "https://s3.amazonaws.com";
public static final String TEST_ENDPOINT = "http://127.0.0.1:8001";
public static final String TEST_FILE_NAME = "optOutDummy.txt";
public static final String TEST_BFD_BUCKET_NAME = "bfd-test-eft";
public static final Region S3_REGION = Region.US_EAST_1;
public static final String HEADER_RESP = "HDR_BENEDATARSP";
public static final String TRAILER_RESP = "TLR_BENEDATARSP";
Expand Down
11 changes: 11 additions & 0 deletions optout/src/test/java/gov/cms/ab2d/optout/OptOutConstantsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package gov.cms.ab2d.optout;

public class OptOutConstantsTest {
public static final String TEST_ENDPOINT = "http://127.0.0.1:8001";
public static final String TEST_FILE_NAME = "optOutDummy.txt";
public static final String TEST_BUCKET_PATH = "bfdeft01/ab2d";
public static final String TEST_BFD_BUCKET_NAME = "bfd-test-eft";

private OptOutConstantsTest() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.file.Paths;
import java.util.Collections;

import static gov.cms.ab2d.optout.OptOutConstantsTest.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -51,8 +52,8 @@ void getBucketAndFileNamesTest() throws IOException, ParseException {

var notification = S3EventNotification.parseJson(s3EventMessage.toString()).getRecords().get(0);

assertEquals("bfdeft01/ab2d/in/optOutDummy.txt", handler.getFileName(notification));
assertEquals("bfd-test-eft", handler.getBucketName(notification));
assertEquals(TEST_BUCKET_PATH + "/in/" + TEST_FILE_NAME, handler.getFileName(notification));
assertEquals(TEST_BFD_BUCKET_NAME, handler.getBucketName(notification));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.ExtendWith;

import java.io.IOException;
Expand All @@ -22,6 +21,7 @@
import java.util.Date;

import static gov.cms.ab2d.optout.OptOutConstants.*;
import static gov.cms.ab2d.optout.OptOutConstantsTest.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

Expand Down
9 changes: 5 additions & 4 deletions optout/src/test/java/gov/cms/ab2d/optout/OptOutS3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import java.nio.file.Files;
import java.nio.file.Paths;

import static gov.cms.ab2d.optout.OptOutConstants.*;
import static gov.cms.ab2d.optout.OptOutConstants.CONF_FILE_FORMAT;
import static gov.cms.ab2d.optout.OptOutConstants.CONF_FILE_NAME;
import static gov.cms.ab2d.optout.OptOutConstantsTest.*;
import static gov.cms.ab2d.optout.S3MockAPIExtension.S3_CLIENT;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -60,10 +62,9 @@ void deleteFileFromS3Test() {

@Test
void getOutFileName() {
var subFolders = "bfdeft01/ab2d";
OPT_OUT_S3 = new OptOutS3(S3_CLIENT, subFolders + "/in/" + TEST_FILE_NAME, TEST_BFD_BUCKET_NAME, mock(LambdaLogger.class));
OPT_OUT_S3 = new OptOutS3(S3_CLIENT, TEST_BUCKET_PATH + "/in/" + TEST_FILE_NAME, TEST_BFD_BUCKET_NAME, mock(LambdaLogger.class));
var outFileName = OPT_OUT_S3.getOutFileName();
Assertions.assertTrue(outFileName.startsWith(subFolders + "/out/" + CONF_FILE_NAME));
Assertions.assertTrue(outFileName.startsWith(TEST_BUCKET_PATH + "/out/" + CONF_FILE_NAME));
Assertions.assertTrue(outFileName.endsWith(CONF_FILE_FORMAT));
}
}
11 changes: 7 additions & 4 deletions optout/src/test/java/gov/cms/ab2d/optout/S3MockAPIExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import org.junit.jupiter.api.extension.ExtensionContext;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3ClientBuilder;
import software.amazon.awssdk.services.s3.model.*;

import java.net.URI;

import static gov.cms.ab2d.optout.OptOutConstants.*;
import static gov.cms.ab2d.optout.OptOutConstants.S3_REGION;
import static gov.cms.ab2d.optout.OptOutConstantsTest.*;
import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL;

public class S3MockAPIExtension implements BeforeAllCallback, ExtensionContext.Store.CloseableResource {
Expand All @@ -25,9 +27,10 @@ public void beforeAll(ExtensionContext context) throws Exception {

API.start();

S3_CLIENT = S3Client.builder()
.region(S3_REGION)
.endpointOverride(new URI(TEST_ENDPOINT))
S3ClientBuilder builder = S3Client.builder();
builder.region(S3_REGION);
builder.endpointOverride(new URI(TEST_ENDPOINT));
S3_CLIENT = builder
.build();

createBucket();
Expand Down

0 comments on commit e62c933

Please sign in to comment.