From cbf82c5edaf4e4b3c0bed4cfeb1112df8b1a1bde Mon Sep 17 00:00:00 2001 From: sadilchamishka Date: Thu, 31 Aug 2023 18:49:12 +0530 Subject: [PATCH 1/3] Onboard B2B feature related integration tests --- .../test/rest/api/common/B2BRESTTestBase.java | 222 ++++++++++++++++++ .../common/B2BRESTAPIServerTestBase.java | 50 ++++ .../v1/OrganizationManagementBaseTest.java | 179 ++++++++++++++ .../v1/OrganizationManagementFailureTest.java | 85 +++++++ .../v1/OrganizationManagementSuccessTest.java | 147 ++++++++++++ .../v1/OrganizationManagementTestData.java | 157 +++++++++++++ .../organization/management/v1/Utils.java | 38 +++ .../management/v1/model/OrganizationType.java | 24 ++ .../src/test/resources/testng.xml | 6 + 9 files changed, 908 insertions(+) create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/common/B2BRESTTestBase.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/common/B2BRESTAPIServerTestBase.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementBaseTest.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementTestData.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/Utils.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/model/OrganizationType.java diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/common/B2BRESTTestBase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/common/B2BRESTTestBase.java new file mode 100644 index 00000000000..41186758e35 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/common/B2BRESTTestBase.java @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.common; + +import io.restassured.http.ContentType; +import io.restassured.response.Response; +import org.apache.commons.lang.StringUtils; +import org.apache.http.HttpHeaders; +import org.hamcrest.Matcher; +import org.wso2.carbon.automation.engine.context.AutomationContext; +import org.wso2.identity.integration.common.clients.usermgt.remote.RemoteUserStoreManagerServiceClient; + +import java.rmi.RemoteException; +import java.util.ResourceBundle; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.StringContains.containsString; + +/** + * Base test class for B2B organization management REST API tests. + */ +public class B2BRESTTestBase extends RESTTestBase { + + protected static final String ORGANIZATION_CONTEXT_IN_URL = "/o/%s"; + protected static final String SERVICES = "/services"; + private static ResourceBundle errorProperties = ResourceBundle.getBundle("RESTAPIErrors"); + + protected String authenticatingUserName; + protected String authenticatingCredential; + protected String tenant; + protected AutomationContext context; + + protected RemoteUserStoreManagerServiceClient remoteUSMServiceClient; + protected String swaggerDefinition; + + protected String basePath = StringUtils.EMPTY; + + /** + * Initialize the REST API validation requirements configuring the OpenApiValidationFilter + * + * @param swaggerDefinition Swagger definition name. + * @param basePathInSwagger Basepath that is defined in the swagger definition (ex: /api/users/v1). + * @param basePath Basepath of the current test run (ex: /o/{organization-domain}/api/users/v1). + * @throws RemoteException Throws this exception. + */ + protected void init(String swaggerDefinition, String basePathInSwagger, String basePath) throws RemoteException { + + super.init(swaggerDefinition, basePathInSwagger, basePath); + this.basePath = basePath; + } + + /** + * Invoke given endpointUri for GET with Basic authentication, authentication credential being the + * authenticatingUserName and authenticatingCredential. + * + * @param endpointUri Endpoint to be invoked. + * @return response of get request. + */ + protected Response getResponseOfGet(String endpointUri) { + + return given().auth().preemptive().basic(authenticatingUserName, authenticatingCredential) + .contentType(ContentType.JSON) + .header(HttpHeaders.ACCEPT, ContentType.JSON) + .log().ifValidationFails() + .when() + .get(endpointUri); + } + + /** + * Invoke given endpointUri for POST with given body and Basic authentication, authentication credential being the + * authenticatingUserName and authenticatingCredential. + * + * @param endpointUri Endpoint to be invoked. + * @param body Payload. + * @return Response of post request. + */ + protected Response getResponseOfPost(String endpointUri, String body) { + return given().auth().preemptive().basic(authenticatingUserName, authenticatingCredential) + .contentType(ContentType.JSON) + .header(HttpHeaders.ACCEPT, ContentType.JSON) + .body(body) + .log().ifValidationFails() + .log().ifValidationFails() + .when() + .log().ifValidationFails() + .post(endpointUri); + } + + /** + * Invoke given endpointUri for DELETE with given body and Basic authentication, authentication credential being + * the authenticatingUserName and authenticatingCredential. + * + * @param endpointURI Endpoint of the request. + * @return Response of delete request. + */ + protected Response getResponseOfDelete(String endpointURI) { + + return given().auth().preemptive().basic(authenticatingUserName, authenticatingCredential) + .contentType(ContentType.JSON) + .header(HttpHeaders.ACCEPT, ContentType.JSON) + .log().ifValidationFails() + .log().ifValidationFails() + .when() + .log().ifValidationFails() + .delete(endpointURI); + } + + /** + * Validate the error response of a request. + * + * @param response Response of the request. + * @param httpStatusCode Status code of the response. + * @param errorCode Error code of the response. + * @param errorDescriptionArgs Error msg and the description of the response. + */ + protected void validateErrorResponse(Response response, int httpStatusCode, String errorCode, String... + errorDescriptionArgs) { + + validateHttpStatusCode(response, httpStatusCode); + validateResponseElement(response, "code", is(errorCode)); + validateErrorMessage(response, errorCode); + validateErrorDescription(response, errorCode, errorDescriptionArgs); + } + + /** + * Validate http status code of the response + * + * @param response Response. + * @param httpStatusCode Expected status code. + */ + protected void validateHttpStatusCode(Response response, int httpStatusCode) { + + response + .then() + .assertThat() + .log().ifValidationFails() + .statusCode(httpStatusCode); + } + + /** + * Validate error description of the response, if an entry is available in RESTAPIErrors.properties + * + * @param response Response. + * @param errorCode Error code. + * @param placeHolders Values to be replaced in the error description in the corresponding entry in + * RESTAPIError.properties. + */ + private void validateErrorDescription(Response response, String errorCode, String... placeHolders) { + + validateElementAgainstErrorProperties(response, errorCode, "description", placeHolders); + } + + /** + * Validate error message of the response, if an entry is available in RESTAPIErrors.properties. + * + * @param response Response. + * @param errorCode Error code. + */ + private void validateErrorMessage(Response response, String errorCode) { + + validateElementAgainstErrorProperties(response, errorCode, "message"); + } + + /** + * Validate elements in error response against entries in RESTAPIErrors.properties + * + * @param response Response. + * @param errorCode API error code. + * @param element Element. + * @param placeHolderValues Placeholder values. + * arg[0], key element in the RESTAPIErrors.properties (error-code.arg[0]). + * arg[1-n] place holder values to replace in value in the RESTAPIErrors.properties. + */ + private void validateElementAgainstErrorProperties(Response response, String errorCode, String element, String... + placeHolderValues) { + + String expected = StringUtils.EMPTY; + try { + expected = errorProperties.getString(String.format("%s.%s", errorCode, element)); + } catch (Throwable e) { + //Ignore if error properties are not defined as keys in RESTAPIErrors.properties + } + if (StringUtils.isNotEmpty(expected)) { + expected = String.format(expected, placeHolderValues); + validateResponseElement(response, element, containsString(expected)); + } + } + + /** + * Validate a response element against a matcher. + * + * @param response Response. + * @param element JSON path element to match. + * @param responseAwareMatcher Expected matcher. + */ + protected void validateResponseElement(Response response, String element, Matcher + responseAwareMatcher) { + + response + .then() + .assertThat() + .log().ifValidationFails() + .body(element, responseAwareMatcher); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/common/B2BRESTAPIServerTestBase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/common/B2BRESTAPIServerTestBase.java new file mode 100644 index 00000000000..9bc6073b328 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/common/B2BRESTAPIServerTestBase.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.common; + +import org.wso2.identity.integration.test.rest.api.common.B2BRESTTestBase; + +import java.rmi.RemoteException; + +/** + * Base Test Class for server based B2B REST API test cases. + * ex: /o/{organization-domain}/api/server/{version} + */ +public class B2BRESTAPIServerTestBase extends B2BRESTTestBase { + + protected static final String API_SERVER_BASE_PATH = "/api/server/%s"; + protected static final String API_SERVER_BASE_PATH_IN_SWAGGER = "/o/\\{organization-domain\\}" + + API_SERVER_BASE_PATH; + protected static final String API_SERVER_BASE_PATH_WITH_ORGANIZATION_CONTEXT = + ORGANIZATION_CONTEXT_IN_URL + API_SERVER_BASE_PATH; + + protected void testInit(String apiVersion, String apiDefinition, String organizationID) throws RemoteException { + + String basePathInSwagger = String.format(API_SERVER_BASE_PATH_IN_SWAGGER, apiVersion); + String basePath = String.format(API_SERVER_BASE_PATH_WITH_ORGANIZATION_CONTEXT, + organizationID, apiVersion); + super.init(apiDefinition, basePathInSwagger, basePath); + } + + protected void testInitWithoutTenantQualifiedPath(String apiVersion, String apiDefinition) throws RemoteException { + + String basePathInSwagger = String.format(API_SERVER_BASE_PATH, apiVersion); + super.init(apiDefinition, basePathInSwagger, basePathInSwagger); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementBaseTest.java new file mode 100644 index 00000000000..2913cf35d32 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementBaseTest.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.organization.management.v1; + +import io.restassured.RestAssured; +import io.restassured.response.Response; +import org.apache.commons.lang.StringUtils; +import org.apache.http.HttpHeaders; +import org.apache.http.HttpStatus; +import org.testng.Assert; +import org.testng.ISuite; +import org.testng.ITestContext; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.identity.integration.test.rest.api.server.common.B2BRESTAPIServerTestBase; +import org.wso2.identity.integration.test.rest.api.server.organization.management.v1.model.OrganizationType; + +import java.io.IOException; +import java.util.Set; + +import static org.hamcrest.core.IsNull.notNullValue; +import static org.wso2.identity.integration.test.rest.api.server.organization.management.v1.Utils.assertNotBlank; +import static org.wso2.identity.integration.test.rest.api.server.organization.management.v1.Utils.extractOrganizationIdFromLocationHeader; + +/** + * Base test class for Organization Management REST APIs. + */ +public class OrganizationManagementBaseTest extends B2BRESTAPIServerTestBase { + + private static final String API_DEFINITION_NAME = "org.wso2.carbon.identity.organization.management.yaml"; + static final String API_VERSION = "v1"; + public final OrganizationType organizationType; + static final String SUPER_ORGANIZATION_NAME = "Super"; + static final String ORGANIZATION_NAME = "name"; + static final String ORGANIZATION_PARENT_ID = "parentId"; + static final String SUPER_ORGANIZATION_ID = "10084a8d-113f-4211-a0d5-efe36b082211"; + protected String subOrganizationId; + protected static final String ORGANIZATION_MANAGEMENT_API_BASE_PATH = "/organizations"; + protected static String swaggerDefinition; + + static { + String apiPackageName = "org.wso2.carbon.identity.api.server.organization.management.v1"; + try { + swaggerDefinition = getAPISwaggerDefinition(apiPackageName, API_DEFINITION_NAME); + } catch (IOException e) { + Assert.fail(String.format("Unable to read the swagger definition %s from %s", API_DEFINITION_NAME, + apiPackageName), e); + } + } + + public OrganizationManagementBaseTest(TestUserMode userMode, OrganizationType organizationType) throws Exception { + + this.organizationType = organizationType; + super.init(userMode); + this.context = isServer; + this.authenticatingUserName = context.getContextTenant().getTenantAdmin().getUserName(); + this.authenticatingCredential = context.getContextTenant().getTenantAdmin().getPassword(); + } + + @BeforeClass(alwaysRun = true) + public void init(ITestContext context) throws Exception { + + ISuite suite = context.getSuite(); + String orgId = (String) suite.getAttribute("createdOrgId"); + if (orgId == null) { + orgId = SUPER_ORGANIZATION_ID; + } + this.subOrganizationId = orgId; + if (this.organizationType.name().equals("SUPER_ORGANIZATION")) { + super.testInitWithoutTenantQualifiedPath(API_VERSION, swaggerDefinition); + } else { + this.tenant = subOrganizationId; + this.authenticatingUserName = "admin@" + SUPER_ORGANIZATION_ID; + super.testInit(API_VERSION, swaggerDefinition, tenant); + } + } + + @AfterClass(alwaysRun = true) + public void testConclude() throws Exception { + + super.conclude(); + } + + @BeforeMethod(alwaysRun = true) + public void testInit(ITestContext context) throws Exception { + + RestAssured.basePath = basePath; + ISuite suite = context.getSuite(); + String orgId = (String) suite.getAttribute("createdOrgId"); + + if (orgId == null) { + orgId = createBaseOrg(); + suite.setAttribute("createdOrgId", orgId); + } + } + + @AfterMethod(alwaysRun = true) + public void testFinish() { + + RestAssured.basePath = StringUtils.EMPTY; + } + + @DataProvider(name = "restAPIUserConfigProvider") + public static Object[][] restAPIUserConfigProvider() { + + return new Object[][]{ + {TestUserMode.SUPER_TENANT_ADMIN, OrganizationType.SUPER_ORGANIZATION}, + {TestUserMode.SUPER_TENANT_ADMIN, OrganizationType.SUB_ORGANIZATION} + }; + } + + @DataProvider(name = "initRESTAPIUserConfigProvider") + public static Object[][] initRESTAPIUserConfigProvider() { + + return new Object[][]{ + {TestUserMode.SUPER_TENANT_ADMIN, OrganizationType.SUPER_ORGANIZATION}, + }; + } + + protected void cleanUpOrganizations(Set orgsToCleanUp) { + + orgsToCleanUp.forEach(orgId -> { + String organizationPath = ORGANIZATION_MANAGEMENT_API_BASE_PATH + "/" + orgId; + Response responseOfDelete = getResponseOfDelete(organizationPath); + responseOfDelete.then() + .log() + .ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_NO_CONTENT); + }); + } + + private String createBaseOrg() { + + String body = "{\n" + + " \"name\": \"ABC Builders\",\n" + + " \"description\": \"Building constructions\",\n" + + " \"type\": \"TENANT\",\n" + + " \"parentId\": \"Super\",\n" + + " \"attributes\": [\n" + + " {\n" + + " \"key\": \"Country\",\n" + + " \"value\": \"Sri Lanka\"\n" + + " }\n" + + " ]\n" + + "}"; + Response responseOfPost = getResponseOfPost(ORGANIZATION_MANAGEMENT_API_BASE_PATH, body); + responseOfPost.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_CREATED) + .header(HttpHeaders.LOCATION, notNullValue()); + + String location = responseOfPost.getHeader(HttpHeaders.LOCATION); + String createdOrgId = extractOrganizationIdFromLocationHeader(location); + assertNotBlank(createdOrgId); + return createdOrgId; + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java new file mode 100644 index 00000000000..f5dd55f002a --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.organization.management.v1; + +import io.restassured.response.Response; +import org.apache.http.HttpStatus; +import org.json.JSONObject; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.Factory; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.identity.integration.test.rest.api.server.organization.management.v1.model.OrganizationType; + +/** + * Tests for negative paths of the Organization Management REST API. + */ +public class OrganizationManagementFailureTest extends OrganizationManagementBaseTest { + + @Factory(dataProvider = "restAPIUserConfigProvider") + public OrganizationManagementFailureTest(TestUserMode userMode, OrganizationType organizationType) + throws Exception { + + super(userMode, organizationType); + } + + @AfterMethod(alwaysRun = true) + @Override + public void testFinish() { + + super.testFinish(); + } + + @Test + public void testCreateOrganizationWithoutRequiredField() throws Exception { + + JSONObject organizationObject = new JSONObject(); + String parentId; + + if (organizationType.name().equals("SUPER_ORGANIZATION")) { + parentId = SUPER_ORGANIZATION_NAME; + } else { + parentId = subOrganizationId; + } + organizationObject.put("parentId", parentId); + String payload = organizationObject.toString(); + + Response response = getResponseOfPost(ORGANIZATION_MANAGEMENT_API_BASE_PATH, payload); + validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, "UE-10000"); + } + + @Test + public void testCreateOrganizationWithABlankName() throws Exception { + + JSONObject organizationObject = new JSONObject(); + String parentId; + + if (organizationType.name().equals("SUPER_ORGANIZATION")) { + parentId = SUPER_ORGANIZATION_NAME; + } else { + parentId = subOrganizationId; + } + organizationObject.put(ORGANIZATION_NAME, ""); + organizationObject.put(ORGANIZATION_PARENT_ID, parentId); + String payload = organizationObject.toString(); + + Response response = getResponseOfPost(ORGANIZATION_MANAGEMENT_API_BASE_PATH, payload); + validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, "ORG-60002", ORGANIZATION_NAME); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java new file mode 100644 index 00000000000..5733df3c029 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.organization.management.v1; + +import io.restassured.http.ContentType; +import io.restassured.response.Response; +import org.apache.http.HttpHeaders; +import org.apache.http.HttpStatus; +import org.json.JSONObject; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Factory; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.identity.integration.test.rest.api.server.organization.management.v1.model.OrganizationType; + +import java.util.HashSet; +import java.util.Set; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.wso2.identity.integration.test.rest.api.server.organization.management.v1.OrganizationManagementTestData.APPLICATION_PAYLOAD; +import static org.wso2.identity.integration.test.rest.api.server.organization.management.v1.Utils.assertNotBlank; +import static org.wso2.identity.integration.test.rest.api.server.organization.management.v1.Utils.extractOrganizationIdFromLocationHeader; + +/** + * Tests for happy paths of the Organization Management REST API. + */ +public class OrganizationManagementSuccessTest extends OrganizationManagementBaseTest { + + private Set createdOrgs = new HashSet<>(); + private String createdOrganizationId; + private String createdOrganizationName; + + @Factory(dataProvider = "restAPIUserConfigProvider") + public OrganizationManagementSuccessTest(TestUserMode userMode, OrganizationType organizationType) + throws Exception { + + super(userMode, organizationType); + } + + @AfterClass(alwaysRun = true) + @Override + public void testFinish() { + + cleanUpOrganizations(createdOrgs); + super.testFinish(); + } + + @Test + public void createOrganization() throws Exception { + + JSONObject organizationObject = new JSONObject(); + String org; + String parentId; + + if (organizationType.name().equals("SUPER_ORGANIZATION")) { + org = "Level1Org"; + parentId = SUPER_ORGANIZATION_NAME; + } else { + org = "Level2Org"; + parentId = subOrganizationId; + } + organizationObject.put(ORGANIZATION_NAME, org); + organizationObject.put(ORGANIZATION_PARENT_ID, parentId); + + Response responseOfPost = getResponseOfPost(ORGANIZATION_MANAGEMENT_API_BASE_PATH, + organizationObject.toString()); + responseOfPost.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_CREATED) + .header(HttpHeaders.LOCATION, notNullValue()); + + String location = responseOfPost.getHeader(HttpHeaders.LOCATION); + String createdOrgId = extractOrganizationIdFromLocationHeader(location); + createdOrgs.add(createdOrgId); + createdOrganizationId = createdOrgId; + createdOrganizationName = org; + + assertNotBlank(createdOrgId); + if (organizationType == OrganizationType.SUB_ORGANIZATION) { + // Check whether password recovery is enabled in the created sub-organization. + String governanceURL = "/o/" + createdOrganizationId + + "/api/server/v1/identity-governance/QWNjb3VudCBNYW5hZ2VtZW50/connectors/YWNjb3VudC1yZWNvdmVyeQ"; + given() + .auth().preemptive().basic(authenticatingUserName, authenticatingCredential) + .contentType(ContentType.JSON) + .header(HttpHeaders.ACCEPT, ContentType.JSON) + .log().ifValidationFails() + .when() + .get(backendURL.replace(SERVICES, governanceURL)) + .then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .body("properties.find { it.name == 'Recovery.Notification.Password.Enable' }.value", + equalTo("true")) + .body("properties.find { it.name == 'Recovery.NotifySuccess' }.value", equalTo("true")); + + // Check whether application creation is disabled in the sub-organization. + String appCreationURL = "/o/" + createdOrganizationId + "/api/server/v1/applications"; + Response response = given() + .auth().preemptive().basic(authenticatingUserName, authenticatingCredential) + .contentType(ContentType.JSON) + .header(HttpHeaders.ACCEPT, ContentType.JSON) + .body(APPLICATION_PAYLOAD) + .log().ifValidationFails() + .when() + .post(backendURL.replace(SERVICES, appCreationURL)); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_BAD_REQUEST) + .body("code", equalTo("ORG-60078")) + .body("message", equalTo("Error creating application.")) + .body("description", equalTo("Applications cannot be created for sub-organizations.")); + } + } + + @Test(dependsOnMethods = {"createOrganization"}) + public void testGetOrganizationById() throws Exception { + + getResponseOfGet(ORGANIZATION_MANAGEMENT_API_BASE_PATH + "/" + createdOrganizationId) + .then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .body(ORGANIZATION_NAME, equalTo(createdOrganizationName)); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementTestData.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementTestData.java new file mode 100644 index 00000000000..1ae0212a2be --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementTestData.java @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.organization.management.v1; + +/** + * Contains test data for organization management REST API tests. + */ +public class OrganizationManagementTestData { + + public static final String APPLICATION_PAYLOAD = "{" + + "\"name\": \"pickup-dispatch\"," + + "\"description\": \"This is the configuration for Pickup-dispatch application.\"," + + "\"imageUrl\": \"https://example.com/logo/my-logo.png\"," + + "\"accessUrl\": \"https://example.com/login\"," + + "\"templateId\": \"b9c5e11e-fc78-484b-9bec-015d247561b8\"," + + "\"isManagementApp\": false," + + "\"claimConfiguration\": {" + + " \"dialect\": \"LOCAL\"," + + " \"claimMappings\": [" + + " {" + + " \"applicationClaim\": \"firstname\"," + + " \"localClaim\": {" + + " \"uri\": \"http://wso2.org/claims/username\"" + + " }" + + " }" + + " ]," + + " \"requestedClaims\": [" + + " {" + + " \"claim\": {" + + " \"uri\": \"http://wso2.org/claims/username\"" + + " }," + + " \"mandatory\": false" + + " }" + + " ]," + + " \"subject\": {" + + " \"claim\": {" + + " \"uri\": \"http://wso2.org/claims/username\"" + + " }," + + " \"includeUserDomain\": false," + + " \"includeTenantDomain\": false," + + " \"useMappedLocalSubject\": false" + + " }," + + " \"role\": {" + + " \"mappings\": [" + + " {" + + " \"localRole\": \"admin\"," + + " \"applicationRole\": \"Administrator\"" + + " }" + + " ]," + + " \"includeUserDomain\": true," + + " \"claim\": {" + + " \"uri\": \"http://wso2.org/claims/username\"" + + " }" + + " }" + + "}," + + "\"inboundProtocolConfiguration\": {" + + " \"oidc\": {" + + " \"clientId\": \"rMfbPgCi5oWljNhv8c4Pugfuo8Aa\"," + + " \"clientSecret\": \"MkHGGiTdAPfTyUKfXLdyOwelMywt\"," + + " \"grantTypes\": [" + + " \"authorization_code\"," + + " \"password\"" + + " ]," + + " \"callbackURLs\": [" + + " \"regexp=(https://app.example.com/callback1|https://app.example.com/callback2)\"" + + " ]," + + " \"allowedOrigins\": [" + + " \"https://app.example.com\"" + + " ]," + + " \"publicClient\": false," + + " \"pkce\": {" + + " \"mandatory\": false," + + " \"supportPlainTransformAlgorithm\": true" + + " }," + + " \"accessToken\": {" + + " \"type\": \"JWT\"," + + " \"userAccessTokenExpiryInSeconds\": 3600," + + " \"applicationAccessTokenExpiryInSeconds\": 3600," + + " \"bindingType\": \"cookie\"," + + " \"revokeTokensWhenIDPSessionTerminated\": true," + + " \"validateTokenBinding\": true" + + " }," + + " \"refreshToken\": {" + + " \"expiryInSeconds\": 86400," + + " \"renewRefreshToken\": true" + + " }," + + " \"idToken\": {" + + " \"expiryInSeconds\": 3600," + + " \"audience\": [" + + " \"http://idp.xyz.com\"," + + " \"http://idp.abc.com\"" + + " ]," + + " \"encryption\": {" + + " \"enabled\": false," + + " \"algorithm\": \"RSA-OAEP\"," + + " \"method\": \"A128CBC+HS256\"" + + " }" + + " }," + + " \"logout\": {" + + " \"backChannelLogoutUrl\": \"https://app.example.com/backchannel/callback\"," + + " \"frontChannelLogoutUrl\": \"https://app.example.com/frontchannel/callback\"" + + " }," + + " \"validateRequestObjectSignature\": false," + + " \"scopeValidators\": [" + + " \"Role based scope validator\"" + + " ]" + + " }" + + "}," + + "\"authenticationSequence\": {" + + " \"type\": \"DEFAULT\"," + + " \"steps\": [" + + " {" + + " \"id\": 1," + + " \"options\": [" + + " {" + + " \"idp\": \"LOCAL\"," + + " \"authenticator\": \"basic\"" + + " }" + + " ]" + + " }" + + " ]," + + " \"script\": \"string\"," + + " \"subjectStepId\": 1," + + " \"attributeStepId\": 1" + + "}," + + "\"advancedConfigurations\": {" + + " \"saas\": false," + + " \"discoverableByEndUsers\": false," + + " \"certificate\": {" + + " \"type\": \"string\"," + + " \"value\": \"string\"" + + " }," + + " \"skipLoginConsent\": false," + + " \"skipLogoutConsent\": false," + + " \"useExternalConsentPage\": false," + + " \"returnAuthenticatedIdpList\": false," + + " \"enableAuthorization\": true" + + "}" + + "}"; +} + diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/Utils.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/Utils.java new file mode 100644 index 00000000000..21cf0f76900 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/Utils.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.organization.management.v1; + +import org.apache.commons.lang.StringUtils; +import org.testng.Assert; + +/** + * Common utility functions used in organization management REST API tests. + */ +public class Utils { + + public static String extractOrganizationIdFromLocationHeader(String locationHeaderValue) { + + return StringUtils.substringAfterLast(locationHeaderValue, "/"); + } + + public static void assertNotBlank(String value) { + + Assert.assertTrue(StringUtils.isNotBlank(value)); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/model/OrganizationType.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/model/OrganizationType.java new file mode 100644 index 00000000000..fd9f488b611 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/model/OrganizationType.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.organization.management.v1.model; + +public enum OrganizationType { + SUPER_ORGANIZATION, + SUB_ORGANIZATION +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml index 09108d5dd98..2c342edaddb 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml @@ -358,4 +358,10 @@ + + + + + + From 177717a2f7457f7a3e486d6359b440b160ab1fe5 Mon Sep 17 00:00:00 2001 From: sadilchamishka <35717390+sadilchamishka@users.noreply.github.com> Date: Wed, 20 Sep 2023 11:49:51 +0530 Subject: [PATCH 2/3] Address review comments --- .../integration/test/rest/api/common/B2BRESTTestBase.java | 7 ++++--- .../management/v1/OrganizationManagementBaseTest.java | 2 +- .../management/v1/OrganizationManagementFailureTest.java | 7 ++++--- .../management/v1/OrganizationManagementSuccessTest.java | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/common/B2BRESTTestBase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/common/B2BRESTTestBase.java index 41186758e35..fbc37f5c2b6 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/common/B2BRESTTestBase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/common/B2BRESTTestBase.java @@ -92,6 +92,7 @@ protected Response getResponseOfGet(String endpointUri) { * @return Response of post request. */ protected Response getResponseOfPost(String endpointUri, String body) { + return given().auth().preemptive().basic(authenticatingUserName, authenticatingCredential) .contentType(ContentType.JSON) .header(HttpHeaders.ACCEPT, ContentType.JSON) @@ -140,7 +141,7 @@ protected void validateErrorResponse(Response response, int httpStatusCode, Stri } /** - * Validate http status code of the response + * Validate http status code of the response. * * @param response Response. * @param httpStatusCode Expected status code. @@ -155,7 +156,7 @@ protected void validateHttpStatusCode(Response response, int httpStatusCode) { } /** - * Validate error description of the response, if an entry is available in RESTAPIErrors.properties + * Validate error description of the response, if an entry is available in RESTAPIErrors.properties. * * @param response Response. * @param errorCode Error code. @@ -179,7 +180,7 @@ private void validateErrorMessage(Response response, String errorCode) { } /** - * Validate elements in error response against entries in RESTAPIErrors.properties + * Validate elements in error response against entries in RESTAPIErrors.properties. * * @param response Response. * @param errorCode API error code. diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementBaseTest.java index 2913cf35d32..326c1f532e4 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementBaseTest.java @@ -86,7 +86,7 @@ public void init(ITestContext context) throws Exception { orgId = SUPER_ORGANIZATION_ID; } this.subOrganizationId = orgId; - if (this.organizationType.name().equals("SUPER_ORGANIZATION")) { + if (OrganizationType.SUPER_ORGANIZATION.equals(this.organizationType)) { super.testInitWithoutTenantQualifiedPath(API_VERSION, swaggerDefinition); } else { this.tenant = subOrganizationId; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java index f5dd55f002a..d75de0cfa6e 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java @@ -19,6 +19,7 @@ package org.wso2.identity.integration.test.rest.api.server.organization.management.v1; import io.restassured.response.Response; +import org.apache.commons.lang.StringUtils; import org.apache.http.HttpStatus; import org.json.JSONObject; import org.testng.annotations.AfterMethod; @@ -52,7 +53,7 @@ public void testCreateOrganizationWithoutRequiredField() throws Exception { JSONObject organizationObject = new JSONObject(); String parentId; - if (organizationType.name().equals("SUPER_ORGANIZATION")) { + if (OrganizationType.SUPER_ORGANIZATION.equals(this.organizationType)) { parentId = SUPER_ORGANIZATION_NAME; } else { parentId = subOrganizationId; @@ -70,12 +71,12 @@ public void testCreateOrganizationWithABlankName() throws Exception { JSONObject organizationObject = new JSONObject(); String parentId; - if (organizationType.name().equals("SUPER_ORGANIZATION")) { + if (OrganizationType.SUPER_ORGANIZATION.equals(this.organizationType)) { parentId = SUPER_ORGANIZATION_NAME; } else { parentId = subOrganizationId; } - organizationObject.put(ORGANIZATION_NAME, ""); + organizationObject.put(ORGANIZATION_NAME, StringUtils.EMPTY); organizationObject.put(ORGANIZATION_PARENT_ID, parentId); String payload = organizationObject.toString(); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java index 5733df3c029..5c624cde9c7 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java @@ -70,7 +70,7 @@ public void createOrganization() throws Exception { String org; String parentId; - if (organizationType.name().equals("SUPER_ORGANIZATION")) { + if (OrganizationType.SUPER_ORGANIZATION.equals(this.organizationType)) { org = "Level1Org"; parentId = SUPER_ORGANIZATION_NAME; } else { From ea69e87621a1e12d4b0c74eea79ad2d25a22e8cc Mon Sep 17 00:00:00 2001 From: sadilchamishka Date: Wed, 20 Sep 2023 15:00:17 +0530 Subject: [PATCH 3/3] Refactor organization type variable to organization level --- .../v1/OrganizationManagementBaseTest.java | 16 ++++++++-------- .../v1/OrganizationManagementFailureTest.java | 10 +++++----- .../v1/OrganizationManagementSuccessTest.java | 10 +++++----- ...anizationType.java => OrganizationLevel.java} | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) rename modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/model/{OrganizationType.java => OrganizationLevel.java} (96%) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementBaseTest.java index 326c1f532e4..09027596e68 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementBaseTest.java @@ -33,7 +33,7 @@ import org.testng.annotations.DataProvider; import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.identity.integration.test.rest.api.server.common.B2BRESTAPIServerTestBase; -import org.wso2.identity.integration.test.rest.api.server.organization.management.v1.model.OrganizationType; +import org.wso2.identity.integration.test.rest.api.server.organization.management.v1.model.OrganizationLevel; import java.io.IOException; import java.util.Set; @@ -49,7 +49,7 @@ public class OrganizationManagementBaseTest extends B2BRESTAPIServerTestBase { private static final String API_DEFINITION_NAME = "org.wso2.carbon.identity.organization.management.yaml"; static final String API_VERSION = "v1"; - public final OrganizationType organizationType; + public final OrganizationLevel organizationLevel; static final String SUPER_ORGANIZATION_NAME = "Super"; static final String ORGANIZATION_NAME = "name"; static final String ORGANIZATION_PARENT_ID = "parentId"; @@ -68,9 +68,9 @@ public class OrganizationManagementBaseTest extends B2BRESTAPIServerTestBase { } } - public OrganizationManagementBaseTest(TestUserMode userMode, OrganizationType organizationType) throws Exception { + public OrganizationManagementBaseTest(TestUserMode userMode, OrganizationLevel organizationLevel) throws Exception { - this.organizationType = organizationType; + this.organizationLevel = organizationLevel; super.init(userMode); this.context = isServer; this.authenticatingUserName = context.getContextTenant().getTenantAdmin().getUserName(); @@ -86,7 +86,7 @@ public void init(ITestContext context) throws Exception { orgId = SUPER_ORGANIZATION_ID; } this.subOrganizationId = orgId; - if (OrganizationType.SUPER_ORGANIZATION.equals(this.organizationType)) { + if (OrganizationLevel.SUPER_ORGANIZATION.equals(this.organizationLevel)) { super.testInitWithoutTenantQualifiedPath(API_VERSION, swaggerDefinition); } else { this.tenant = subOrganizationId; @@ -124,8 +124,8 @@ public void testFinish() { public static Object[][] restAPIUserConfigProvider() { return new Object[][]{ - {TestUserMode.SUPER_TENANT_ADMIN, OrganizationType.SUPER_ORGANIZATION}, - {TestUserMode.SUPER_TENANT_ADMIN, OrganizationType.SUB_ORGANIZATION} + {TestUserMode.SUPER_TENANT_ADMIN, OrganizationLevel.SUPER_ORGANIZATION}, + {TestUserMode.SUPER_TENANT_ADMIN, OrganizationLevel.SUB_ORGANIZATION} }; } @@ -133,7 +133,7 @@ public static Object[][] restAPIUserConfigProvider() { public static Object[][] initRESTAPIUserConfigProvider() { return new Object[][]{ - {TestUserMode.SUPER_TENANT_ADMIN, OrganizationType.SUPER_ORGANIZATION}, + {TestUserMode.SUPER_TENANT_ADMIN, OrganizationLevel.SUPER_ORGANIZATION}, }; } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java index d75de0cfa6e..3a6b62fee16 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java @@ -26,7 +26,7 @@ import org.testng.annotations.Factory; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; -import org.wso2.identity.integration.test.rest.api.server.organization.management.v1.model.OrganizationType; +import org.wso2.identity.integration.test.rest.api.server.organization.management.v1.model.OrganizationLevel; /** * Tests for negative paths of the Organization Management REST API. @@ -34,10 +34,10 @@ public class OrganizationManagementFailureTest extends OrganizationManagementBaseTest { @Factory(dataProvider = "restAPIUserConfigProvider") - public OrganizationManagementFailureTest(TestUserMode userMode, OrganizationType organizationType) + public OrganizationManagementFailureTest(TestUserMode userMode, OrganizationLevel organizationLevel) throws Exception { - super(userMode, organizationType); + super(userMode, organizationLevel); } @AfterMethod(alwaysRun = true) @@ -53,7 +53,7 @@ public void testCreateOrganizationWithoutRequiredField() throws Exception { JSONObject organizationObject = new JSONObject(); String parentId; - if (OrganizationType.SUPER_ORGANIZATION.equals(this.organizationType)) { + if (OrganizationLevel.SUPER_ORGANIZATION.equals(this.organizationLevel)) { parentId = SUPER_ORGANIZATION_NAME; } else { parentId = subOrganizationId; @@ -71,7 +71,7 @@ public void testCreateOrganizationWithABlankName() throws Exception { JSONObject organizationObject = new JSONObject(); String parentId; - if (OrganizationType.SUPER_ORGANIZATION.equals(this.organizationType)) { + if (OrganizationLevel.SUPER_ORGANIZATION.equals(this.organizationLevel)) { parentId = SUPER_ORGANIZATION_NAME; } else { parentId = subOrganizationId; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java index 5c624cde9c7..df59a76377a 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java @@ -27,7 +27,7 @@ import org.testng.annotations.Factory; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; -import org.wso2.identity.integration.test.rest.api.server.organization.management.v1.model.OrganizationType; +import org.wso2.identity.integration.test.rest.api.server.organization.management.v1.model.OrganizationLevel; import java.util.HashSet; import java.util.Set; @@ -49,10 +49,10 @@ public class OrganizationManagementSuccessTest extends OrganizationManagementBas private String createdOrganizationName; @Factory(dataProvider = "restAPIUserConfigProvider") - public OrganizationManagementSuccessTest(TestUserMode userMode, OrganizationType organizationType) + public OrganizationManagementSuccessTest(TestUserMode userMode, OrganizationLevel organizationLevel) throws Exception { - super(userMode, organizationType); + super(userMode, organizationLevel); } @AfterClass(alwaysRun = true) @@ -70,7 +70,7 @@ public void createOrganization() throws Exception { String org; String parentId; - if (OrganizationType.SUPER_ORGANIZATION.equals(this.organizationType)) { + if (OrganizationLevel.SUPER_ORGANIZATION.equals(this.organizationLevel)) { org = "Level1Org"; parentId = SUPER_ORGANIZATION_NAME; } else { @@ -95,7 +95,7 @@ public void createOrganization() throws Exception { createdOrganizationName = org; assertNotBlank(createdOrgId); - if (organizationType == OrganizationType.SUB_ORGANIZATION) { + if (organizationLevel == OrganizationLevel.SUB_ORGANIZATION) { // Check whether password recovery is enabled in the created sub-organization. String governanceURL = "/o/" + createdOrganizationId + "/api/server/v1/identity-governance/QWNjb3VudCBNYW5hZ2VtZW50/connectors/YWNjb3VudC1yZWNvdmVyeQ"; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/model/OrganizationType.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/model/OrganizationLevel.java similarity index 96% rename from modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/model/OrganizationType.java rename to modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/model/OrganizationLevel.java index fd9f488b611..52fa3423c04 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/model/OrganizationType.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/model/OrganizationLevel.java @@ -18,7 +18,7 @@ package org.wso2.identity.integration.test.rest.api.server.organization.management.v1.model; -public enum OrganizationType { +public enum OrganizationLevel { SUPER_ORGANIZATION, SUB_ORGANIZATION }