From f87b7149649d7969f774393bb192365e8c851c39 Mon Sep 17 00:00:00 2001 From: Jorden_Reuter Date: Wed, 13 Nov 2024 11:56:12 +0100 Subject: [PATCH] fix: sonar --- .../bff/rs/controllers/CrdRestController.java | 26 ++++++++++--------- .../bff/rs/mappers/CrdMapper.java | 7 ++--- .../bff/rs/CrdRestControllerDataTest.java | 6 ++--- .../bff/rs/CrdRestControllerDatabaseTest.java | 8 +++--- .../rs/CrdRestControllerExceptionTest.java | 2 +- .../bff/rs/CrdRestControllerGeneralTest.java | 6 ++--- .../bff/rs/CrdRestControllerKcTest.java | 8 +++--- .../CrdRestControllerMicrofrontendTest.java | 8 +++--- .../rs/CrdRestControllerMicroserviceTest.java | 8 +++--- .../rs/CrdRestControllerPermissionTest.java | 8 +++--- .../bff/rs/CrdRestControllerProductTest.java | 8 +++--- .../bff/rs/CrdRestControllerSlotTest.java | 8 +++--- 12 files changed, 53 insertions(+), 50 deletions(-) diff --git a/src/main/java/org/tkit/onecx/data/orchestrator/bff/rs/controllers/CrdRestController.java b/src/main/java/org/tkit/onecx/data/orchestrator/bff/rs/controllers/CrdRestController.java index e0d95b8..d250375 100644 --- a/src/main/java/org/tkit/onecx/data/orchestrator/bff/rs/controllers/CrdRestController.java +++ b/src/main/java/org/tkit/onecx/data/orchestrator/bff/rs/controllers/CrdRestController.java @@ -75,18 +75,20 @@ public class CrdRestController implements DataApiService { .withNamespaced(true) .build(); - Map contextMap = new HashMap<>() { - { - put("Data", DATA_CONTEXT); - put("Database", DATABASE_CONTEXT); - put("KeycloakClient", KEYCLOAKCLIENT_CONTEXT); - put("Microfrontend", MICROFRONTEND_CONTEXT); - put("Microservice", MICROSERVICE_CONTEXT); - put("Permission", PERMISSION_CONTEXT); - put("Product", PRODUCT_CONTEXT); - put("Slot", SLOT_CONTEXT); - } - }; + private Map contextMap = createContextMap(); + + private static Map createContextMap() { + Map map = new HashMap<>(); + map.put("Data", DATA_CONTEXT); + map.put("Database", DATABASE_CONTEXT); + map.put("KeycloakClient", KEYCLOAKCLIENT_CONTEXT); + map.put("Microfrontend", MICROFRONTEND_CONTEXT); + map.put("Microservice", MICROSERVICE_CONTEXT); + map.put("Permission", PERMISSION_CONTEXT); + map.put("Product", PRODUCT_CONTEXT); + map.put("Slot", SLOT_CONTEXT); + return map; + } @Override public Response getCustomResourcesByCriteria(CrdSearchCriteriaDTO crdSearchCriteriaDTO) { diff --git a/src/main/java/org/tkit/onecx/data/orchestrator/bff/rs/mappers/CrdMapper.java b/src/main/java/org/tkit/onecx/data/orchestrator/bff/rs/mappers/CrdMapper.java index 94790e3..20b9323 100644 --- a/src/main/java/org/tkit/onecx/data/orchestrator/bff/rs/mappers/CrdMapper.java +++ b/src/main/java/org/tkit/onecx/data/orchestrator/bff/rs/mappers/CrdMapper.java @@ -68,18 +68,19 @@ public GenericKubernetesResource mapMicroserviceDtoToGeneric(CustomResourceMicro } public GenericCrdDTO mapToGenericCrdDTO(GenericKubernetesResource genericKubernetesResource) { + final String STATUS = "status"; GenericCrdDTO genericCrdDTO = new GenericCrdDTO(); genericCrdDTO.setKind(genericKubernetesResource.getKind()); genericCrdDTO.setName(genericKubernetesResource.getMetadata().getName()); genericCrdDTO.setCreationTimestamp(genericKubernetesResource.getMetadata().getCreationTimestamp()); genericCrdDTO.setResourceVersion(genericKubernetesResource.getMetadata().getResourceVersion()); genericCrdDTO.setVersion(genericKubernetesResource.getMetadata().getLabels().get("version")); - Map status = (Map) genericKubernetesResource.getAdditionalProperties().get("status"); + Map status = (Map) genericKubernetesResource.getAdditionalProperties().get(STATUS); if (status != null) { genericCrdDTO.setMessage(status.get("message")); - genericCrdDTO.setStatus(GenericCrdDTO.StatusEnum.valueOf(status.get("status"))); + genericCrdDTO.setStatus(GenericCrdDTO.StatusEnum.valueOf(status.get(STATUS))); Map statusCode = (Map) genericKubernetesResource.getAdditionalProperties() - .get("status"); + .get(STATUS); genericCrdDTO.setResponseCode(statusCode.get("responseCode")); } return genericCrdDTO; diff --git a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerDataTest.java b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerDataTest.java index 0911589..cf0965f 100644 --- a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerDataTest.java +++ b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerDataTest.java @@ -96,7 +96,7 @@ public void test_searchJustByType() { } @Test - public void testEditResource() { + void testEditResource() { var response = given() .when() .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) @@ -133,11 +133,11 @@ public void testEditResource() { .extract().as(GetCRDResponseDTO.class); editedData = objectMapper.convertValue(response.getCrd(), CustomResourceDataDTO.class); Assertions.assertNotNull(editedData); - Assertions.assertEquals(editedData.getSpec().getAppId(), "EditedAppId"); + Assertions.assertEquals("EditedAppId", editedData.getSpec().getAppId()); } @Test - public void testTouchResource() { + void testTouchResource() { given() .when() .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) diff --git a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerDatabaseTest.java b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerDatabaseTest.java index 642ecdd..8f23039 100644 --- a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerDatabaseTest.java +++ b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerDatabaseTest.java @@ -35,7 +35,7 @@ class CrdRestControllerDatabaseTest extends AbstractTest { ObjectMapper objectMapper; @BeforeAll - public void before() { + void before() { // Creating a custom resource from yaml CustomResourceDefinition aCustomResourceDefinition = client.apiextensions().v1().customResourceDefinitions() .load(CrdRestControllerDatabaseTest.class.getResourceAsStream("/mocks/databaseDefinition.yml")).item(); @@ -44,7 +44,7 @@ public void before() { } @Test - public void testInteractionWithAPIServer() { + void testInteractionWithAPIServer() { CrdSearchCriteriaDTO criteriaDTO = new CrdSearchCriteriaDTO(); criteriaDTO.setName("onecx-help-svc-db"); criteriaDTO.setType(List.of(ContextKindDTO.DATABASE)); @@ -64,7 +64,7 @@ public void testInteractionWithAPIServer() { } @Test - public void testEditResource() { + void testEditResource() { var response = given() .when() .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) @@ -101,6 +101,6 @@ public void testEditResource() { .extract().as(GetCRDResponseDTO.class); editedData = objectMapper.convertValue(response.getCrd(), CustomResourceDatabaseDTO.class); Assertions.assertNotNull(editedData); - Assertions.assertEquals(editedData.getSpec().getHost(), "EditedHost"); + Assertions.assertEquals("EditedHost", editedData.getSpec().getHost()); } } diff --git a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerExceptionTest.java b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerExceptionTest.java index ab12231..e555818 100644 --- a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerExceptionTest.java +++ b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerExceptionTest.java @@ -20,7 +20,7 @@ class CrdRestControllerExceptionTest extends AbstractTest { CrdRestController restController; @Test - public void kubernetes_client_exception_test() { + void kubernetes_client_exception_test() { Status status = new Status(); status.setStatus("error"); status.setCode(400); diff --git a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerGeneralTest.java b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerGeneralTest.java index 30d951d..20abadd 100644 --- a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerGeneralTest.java +++ b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerGeneralTest.java @@ -24,7 +24,7 @@ class CrdRestControllerGeneralTest extends AbstractTest { @Test - public void edit_without_crds_test() { + void edit_without_crds_test() { EditResourceRequestDTO editResourceRequestDTO = new EditResourceRequestDTO(); given() @@ -35,7 +35,7 @@ public void edit_without_crds_test() { } @Test - public void edit_without_body_test() { + void edit_without_body_test() { given() .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) .header(APM_HEADER_PARAM, ADMIN).when().contentType(APPLICATION_JSON) @@ -43,7 +43,7 @@ public void edit_without_body_test() { } @Test - public void search_no_crds_existing() { + void search_no_crds_existing() { CrdSearchCriteriaDTO criteriaDTO = new CrdSearchCriteriaDTO(); criteriaDTO.setType(List.of(ContextKindDTO.DATA)); criteriaDTO.setName("Not_Existing"); diff --git a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerKcTest.java b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerKcTest.java index f8405aa..95eafb1 100644 --- a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerKcTest.java +++ b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerKcTest.java @@ -36,7 +36,7 @@ class CrdRestControllerKcTest extends AbstractTest { ObjectMapper objectMapper; @BeforeAll - public void before() { + void before() { // Creating a custom resource from yaml CustomResourceDefinition aCustomResourceDefinition = client.apiextensions().v1().customResourceDefinitions() .load(CrdRestControllerKcTest.class.getResourceAsStream("/mocks/keycloakClientDefinition.yml")).item(); @@ -45,7 +45,7 @@ public void before() { } @Test - public void testInteractionWithAPIServer() { + void testInteractionWithAPIServer() { CrdSearchCriteriaDTO criteriaDTO = new CrdSearchCriteriaDTO(); criteriaDTO.setName("onecx-help-bff"); criteriaDTO.setType(List.of(ContextKindDTO.KEYCLOAK_CLIENT)); @@ -65,7 +65,7 @@ public void testInteractionWithAPIServer() { } @Test - public void testEditResource() { + void testEditResource() { var response = given() .when() .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) @@ -103,6 +103,6 @@ public void testEditResource() { .extract().as(GetCRDResponseDTO.class); editedData = objectMapper.convertValue(response.getCrd(), CustomResourceKeycloakClientDTO.class); Assertions.assertNotNull(editedData); - Assertions.assertEquals(editedData.getSpec().getRealm(), "editedRealm"); + Assertions.assertEquals("editedRealm", editedData.getSpec().getRealm()); } } diff --git a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerMicrofrontendTest.java b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerMicrofrontendTest.java index 30d999a..f47368d 100644 --- a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerMicrofrontendTest.java +++ b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerMicrofrontendTest.java @@ -36,7 +36,7 @@ class CrdRestControllerMicrofrontendTest extends AbstractTest { ObjectMapper objectMapper; @BeforeAll - public void before() { + void before() { // Creating a custom resource from yaml CustomResourceDefinition aCustomResourceDefinition = client.apiextensions().v1().customResourceDefinitions() .load(CrdRestControllerMicrofrontendTest.class.getResourceAsStream("/mocks/microfrontendDefinition.yml")) @@ -46,7 +46,7 @@ public void before() { } @Test - public void testInteractionWithAPIServer() { + void testInteractionWithAPIServer() { CrdSearchCriteriaDTO criteriaDTO = new CrdSearchCriteriaDTO(); criteriaDTO.setName("onecx-help-ui-main"); criteriaDTO.setType(List.of(ContextKindDTO.MICROFRONTEND)); @@ -66,7 +66,7 @@ public void testInteractionWithAPIServer() { } @Test - public void testEditResource() { + void testEditResource() { var response = given() .when() .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) @@ -104,6 +104,6 @@ public void testEditResource() { .extract().as(GetCRDResponseDTO.class); editedData = objectMapper.convertValue(response.getCrd(), CustomResourceMicrofrontendDTO.class); Assertions.assertNotNull(editedData); - Assertions.assertEquals(editedData.getSpec().getAppId(), "EditedAppId"); + Assertions.assertEquals("EditedAppId", editedData.getSpec().getAppId()); } } diff --git a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerMicroserviceTest.java b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerMicroserviceTest.java index 5a0046d..2a9e15b 100644 --- a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerMicroserviceTest.java +++ b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerMicroserviceTest.java @@ -36,7 +36,7 @@ class CrdRestControllerMicroserviceTest extends AbstractTest { ObjectMapper objectMapper; @BeforeAll - public void before() { + void before() { // Creating a custom resource from yaml CustomResourceDefinition aCustomResourceDefinition = client.apiextensions().v1().customResourceDefinitions() .load(CrdRestControllerMicroserviceTest.class.getResourceAsStream("/mocks/microserviceDefinition.yml")).item(); @@ -45,7 +45,7 @@ public void before() { } @Test - public void testInteractionWithAPIServer() { + void testInteractionWithAPIServer() { CrdSearchCriteriaDTO criteriaDTO = new CrdSearchCriteriaDTO(); criteriaDTO.setName("onecx-help-ui"); criteriaDTO.setType(List.of(ContextKindDTO.MICROSERVICE)); @@ -65,7 +65,7 @@ public void testInteractionWithAPIServer() { } @Test - public void testEditResource() { + void testEditResource() { var response = given() .when() .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) @@ -103,6 +103,6 @@ public void testEditResource() { .extract().as(GetCRDResponseDTO.class); editedData = objectMapper.convertValue(response.getCrd(), CustomResourceMicroserviceDTO.class); Assertions.assertNotNull(editedData); - Assertions.assertEquals(editedData.getSpec().getAppId(), "EditedAppId"); + Assertions.assertEquals("EditedAppId", editedData.getSpec().getAppId()); } } diff --git a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerPermissionTest.java b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerPermissionTest.java index b114304..0a18e0e 100644 --- a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerPermissionTest.java +++ b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerPermissionTest.java @@ -36,7 +36,7 @@ class CrdRestControllerPermissionTest extends AbstractTest { ObjectMapper objectMapper; @BeforeAll - public void before() { + void before() { // Creating a custom resource from yaml CustomResourceDefinition aCustomResourceDefinition = client.apiextensions().v1().customResourceDefinitions() .load(CrdRestControllerPermissionTest.class.getResourceAsStream("/mocks/permissionDefinition.yml")).item(); @@ -45,7 +45,7 @@ public void before() { } @Test - public void testInteractionWithAPIServer() { + void testInteractionWithAPIServer() { CrdSearchCriteriaDTO criteriaDTO = new CrdSearchCriteriaDTO(); criteriaDTO.setName("onecx-help-ui"); criteriaDTO.setType(List.of(ContextKindDTO.PERMISSION)); @@ -65,7 +65,7 @@ public void testInteractionWithAPIServer() { } @Test - public void testEditResource() { + void testEditResource() { var response = given() .when() .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) @@ -103,6 +103,6 @@ public void testEditResource() { .extract().as(GetCRDResponseDTO.class); editedData = objectMapper.convertValue(response.getCrd(), CustomResourcePermissionDTO.class); Assertions.assertNotNull(editedData); - Assertions.assertEquals(editedData.getSpec().getAppId(), "EditedAppId"); + Assertions.assertEquals("EditedAppId", editedData.getSpec().getAppId()); } } diff --git a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerProductTest.java b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerProductTest.java index e612d98..61b389d 100644 --- a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerProductTest.java +++ b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerProductTest.java @@ -36,7 +36,7 @@ class CrdRestControllerProductTest extends AbstractTest { ObjectMapper objectMapper; @BeforeAll - public void before() { + void before() { // Creating a custom resource from yaml CustomResourceDefinition aCustomResourceDefinition = client.apiextensions().v1().customResourceDefinitions() .load(CrdRestControllerProductTest.class.getResourceAsStream("/mocks/productDefinition.yml")).item(); @@ -45,7 +45,7 @@ public void before() { } @Test - public void testInteractionWithAPIServer() { + void testInteractionWithAPIServer() { CrdSearchCriteriaDTO criteriaDTO = new CrdSearchCriteriaDTO(); criteriaDTO.setName("onecx-help"); criteriaDTO.setType(List.of(ContextKindDTO.PRODUCT)); @@ -65,7 +65,7 @@ public void testInteractionWithAPIServer() { } @Test - public void testEditResource() { + void testEditResource() { var response = given() .when() .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) @@ -102,6 +102,6 @@ public void testEditResource() { .extract().as(GetCRDResponseDTO.class); editedData = objectMapper.convertValue(response.getCrd(), CustomResourceProductDTO.class); Assertions.assertNotNull(editedData); - Assertions.assertEquals(editedData.getSpec().getBasePath(), "EditedBasePath"); + Assertions.assertEquals("EditedBasePath", editedData.getSpec().getBasePath()); } } diff --git a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerSlotTest.java b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerSlotTest.java index 78bfad2..3566eb6 100644 --- a/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerSlotTest.java +++ b/src/test/java/org/tkit/onecx/data/orchestrator/bff/rs/CrdRestControllerSlotTest.java @@ -36,7 +36,7 @@ class CrdRestControllerSlotTest extends AbstractTest { ObjectMapper objectMapper; @BeforeAll - public void before() { + void before() { // Creating a custom resource from yaml CustomResourceDefinition aCustomResourceDefinition = client.apiextensions().v1().customResourceDefinitions() .load(CrdRestControllerSlotTest.class.getResourceAsStream("/mocks/slotDefinition.yml")).item(); @@ -45,7 +45,7 @@ public void before() { } @Test - public void testInteractionWithAPIServer() { + void testInteractionWithAPIServer() { CrdSearchCriteriaDTO criteriaDTO = new CrdSearchCriteriaDTO(); criteriaDTO.setName("onecx-workspace-ui-onecx-avatar-image"); criteriaDTO.setType(List.of(ContextKindDTO.SLOT)); @@ -65,7 +65,7 @@ public void testInteractionWithAPIServer() { } @Test - public void testEditResource() { + void testEditResource() { var response = given() .when() .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) @@ -102,6 +102,6 @@ public void testEditResource() { .extract().as(GetCRDResponseDTO.class); editedData = objectMapper.convertValue(response.getCrd(), CustomResourceSlotDTO.class); Assertions.assertNotNull(editedData); - Assertions.assertEquals(editedData.getSpec().getAppId(), "EditedAppId"); + Assertions.assertEquals("EditedAppId", editedData.getSpec().getAppId()); } }