Skip to content

Commit

Permalink
fix: sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
JordenReuter committed Nov 13, 2024
1 parent 445d180 commit f87b714
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,20 @@ public class CrdRestController implements DataApiService {
.withNamespaced(true)
.build();

Map<String, ResourceDefinitionContext> 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<String, ResourceDefinitionContext> contextMap = createContextMap();

private static Map<String, ResourceDefinitionContext> createContextMap() {
Map<String, ResourceDefinitionContext> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> status = (Map<String, String>) genericKubernetesResource.getAdditionalProperties().get("status");
Map<String, String> status = (Map<String, String>) 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<String, Integer> statusCode = (Map<String, Integer>) genericKubernetesResource.getAdditionalProperties()
.get("status");
.get(STATUS);
genericCrdDTO.setResponseCode(statusCode.get("responseCode"));
}
return genericCrdDTO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void test_searchJustByType() {
}

@Test
public void testEditResource() {
void testEditResource() {
var response = given()
.when()
.auth().oauth2(keycloakClient.getAccessToken(ADMIN))
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -64,7 +64,7 @@ public void testInteractionWithAPIServer() {
}

@Test
public void testEditResource() {
void testEditResource() {
var response = given()
.when()
.auth().oauth2(keycloakClient.getAccessToken(ADMIN))
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -35,15 +35,15 @@ 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)
.post("/edit").then().statusCode(BAD_REQUEST.getStatusCode());
}

@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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -65,7 +65,7 @@ public void testInteractionWithAPIServer() {
}

@Test
public void testEditResource() {
void testEditResource() {
var response = given()
.when()
.auth().oauth2(keycloakClient.getAccessToken(ADMIN))
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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));
Expand All @@ -66,7 +66,7 @@ public void testInteractionWithAPIServer() {
}

@Test
public void testEditResource() {
void testEditResource() {
var response = given()
.when()
.auth().oauth2(keycloakClient.getAccessToken(ADMIN))
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -65,7 +65,7 @@ public void testInteractionWithAPIServer() {
}

@Test
public void testEditResource() {
void testEditResource() {
var response = given()
.when()
.auth().oauth2(keycloakClient.getAccessToken(ADMIN))
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -65,7 +65,7 @@ public void testInteractionWithAPIServer() {
}

@Test
public void testEditResource() {
void testEditResource() {
var response = given()
.when()
.auth().oauth2(keycloakClient.getAccessToken(ADMIN))
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -65,7 +65,7 @@ public void testInteractionWithAPIServer() {
}

@Test
public void testEditResource() {
void testEditResource() {
var response = given()
.when()
.auth().oauth2(keycloakClient.getAccessToken(ADMIN))
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -65,7 +65,7 @@ public void testInteractionWithAPIServer() {
}

@Test
public void testEditResource() {
void testEditResource() {
var response = given()
.when()
.auth().oauth2(keycloakClient.getAccessToken(ADMIN))
Expand Down Expand Up @@ -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());
}
}

0 comments on commit f87b714

Please sign in to comment.