Skip to content

Commit

Permalink
tests: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Apr 18, 2024
1 parent 9d1d8c1 commit 2d29af4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2d29af4

Please sign in to comment.