Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onboard organization management integration tests #18343

Merged
merged 6 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,87 +15,43 @@
* 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.OrganizationLevel;
import org.wso2.identity.integration.test.utils.CarbonUtils;
import org.wso2.identity.integration.test.rest.api.server.common.RESTAPIServerTestBase;
import org.wso2.identity.integration.test.restclients.OAuth2RestClient;

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.
* Base test class for the Organization Management REST APIs.
*/
public class OrganizationManagementBaseTest extends B2BRESTAPIServerTestBase {
public class OrganizationManagementBaseTest extends RESTAPIServerTestBase {

public static final String SUPER_ORGANIZATION_ID = "10084a8d-113f-4211-a0d5-efe36b082211";
public static final String SUPER_TENANT_DOMAIN = "carbon.super";
private static final String API_DEFINITION_NAME = "org.wso2.carbon.identity.organization.management.yaml";
static final String API_VERSION = "v1";
public final OrganizationLevel organizationLevel;
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";

static final String ORGANIZATION_MANAGEMENT_API_BASE_PATH = "/organizations";
static final String PATH_SEPARATOR = "/";

protected static String swaggerDefinition;
static boolean isLegacyRuntimeEnabled;
protected OAuth2RestClient oAuth2RestClient;

static {
String apiPackageName = "org.wso2.carbon.identity.api.server.organization.management.v1";
String API_PACKAGE_NAME = "org.wso2.carbon.identity.api.server.organization.management.v1";

try {
swaggerDefinition = getAPISwaggerDefinition(apiPackageName, API_DEFINITION_NAME);
swaggerDefinition = getAPISwaggerDefinition(API_PACKAGE_NAME, 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, OrganizationLevel organizationLevel) throws Exception {

this.organizationLevel = organizationLevel;
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();
isLegacyRuntimeEnabled = CarbonUtils.isLegacyAuthzRuntimeEnabled();
String orgId = (String) suite.getAttribute("createdOrgId");
if (orgId == null) {
orgId = SUPER_ORGANIZATION_ID;
}
this.subOrganizationId = orgId;
if (OrganizationLevel.SUPER_ORGANIZATION.equals(this.organizationLevel)) {
super.testInitWithoutTenantQualifiedPath(API_VERSION, swaggerDefinition);
} else {
this.tenant = subOrganizationId;
String tenantDomain = tenantInfo.getDomain();
this.authenticatingUserName = "admin@" + tenantDomain;
super.testInit(API_VERSION, swaggerDefinition, tenantDomain);
API_PACKAGE_NAME), e);
}
}

Expand All @@ -106,78 +62,14 @@ public void testConclude() throws Exception {
}

@BeforeMethod(alwaysRun = true)
public void testInit(ITestContext context) throws Exception {
public void testInit() {

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() throws Exception{
public void testFinish() {

RestAssured.basePath = StringUtils.EMPTY;
}

@DataProvider(name = "restAPIUserConfigProvider")
public static Object[][] restAPIUserConfigProvider() {

return new Object[][]{
{TestUserMode.SUPER_TENANT_ADMIN, OrganizationLevel.SUPER_ORGANIZATION},
{TestUserMode.SUPER_TENANT_ADMIN, OrganizationLevel.SUB_ORGANIZATION}
};
}

@DataProvider(name = "initRESTAPIUserConfigProvider")
public static Object[][] initRESTAPIUserConfigProvider() {

return new Object[][]{
{TestUserMode.SUPER_TENANT_ADMIN, OrganizationLevel.SUPER_ORGANIZATION},
};
}

protected void cleanUpOrganizations(Set<String> 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\": \"10084a8d-113f-4211-a0d5-efe36b082211\",\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;
}
}

This file was deleted.

Loading