-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b86783e
commit 3e8cbb7
Showing
5 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...st/java/io/github/onecx/permission/rs/external/v1/PermissionRestControllerTenantTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package io.github.onecx.permission.rs.external.v1; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.jboss.resteasy.reactive.RestResponse.Status.*; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.tkit.quarkus.test.WithDBData; | ||
|
||
import gen.io.github.onecx.permission.rs.external.v1.model.*; | ||
import io.github.onecx.permission.rs.external.v1.controllers.PermissionRestController; | ||
import io.github.onecx.permission.test.AbstractTest; | ||
import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
@TestHTTPEndpoint(PermissionRestController.class) | ||
@WithDBData(value = "data/test-v1.xml", deleteBeforeInsert = true, deleteAfterTest = true, rinseAndRepeat = true) | ||
class PermissionRestControllerTenantTest extends AbstractTest { | ||
|
||
@Test | ||
void getApplicationPermissionsTest() { | ||
|
||
var accessToken = createToken("org1", List.of("n3-100")); | ||
|
||
var dto = given() | ||
.contentType(APPLICATION_JSON) | ||
.header(APM_HEADER_PARAM, accessToken) | ||
.body(new PermissionRequestDTOV1().token(accessToken)) | ||
.post("/application/app1") | ||
.then() | ||
.statusCode(OK.getStatusCode()) | ||
.extract() | ||
.body().as(ApplicationPermissionsDTOV1.class); | ||
|
||
assertThat(dto).isNotNull(); | ||
assertThat(dto.getPermissions()).isNotNull().hasSize(1); | ||
assertThat(dto.getPermissions().get("o1")).isNotNull().hasSize(1).containsExactly("a2"); | ||
|
||
} | ||
|
||
@Test | ||
void getWorkspacePermissionsTest() { | ||
|
||
var accessToken = createToken("org1", List.of("n3-100")); | ||
|
||
var dto = given() | ||
.contentType(APPLICATION_JSON) | ||
.header(APM_HEADER_PARAM, accessToken) | ||
.body(new PermissionRequestDTOV1().token(accessToken)) | ||
.post("/workspace/wapp1") | ||
.then() | ||
.statusCode(OK.getStatusCode()) | ||
.extract() | ||
.body().as(WorkspacePermissionsDTOV1.class); | ||
|
||
assertThat(dto).isNotNull(); | ||
assertThat(dto.getPermissions()).isNotNull().isEmpty(); | ||
|
||
dto = given() | ||
.contentType(APPLICATION_JSON) | ||
.header(APM_HEADER_PARAM, accessToken) | ||
.body(new PermissionRequestDTOV1().token(accessToken)) | ||
.post("/workspace/wapp1-100") | ||
.then() | ||
.statusCode(OK.getStatusCode()) | ||
.extract() | ||
.body().as(WorkspacePermissionsDTOV1.class); | ||
|
||
assertThat(dto).isNotNull(); | ||
assertThat(dto.getPermissions()).isNotNull().hasSize(1); | ||
assertThat(dto.getPermissions().get("o1")).isNotNull().hasSize(1).containsExactly("a1"); | ||
|
||
} | ||
|
||
@Test | ||
void getWorkspacePermissionApplicationsTest() { | ||
|
||
var accessToken = createToken("org1", List.of("n3-100")); | ||
|
||
var dto = given() | ||
.contentType(APPLICATION_JSON) | ||
.header(APM_HEADER_PARAM, accessToken) | ||
.body(new PermissionRequestDTOV1().token(accessToken)) | ||
.post("/workspace/wapp1/applications") | ||
.then() | ||
.statusCode(OK.getStatusCode()) | ||
.extract() | ||
.body().as(WorkspacePermissionApplicationsDTOV1.class); | ||
|
||
assertThat(dto).isNotNull(); | ||
assertThat(dto.getWorkspace()).isNotNull(); | ||
assertThat(dto.getWorkspace().getPermissions()).isNotNull().isEmpty(); | ||
|
||
dto = given() | ||
.contentType(APPLICATION_JSON) | ||
.header(APM_HEADER_PARAM, accessToken) | ||
.body(new PermissionRequestDTOV1().token(accessToken)) | ||
.post("/workspace/wapp1-100/applications") | ||
.then() | ||
.statusCode(OK.getStatusCode()) | ||
.extract() | ||
.body().as(WorkspacePermissionApplicationsDTOV1.class); | ||
|
||
assertThat(dto).isNotNull(); | ||
assertThat(dto.getWorkspace()).isNotNull(); | ||
assertThat(dto.getWorkspace().getPermissions()).isNotNull().hasSize(1); | ||
assertThat(dto.getWorkspace().getPermissions().get("o1")).isNotNull().hasSize(1).containsExactly("a1"); | ||
assertThat(dto.getApplications()).isNotNull().hasSize(1); | ||
assertThat(dto.getApplications().get(0)).isNotNull(); | ||
assertThat(dto.getApplications().get(0).getPermissions()).isNotNull().hasSize(1); | ||
assertThat(dto.getApplications().get(0).getPermissions().get("o1")).isNotNull().hasSize(1).containsExactly("a2"); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.../java/io/github/onecx/permission/rs/external/v1/PermissionRestControllerTenantTestIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.github.onecx.permission.rs.external.v1; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
@QuarkusIntegrationTest | ||
class PermissionRestControllerTenantTestIT extends PermissionRestControllerTenantTest { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters