From 9bea53d85ef62b711220e869225408084b26f202 Mon Sep 17 00:00:00 2001 From: davdarras Date: Wed, 10 Jul 2024 11:33:05 +0200 Subject: [PATCH] test: resolve sonar issues --- .../auth/GrantedAuthorityConverterTest.java | 34 +++++++++---------- .../controller/dummy/SchemaFakeComponent.java | 31 ----------------- .../service/dummy/DataFakeService.java | 2 +- .../service/dummy/SurveyUnitFakeService.java | 8 ++--- .../service/dummy/SurveyUnitFakeService.java | 8 ++--- 5 files changed, 26 insertions(+), 57 deletions(-) delete mode 100644 queen-application/src/test/java/fr/insee/queen/application/integration/controller/dummy/SchemaFakeComponent.java diff --git a/queen-application/src/test/java/fr/insee/queen/application/configuration/auth/GrantedAuthorityConverterTest.java b/queen-application/src/test/java/fr/insee/queen/application/configuration/auth/GrantedAuthorityConverterTest.java index a906e203..f0e39f61 100644 --- a/queen-application/src/test/java/fr/insee/queen/application/configuration/auth/GrantedAuthorityConverterTest.java +++ b/queen-application/src/test/java/fr/insee/queen/application/configuration/auth/GrantedAuthorityConverterTest.java @@ -26,12 +26,12 @@ class GrantedAuthorityConverterTest { private Map jwtHeaders; - private static final String jwtRoleInterviewer = "interviewer"; - private static final String jwtRoleReviewer = "reviewer"; - private static final String jwtRoleReviewerAlternative = "reviewerAlternative"; - private static final String jwtRoleAdmin = "admin"; - private static final String jwtRoleWebclient = "webclient"; - private static final String jwtRoleSurveyUnit = "surveyUnit"; + private static final String JWT_ROLE_INTERVIEWER = "interviewer"; + private static final String JWT_ROLE_REVIEWER = "reviewer"; + private static final String JWT_ROLE_REVIEWER_ALTERNATIVE = "reviewerAlternative"; + private static final String JWT_ROLE_ADMIN = "admin"; + private static final String JWT_ROLE_WEBCLIENT = "webclient"; + private static final String JWT_ROLE_SURVEY_UNIT = "surveyUnit"; @BeforeEach void init() { @@ -43,7 +43,7 @@ void init() { @Test @DisplayName("Given a JWT, when converting null or empty JWT role, then converting ignore these roles") void testConverter01() { - RoleProperties roleProperties = new RoleProperties("", null, jwtRoleAdmin, jwtRoleWebclient, jwtRoleReviewerAlternative, jwtRoleSurveyUnit); + RoleProperties roleProperties = new RoleProperties("", null, JWT_ROLE_ADMIN, JWT_ROLE_WEBCLIENT, JWT_ROLE_REVIEWER_ALTERNATIVE, JWT_ROLE_SURVEY_UNIT); converter = new GrantedAuthorityConverter(oidcProperties, roleProperties); Map claims = new HashMap<>(); List tokenRoles = new ArrayList<>(); @@ -60,7 +60,7 @@ void testConverter01() { @Test @DisplayName("Given a JWT, when converting roles, then convert only JWT roles matching roles in role properties") void testConverter02() { - RoleProperties roleProperties = new RoleProperties(jwtRoleInterviewer, jwtRoleReviewer, jwtRoleAdmin, jwtRoleWebclient, jwtRoleReviewerAlternative, jwtRoleSurveyUnit); + RoleProperties roleProperties = new RoleProperties(JWT_ROLE_INTERVIEWER, JWT_ROLE_REVIEWER, JWT_ROLE_ADMIN, JWT_ROLE_WEBCLIENT, JWT_ROLE_REVIEWER_ALTERNATIVE, JWT_ROLE_SURVEY_UNIT); converter = new GrantedAuthorityConverter(oidcProperties, roleProperties); Map claims = new HashMap<>(); List tokenRoles = List.of("dummyRole1", roleProperties.reviewer(), "dummyRole2", roleProperties.interviewer(), "dummyRole3", roleProperties.surveyUnit()); @@ -80,7 +80,7 @@ void testConverter02() { @MethodSource("provideJWTRoleWithAppRoleAssociated") @DisplayName("Given a JWT, when converting roles, then assure each JWT role is converted to equivalent app role") void testConverter03(String jwtRole, AuthorityRoleEnum appRole) { - RoleProperties roleProperties = new RoleProperties(jwtRoleInterviewer, jwtRoleReviewer, jwtRoleAdmin, jwtRoleWebclient, jwtRoleReviewerAlternative, jwtRoleSurveyUnit); + RoleProperties roleProperties = new RoleProperties(JWT_ROLE_INTERVIEWER, JWT_ROLE_REVIEWER, JWT_ROLE_ADMIN, JWT_ROLE_WEBCLIENT, JWT_ROLE_REVIEWER_ALTERNATIVE, JWT_ROLE_SURVEY_UNIT); converter = new GrantedAuthorityConverter(oidcProperties, roleProperties); Map claims = new HashMap<>(); List tokenRoles = List.of(jwtRole); @@ -97,11 +97,11 @@ void testConverter03(String jwtRole, AuthorityRoleEnum appRole) { @DisplayName("Given a JWT, when no role claim is defined, then default role claim is used") void testConverter04() { oidcProperties = new OidcProperties(true, "host", "url", "realm", "principal-attribute", "", "client-id"); - RoleProperties roleProperties = new RoleProperties(jwtRoleInterviewer, jwtRoleReviewer, jwtRoleAdmin, jwtRoleWebclient, jwtRoleReviewerAlternative, jwtRoleSurveyUnit); + RoleProperties roleProperties = new RoleProperties(JWT_ROLE_INTERVIEWER, JWT_ROLE_REVIEWER, JWT_ROLE_ADMIN, JWT_ROLE_WEBCLIENT, JWT_ROLE_REVIEWER_ALTERNATIVE, JWT_ROLE_SURVEY_UNIT); converter = new GrantedAuthorityConverter(oidcProperties, roleProperties); Map claims = new HashMap<>(); Map roleClaims = new HashMap<>(); - List tokenRoles = List.of(jwtRoleInterviewer, jwtRoleReviewer); + List tokenRoles = List.of(JWT_ROLE_INTERVIEWER, JWT_ROLE_REVIEWER); roleClaims.put(GrantedAuthorityConverter.ROLES, tokenRoles); claims.put(GrantedAuthorityConverter.REALM_ACCESS, roleClaims); @@ -115,11 +115,11 @@ void testConverter04() { private static Stream provideJWTRoleWithAppRoleAssociated() { return Stream.of( - Arguments.of(jwtRoleInterviewer, AuthorityRoleEnum.INTERVIEWER), - Arguments.of(jwtRoleReviewer, AuthorityRoleEnum.REVIEWER), - Arguments.of(jwtRoleReviewerAlternative, AuthorityRoleEnum.REVIEWER_ALTERNATIVE), - Arguments.of(jwtRoleAdmin, AuthorityRoleEnum.ADMIN), - Arguments.of(jwtRoleWebclient, AuthorityRoleEnum.WEBCLIENT), - Arguments.of(jwtRoleSurveyUnit, AuthorityRoleEnum.SURVEY_UNIT)); + Arguments.of(JWT_ROLE_INTERVIEWER, AuthorityRoleEnum.INTERVIEWER), + Arguments.of(JWT_ROLE_REVIEWER, AuthorityRoleEnum.REVIEWER), + Arguments.of(JWT_ROLE_REVIEWER_ALTERNATIVE, AuthorityRoleEnum.REVIEWER_ALTERNATIVE), + Arguments.of(JWT_ROLE_ADMIN, AuthorityRoleEnum.ADMIN), + Arguments.of(JWT_ROLE_WEBCLIENT, AuthorityRoleEnum.WEBCLIENT), + Arguments.of(JWT_ROLE_SURVEY_UNIT, AuthorityRoleEnum.SURVEY_UNIT)); } } diff --git a/queen-application/src/test/java/fr/insee/queen/application/integration/controller/dummy/SchemaFakeComponent.java b/queen-application/src/test/java/fr/insee/queen/application/integration/controller/dummy/SchemaFakeComponent.java deleted file mode 100644 index da110b91..00000000 --- a/queen-application/src/test/java/fr/insee/queen/application/integration/controller/dummy/SchemaFakeComponent.java +++ /dev/null @@ -1,31 +0,0 @@ -package fr.insee.queen.application.integration.controller.dummy; - -import fr.insee.queen.application.integration.component.builder.schema.SchemaComponent; -import fr.insee.queen.application.integration.component.exception.IntegrationValidationException; -import fr.insee.queen.application.web.validation.json.SchemaType; -import org.w3c.dom.Document; - -import java.io.InputStream; -import java.util.zip.ZipFile; - -public class SchemaFakeComponent implements SchemaComponent { - @Override - public void throwExceptionIfXmlDataFileNotValid(ZipFile zipFile, String xmlFileName, String xsdSchemaFileName) { - - } - - @Override - public void throwExceptionIfDataFileNotExist(ZipFile zipFile, String fileName) throws IntegrationValidationException { - - } - - @Override - public void throwExceptionIfJsonDataFileNotValid(ZipFile zipFile, String fileName, SchemaType schemaType) throws IntegrationValidationException { - - } - - @Override - public Document buildDocument(InputStream xmlFileStream) { - return null; - } -} diff --git a/queen-application/src/test/java/fr/insee/queen/application/surveyunit/service/dummy/DataFakeService.java b/queen-application/src/test/java/fr/insee/queen/application/surveyunit/service/dummy/DataFakeService.java index 01d31538..dee93d4c 100644 --- a/queen-application/src/test/java/fr/insee/queen/application/surveyunit/service/dummy/DataFakeService.java +++ b/queen-application/src/test/java/fr/insee/queen/application/surveyunit/service/dummy/DataFakeService.java @@ -15,7 +15,7 @@ public ObjectNode getData(String surveyUnitId) { @Override public void saveData(String surveyUnitId, ObjectNode dataValue) { - + // not used for test at this moment } @Override diff --git a/queen-domain-pilotage/src/test/java/fr/insee/queen/domain/surveyunit/service/dummy/SurveyUnitFakeService.java b/queen-domain-pilotage/src/test/java/fr/insee/queen/domain/surveyunit/service/dummy/SurveyUnitFakeService.java index 3f8f39e8..cf0e4da7 100644 --- a/queen-domain-pilotage/src/test/java/fr/insee/queen/domain/surveyunit/service/dummy/SurveyUnitFakeService.java +++ b/queen-domain-pilotage/src/test/java/fr/insee/queen/domain/surveyunit/service/dummy/SurveyUnitFakeService.java @@ -62,17 +62,17 @@ public List findAllSurveyUnitIds() { @Override public void updateSurveyUnit(SurveyUnit surveyUnit) { - + // not used for test at this moment } @Override public void updateSurveyUnit(String surveyUnitId, ObjectNode data, StateData stateData) { - + // not used for test at this moment } @Override public void createSurveyUnit(SurveyUnit surveyUnit) { - + // not used for test at this moment } @Override @@ -96,7 +96,7 @@ public List findWithStateByIds(List surveyUnits) { @Override public void delete(String surveyUnitId) { - + // not used for test at this moment } @Override diff --git a/queen-domain/src/test/java/fr/insee/queen/domain/surveyunit/service/dummy/SurveyUnitFakeService.java b/queen-domain/src/test/java/fr/insee/queen/domain/surveyunit/service/dummy/SurveyUnitFakeService.java index 3f8f39e8..cf0e4da7 100644 --- a/queen-domain/src/test/java/fr/insee/queen/domain/surveyunit/service/dummy/SurveyUnitFakeService.java +++ b/queen-domain/src/test/java/fr/insee/queen/domain/surveyunit/service/dummy/SurveyUnitFakeService.java @@ -62,17 +62,17 @@ public List findAllSurveyUnitIds() { @Override public void updateSurveyUnit(SurveyUnit surveyUnit) { - + // not used for test at this moment } @Override public void updateSurveyUnit(String surveyUnitId, ObjectNode data, StateData stateData) { - + // not used for test at this moment } @Override public void createSurveyUnit(SurveyUnit surveyUnit) { - + // not used for test at this moment } @Override @@ -96,7 +96,7 @@ public List findWithStateByIds(List surveyUnits) { @Override public void delete(String surveyUnitId) { - + // not used for test at this moment } @Override