From 2d29af41cfa537917b40a63873c43e9fc634fa04 Mon Sep 17 00:00:00 2001 From: Andrej Petras Date: Thu, 18 Apr 2024 17:30:03 +0200 Subject: [PATCH] tests: update tests --- .../controllers/AssignmentRestController.java | 31 ++++++------------- .../rs/AssignmentRestControllerTest.java | 28 +++++++++++++++++ 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/AssignmentRestController.java b/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/AssignmentRestController.java index 348a72a..0904a74 100644 --- a/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/AssignmentRestController.java +++ b/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/AssignmentRestController.java @@ -51,32 +51,21 @@ public Response grantAssignments(CreateProductAssignmentsRequestDTO createProduc // app-id not null, take only first product from list if (createProductAssignmentsRequestDTO.getAppId() != null && !createProductAssignmentsRequestDTO.getAppId().isEmpty()) { - if (createProductAssignmentsRequestDTO.getProductNames() != null - && !createProductAssignmentsRequestDTO.getProductNames().isEmpty()) { - int status = Response.Status.BAD_REQUEST.getStatusCode(); - for (int i = 0; i < createProductAssignmentsRequestDTO.getProductNames().size(); i++) { - try (Response response = assignmentClient.grantRoleProductAssignments( - createProductAssignmentsRequestDTO.getRoleId(), - mapper.mapRoleProduct(createProductAssignmentsRequestDTO, i))) { - status = response.getStatus(); - } + int status = Response.Status.BAD_REQUEST.getStatusCode(); + for (int i = 0; i < createProductAssignmentsRequestDTO.getProductNames().size(); i++) { + try (Response response = assignmentClient.grantRoleProductAssignments( + createProductAssignmentsRequestDTO.getRoleId(), + mapper.mapRoleProduct(createProductAssignmentsRequestDTO, i))) { + status = response.getStatus(); } - return Response.status(status).build(); } + return Response.status(status).build(); } // list of product-names - if (createProductAssignmentsRequestDTO.getProductNames() != null - && !createProductAssignmentsRequestDTO.getProductNames().isEmpty()) { - try (Response response = assignmentClient.grantRoleProductsAssignments( - createProductAssignmentsRequestDTO.getRoleId(), - mapper.mapRoleProducts(createProductAssignmentsRequestDTO))) { - return Response.status(response.getStatus()).build(); - } - } - - // only role-id defined - try (Response response = assignmentClient.grantRoleAssignments(createProductAssignmentsRequestDTO.getRoleId())) { + try (Response response = assignmentClient.grantRoleProductsAssignments( + createProductAssignmentsRequestDTO.getRoleId(), + mapper.mapRoleProducts(createProductAssignmentsRequestDTO))) { return Response.status(response.getStatus()).build(); } } diff --git a/src/test/java/org/tkit/onecx/permission/rs/AssignmentRestControllerTest.java b/src/test/java/org/tkit/onecx/permission/rs/AssignmentRestControllerTest.java index a2f31e5..76e54c1 100644 --- a/src/test/java/org/tkit/onecx/permission/rs/AssignmentRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/permission/rs/AssignmentRestControllerTest.java @@ -274,6 +274,34 @@ void createProductAssignmentsTest() { .post("/grant") .then() .statusCode(Response.Status.CREATED.getStatusCode()); + + requestDTO.setAppId(""); + given() + .when() + .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) + .header(APM_HEADER_PARAM, ADMIN) + .contentType(APPLICATION_JSON) + .body(requestDTO) + .post("/grant") + .then() + .statusCode(Response.Status.CREATED.getStatusCode()); + + mockServerClient.when(request().withPath("/internal/assignments/grant/role1/product").withMethod(HttpMethod.POST)) + .withId(MOCKID) + .respond(httpRequest -> response().withStatusCode(Response.Status.CREATED.getStatusCode()) + .withContentType(MediaType.APPLICATION_JSON)); + + requestDTO.setAppId("app1"); + given() + .when() + .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) + .header(APM_HEADER_PARAM, ADMIN) + .contentType(APPLICATION_JSON) + .body(requestDTO) + .post("/grant") + .then() + .statusCode(Response.Status.CREATED.getStatusCode()); + } @Test