Skip to content

Commit

Permalink
Merge pull request #21023 from BimsaraBodaragama/fix/integration-test…
Browse files Browse the repository at this point in the history
…s-for-organization-discovery-pagination

Add integration tests for Organizations Discovery GET API
  • Loading branch information
sahandilshan authored Sep 4, 2024
2 parents 4cd5b83 + 6ce4d22 commit efc6e95
Show file tree
Hide file tree
Showing 3 changed files with 822 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,23 @@ public class OrganizationManagementBaseTest extends RESTAPIServerTestBase {
protected static final String ORGANIZATION_NAME = "name";
protected static final String ORGANIZATION_NAME_FORMAT = "Org-%d";

protected static final String ORGANIZATION_EMAIL_FORMAT_1 = "org%d.com";
protected static final String ORGANIZATION_EMAIL_FORMAT_2 = "organization%d.com";

protected static final String LIMIT_QUERY_PARAM = "limit";
protected static final String AFTER_QUERY_PARAM = "after";
protected static final String BEFORE_QUERY_PARAM = "before";
protected static final String RECURSIVE_QUERY_PARAM = "recursive";
protected static final String OFFSET_QUERY_PARAM = "offset";
protected static final String FILTER_QUERY_PARAM = "filter";

protected static final String ORGANIZATIONS_PATH_PARAM = "organizations";
protected static final String LINKS_PATH_PARAM = "links";
protected static final String COUNT_PATH_PARAM = "count";
protected static final String TOTAL_RESULTS_PATH_PARAM = "totalResults";
protected static final String START_INDEX_PATH_PARAM = "startIndex";

protected static final String ORGANIZATION_NAME_ATTRIBUTE = "organizationName";

protected static final String LINK_REL_PREVIOUS = "previous";
protected static final String LINK_REL_NEXT = "next";
Expand All @@ -65,8 +75,17 @@ public class OrganizationManagementBaseTest extends RESTAPIServerTestBase {
protected static final String QUESTION_MARK = "?";
protected static final String EQUAL = "=";

protected static final String ZERO = "0";

protected static final String FALSE = "false";

protected static final String TOTAL_RESULT_MISMATCH_ERROR = "Total results mismatched.";
protected static final String START_INDEX_MISMATCH_ERROR = "Start index mismatched.";
protected static final String COUNT_MISMATCH_ERROR = "Count mismatch";

protected static final int NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS = 20;
protected static final int DEFAULT_ORG_LIMIT = 15;

protected static String swaggerDefinition;
protected OAuth2RestClient oAuth2RestClient;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class OrganizationManagementFailureTest extends OrganizationManagementBas

private static final String ERROR_CODE_BAD_REQUEST = "UE-10000";
private static final String ERROR_CODE_INVALID_PAGINATION_CURSOR = "ORG-60026";
private static final String ERROR_CODE_SERVER_ERROR = "SE-50000";

private List<String> organizationIDs = new ArrayList<>();
private String applicationID;
Expand Down Expand Up @@ -380,26 +381,77 @@ public void deleteOrganizations() {
@Test(dependsOnMethods = "testUpdateDiscoveryAttributesUnauthorized")
public void testGetPaginatedOrganizationsWithInvalidLimit() {

String invalidLimitUrl = ORGANIZATION_MANAGEMENT_API_BASE_PATH + QUESTION_MARK + LIMIT_QUERY_PARAM + EQUAL + "-1";
String invalidLimitUrl =
ORGANIZATION_MANAGEMENT_API_BASE_PATH + QUESTION_MARK + LIMIT_QUERY_PARAM + EQUAL + "-1";
Response response = getResponseOfGetWithOAuth2(invalidLimitUrl, m2mToken);
validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, ERROR_CODE_BAD_REQUEST);
}

@Test(dependsOnMethods = "testGetPaginatedOrganizationsWithInvalidLimit")
public void testGetPaginatedOrganizationsWithInvalidAfterCursor() {

String invalidAfterCursorUrl = ORGANIZATION_MANAGEMENT_API_BASE_PATH + QUESTION_MARK + LIMIT_QUERY_PARAM + EQUAL + "10"
+ AMPERSAND + AFTER_QUERY_PARAM + EQUAL + INVALID_CURSOR;
String invalidAfterCursorUrl =
ORGANIZATION_MANAGEMENT_API_BASE_PATH + QUESTION_MARK + LIMIT_QUERY_PARAM + EQUAL + "10"
+ AMPERSAND + AFTER_QUERY_PARAM + EQUAL + INVALID_CURSOR;
Response response = getResponseOfGetWithOAuth2(invalidAfterCursorUrl, m2mToken);
validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, ERROR_CODE_INVALID_PAGINATION_CURSOR);
}

@Test(dependsOnMethods = "testGetPaginatedOrganizationsWithInvalidAfterCursor")
public void testGetPaginatedOrganizationsWithInvalidBeforeCursor() {

String invalidBeforeCursorUrl = ORGANIZATION_MANAGEMENT_API_BASE_PATH + QUESTION_MARK + LIMIT_QUERY_PARAM + EQUAL + "10"
+ AMPERSAND + BEFORE_QUERY_PARAM + EQUAL + INVALID_CURSOR;
String invalidBeforeCursorUrl =
ORGANIZATION_MANAGEMENT_API_BASE_PATH + QUESTION_MARK + LIMIT_QUERY_PARAM + EQUAL + "10"
+ AMPERSAND + BEFORE_QUERY_PARAM + EQUAL + INVALID_CURSOR;
Response response = getResponseOfGetWithOAuth2(invalidBeforeCursorUrl, m2mToken);
validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, ERROR_CODE_INVALID_PAGINATION_CURSOR);
}

@DataProvider(name = "organizationDiscoveryInvalidLimitAndOffsetDataProvider")
public Object[][] organizationDiscoveryInvalidLimitAndInvalidOffsetDataProvider() {

return new Object[][]{
{"0", "-1"}, {"5", "-1"}, {"20", "-1"}, {"25", "-1"}, {"", "-1"}, // Invalid limit.
{"-1", "0"}, {"-1", "2"}, {"-1", "20"}, {"-1", "25"}, {"-1", ""}, // Invalid offset
{"-1", "-1"} // Invalid offset and invalid limit.
};
}

@Test(dependsOnMethods = "testGetPaginatedOrganizationsWithInvalidAfterCursor",
dataProvider = "organizationDiscoveryInvalidLimitAndInvalidOffsetDataProvider")
public void testGetPaginatedOrganizationsDiscoveryWithInvalidLimitAndOffset(String offset, String limit) {

String url = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK +
OFFSET_QUERY_PARAM + EQUAL + offset + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL + limit;

Response response = getResponseOfGetWithOAuth2(url, m2mToken);
validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, ERROR_CODE_BAD_REQUEST);
}

/*
* TODO: After the issue https://github.com/wso2/product-is/issues/21025 is fixed,
* remove the method testGetPaginatedOrganizationsDiscoveryWithInvalidOffsetAndLimitZero
* along with its data provider organizationDiscoveryInvalidOffsetAtLimitAndLimitZeroDataProvider.
*/
@DataProvider(name = "organizationDiscoveryInvalidOffsetAtLimitAndLimitZeroDataProvider")
public Object[][] organizationDiscoveryInvalidOffsetAtLimitAndLimitZeroDataProvider() {

return new Object[][]{
{"20", "0"},
{"25", "0"}
};
}

@Test(dependsOnMethods = "testGetPaginatedOrganizationsDiscoveryWithInvalidLimitAndOffset",
dataProvider = "organizationDiscoveryInvalidOffsetAtLimitAndLimitZeroDataProvider")
public void testGetPaginatedOrganizationsDiscoveryWithInvalidOffsetAndLimitZero(String offset,
String limit) {

String url = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK +
OFFSET_QUERY_PARAM + EQUAL + offset + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL + limit;

Response response = getResponseOfGetWithOAuth2(url, m2mToken);
validateErrorResponse(response, HttpStatus.SC_INTERNAL_SERVER_ERROR, ERROR_CODE_SERVER_ERROR);
}

}
Loading

0 comments on commit efc6e95

Please sign in to comment.