Skip to content

Commit

Permalink
Fix Sonarqube
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnovaae committed Apr 25, 2024
1 parent 7b8719e commit dd58b45
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gov.cms.ab2d.attributionDataShare;
package gov.cms.ab2d.attributiondatashare;

import software.amazon.awssdk.regions.Region;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gov.cms.ab2d.attributionDataShare;
package gov.cms.ab2d.attributiondatashare;

public class AttributionDataShareException extends RuntimeException {
public AttributionDataShareException(String message, Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gov.cms.ab2d.attributionDataShare;
package gov.cms.ab2d.attributiondatashare;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
Expand All @@ -12,14 +12,13 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

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

public class AttributionDataShareHandler implements RequestStreamHandler {

Expand All @@ -41,15 +40,15 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
helper.copyDataToFile(dbConnection);
helper.uploadToS3(getAsyncS3Client(ENDPOINT, parameterStore));

} catch (NullPointerException | URISyntaxException | SQLException ex) {
} catch (NullPointerException | SQLException ex) {
throwAttributionDataShareException(logger, ex);
} finally {
FileUtil.deleteDirectoryRecursion(Paths.get(fileFullPath));
logger.log("AttributionDataShare Lambda is completed");
}
}

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

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

import com.amazonaws.services.lambda.runtime.LambdaLogger;
import software.amazon.awssdk.services.s3.S3AsyncClient;
Expand All @@ -16,7 +16,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;

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

public class AttributionDataShareHelper {
LambdaLogger logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package gov.cms.ab2d.attributionDataShare;
package gov.cms.ab2d.attributiondatashare;

import software.amazon.awssdk.services.ssm.SsmClient;
import software.amazon.awssdk.services.ssm.model.GetParameterRequest;

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

public class AttributionParameterStore {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gov.cms.ab2d.attributionDataShare;
package gov.cms.ab2d.attributiondatashare;

import com.amazonaws.services.lambda.runtime.LambdaLogger;
import gov.cms.ab2d.testutils.AB2DPostgresqlContainer;
Expand All @@ -8,11 +8,10 @@
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.DriverManager;

import static gov.cms.ab2d.attributionDataShare.AttributionDataShareConstants.TEST_ENDPOINT;
import static gov.cms.ab2d.attributiondatashare.AttributionDataShareConstants.TEST_ENDPOINT;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

Expand Down Expand Up @@ -50,7 +49,7 @@ void attributionDataShareExceptionTest() {
}

@Test
void getS3ClientTest() throws URISyntaxException {
void getS3ClientTest() {
assertNotNull(handler.getAsyncS3Client(TEST_ENDPOINT, parameterStore));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gov.cms.ab2d.attributionDataShare;
package gov.cms.ab2d.attributiondatashare;

import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.mockrunner.mock.jdbc.MockResultSet;
Expand All @@ -22,16 +22,16 @@
import java.text.SimpleDateFormat;
import java.util.*;

import static gov.cms.ab2d.attributionDataShare.AttributionDataShareConstants.*;
import static gov.cms.ab2d.attributionDataShare.AttributionDataShareHelper.getExecuteQuery;
import static gov.cms.ab2d.attributionDataShare.S3MockAPIExtension.getBucketName;
import static gov.cms.ab2d.attributionDataShare.S3MockAPIExtension.getUploadPath;
import static gov.cms.ab2d.attributiondatashare.AttributionDataShareConstants.*;
import static gov.cms.ab2d.attributiondatashare.AttributionDataShareHelper.getExecuteQuery;
import static gov.cms.ab2d.attributiondatashare.S3MockAPIExtension.getBucketName;
import static gov.cms.ab2d.attributiondatashare.S3MockAPIExtension.getUploadPath;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

@Testcontainers
@ExtendWith({S3MockAPIExtension.class})
public class AttributionDataShareTest {
class AttributionDataShareTest {
@SuppressWarnings({"rawtypes", "unused"})
@Container
private static final PostgreSQLContainer POSTGRE_SQL_CONTAINER = new AB2DPostgresqlContainer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gov.cms.ab2d.attributionDataShare;
package gov.cms.ab2d.attributiondatashare;

import io.findify.s3mock.S3Mock;
import org.junit.jupiter.api.extension.BeforeAllCallback;
Expand All @@ -8,7 +8,7 @@

import java.net.URI;

import static gov.cms.ab2d.attributionDataShare.AttributionDataShareConstants.*;
import static gov.cms.ab2d.attributiondatashare.AttributionDataShareConstants.*;
import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL;

public class S3MockAPIExtension implements BeforeAllCallback, ExtensionContext.Store.CloseableResource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.nio.file.Path;

public class FileUtil {

private FileUtil() {}
public static void deleteDirectoryRecursion(Path path) throws IOException {
if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) {
try (DirectoryStream<Path> entries = Files.newDirectoryStream(path)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;

public class FileUtilTest {
class FileUtilTest {
final Path FILE_PATH = Paths.get("/tmp/opt/");
final String FILE_NAME = "testFile.txt";

Expand Down
2 changes: 1 addition & 1 deletion optout/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test {

sonarqube {
properties {
property 'sonar.coverage.exclusions', "**/OptOutParameterStore.java"
property 'sonar.coverage.exclusions', "**/OptOutParameterStore.java, **/OptOutConstants.java"
}
}

Expand Down
8 changes: 4 additions & 4 deletions optout/src/main/java/gov/cms/ab2d/optout/OptOutHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public OptOutProcessor processorInit(LambdaLogger logger) {
return new OptOutProcessor(logger);
}

public String getBucketName(S3EventNotification.S3EventNotificationRecord record) {
return record.getS3().getBucket().getName();
public String getBucketName(S3EventNotification.S3EventNotificationRecord notificationRecord) {
return notificationRecord.getS3().getBucket().getName();
}

public String getFileName(S3EventNotification.S3EventNotificationRecord record) {
return record.getS3().getObject().getUrlDecodedKey();
public String getFileName(S3EventNotification.S3EventNotificationRecord notificationRecord) {
return notificationRecord.getS3().getObject().getUrlDecodedKey();
}
}
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 @@ -93,8 +93,8 @@ public OptOutInformation createOptOutInformation(String information) {
}

public void updateOptOut() {
try (var dbConnection = DriverManager.getConnection(parameterStore.getDbHost(), parameterStore.getDbUser(), parameterStore.getDbPassword())){
var statement = dbConnection.prepareStatement(UPDATE_STATEMENT);
try (var dbConnection = DriverManager.getConnection(parameterStore.getDbHost(), parameterStore.getDbUser(), parameterStore.getDbPassword());
var statement = dbConnection.prepareStatement(UPDATE_STATEMENT)) {
for (var optOutInformation : optOutInformationList) {
statement.setBoolean(1, optOutInformation.getOptOutFlag());
statement.setString(2, optOutInformation.getMbi());
Expand All @@ -106,6 +106,7 @@ public void updateOptOut() {
isRejected = true;
}
}

public String createResponseContent() {
var date = new SimpleDateFormat(EFFECTIVE_DATE_PATTERN).format(new Date());
var responseContent = new StringBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static org.mockito.Mockito.*;

@Testcontainers
public class OptOutHandlerTest {
class OptOutHandlerTest {

@SuppressWarnings({"rawtypes", "unused"})
@Container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import static org.mockito.Mockito.*;

@ExtendWith({S3MockAPIExtension.class})
public class OptOutProcessorTest {
class OptOutProcessorTest {
private static final Connection dbConnection = mock(Connection.class);
private static final MockedStatic<OptOutParameterStore> parameterStore = mockStatic(OptOutParameterStore.class);
private static final String DATE = new SimpleDateFormat(EFFECTIVE_DATE_PATTERN).format(new Date());
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 @@ -20,7 +20,7 @@
import static org.mockito.Mockito.mock;

@ExtendWith({S3MockAPIExtension.class})
public class OptOutS3Test {
class OptOutS3Test {

private static OptOutS3 OPT_OUT_S3;

Expand Down

0 comments on commit dd58b45

Please sign in to comment.