Skip to content

Commit

Permalink
Improve tenanted url resolving logic in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ImalshaG committed Oct 23, 2023
1 parent ab7c8ef commit 76fd26d
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public class OAuth2ScopesTestCase extends ISIntegrationTest {
public void testInit() throws Exception {
super.init();
String isServerBackendUrl = isServer.getContextUrls().getWebAppURLHttps();
scopeEndpoint = isServerBackendUrl + "/t/" + isServer.getContextTenant().getDomain() + SCOPE_ENDPOINT_SUFFIX;
scopeEndpoint = isServerBackendUrl +
getTenantedRelativePath(SCOPE_ENDPOINT_SUFFIX, isServer.getContextTenant().getDomain());
}

@AfterClass(alwaysRun = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public class RESTTestBase extends ISIntegrationTest {
+ File.separator + "deployment" + File.separator + "server" + File.separator + "webapps" + File
.separator + "api" + File.separator + "WEB-INF" + File.separator
+ "lib" + File.separator;
protected static final String TENANT_CONTEXT_IN_URL = "/t/%s";
private static final String JAR_EXTENSION = ".jar";
protected static final String SERVICES = "/services";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.wso2.identity.integration.test.rest.api.server.common;

import org.apache.axis2.AxisFault;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.rest.api.common.RESTTestBase;

import java.rmi.RemoteException;
Expand All @@ -29,15 +30,13 @@ public class RESTAPIServerTestBase extends RESTTestBase {

protected static final String API_SERVER_BASE_PATH = "/api/server/%s";
protected static final String API_SERVER_BASE_PATH_IN_SWAGGER = "/t/\\{tenant-domain\\}" + API_SERVER_BASE_PATH;
protected static final String API_SERVER_BASE_PATH_WITH_TENANT_CONTEXT =
TENANT_CONTEXT_IN_URL + API_SERVER_BASE_PATH;

protected void testInit(String apiVersion, String apiDefinition, String tenantDomain)
throws RemoteException {

String basePathInSwagger = String.format(API_SERVER_BASE_PATH_IN_SWAGGER, apiVersion);
String basePath = String.format(API_SERVER_BASE_PATH_WITH_TENANT_CONTEXT,
tenantDomain, apiVersion);
String basePath = ISIntegrationTest.getTenantedRelativePath(String.format(API_SERVER_BASE_PATH, apiVersion),
tenantDomain);
super.init(apiDefinition, basePathInSwagger, basePath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty;
import org.wso2.carbon.integration.common.admin.client.AuthenticatorClient;
import org.wso2.identity.integration.common.clients.Idp.IdentityProviderMgtServiceClient;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.rest.api.common.RESTTestBase;

/**
Expand All @@ -34,7 +35,6 @@ public class RESTAPIUserTestBase extends RESTTestBase {

protected static final String API_USERS_BASE_PATH = "/api/users/%s";
protected static final String API_USERS_BASE_PATH_IN_SWAGGER = "/t/\\{tenant-domain\\}" + API_USERS_BASE_PATH;
protected static final String API_USERS_BASE_PATH_WITH_TENANT_CONTEXT = TENANT_CONTEXT_IN_URL + API_USERS_BASE_PATH;
private static final String ADMIN = "admin";
private IdentityProviderMgtServiceClient superTenantIDPMgtClient;
private IdentityProviderMgtServiceClient tenantIDPMgtClient;
Expand All @@ -45,8 +45,8 @@ protected void testInit(String apiVersion, String apiDefinition, String tenantDo
throws XPathExpressionException, RemoteException {

String basePathInSwagger = String.format(API_USERS_BASE_PATH_IN_SWAGGER, apiVersion);
String basePath = String.format(API_USERS_BASE_PATH_WITH_TENANT_CONTEXT,
tenantDomain, apiVersion);
String basePath = ISIntegrationTest.getTenantedRelativePath(String.format(API_USERS_BASE_PATH, apiVersion),
tenantDomain);
super.init(apiDefinition, basePathInSwagger, basePath);
}

Expand All @@ -64,8 +64,8 @@ protected void testInit(String apiVersion, String apiDefinition, String tenantDo
throws XPathExpressionException, RemoteException {

String basePathInSwagger = String.format(apiUserBasePathInSwagger, apiVersion);
String basePath = String.format(apiUserBasePathWithTenantContext,
tenantDomain, apiVersion);
String basePath = ISIntegrationTest.getTenantedRelativePath(String.format(apiUserBasePathWithTenantContext,
apiVersion), tenantDomain);
super.init(apiDefinition, basePathInSwagger, basePath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ public class LiteUserRegisterTestCase extends LiteUserRegisterTestBase {
protected static final String API_LITE_USER_REGISTER_BASE_PATH = "/api/identity/user/%s";
protected static final String API_LITE_USER_REGISTER_BASE_PATH_IN_SWAGGER =
"/t/\\{tenant-domain\\}" + API_LITE_USER_REGISTER_BASE_PATH;
protected static final String API_LITE_USER_REGISTER_BASE_PATH_WITH_TENANT_CONTEXT =
TENANT_CONTEXT_IN_URL + API_LITE_USER_REGISTER_BASE_PATH;
protected static final String API_VERSION_LITE_USER = "v1.0";

@BeforeClass(alwaysRun = true)
public void init() throws Exception {

super.testInit(API_VERSION_LITE_USER, swaggerDefinitionLiteUserRegister, tenant,
API_LITE_USER_REGISTER_BASE_PATH_IN_SWAGGER, API_LITE_USER_REGISTER_BASE_PATH_WITH_TENANT_CONTEXT);
API_LITE_USER_REGISTER_BASE_PATH_IN_SWAGGER, API_LITE_USER_REGISTER_BASE_PATH);
}

@BeforeMethod(alwaysRun = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void init() throws Exception {
this.tenant = context.getContextTenant().getDomain();

super.testInit(API_VERSION_SELF_REGISTER, swaggerDefinitionSelfRegister, tenant,
API_SELF_REGISTER_BASE_PATH_IN_SWAGGER, API_SELF_REGISTER_BASE_PATH_WITH_TENANT_CONTEXT);
API_SELF_REGISTER_BASE_PATH_IN_SWAGGER, API_SELF_REGISTER_BASE_PATH);
selfRegisterUserInfo = readResource("self-register-tenanted-user-request-body.json");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public class SelfRegisterTestBase extends RESTAPIUserTestBase {
protected static final String API_SELF_REGISTER_BASE_PATH = "/api/identity/user/%s";
protected static final String API_SELF_REGISTER_BASE_PATH_IN_SWAGGER =
"/t/\\{tenant-domain\\}" + API_SELF_REGISTER_BASE_PATH;
protected static final String API_SELF_REGISTER_BASE_PATH_WITH_TENANT_CONTEXT =
TENANT_CONTEXT_IN_URL + API_SELF_REGISTER_BASE_PATH;
protected static final String API_VERSION_SELF_REGISTER = "v1.0";

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void init() throws Exception {
this.tenant = context.getContextTenant().getDomain();

super.testInit(API_VERSION_SELF_REGISTER, swaggerDefinitionSelfRegister, tenant,
API_SELF_REGISTER_BASE_PATH_IN_SWAGGER, API_SELF_REGISTER_BASE_PATH_WITH_TENANT_CONTEXT);
API_SELF_REGISTER_BASE_PATH_IN_SWAGGER, API_SELF_REGISTER_BASE_PATH);
selfRegisterUserInfo = readResource("self-register-request-body.json");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.http.message.BasicHeader;
import org.testng.Assert;
import org.wso2.carbon.automation.engine.context.beans.Tenant;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.rest.api.server.challenge.v1.model.UserChallengeAnswer;
import org.wso2.identity.integration.test.utils.OAuth2Constant;

Expand Down Expand Up @@ -57,8 +58,8 @@ public void setChallengeQuestionAnswer(String userId, String questionSetId,
UserChallengeAnswer challengeAsnwerObj) throws Exception {

String jsonRequest = toJSONString(challengeAsnwerObj);
String endPointUrl = serverUrl + TENANT_PATH + tenantDomain + PATH_SEPARATOR +
String.format(CHALLENGE_QUESTION_BASE_PATH, userId) + PATH_SEPARATOR + questionSetId;
String endPointUrl = serverUrl + ISIntegrationTest.getTenantedRelativePath(String.format(
CHALLENGE_QUESTION_BASE_PATH, userId) + PATH_SEPARATOR + questionSetId, tenantDomain);

try (CloseableHttpResponse response = getResponseOfHttpPost(endPointUrl, jsonRequest, getHeaders())) {
Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpServletResponse.SC_CREATED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
import org.json.simple.JSONObject;
import org.testng.Assert;
import org.wso2.carbon.automation.engine.context.beans.Tenant;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.rest.api.server.claim.management.v1.model.ExternalClaimReq;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ClaimManagementRestClient extends RestBaseClient {

private static final String TENANT_PATH = "t/%s";
private static final String API_SERVER_BASE_PATH = "/api/server/v1";
private static final String CLAIM_DIALECTS_ENDPOINT_URI = "/claim-dialects";

Expand All @@ -54,7 +54,7 @@ public ClaimManagementRestClient(String backendURL, Tenant tenantInfo) {

String tenantDomain = tenantInfo.getContextUser().getUserDomain();

serverBasePath = backendURL + String.format(TENANT_PATH, tenantDomain) + API_SERVER_BASE_PATH;
serverBasePath = backendURL + ISIntegrationTest.getTenantedRelativePath(API_SERVER_BASE_PATH, tenantDomain);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.wso2.carbon.automation.engine.context.beans.Tenant;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;

import java.io.IOException;

public class EmailTemplatesRestClient extends RestBaseClient {

private static final String TENANT_PATH = "t/%s";
private static final String API_SERVER_BASE_PATH = "/api/server/v1";
private static final String EMAIL_TEMPLATES_EMAIL_BASE_PATH = "/email";
private static final String EMAIL_TEMPLATE_TYPES_PATH = "/template-types";
Expand All @@ -51,8 +52,8 @@ public EmailTemplatesRestClient(String backendURL, Tenant tenantInfo) {

String tenantDomain = tenantInfo.getContextUser().getUserDomain();

emailTemplateApiBasePath = backendURL + String.format(TENANT_PATH, tenantDomain) + API_SERVER_BASE_PATH +
EMAIL_TEMPLATES_EMAIL_BASE_PATH + EMAIL_TEMPLATE_TYPES_PATH;
emailTemplateApiBasePath = backendURL + ISIntegrationTest.getTenantedRelativePath(API_SERVER_BASE_PATH
+ EMAIL_TEMPLATES_EMAIL_BASE_PATH + EMAIL_TEMPLATE_TYPES_PATH, tenantDomain);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
import org.apache.http.message.BasicHeader;
import org.testng.Assert;
import org.wso2.carbon.automation.engine.context.beans.Tenant;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.ConnectorsPatchReq;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class IdentityGovernanceRestClient extends RestBaseClient {

private static final String TENANT_PATH = "t/%s";
private static final String API_SERVER_BASE_PATH = "/api/server/v1";
private static final String IDENTITY_GOVERNANCE_BASE_PATH = "/identity-governance";
private static final String CONNECTORS_BASE_PATH = "/connectors";
Expand All @@ -54,8 +54,8 @@ public IdentityGovernanceRestClient(String backendURL, Tenant tenantInfo) {

String tenantDomain = tenantInfo.getContextUser().getUserDomain();

identityGovernanceApiBasePath = backendURL + String.format(TENANT_PATH, tenantDomain) + API_SERVER_BASE_PATH +
IDENTITY_GOVERNANCE_BASE_PATH;
identityGovernanceApiBasePath = backendURL + ISIntegrationTest.getTenantedRelativePath(
API_SERVER_BASE_PATH + IDENTITY_GOVERNANCE_BASE_PATH, tenantDomain);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
import org.testng.Assert;
import org.wso2.carbon.automation.engine.context.beans.Tenant;
import org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.UserStoreReq;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UserStoreMgtRestClient extends RestBaseClient {
private static final String TENANT_PATH = "t/%s";
private static final String API_SERVER_BASE_PATH = "/api/server/v1";
public static final String USER_STORES_ENDPOINT_URI = "/userstores";
private final CloseableHttpClient client;
Expand All @@ -53,8 +53,8 @@ public UserStoreMgtRestClient(String backendURL, Tenant tenantInfo) {
this.password = tenantInfo.getContextUser().getPassword();
String tenantDomain = tenantInfo.getContextUser().getUserDomain();

userStoreBasePath = backendURL + String.format(TENANT_PATH, tenantDomain) + API_SERVER_BASE_PATH +
USER_STORES_ENDPOINT_URI;
userStoreBasePath = backendURL + ISIntegrationTest.getTenantedRelativePath(API_SERVER_BASE_PATH
+ USER_STORES_ENDPOINT_URI, tenantDomain);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.test.rest.api.common.RESTTestBase;

import java.io.File;
Expand All @@ -38,7 +39,6 @@ public class SCIM2BaseTest extends RESTTestBase {
protected static String swaggerDefinition;
protected static final String SCIM_CONTENT_TYPE = "application/scim+json";
protected static final String SCIM2_BASE_PATH_IN_SWAGGER = "/t/\\{tenant-domain\\}" + SCIM2_ENDPOINT;
protected static final String SCIM2_BASE_PATH_WITH_TENANT_CONTEXT = TENANT_CONTEXT_IN_URL + SCIM2_ENDPOINT;
public static final String FILE_BASE_PATH = (System.getProperty("basedir", "."))
+ File.separator + "src" + File.separator + "test"
+ File.separator + "resources" + File.separator;
Expand All @@ -59,8 +59,7 @@ public void testInit(String apiDefinition, String tenantDomain)
if ("carbon.super".equals(tenantDomain)) {
basePath = String.format(SCIM2_ENDPOINT);
} else {
basePath = String.format(SCIM2_BASE_PATH_WITH_TENANT_CONTEXT,
tenantDomain);
basePath = ISIntegrationTest.getTenantedRelativePath(SCIM2_ENDPOINT, tenantDomain);
}
super.init(apiDefinition, SCIM2_BASE_PATH_IN_SWAGGER, basePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.testng.annotations.Factory;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -194,7 +195,7 @@ private String getContext() {
if (CARBON_SUPER.equals(tenant)) {
return API_SERVER_BASE_CONTEXT;
} else {
return String.format(TENANT_CONTEXT_IN_URL, tenant) + API_SERVER_BASE_CONTEXT;
return ISIntegrationTest.getTenantedRelativePath(API_SERVER_BASE_CONTEXT, tenant);
}
}
}

0 comments on commit 76fd26d

Please sign in to comment.