Skip to content

Commit

Permalink
Fix duplicate lines in sonarqube
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnovaae committed Nov 15, 2024
1 parent dba52d4 commit 056895f
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 98 deletions.
1 change: 0 additions & 1 deletion attribution-data-file-share/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ dependencies {
implementation 'software.amazon.awssdk:s3-transfer-manager:2.25.7'
implementation 'software.amazon.awssdk.crt:aws-crt:0.29.11'
implementation 'org.postgresql:postgresql:42.7.2'
implementation 'software.amazon.awssdk:ssm:2.25.7'
implementation 'software.amazon.awssdk:sts:2.25.6'
implementation project(path: ':lambda-lib')
testImplementation 'org.mockito:mockito-core:4.8.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
import gov.cms.ab2d.lambdalibs.lib.FileUtil;
import gov.cms.ab2d.lambdalibs.lib.ParameterStoreUtil;
import software.amazon.awssdk.services.s3.S3AsyncClient;
import software.amazon.awssdk.services.sts.StsClient;
import software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider;
Expand Down Expand Up @@ -33,7 +34,7 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
var prefix = (System.getenv(BUCKET_NAME_PROP).contains("prod")) ? "P" : "T";
String fileName = prefix + REQ_FILE_NAME + currentDate;
String fileFullPath = FILE_PATH + fileName;
var parameterStore = AttributionParameterStore.getParameterStore();
var parameterStore = ParameterStoreUtil.getParameterStore(ROLE_PARAM, DB_HOST_PARAM, DB_USER_PARAM, DB_PASS_PARAM);
AttributionDataShareHelper helper = helperInit(fileName, fileFullPath, logger);
try (var dbConnection = DriverManager.getConnection(parameterStore.getDbHost(), parameterStore.getDbUser(), parameterStore.getDbPassword())) {

Expand All @@ -48,7 +49,7 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
}
}

public S3AsyncClient getAsyncS3Client(String endpoint, AttributionParameterStore parameterStore) {
public S3AsyncClient getAsyncS3Client(String endpoint, ParameterStoreUtil parameterStore) {
var client = S3AsyncClient.crtCreate();

if (endpoint.equals(ENDPOINT)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gov.cms.ab2d.attributiondatashare;

import com.amazonaws.services.lambda.runtime.LambdaLogger;
import gov.cms.ab2d.lambdalibs.lib.ParameterStoreUtil;
import gov.cms.ab2d.testutils.AB2DPostgresqlContainer;
import gov.cms.ab2d.testutils.TestContext;
import org.junit.jupiter.api.Test;
Expand All @@ -22,15 +23,15 @@ class AttributionDataShareHandlerTest {
@Container
private static final PostgreSQLContainer POSTGRE_SQL_CONTAINER = new AB2DPostgresqlContainer();
LambdaLogger LOGGER = mock(LambdaLogger.class);
AttributionParameterStore parameterStore = new AttributionParameterStore("", "", "", "");
ParameterStoreUtil parameterStore = new ParameterStoreUtil("", "", "", "");
AttributionDataShareHelper helper = mock(AttributionDataShareHelper.class);
AttributionDataShareHandler handler = spy(new AttributionDataShareHandler());

@Test
void attributionDataShareInvoke() {
var mockParameterStore = mockStatic(AttributionParameterStore.class);
var mockParameterStore = mockStatic(ParameterStoreUtil.class);
mockParameterStore
.when(AttributionParameterStore::getParameterStore)
.when(() -> ParameterStoreUtil.getParameterStore(anyString(), anyString(), anyString(), anyString()))
.thenReturn(parameterStore);

Connection dbConnection = mock(Connection.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
package gov.cms.ab2d.attributiondatashare;
package gov.cms.ab2d.lambdalibs.lib;

import gov.cms.ab2d.lambdalibs.lib.SsmClientUtil;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.ssm.SsmClient;
import software.amazon.awssdk.services.ssm.model.GetParameterRequest;

import static gov.cms.ab2d.attributiondatashare.AttributionDataShareConstants.*;

public class AttributionParameterStore {
public class ParameterStoreUtil {

private final String role;
private final String dbHost;
private final String dbUser;
private final String dbPassword;

public AttributionParameterStore(String role, String dbHost, String dbUser, String dbPassword) {
public ParameterStoreUtil(String role, String dbHost, String dbUser, String dbPassword) {
this.role = role;
this.dbHost = dbHost;
this.dbUser = dbUser;
this.dbPassword = dbPassword;
}

public static AttributionParameterStore getParameterStore() {
var ssmClient = SsmClientUtil.getClient();
public static SsmClient getClient(){
return SsmClient.builder()
.region(Region.US_EAST_1)
.build();
}

public static ParameterStoreUtil getParameterStore(String roleParam, String dbHostParam, String dbUserParam, String dbPasswordParam) {
var ssmClient = ParameterStoreUtil.getClient();

var role = getValueFromParameterStore(ROLE_PARAM, ssmClient);
var dbHost = getValueFromParameterStore(DB_HOST_PARAM, ssmClient);
var dbUser = getValueFromParameterStore(DB_USER_PARAM, ssmClient);
var dbPassword = getValueFromParameterStore(DB_PASS_PARAM, ssmClient);
var role = getValueFromParameterStore(roleParam, ssmClient);
var dbHost = getValueFromParameterStore(dbHostParam, ssmClient);
var dbUser = getValueFromParameterStore(dbUserParam, ssmClient);
var dbPassword = getValueFromParameterStore(dbPasswordParam, ssmClient);

ssmClient.close();
return new AttributionParameterStore(role, dbHost, dbUser, dbPassword);
return new ParameterStoreUtil(role, dbHost, dbUser, dbPassword);
}

private static String getValueFromParameterStore(String key, SsmClient ssmClient) {
Expand Down Expand Up @@ -58,6 +62,3 @@ public String getRole() {
return role;
}
}



This file was deleted.

1 change: 0 additions & 1 deletion optout/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ dependencies {
implementation 'com.amazonaws:aws-java-sdk-s3:1.12.529'
implementation 'org.postgresql:postgresql:42.7.2'
implementation 'software.amazon.awssdk:s3:2.25.6'
implementation 'software.amazon.awssdk:ssm:2.25.7'
implementation 'software.amazon.awssdk:sts:2.25.6'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
implementation(project(":lambda-lib"))
Expand Down
56 changes: 0 additions & 56 deletions optout/src/main/java/gov/cms/ab2d/optout/OptOutParameterStore.java

This file was deleted.

5 changes: 3 additions & 2 deletions optout/src/main/java/gov/cms/ab2d/optout/OptOutProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.amazonaws.services.lambda.runtime.LambdaLogger;
import gov.cms.ab2d.lambdalibs.lib.ParameterStoreUtil;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.sts.StsClient;
import software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider;
Expand All @@ -26,13 +27,13 @@ public class OptOutProcessor {
public List<OptOutInformation> optOutInformationList;
public boolean isRejected;

OptOutParameterStore parameterStore;
ParameterStoreUtil parameterStore;

public OptOutProcessor(LambdaLogger logger) {
this.logger = logger;
this.optOutInformationList = new ArrayList<>();
isRejected = false;
parameterStore = OptOutParameterStore.getParameterStore();
parameterStore = ParameterStoreUtil.getParameterStore(ROLE_PARAM, DB_HOST_PARAM, DB_USER_PARAM, DB_PASS_PARAM);
}

public OptOutResults process(String fileName, String bfdBucket, String endpoint) throws URISyntaxException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.amazonaws.services.lambda.runtime.LambdaLogger;
import gov.cms.ab2d.lambdalibs.lib.ParameterStoreUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -32,7 +33,7 @@ class OptOutProcessorTest {
private static final ResultSet resultSet = mock(ResultSet.class);
private static final PreparedStatement preparedStatement = mock(PreparedStatement.class);
private static final Connection dbConnection = mock(Connection.class);
private static final MockedStatic<OptOutParameterStore> parameterStore = mockStatic(OptOutParameterStore.class);
private static final MockedStatic<ParameterStoreUtil> parameterStore = mockStatic(ParameterStoreUtil.class);
private static final String DATE = new SimpleDateFormat(EFFECTIVE_DATE_PATTERN).format(new Date());
private static final String MBI = "DUMMY000001";
private static final String TRAILER_COUNT = "0000000001";
Expand All @@ -43,8 +44,6 @@ private static String validLine(char isOptOut) {

@BeforeAll
static void beforeAll() throws SQLException {
parameterStore.when(OptOutParameterStore::getParameterStore).thenReturn(new OptOutParameterStore("", "", "", ""));

mockStatic(DriverManager.class)
.when(() -> DriverManager.getConnection(anyString(), anyString(), anyString())).thenReturn(dbConnection);
when(dbConnection.prepareStatement(anyString())).thenReturn(preparedStatement);
Expand All @@ -55,7 +54,9 @@ 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), TEST_FILE_NAME);
parameterStore.when(OptOutParameterStore::getParameterStore).thenReturn(new OptOutParameterStore("", "", "", ""));
parameterStore.
when(() -> ParameterStoreUtil.getParameterStore(anyString(), anyString(), anyString(), anyString()))
.thenReturn(new ParameterStoreUtil("", "", "", ""));
optOutProcessing = spy(new OptOutProcessor(mock(LambdaLogger.class)));
optOutProcessing.isRejected = false;
}
Expand Down

0 comments on commit 056895f

Please sign in to comment.