From b00652fc979aa6923a88dc2f18b618d7c25508ef Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Thu, 29 Aug 2024 12:45:03 +0530 Subject: [PATCH 01/15] Sucess Tests for org Discovery --- .../v1/OrganizationManagementBaseTest.java | 12 + .../v1/OrganizationManagementSuccessTest.java | 420 ++++++++++++++++-- 2 files changed, 397 insertions(+), 35 deletions(-) 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 b4c940bfca6..5509606f0b9 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 @@ -48,14 +48,21 @@ 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 ORGANIZATION_NAME_ATTRIBUTE = "organizationName"; + protected static final String LINK_REL_PREVIOUS = "previous"; protected static final String LINK_REL_NEXT = "next"; protected static final String REL = "rel"; @@ -65,8 +72,13 @@ 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 int NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS = 20; + protected static final int DEFAULT_ORG_LIMIT = 15; + protected static String swaggerDefinition; protected OAuth2RestClient oAuth2RestClient; 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 cad6b783254..150a4071173 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 @@ -75,6 +75,7 @@ import java.net.URI; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -86,6 +87,7 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.core.IsNull.notNullValue; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.wso2.identity.integration.test.restclients.RestBaseClient.API_SERVER_PATH; import static org.wso2.identity.integration.test.restclients.RestBaseClient.CONTENT_TYPE_ATTRIBUTE; @@ -111,9 +113,6 @@ public class OrganizationManagementSuccessTest extends OrganizationManagementBas protected OAuth2RestClient restClient; - private static final int NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS = 20; - private static final int DEFAULT_ORG_LIMIT = 15; - @Factory(dataProvider = "restAPIUserConfigProvider") public OrganizationManagementSuccessTest(TestUserMode userMode) throws Exception { @@ -669,7 +668,8 @@ public Object[][] organizationCursorValidationProvider() { }; } - @Test(dependsOnMethods = "createOrganizationsForPaginationTests", dataProvider = "organizationCursorValidationProvider") + @Test(dependsOnMethods = "createOrganizationsForPaginationTests", + dataProvider = "organizationCursorValidationProvider") public void testGetPaginatedOrganizationsWithCursor(int limit) { String after; @@ -742,7 +742,8 @@ public Object[][] organizationCursorEdgeCasesProvider() { }; } - @Test(dependsOnMethods = "createOrganizationsForPaginationTests", dataProvider = "organizationCursorEdgeCasesProvider") + @Test(dependsOnMethods = "createOrganizationsForPaginationTests", + dataProvider = "organizationCursorEdgeCasesProvider") public void testGetPaginatedOrganizationsForEdgeCases(int limit) { String limitUrl = @@ -785,48 +786,206 @@ public void testGetPaginatedOrganizationsWithDefaultLimit() { validateOrganizationsForDefaultLimit(responseWithoutLimit, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS); } - private List> createOrganizations(int numberOfOrganizations) throws JSONException { + @Test(dependsOnMethods = "createOrganizationsForPaginationTests") + public void testEnableEmailDomainDiscovery() { - List> newOrganizations = new ArrayList<>(); + String enableDiscoveryPayload = "{\"properties\":[{\"key\":\"emailDomain.enable\",\"value\":true}]}"; - for (int i = 0; i < numberOfOrganizations; i++) { - JSONObject body = new JSONObject() - .put(ORGANIZATION_NAME, String.format(ORGANIZATION_NAME_FORMAT, i)); + // Send POST request to enable email domain discovery + Response response = getResponseOfPostWithOAuth2( + ORGANIZATION_CONFIGS_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH, + enableDiscoveryPayload, + m2mToken); - Response response = - getResponseOfPostWithOAuth2(ORGANIZATION_MANAGEMENT_API_BASE_PATH, body.toString(), m2mToken); + // Validate that the request was successful + validateHttpStatusCode(response, HttpStatus.SC_CREATED); - if (response.getStatusCode() == HttpStatus.SC_CREATED) { - // Extract the organization ID (UUID) from the response body. - JSONObject responseBody = new JSONObject(response.getBody().asString()); - String organizationId = responseBody.getString("id"); + // Validate the response content + boolean isEnabled = response.jsonPath().getBoolean("properties.find { it.key == 'emailDomain.enable' }.value"); + Assert.assertTrue(isEnabled, "Email domain discovery was not successfully enabled."); + } - // Store the created organization details. - Map org = new HashMap<>(); - org.put(ORGANIZATION_NAME, String.format(ORGANIZATION_NAME_FORMAT, i)); - org.put(ORGANIZATION_ID, organizationId); - newOrganizations.add(org); - } else { - throw new RuntimeException("Failed to create organization " + i); - } + @Test(dependsOnMethods = "testEnableEmailDomainDiscovery") + public void testAddEmailDomainsToOrganization() { + + for (int i = 0; i < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS; i++) { + String organizationId = organizations.get(i).get(ORGANIZATION_ID); + addEmailDomainsToOrganization(organizationId, String.format(ORGANIZATION_EMAIL_FORMAT_1, i), + String.format(ORGANIZATION_EMAIL_FORMAT_2, i)); } - return newOrganizations; } - private String getLink(List> links, String rel) { + @DataProvider(name = "organizationDiscoveryLimitProvider") + public Object[][] organizationDiscoveryLimitProvider() { - for (Map link : links) { - if (rel.equals(link.get(REL))) { - String href = link.get(HREF); - if (href.contains(AFTER_QUERY_PARAM + EQUAL)) { - return href.substring(href.indexOf(AFTER_QUERY_PARAM + EQUAL) + AFTER_QUERY_PARAM.length() + 1); - } else if (href.contains(BEFORE_QUERY_PARAM + EQUAL)) { - return href.substring(href.indexOf(BEFORE_QUERY_PARAM + EQUAL) + BEFORE_QUERY_PARAM.length() + 1); - } + return new Object[][]{ + {3}, {5}, {10}, {15}, {17}, {20}, {25} + }; + } + + @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", + dataProvider = "organizationDiscoveryLimitProvider") + public void testOrganizationDiscoveryGetLimit(int limit) { + + int offset = 0; + List accumulatedOrganizationNames = new ArrayList<>(); + + // Loop through each page to test the organization discovery GET API limit + while (offset < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { + String queryUrl = + 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(queryUrl, m2mToken); + + validateHttpStatusCode(response, HttpStatus.SC_OK); + + List> returnedOrganizations = response.jsonPath().getList(ORGANIZATIONS_PATH_PARAM); + + Assert.assertEquals(returnedOrganizations.size(), + Math.min(limit, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS - offset)); + + // Validate no duplicate organization names + for (Map org : returnedOrganizations) { + String orgName = org.get(ORGANIZATION_NAME_ATTRIBUTE); + assertFalse(accumulatedOrganizationNames.contains(orgName), + "Duplicate organization found: " + orgName); + accumulatedOrganizationNames.add(orgName); } + + offset += limit; } - return null; + + // Sort the list based on the numeric part of the organization name + accumulatedOrganizationNames.sort(Comparator.comparingInt(s -> Integer.parseInt(s.split("-")[1]))); + + // Compare accumulated organization names with the original list (order does not matter) + validateOrgNamesForOrganizationDiscoveryGet(accumulatedOrganizationNames); + } + + @DataProvider(name = "organizationDiscoveryPaginationProvider") + public Object[][] organizationDiscoveryPaginationProvider() { + + return new Object[][]{ + {1}, {2}, {5}, {6}, {10}, {17} + }; + } + + @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", + dataProvider = "organizationDiscoveryPaginationProvider") + public void testGetPaginatedOrganizationsDiscovery(int limit) { + + int offset = 0; + String nextLink; + String previousLink; + String queryUrl = buildQueryUrl(offset, limit); + + List> links; + List forwardAccumulatedOrganizationNames = new ArrayList<>(); + List backwardAccumulatedOrganizationNames = new ArrayList<>(); + + // Forward Pagination + do { + links = getPaginationLinksForOrganizationDiscovery(queryUrl, offset, limit, + forwardAccumulatedOrganizationNames, true); + nextLink = getLink(links, LINK_REL_NEXT); + previousLink = getLink(links, LINK_REL_PREVIOUS); + queryUrl = buildNewQueryUrl(nextLink, queryUrl); + + validatePaginationLinksForOrganizationDiscovery(offset == 0, + offset + limit >= NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, + nextLink, previousLink); + + offset += limit; + + } while (nextLink != null); + + // Backward Pagination + do { + links = getPaginationLinksForOrganizationDiscovery(queryUrl, offset, limit, + backwardAccumulatedOrganizationNames, false); + nextLink = getLink(links, LINK_REL_NEXT); + previousLink = getLink(links, LINK_REL_PREVIOUS); + queryUrl = buildNewQueryUrl(previousLink, queryUrl); + + validatePaginationLinksForOrganizationDiscovery(offset == limit, + offset >= NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, + nextLink, previousLink); + + offset -= limit; + + } while (previousLink != null); + + forwardAccumulatedOrganizationNames.sort(Comparator.comparingInt(s -> Integer.parseInt(s.split("-")[1]))); + validateOrgNamesForOrganizationDiscoveryGet(forwardAccumulatedOrganizationNames); + + backwardAccumulatedOrganizationNames.sort(Comparator.comparingInt(s -> Integer.parseInt(s.split("-")[1]))); + validateOrgNamesForOrganizationDiscoveryGet(backwardAccumulatedOrganizationNames); + } + + @DataProvider(name = "organizationDiscoveryPaginationEdgeCaseDataProvider") + public Object[][] organizationDiscoveryPaginationEdgeCaseDataProvider() { + + return new Object[][]{ + {0}, {20}, {25} + }; + } + + @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", + dataProvider = "organizationDiscoveryPaginationEdgeCaseDataProvider") + public void testOrganizationDiscoveryPaginationEdgeCases(int limit) { + + String queryUrl = buildQueryUrl(0, limit); + + // Send GET request with the specified limit + Response response = getResponseOfGetWithOAuth2(queryUrl, m2mToken); + + // Validate the HTTP status code + validateHttpStatusCode(response, HttpStatus.SC_OK); + + int expectedCount = Math.min(limit, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS); + + // Validate the response content + int actualCount = response.jsonPath().getInt("count"); + int totalResults = response.jsonPath().getInt("totalResults"); + int startIndex = response.jsonPath().getInt("startIndex"); + List> links = response.jsonPath().getList(LINKS_PATH_PARAM); + List> returnedOrganizations = response.jsonPath().getList("organizations"); + + Assert.assertEquals(actualCount, expectedCount, + "Unexpected number of organizations returned for limit: " + limit); + Assert.assertEquals(totalResults, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, + "Total results should match the number of organizations available."); + Assert.assertEquals(startIndex, 1, "Start index should always be 1 for offset 0."); + + validateOrganizationDiscoveryEdgeCaseLinks(links, limit); + validateOrganizationDiscoveryEdgeCaseOrganizations(returnedOrganizations, limit); + } + + @Test(dependsOnMethods = "testAddEmailDomainsToOrganization") + public void testOrganizationDiscoveryGetLimitEdgeCases() { + + // Test case 1: URL with LIMIT_QUERY_PARAM but no value. + String endpointURLWithEmptyLimit = + ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + FILTER_QUERY_PARAM + EQUAL + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL + AMPERSAND + + OFFSET_QUERY_PARAM + EQUAL + ZERO; + + Response responseWithEmptyLimit = getResponseOfGetWithOAuth2(endpointURLWithEmptyLimit, m2mToken); + validateHttpStatusCode(responseWithEmptyLimit, HttpStatus.SC_OK); + + validateResponseForOrganizationDiscoveryLDefaultCases(responseWithEmptyLimit); + + // Test case 2: URL without LIMIT_QUERY_PARAM. + String endpointURLWithoutLimit = + ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + FILTER_QUERY_PARAM + EQUAL + AMPERSAND + OFFSET_QUERY_PARAM + EQUAL + ZERO; + + Response responseWithoutLimit = getResponseOfGetWithOAuth2(endpointURLWithoutLimit, m2mToken); + validateHttpStatusCode(responseWithoutLimit, HttpStatus.SC_OK); + + validateResponseForOrganizationDiscoveryLDefaultCases(responseWithoutLimit); } private void validateOrganizationsOnPage(Response response, int pageNum, int totalOrganizations, int limit) { @@ -884,4 +1043,195 @@ private void validateOrganizationsForDefaultLimit(Response response, int totalOr "'after' link should not be present when organizations are within default limit."); } } + + private void validateOrgNamesForOrganizationDiscoveryGet(List accumulatedOrganizationNames) { + + // Ensure both sets contain the same organization names + for (int i = 0; i < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS; i++) { + assertEquals(accumulatedOrganizationNames.get(i), organizations.get(i).get(ORGANIZATION_NAME), + "Organization names do not match."); + } + } + + private void validatePaginationLinksForOrganizationDiscovery(boolean isFirstPage, boolean isLastPage, + String nextLink, + String previousLink) { + + if (isFirstPage) { + Assert.assertNotNull(nextLink, "Next link should be available on the first page."); + Assert.assertNull(previousLink, "Previous link should be null on the first page."); + } else if (isLastPage) { + Assert.assertNull(nextLink, "Next link should be null on the last page."); + Assert.assertNotNull(previousLink, "Previous link should be available on the last page."); + } else { + Assert.assertNotNull(nextLink, "Next link should be available on middle pages."); + Assert.assertNotNull(previousLink, "Previous link should be available on middle pages."); + } + } + + private void validateOrganizationDiscoveryEdgeCaseLinks(List> links, int limit) { + + if (limit == 0) { + Assert.assertNotNull(getLink(links, LINK_REL_NEXT), + "'next' link should be present when the limit is 0."); + } else { + Assert.assertTrue(links.isEmpty(), + "'links' should be empty for non-zero edge case limits."); + } + } + + private void validateOrganizationDiscoveryEdgeCaseOrganizations(List> organizations, + int limit) { + + if (limit == 0) { + Assert.assertNull(organizations, + "No organizations should be returned when limit is 0."); + } else { + Assert.assertEquals(organizations.size(), Math.min(limit, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS), + "Number of organizations in the response does not match the expected count."); + + // Validation to ensure correct organization data is returned + validateOrgNamesOfOrganizationDiscoveryGet(organizations); + } + } + + private void validateOrgNamesOfOrganizationDiscoveryGet(List> organizations) { + + List accumulatedOrganizationNames = new ArrayList<>(); + for (Map org : organizations) { + String orgName = org.get(ORGANIZATION_NAME_ATTRIBUTE); + accumulatedOrganizationNames.add(orgName); + } + accumulatedOrganizationNames.sort(Comparator.comparingInt(s -> Integer.parseInt(s.split("-")[1]))); + + validateOrgNamesForOrganizationDiscoveryGet(accumulatedOrganizationNames); + } + + private void validateResponseForOrganizationDiscoveryLDefaultCases(Response response) { + + int actualCount = response.jsonPath().getInt("count"); + int totalResults = response.jsonPath().getInt("totalResults"); + int startIndex = response.jsonPath().getInt("startIndex"); + List> links = response.jsonPath().getList(LINKS_PATH_PARAM); + List> returnedOrganizations = response.jsonPath().getList("organizations"); + + Assert.assertEquals(actualCount, DEFAULT_ORG_LIMIT, "Unexpected count of organizations returned."); + Assert.assertEquals(totalResults, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Unexpected total results."); + Assert.assertEquals(startIndex, 1, "Start index should be 1."); + + if (totalResults > DEFAULT_ORG_LIMIT) { + Assert.assertNotNull(getLink(links, LINK_REL_NEXT), "'next' link should be present."); + } else { + Assert.assertTrue(links.isEmpty(), "'links' should be empty for non-zero edge case limits."); + } + + Assert.assertEquals(returnedOrganizations.size(), + Math.min(DEFAULT_ORG_LIMIT, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS), + "Number of organizations in the response does not match the expected count."); + } + + private String getLink(List> links, String rel) { + + for (Map link : links) { + if (rel.equals(link.get(REL))) { + String href = link.get(HREF); + if (href.contains(AFTER_QUERY_PARAM + EQUAL)) { + return href.substring(href.indexOf(AFTER_QUERY_PARAM + EQUAL) + AFTER_QUERY_PARAM.length() + 1); + } else if (href.contains(BEFORE_QUERY_PARAM + EQUAL)) { + return href.substring(href.indexOf(BEFORE_QUERY_PARAM + EQUAL) + BEFORE_QUERY_PARAM.length() + 1); + } else { + return href; + } + } + } + return null; + } + + private List> getPaginationLinksForOrganizationDiscovery( + String queryUrl, int offset, int limit, List accumulatedOrganizationNames, boolean isForward) { + + Response response = getResponseOfGetWithOAuth2(queryUrl, m2mToken); + validateHttpStatusCode(response, HttpStatus.SC_OK); + + List> returnedOrganizations = response.jsonPath().getList(ORGANIZATIONS_PATH_PARAM); + + int expectedSize = isForward + ? Math.min(limit, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS - offset) + : Math.min(limit, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS - offset + limit); + + Assert.assertEquals(returnedOrganizations.size(), expectedSize); + + addReturnedOrganizationsToList(returnedOrganizations, accumulatedOrganizationNames); + + return response.jsonPath().getList(LINKS_PATH_PARAM); + } + + private void addEmailDomainsToOrganization(String organizationId, String... domains) { + + String addDomainsPayload = String.format( + "{" + + "\"attributes\": [{" + + "\"type\": \"emailDomain\"," + + "\"values\": [\"%s\"]" + + "}]," + + "\"organizationId\": \"%s\"" + + "}", + String.join("\",\"", domains), + organizationId); + + Response response = + getResponseOfPostWithOAuth2(ORGANIZATION_MANAGEMENT_API_BASE_PATH + + ORGANIZATION_DISCOVERY_API_PATH, addDomainsPayload, m2mToken); + validateHttpStatusCode(response, HttpStatus.SC_CREATED); + } + + private void addReturnedOrganizationsToList(List> returnedOrganizations, + List accumulatedOrganizationNames) { + + for (Map org : returnedOrganizations) { + accumulatedOrganizationNames.add(org.get(ORGANIZATION_NAME_ATTRIBUTE)); + } + } + + private List> createOrganizations(int numberOfOrganizations) throws JSONException { + + List> newOrganizations = new ArrayList<>(); + + for (int i = 0; i < numberOfOrganizations; i++) { + JSONObject body = new JSONObject() + .put(ORGANIZATION_NAME, String.format(ORGANIZATION_NAME_FORMAT, i)); + + Response response = + getResponseOfPostWithOAuth2(ORGANIZATION_MANAGEMENT_API_BASE_PATH, body.toString(), m2mToken); + + if (response.getStatusCode() == HttpStatus.SC_CREATED) { + // Extract the organization ID (UUID) from the response body. + JSONObject responseBody = new JSONObject(response.getBody().asString()); + String organizationId = responseBody.getString("id"); + + // Store the created organization details. + Map org = new HashMap<>(); + org.put(ORGANIZATION_NAME, String.format(ORGANIZATION_NAME_FORMAT, i)); + org.put(ORGANIZATION_ID, organizationId); + newOrganizations.add(org); + } else { + throw new RuntimeException("Failed to create organization " + i); + } + } + + return newOrganizations; + } + + private String buildQueryUrl(int offset, int limit) { + + return ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + OFFSET_QUERY_PARAM + EQUAL + offset + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL + limit; + } + + private String buildNewQueryUrl(String link, String queryUrl) { + + return link != null ? + link.substring(link.lastIndexOf( + ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH)) : queryUrl; + } } From 08163d5281f3b1aad9d258c581cf77e5888cc4b7 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Fri, 30 Aug 2024 19:13:39 +0530 Subject: [PATCH 02/15] Structure Method names --- .../v1/OrganizationManagementSuccessTest.java | 62 ++++++++++++------- 1 file changed, 38 insertions(+), 24 deletions(-) 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 150a4071173..f4281809836 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 @@ -619,8 +619,8 @@ public void createOrganizationsForPaginationTests() throws JSONException { assertEquals(organizations.size(), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS); } - @DataProvider(name = "organizationLimitValidationProvider") - public Object[][] organizationLimitValidationProvider() { + @DataProvider(name = "organizationLimitValidationDataProvider") + public Object[][] organizationLimitValidationDataProvider() { return new Object[][]{ {10}, @@ -630,7 +630,7 @@ public Object[][] organizationLimitValidationProvider() { } @Test(dependsOnMethods = "createOrganizationsForPaginationTests", - dataProvider = "organizationLimitValidationProvider") + dataProvider = "organizationLimitValidationDataProvider") public void testGetPaginatedOrganizationsWithLimit(int limit) { String endpointURL = ORGANIZATION_MANAGEMENT_API_BASE_PATH + QUESTION_MARK + LIMIT_QUERY_PARAM + EQUAL + limit; @@ -660,8 +660,8 @@ public void testGetPaginatedOrganizationsWithLimit(int limit) { } } - @DataProvider(name = "organizationCursorValidationProvider") - public Object[][] organizationCursorValidationProvider() { + @DataProvider(name = "organizationPaginationValidationProvider") + public Object[][] organizationPaginationValidationProvider() { return new Object[][]{ {1}, {2}, {5}, {6}, {10}, {17} @@ -669,8 +669,8 @@ public Object[][] organizationCursorValidationProvider() { } @Test(dependsOnMethods = "createOrganizationsForPaginationTests", - dataProvider = "organizationCursorValidationProvider") - public void testGetPaginatedOrganizationsWithCursor(int limit) { + dataProvider = "organizationPaginationValidationProvider") + public void testGetPaginatedOrganizations(int limit) { String after; String before; @@ -734,8 +734,8 @@ public void testGetPaginatedOrganizationsWithCursor(int limit) { validateOrganizationsOnPage(previousPageResponse, 1, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, limit); } - @DataProvider(name = "organizationCursorEdgeCasesProvider") - public Object[][] organizationCursorEdgeCasesProvider() { + @DataProvider(name = "organizationPaginationNumericLimitEdgeCasesProvider") + public Object[][] organizationPaginationNumericLimitEdgeCasesProvider() { return new Object[][]{ {0}, {20}, {25} @@ -743,8 +743,8 @@ public Object[][] organizationCursorEdgeCasesProvider() { } @Test(dependsOnMethods = "createOrganizationsForPaginationTests", - dataProvider = "organizationCursorEdgeCasesProvider") - public void testGetPaginatedOrganizationsForEdgeCases(int limit) { + dataProvider = "organizationPaginationNumericLimitEdgeCasesProvider") + public void testGetPaginatedOrganizationsForNumericEdgeCasesOfLimit(int limit) { String limitUrl = ORGANIZATION_MANAGEMENT_API_BASE_PATH + QUESTION_MARK + LIMIT_QUERY_PARAM + EQUAL + limit + AMPERSAND + @@ -762,7 +762,7 @@ public void testGetPaginatedOrganizationsForEdgeCases(int limit) { } @Test(dependsOnMethods = "createOrganizationsForPaginationTests") - public void testGetPaginatedOrganizationsWithDefaultLimit() { + public void testGetPaginatedOrganizationsForNonNumericEdgeCasesOfLimit() { // Test case 1: URL with LIMIT_QUERY_PARAM but no value. String endpointURLWithEmptyLimit = @@ -816,8 +816,8 @@ public void testAddEmailDomainsToOrganization() { } - @DataProvider(name = "organizationDiscoveryLimitProvider") - public Object[][] organizationDiscoveryLimitProvider() { + @DataProvider(name = "organizationDiscoveryLimitValidationDataProvider") + public Object[][] organizationDiscoveryLimitValidationDataProvider() { return new Object[][]{ {3}, {5}, {10}, {15}, {17}, {20}, {25} @@ -825,8 +825,8 @@ public Object[][] organizationDiscoveryLimitProvider() { } @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", - dataProvider = "organizationDiscoveryLimitProvider") - public void testOrganizationDiscoveryGetLimit(int limit) { + dataProvider = "organizationDiscoveryLimitValidationDataProvider") + public void testGetOrganizationDiscoveryLimit(int limit) { int offset = 0; List accumulatedOrganizationNames = new ArrayList<>(); @@ -864,8 +864,8 @@ public void testOrganizationDiscoveryGetLimit(int limit) { validateOrgNamesForOrganizationDiscoveryGet(accumulatedOrganizationNames); } - @DataProvider(name = "organizationDiscoveryPaginationProvider") - public Object[][] organizationDiscoveryPaginationProvider() { + @DataProvider(name = "organizationDiscoveryPaginationValidationProvider") + public Object[][] organizationDiscoveryPaginationValidationProvider() { return new Object[][]{ {1}, {2}, {5}, {6}, {10}, {17} @@ -873,7 +873,7 @@ public Object[][] organizationDiscoveryPaginationProvider() { } @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", - dataProvider = "organizationDiscoveryPaginationProvider") + dataProvider = "organizationDiscoveryPaginationValidationProvider") public void testGetPaginatedOrganizationsDiscovery(int limit) { int offset = 0; @@ -924,8 +924,8 @@ public void testGetPaginatedOrganizationsDiscovery(int limit) { validateOrgNamesForOrganizationDiscoveryGet(backwardAccumulatedOrganizationNames); } - @DataProvider(name = "organizationDiscoveryPaginationEdgeCaseDataProvider") - public Object[][] organizationDiscoveryPaginationEdgeCaseDataProvider() { + @DataProvider(name = "organizationDiscoveryPaginationNumericLimitEdgeCasesProvider") + public Object[][] organizationDiscoveryPaginationNumericLimitEdgeCasesProvider() { return new Object[][]{ {0}, {20}, {25} @@ -933,8 +933,8 @@ public Object[][] organizationDiscoveryPaginationEdgeCaseDataProvider() { } @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", - dataProvider = "organizationDiscoveryPaginationEdgeCaseDataProvider") - public void testOrganizationDiscoveryPaginationEdgeCases(int limit) { + dataProvider = "organizationDiscoveryPaginationNumericLimitEdgeCasesProvider") + public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int limit) { String queryUrl = buildQueryUrl(0, limit); @@ -964,7 +964,7 @@ public void testOrganizationDiscoveryPaginationEdgeCases(int limit) { } @Test(dependsOnMethods = "testAddEmailDomainsToOrganization") - public void testOrganizationDiscoveryGetLimitEdgeCases() { + public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfLimit() { // Test case 1: URL with LIMIT_QUERY_PARAM but no value. String endpointURLWithEmptyLimit = @@ -988,6 +988,14 @@ public void testOrganizationDiscoveryGetLimitEdgeCases() { validateResponseForOrganizationDiscoveryLDefaultCases(responseWithoutLimit); } + //Numeric and Non-Numeric Offset Edge Cases + //Numeric - Limit != 0 & Offset = {0}, {20}, {25} + //Non-Numeric - Limit != 0 & Offset =, and no Offset param + + //Numeric and Non-Numeric Limit & Offset Edge Cases + //Numeric - Limit = {0}, {20}, {25} & Offset = {0}, {20}, {25} + //Non-Numeric - Limit=&Offset=, and no Limit and Offset params + private void validateOrganizationsOnPage(Response response, int pageNum, int totalOrganizations, int limit) { // Validate the organization count. @@ -1234,4 +1242,10 @@ private String buildNewQueryUrl(String link, String queryUrl) { link.substring(link.lastIndexOf( ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH)) : queryUrl; } + + + //OFFSET= LIMIT=10 + //OFFSET= (NO LIMIT) + //LIMIT=OFFSET= + //LIMIT= OFFSET=n (ntotal) } From b88c5896713a3be8c2737cdd67f071efa2a5016c Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Fri, 30 Aug 2024 21:19:35 +0530 Subject: [PATCH 03/15] Test Org Discover Limit Edge cases for zero and non-zero offsets (except offset edge cases) --- .../v1/OrganizationManagementSuccessTest.java | 59 ++++++++++++------- 1 file changed, 39 insertions(+), 20 deletions(-) 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 f4281809836..a2a371359d8 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 @@ -928,15 +928,16 @@ public void testGetPaginatedOrganizationsDiscovery(int limit) { public Object[][] organizationDiscoveryPaginationNumericLimitEdgeCasesProvider() { return new Object[][]{ - {0}, {20}, {25} + {0, 0}, {0, 20}, {0, 25}, + {2, 0}, {2, 20}, {2, 25} }; } @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "organizationDiscoveryPaginationNumericLimitEdgeCasesProvider") - public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int limit) { + public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int offset, int limit) { - String queryUrl = buildQueryUrl(0, limit); + String queryUrl = buildQueryUrl(offset, limit); // Send GET request with the specified limit Response response = getResponseOfGetWithOAuth2(queryUrl, m2mToken); @@ -944,7 +945,7 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int // Validate the HTTP status code validateHttpStatusCode(response, HttpStatus.SC_OK); - int expectedCount = Math.min(limit, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS); + int expectedCount = Math.min(limit, (NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS - offset)); // Validate the response content int actualCount = response.jsonPath().getInt("count"); @@ -957,10 +958,10 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int "Unexpected number of organizations returned for limit: " + limit); Assert.assertEquals(totalResults, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results should match the number of organizations available."); - Assert.assertEquals(startIndex, 1, "Start index should always be 1 for offset 0."); + Assert.assertEquals(startIndex, offset + 1, "Start index should always be 1 greater than the offset."); - validateOrganizationDiscoveryEdgeCaseLinks(links, limit); - validateOrganizationDiscoveryEdgeCaseOrganizations(returnedOrganizations, limit); + validateOrganizationDiscoveryEdgeCaseLinks(links, limit, offset); + validateOrganizationDiscoveryEdgeCaseOrganizations(returnedOrganizations, limit, offset); } @Test(dependsOnMethods = "testAddEmailDomainsToOrganization") @@ -989,12 +990,12 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfLimit( } //Numeric and Non-Numeric Offset Edge Cases - //Numeric - Limit != 0 & Offset = {0}, {20}, {25} - //Non-Numeric - Limit != 0 & Offset =, and no Offset param + //Numeric - Limit != 0 & Offset = {0}, {20}, {25} + //Non-Numeric - Limit != 0 & Offset =, and no Offset param //Numeric and Non-Numeric Limit & Offset Edge Cases - //Numeric - Limit = {0}, {20}, {25} & Offset = {0}, {20}, {25} - //Non-Numeric - Limit=&Offset=, and no Limit and Offset params + //Numeric - Limit = {0}, {20}, {25} & Offset = {0}, {20}, {25} + //Non-Numeric - Limit=&Offset=, and no Limit and Offset params private void validateOrganizationsOnPage(Response response, int pageNum, int totalOrganizations, int limit) { @@ -1077,29 +1078,47 @@ private void validatePaginationLinksForOrganizationDiscovery(boolean isFirstPage } } - private void validateOrganizationDiscoveryEdgeCaseLinks(List> links, int limit) { + private void validateOrganizationDiscoveryEdgeCaseLinks(List> links, int limit, int offset) { if (limit == 0) { - Assert.assertNotNull(getLink(links, LINK_REL_NEXT), - "'next' link should be present when the limit is 0."); + if (offset == 0) { + Assert.assertNotNull(getLink(links, LINK_REL_NEXT), + "'next' link should be present when the limit and offset is 0."); + } else { + Assert.assertNotNull(getLink(links, LINK_REL_NEXT), + "'next' link should be present when the limit is 0 but the offset is non-zero."); + Assert.assertNotNull(getLink(links, LINK_REL_PREVIOUS), + "'previous' link should be present when the limit is 0 but the offset is non-zero."); + } } else { - Assert.assertTrue(links.isEmpty(), - "'links' should be empty for non-zero edge case limits."); + if (offset == 0) { + Assert.assertTrue(links.isEmpty(), + "'links' should be empty for non-zero edge case limits."); + } else { + Assert.assertNotNull(getLink(links, LINK_REL_PREVIOUS), + "'previous' link should be present for non-zero edge case limits with non-zero offset."); + } } + } private void validateOrganizationDiscoveryEdgeCaseOrganizations(List> organizations, - int limit) { + int limit, int offset) { if (limit == 0) { Assert.assertNull(organizations, "No organizations should be returned when limit is 0."); } else { - Assert.assertEquals(organizations.size(), Math.min(limit, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS), + Assert.assertEquals(organizations.size(), Math.min(limit, + (NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS - offset)), "Number of organizations in the response does not match the expected count."); - // Validation to ensure correct organization data is returned - validateOrgNamesOfOrganizationDiscoveryGet(organizations); + // Validation to ensure correct organization data is returned - Only for non-zero offset. + /* Since, the organizations are ordered in ORG_ID, we cannot validate the OrganizationName results + for non-zero offsets.*/ + if (offset == 0) { + validateOrgNamesOfOrganizationDiscoveryGet(organizations); + } } } From e828e07886d1b8e05825a5cc309f10ec73448f4a Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sat, 31 Aug 2024 14:13:23 +0530 Subject: [PATCH 04/15] Org Discovery GET pagination with offset --- .../v1/OrganizationManagementSuccessTest.java | 91 +++++++++++++++++-- 1 file changed, 82 insertions(+), 9 deletions(-) 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 a2a371359d8..3edcbce13b0 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 @@ -939,14 +939,10 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int String queryUrl = buildQueryUrl(offset, limit); - // Send GET request with the specified limit Response response = getResponseOfGetWithOAuth2(queryUrl, m2mToken); - // Validate the HTTP status code validateHttpStatusCode(response, HttpStatus.SC_OK); - int expectedCount = Math.min(limit, (NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS - offset)); - // Validate the response content int actualCount = response.jsonPath().getInt("count"); int totalResults = response.jsonPath().getInt("totalResults"); @@ -954,14 +950,17 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int List> links = response.jsonPath().getList(LINKS_PATH_PARAM); List> returnedOrganizations = response.jsonPath().getList("organizations"); + int expectedCount = Math.min(limit, (NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS - offset)); + Assert.assertEquals(actualCount, expectedCount, "Unexpected number of organizations returned for limit: " + limit); Assert.assertEquals(totalResults, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results should match the number of organizations available."); - Assert.assertEquals(startIndex, offset + 1, "Start index should always be 1 greater than the offset."); + Assert.assertEquals(startIndex, offset + 1, + "Start index should always be 1 greater than the offset."); - validateOrganizationDiscoveryEdgeCaseLinks(links, limit, offset); - validateOrganizationDiscoveryEdgeCaseOrganizations(returnedOrganizations, limit, offset); + validateOrganizationDiscoveryLimitsEdgeCaseLinks(links, limit, offset); + validateOrganizationDiscoveryLimitEdgeCaseOrganizations(returnedOrganizations, limit, offset); } @Test(dependsOnMethods = "testAddEmailDomainsToOrganization") @@ -989,6 +988,80 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfLimit( validateResponseForOrganizationDiscoveryLDefaultCases(responseWithoutLimit); } + @DataProvider(name = "organizationDiscoveryOffsetValidationDataProvider") + public Object[][] organizationDiscoveryOffsetValidationDataProvider() { + + return new Object[][]{ + {0, 1}, {0, 5}, {0, 10}, + {5, 1}, {5, 5}, {5, 10}, + {10, 1}, {10, 5}, {10, 10} + }; + } + + @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", + dataProvider = "organizationDiscoveryOffsetValidationDataProvider") + public void testGetOrganizationDiscoveryOffset(int offset, int limit) { + + String queryUrl = buildQueryUrl(offset, limit); + + Response response = getResponseOfGetWithOAuth2(queryUrl, m2mToken); + + validateHttpStatusCode(response, HttpStatus.SC_OK); + + // Validate the response content + int totalResults = response.jsonPath().getInt("totalResults"); + int startIndex = response.jsonPath().getInt("startIndex"); + int count = response.jsonPath().getInt("count"); + List> links = response.jsonPath().getList(LINKS_PATH_PARAM); + + int expectedCount = Math.min(limit, totalResults - offset); + + Assert.assertEquals(totalResults, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); + Assert.assertEquals(startIndex, offset + 1, "Start index should be offset + 1."); + Assert.assertEquals(count, expectedCount, "The count of returned organizations is incorrect."); + + validateOrganizationDiscoveryOffsetEdgeCaseLinks(links, limit, offset); + } + + private void validateOrganizationDiscoveryOffsetEdgeCaseLinks(List> links, int limit, + int offset) { + + String nextLink = getLink(links, LINK_REL_NEXT); + if (offset + limit < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { + Assert.assertNotNull(nextLink, "The 'next' link should be present in first/middle pages."); + int expectedOffset = offset + limit; + validateOffsetIsInLink(nextLink, expectedOffset); + } else { + Assert.assertNull(nextLink, "The 'next' link should not be present in the last page."); + } + + String previousLink = getLink(links, LINK_REL_PREVIOUS); + if (offset > 0) { + Assert.assertNotNull(previousLink, "The 'previous' link should be present in last/middle pages."); + int expectedOffset = Math.max((offset - limit), 0); + validateOffsetIsInLink(previousLink, expectedOffset); + } else { + Assert.assertNull(previousLink, "The 'previous' link should not be present in the first page."); + } + } + + private void validateOffsetIsInLink(String link, int expectedOffset) { + + int offsetStartIndex = link.indexOf(OFFSET_QUERY_PARAM + EQUAL); + + if (offsetStartIndex != -1) { + offsetStartIndex += (OFFSET_QUERY_PARAM + EQUAL).length(); + int offsetEndIndex = link.indexOf(AMPERSAND, offsetStartIndex); + + if (offsetEndIndex == -1) offsetEndIndex = link.length(); + + int actualOffset = Integer.parseInt(link.substring(offsetStartIndex, offsetEndIndex)); + Assert.assertEquals(actualOffset, expectedOffset, "Offset in the link is incorrect."); + } else { + Assert.fail("Offset parameter is missing in the link."); + } + } + //Numeric and Non-Numeric Offset Edge Cases //Numeric - Limit != 0 & Offset = {0}, {20}, {25} //Non-Numeric - Limit != 0 & Offset =, and no Offset param @@ -1078,7 +1151,7 @@ private void validatePaginationLinksForOrganizationDiscovery(boolean isFirstPage } } - private void validateOrganizationDiscoveryEdgeCaseLinks(List> links, int limit, int offset) { + private void validateOrganizationDiscoveryLimitsEdgeCaseLinks(List> links, int limit, int offset) { if (limit == 0) { if (offset == 0) { @@ -1102,7 +1175,7 @@ private void validateOrganizationDiscoveryEdgeCaseLinks(List } - private void validateOrganizationDiscoveryEdgeCaseOrganizations(List> organizations, + private void validateOrganizationDiscoveryLimitEdgeCaseOrganizations(List> organizations, int limit, int offset) { if (limit == 0) { From 49b0a6e1d466b7c5ffa821bd5917ad789c49f321 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sat, 31 Aug 2024 14:51:40 +0530 Subject: [PATCH 05/15] Structure Method names for offset --- .../v1/OrganizationManagementSuccessTest.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) 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 3edcbce13b0..d9326c6eb5f 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 @@ -734,8 +734,8 @@ public void testGetPaginatedOrganizations(int limit) { validateOrganizationsOnPage(previousPageResponse, 1, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, limit); } - @DataProvider(name = "organizationPaginationNumericLimitEdgeCasesProvider") - public Object[][] organizationPaginationNumericLimitEdgeCasesProvider() { + @DataProvider(name = "organizationPaginationNumericEdgeCasesOfLimitDataProvider") + public Object[][] organizationPaginationNumericEdgeCasesOfLimitDataProvider() { return new Object[][]{ {0}, {20}, {25} @@ -743,7 +743,7 @@ public Object[][] organizationPaginationNumericLimitEdgeCasesProvider() { } @Test(dependsOnMethods = "createOrganizationsForPaginationTests", - dataProvider = "organizationPaginationNumericLimitEdgeCasesProvider") + dataProvider = "organizationPaginationNumericEdgeCasesOfLimitDataProvider") public void testGetPaginatedOrganizationsForNumericEdgeCasesOfLimit(int limit) { String limitUrl = @@ -826,7 +826,7 @@ public Object[][] organizationDiscoveryLimitValidationDataProvider() { @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "organizationDiscoveryLimitValidationDataProvider") - public void testGetOrganizationDiscoveryLimit(int limit) { + public void testGetPaginatedOrganizationsDiscoveryWithLimit(int limit) { int offset = 0; List accumulatedOrganizationNames = new ArrayList<>(); @@ -924,8 +924,8 @@ public void testGetPaginatedOrganizationsDiscovery(int limit) { validateOrgNamesForOrganizationDiscoveryGet(backwardAccumulatedOrganizationNames); } - @DataProvider(name = "organizationDiscoveryPaginationNumericLimitEdgeCasesProvider") - public Object[][] organizationDiscoveryPaginationNumericLimitEdgeCasesProvider() { + @DataProvider(name = "organizationDiscoveryPaginationNumericEdgeCasesOfLimitDataProvider") + public Object[][] organizationDiscoveryPaginationNumericEdgeCasesOfLimitDataProvider() { return new Object[][]{ {0, 0}, {0, 20}, {0, 25}, @@ -934,7 +934,7 @@ public Object[][] organizationDiscoveryPaginationNumericLimitEdgeCasesProvider() } @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", - dataProvider = "organizationDiscoveryPaginationNumericLimitEdgeCasesProvider") + dataProvider = "organizationDiscoveryPaginationNumericEdgeCasesOfLimitDataProvider") public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int offset, int limit) { String queryUrl = buildQueryUrl(offset, limit); @@ -1000,7 +1000,7 @@ public Object[][] organizationDiscoveryOffsetValidationDataProvider() { @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "organizationDiscoveryOffsetValidationDataProvider") - public void testGetOrganizationDiscoveryOffset(int offset, int limit) { + public void testGetPaginatedOrganizationsDiscoveryWithOffset(int offset, int limit) { String queryUrl = buildQueryUrl(offset, limit); @@ -1020,17 +1020,17 @@ public void testGetOrganizationDiscoveryOffset(int offset, int limit) { Assert.assertEquals(startIndex, offset + 1, "Start index should be offset + 1."); Assert.assertEquals(count, expectedCount, "The count of returned organizations is incorrect."); - validateOrganizationDiscoveryOffsetEdgeCaseLinks(links, limit, offset); + validateOrganizationDiscoveryOffsetLinks(links, limit, offset); } - private void validateOrganizationDiscoveryOffsetEdgeCaseLinks(List> links, int limit, + private void validateOrganizationDiscoveryOffsetLinks(List> links, int limit, int offset) { String nextLink = getLink(links, LINK_REL_NEXT); if (offset + limit < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { Assert.assertNotNull(nextLink, "The 'next' link should be present in first/middle pages."); int expectedOffset = offset + limit; - validateOffsetIsInLink(nextLink, expectedOffset); + validateOrganizationDiscoveryOffsetIsInLinks(nextLink, expectedOffset); } else { Assert.assertNull(nextLink, "The 'next' link should not be present in the last page."); } @@ -1039,13 +1039,13 @@ private void validateOrganizationDiscoveryOffsetEdgeCaseLinks(List 0) { Assert.assertNotNull(previousLink, "The 'previous' link should be present in last/middle pages."); int expectedOffset = Math.max((offset - limit), 0); - validateOffsetIsInLink(previousLink, expectedOffset); + validateOrganizationDiscoveryOffsetIsInLinks(previousLink, expectedOffset); } else { Assert.assertNull(previousLink, "The 'previous' link should not be present in the first page."); } } - private void validateOffsetIsInLink(String link, int expectedOffset) { + private void validateOrganizationDiscoveryOffsetIsInLinks(String link, int expectedOffset) { int offsetStartIndex = link.indexOf(OFFSET_QUERY_PARAM + EQUAL); From 255672809852331b3b1860b837bdcf14bb67e485 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sun, 1 Sep 2024 04:20:00 +0530 Subject: [PATCH 06/15] Add succes tests for edge cases of offset and limit --- .../v1/OrganizationManagementSuccessTest.java | 283 +++++++++++++++++- 1 file changed, 281 insertions(+), 2 deletions(-) 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 d9326c6eb5f..cb4969f445b 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 @@ -89,6 +89,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertSame; import static org.wso2.identity.integration.test.restclients.RestBaseClient.API_SERVER_PATH; import static org.wso2.identity.integration.test.restclients.RestBaseClient.CONTENT_TYPE_ATTRIBUTE; import static org.wso2.identity.integration.test.restclients.RestBaseClient.ORGANIZATION_PATH; @@ -959,7 +960,7 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int Assert.assertEquals(startIndex, offset + 1, "Start index should always be 1 greater than the offset."); - validateOrganizationDiscoveryLimitsEdgeCaseLinks(links, limit, offset); + validateOrganizationDiscoveryLimitEdgeCaseLinks(links, limit, offset); validateOrganizationDiscoveryLimitEdgeCaseOrganizations(returnedOrganizations, limit, offset); } @@ -1056,12 +1057,109 @@ private void validateOrganizationDiscoveryOffsetIsInLinks(String link, int expec if (offsetEndIndex == -1) offsetEndIndex = link.length(); int actualOffset = Integer.parseInt(link.substring(offsetStartIndex, offsetEndIndex)); + Assert.assertEquals(actualOffset, expectedOffset, "Offset in the link is incorrect."); } else { Assert.fail("Offset parameter is missing in the link."); } } + @DataProvider(name = "numericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider") + public Object[][] numericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider() { + return new Object[][]{ + {20, 5}, + {20, 17}, + {20, 20}, + {20, 25}, + {20, 89}, + {25, 5}, + {25, 17}, + {25, 20}, + {25, 25}, + {25, 89} + }; + } + + @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "numericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider") + public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfOffsetAndOffsetWithLimit(int offset, + int limit) { + + String queryUrl = buildQueryUrl(offset, limit); + Response response = getResponseOfGetWithOAuth2(queryUrl, m2mToken); + + validateHttpStatusCode(response, HttpStatus.SC_OK); + + int totalResults = response.jsonPath().getInt("totalResults"); + int startIndex = response.jsonPath().getInt("startIndex"); + int count = response.jsonPath().getInt("count"); + List> links = response.jsonPath().getList("links"); + + // Validate based on the offset and limit + Assert.assertEquals(totalResults, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); + Assert.assertEquals(startIndex, offset + 1, "Start index mismatch."); + Assert.assertEquals(count, 0, "Count mismatch."); + + // Validate links + String nextLink = getLink(links, "next"); + String previousLink = getLink(links, "previous"); + Assert.assertNull(nextLink, "Next link should be null."); + Assert.assertNotNull(previousLink, "Previous link should be present."); + + int expectedOffset = getExpectedOffsetInLinksForOffsetAndLimitEdgeCases(offset, limit); + validateOrganizationDiscoveryOffsetIsInLinks(previousLink, expectedOffset); + + } + + /*private int getExpectedOffsetInLinksForOffsetAndLimitEdgeCases(int offset, int limit) { + + if(offset == NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { + if (limit < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { + return offset - limit; + } else { + return 0; + } + } else if (offset > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { + if (limit < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { + int left = offset - limit; + if (left < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { + return left; + } else { + while(left>=NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS){ + left = left - limit; + } + return left; + } + } else { + int left = offset - limit; + if (left < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { + if(left < 0) { + return 0; + } else { + return left; + } + } else { + return 0; + } + } + } else { + return 0; + } + }*/ + + private int getExpectedOffsetInLinksForOffsetAndLimitEdgeCases(int offset, int limit) { + + if (offset == NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { + return Math.max(0, offset - limit); + } else if (offset > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { + int left = offset - limit; + while (left >= NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) left -= limit; + + return Math.max(0, left); + } else { + return 0; + } + } + //Numeric and Non-Numeric Offset Edge Cases //Numeric - Limit != 0 & Offset = {0}, {20}, {25} //Non-Numeric - Limit != 0 & Offset =, and no Offset param @@ -1070,6 +1168,187 @@ private void validateOrganizationDiscoveryOffsetIsInLinks(String link, int expec //Numeric - Limit = {0}, {20}, {25} & Offset = {0}, {20}, {25} //Non-Numeric - Limit=&Offset=, and no Limit and Offset params + /*@DataProvider(name = "nonNumericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider") + public Object[][] nonNumericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider() { + return new Object[][]{ + {5, 0}, + {5, 5}, + {5, 20}, + {5, 25}, + {0, 5}, + {5, 5}, + {20, 5}, + {25, 5} + }; + }*/ + + @Test(dependsOnMethods = "testAddEmailDomainsToOrganization") + public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffsetAndOffsetWithLimit() { + + // Case 1: When offset param is present (limit = 0) + String queryUrl1 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + OFFSET_QUERY_PARAM + EQUAL + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL + ZERO; + Response response1 = getResponseOfGetWithOAuth2(queryUrl1, m2mToken); + + validateHttpStatusCode(response1, HttpStatus.SC_OK); + + Assert.assertEquals(response1.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); + Assert.assertEquals(response1.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); + Assert.assertEquals(response1.jsonPath().getInt("count"), 0, "Count mismatch."); + + List> links1 = response1.jsonPath().getList("links"); + String nextLink1 = getLink(links1, "next"); + Assert.assertNotNull(nextLink1, "Next link should be present."); + + // Case 2: When offset param is present (limit = 5) + String queryUrl2 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + OFFSET_QUERY_PARAM + EQUAL + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL + 5; + Response response2 = getResponseOfGetWithOAuth2(queryUrl2, m2mToken); + + validateHttpStatusCode(response2, HttpStatus.SC_OK); + + Assert.assertEquals(response2.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); + Assert.assertEquals(response2.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); + Assert.assertEquals(response2.jsonPath().getInt("count"), 5, "Count mismatch."); + + List> links2 = response2.jsonPath().getList("links"); + String nextLink2 = getLink(links2, "next"); + Assert.assertNotNull(nextLink2, "Next link should be present."); + + // Case 3: When offset param is present (limit = NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) + String queryUrl3 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + OFFSET_QUERY_PARAM + EQUAL + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL + NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS; + Response response3 = getResponseOfGetWithOAuth2(queryUrl3, m2mToken); + + validateHttpStatusCode(response3, HttpStatus.SC_OK); + + Assert.assertEquals(response3.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); + Assert.assertEquals(response3.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); + Assert.assertEquals(response3.jsonPath().getInt("count"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Count mismatch."); + + List> links3 = response3.jsonPath().getList("links"); + String nextLink3 = getLink(links3, "next"); + Assert.assertNull(nextLink3, "Next link should be present."); + + // Case 4: When offset param is present (limit > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) + String queryUrl4 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + OFFSET_QUERY_PARAM + EQUAL + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL + 25; + Response response4 = getResponseOfGetWithOAuth2(queryUrl4, m2mToken); + + validateHttpStatusCode(response4, HttpStatus.SC_OK); + + Assert.assertEquals(response4.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); + Assert.assertEquals(response4.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); + Assert.assertEquals(response4.jsonPath().getInt("count"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Count mismatch."); + + List> links4 = response4.jsonPath().getList("links"); + String nextLink4 = getLink(links4, "next"); + Assert.assertNull(nextLink4, "Next link should be present."); + + // Case 5: When offset param is not present (limit = 0) + String queryUrl5 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + LIMIT_QUERY_PARAM + EQUAL + ZERO; + Response response5 = getResponseOfGetWithOAuth2(queryUrl5, m2mToken); + + validateHttpStatusCode(response5, HttpStatus.SC_OK); + + Assert.assertEquals(response5.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); + Assert.assertEquals(response5.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); + Assert.assertEquals(response5.jsonPath().getInt("count"), 0, "Count mismatch."); + + List> links5 = response5.jsonPath().getList("links"); + String nextLink5 = getLink(links5, "next"); + Assert.assertNotNull(nextLink5, "Links should not be null."); + + // Case 6: When offset param is not present (limit = 5) + String queryUrl6 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + LIMIT_QUERY_PARAM + EQUAL + 5; + Response response6 = getResponseOfGetWithOAuth2(queryUrl6, m2mToken); + + validateHttpStatusCode(response6, HttpStatus.SC_OK); + + Assert.assertEquals(response6.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); + Assert.assertEquals(response6.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); + Assert.assertEquals(response6.jsonPath().getInt("count"), 5, "Count mismatch."); + + List> links6 = response6.jsonPath().getList("links"); + String nextLink6 = getLink(links6, "next"); + Assert.assertNotNull(nextLink6, "Links should not be null."); + + // Case 7: When offset param is not present (limit = NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) + String queryUrl7 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + LIMIT_QUERY_PARAM + EQUAL + NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS; + Response response7 = getResponseOfGetWithOAuth2(queryUrl7, m2mToken); + + validateHttpStatusCode(response7, HttpStatus.SC_OK); + + Assert.assertEquals(response7.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); + Assert.assertEquals(response7.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); + Assert.assertEquals(response7.jsonPath().getInt("count"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Count mismatch."); + + List> links7 = response7.jsonPath().getList("links"); + Assert.assertTrue(links7.isEmpty(), "Links should be empty."); + + // Case 8: When offset param is not present (limit > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) + String queryUrl8 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + LIMIT_QUERY_PARAM + EQUAL + 25; + Response response8 = getResponseOfGetWithOAuth2(queryUrl8, m2mToken); + + validateHttpStatusCode(response8, HttpStatus.SC_OK); + + Assert.assertEquals(response8.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); + Assert.assertEquals(response8.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); + Assert.assertEquals(response8.jsonPath().getInt("count"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Count mismatch."); + + List> links8 = response8.jsonPath().getList("links"); + Assert.assertTrue(links8.isEmpty(), "Links should be empty."); + + // Case 9: Offset= and limit= + String queryUrl9 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + OFFSET_QUERY_PARAM + EQUAL + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL; + Response response9 = getResponseOfGetWithOAuth2(queryUrl9, m2mToken); + + validateHttpStatusCode(response9, HttpStatus.SC_OK); + + Assert.assertEquals(response9.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); + Assert.assertEquals(response9.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); + Assert.assertEquals(response9.jsonPath().getInt("count"), Math.min(DEFAULT_ORG_LIMIT, + NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS), + "Count mismatch."); + + List> links9 = response9.jsonPath().getList("links"); + if (NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS > DEFAULT_ORG_LIMIT) { + Assert.assertNotNull(getLink(links9, "next"), + "'next' link should be present when organizations exceed default limit."); + } else { + Assert.assertNull(getLink(links9, "next"), + "'next' link should not be present when organizations are within default limit."); + } + + // Case 10: Offset is not present and limit is not present + String queryUrl10 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + FILTER_QUERY_PARAM + EQUAL; + Response response10 = getResponseOfGetWithOAuth2(queryUrl10, m2mToken); + + validateHttpStatusCode(response10, HttpStatus.SC_OK); + + Assert.assertEquals(response10.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); + Assert.assertEquals(response10.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); + Assert.assertEquals(response10.jsonPath().getInt("count"), Math.min(DEFAULT_ORG_LIMIT, + NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS), "Count mismatch."); + + List> links10 = response10.jsonPath().getList("links"); + if (NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS > DEFAULT_ORG_LIMIT) { + Assert.assertNotNull(getLink(links10, "next"), + "'next' link should be present when organizations exceed default limit."); + } else { + Assert.assertNull(getLink(links10, "next"), + "'next' link should not be present when organizations are within default limit."); + } + + } + + private void validateOrganizationsOnPage(Response response, int pageNum, int totalOrganizations, int limit) { // Validate the organization count. @@ -1151,7 +1430,7 @@ private void validatePaginationLinksForOrganizationDiscovery(boolean isFirstPage } } - private void validateOrganizationDiscoveryLimitsEdgeCaseLinks(List> links, int limit, int offset) { + private void validateOrganizationDiscoveryLimitEdgeCaseLinks(List> links, int limit, int offset) { if (limit == 0) { if (offset == 0) { From 802aff6abda3e02f613406588fd365ea07bfc1be Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sun, 1 Sep 2024 21:38:23 +0530 Subject: [PATCH 07/15] Refactor sucess tests with final variables --- .../v1/OrganizationManagementBaseTest.java | 7 + .../v1/OrganizationManagementSuccessTest.java | 205 +++++++----------- 2 files changed, 81 insertions(+), 131 deletions(-) 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 5509606f0b9..10d9b8beb25 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 @@ -60,6 +60,9 @@ public class OrganizationManagementBaseTest extends RESTAPIServerTestBase { 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"; @@ -76,6 +79,10 @@ public class OrganizationManagementBaseTest extends RESTAPIServerTestBase { 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; 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 cb4969f445b..5faa2f91248 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 @@ -502,7 +502,7 @@ public void testGetDiscoveryAttributesOfOrganizations() { .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_OK) - .body("totalResults", equalTo(1)) + .body(TOTAL_RESULTS_PATH_PARAM, equalTo(1)) .body("organizations[0].organizationId", equalTo(organizationID)) .body("organizations[0].organizationName", equalTo("Greater Hospital")) .body("organizations[0].attributes[0].type", equalTo("emailDomain")) @@ -791,6 +791,7 @@ public void testGetPaginatedOrganizationsForNonNumericEdgeCasesOfLimit() { public void testEnableEmailDomainDiscovery() { String enableDiscoveryPayload = "{\"properties\":[{\"key\":\"emailDomain.enable\",\"value\":true}]}"; + String emailDomainIsEnabled = "properties.find { it.key == 'emailDomain.enable' }.value"; // Send POST request to enable email domain discovery Response response = getResponseOfPostWithOAuth2( @@ -802,7 +803,7 @@ public void testEnableEmailDomainDiscovery() { validateHttpStatusCode(response, HttpStatus.SC_CREATED); // Validate the response content - boolean isEnabled = response.jsonPath().getBoolean("properties.find { it.key == 'emailDomain.enable' }.value"); + boolean isEnabled = response.jsonPath().getBoolean(emailDomainIsEnabled); Assert.assertTrue(isEnabled, "Email domain discovery was not successfully enabled."); } @@ -945,9 +946,9 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int validateHttpStatusCode(response, HttpStatus.SC_OK); // Validate the response content - int actualCount = response.jsonPath().getInt("count"); - int totalResults = response.jsonPath().getInt("totalResults"); - int startIndex = response.jsonPath().getInt("startIndex"); + int actualCount = response.jsonPath().getInt(COUNT_PATH_PARAM); + int totalResults = response.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM); + int startIndex = response.jsonPath().getInt(START_INDEX_PATH_PARAM); List> links = response.jsonPath().getList(LINKS_PATH_PARAM); List> returnedOrganizations = response.jsonPath().getList("organizations"); @@ -1010,14 +1011,14 @@ public void testGetPaginatedOrganizationsDiscoveryWithOffset(int offset, int lim validateHttpStatusCode(response, HttpStatus.SC_OK); // Validate the response content - int totalResults = response.jsonPath().getInt("totalResults"); - int startIndex = response.jsonPath().getInt("startIndex"); - int count = response.jsonPath().getInt("count"); + int totalResults = response.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM); + int startIndex = response.jsonPath().getInt(START_INDEX_PATH_PARAM); + int count = response.jsonPath().getInt(COUNT_PATH_PARAM); List> links = response.jsonPath().getList(LINKS_PATH_PARAM); int expectedCount = Math.min(limit, totalResults - offset); - Assert.assertEquals(totalResults, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); + Assert.assertEquals(totalResults, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); Assert.assertEquals(startIndex, offset + 1, "Start index should be offset + 1."); Assert.assertEquals(count, expectedCount, "The count of returned organizations is incorrect."); @@ -1089,19 +1090,19 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfOffsetAnd validateHttpStatusCode(response, HttpStatus.SC_OK); - int totalResults = response.jsonPath().getInt("totalResults"); - int startIndex = response.jsonPath().getInt("startIndex"); - int count = response.jsonPath().getInt("count"); - List> links = response.jsonPath().getList("links"); + int totalResults = response.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM); + int startIndex = response.jsonPath().getInt(START_INDEX_PATH_PARAM); + int count = response.jsonPath().getInt(COUNT_PATH_PARAM); + List> links = response.jsonPath().getList(LINKS_PATH_PARAM); // Validate based on the offset and limit - Assert.assertEquals(totalResults, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); - Assert.assertEquals(startIndex, offset + 1, "Start index mismatch."); - Assert.assertEquals(count, 0, "Count mismatch."); + Assert.assertEquals(totalResults, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); + Assert.assertEquals(startIndex, offset + 1, START_INDEX_MISMATCH_ERROR); + Assert.assertEquals(count, 0, COUNT_MISMATCH_ERROR); // Validate links - String nextLink = getLink(links, "next"); - String previousLink = getLink(links, "previous"); + String nextLink = getLink(links, LINK_REL_NEXT); + String previousLink = getLink(links, LINK_REL_PREVIOUS); Assert.assertNull(nextLink, "Next link should be null."); Assert.assertNotNull(previousLink, "Previous link should be present."); @@ -1110,42 +1111,6 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfOffsetAnd } - /*private int getExpectedOffsetInLinksForOffsetAndLimitEdgeCases(int offset, int limit) { - - if(offset == NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { - if (limit < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { - return offset - limit; - } else { - return 0; - } - } else if (offset > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { - if (limit < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { - int left = offset - limit; - if (left < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { - return left; - } else { - while(left>=NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS){ - left = left - limit; - } - return left; - } - } else { - int left = offset - limit; - if (left < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { - if(left < 0) { - return 0; - } else { - return left; - } - } else { - return 0; - } - } - } else { - return 0; - } - }*/ - private int getExpectedOffsetInLinksForOffsetAndLimitEdgeCases(int offset, int limit) { if (offset == NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { @@ -1160,28 +1125,6 @@ private int getExpectedOffsetInLinksForOffsetAndLimitEdgeCases(int offset, int l } } - //Numeric and Non-Numeric Offset Edge Cases - //Numeric - Limit != 0 & Offset = {0}, {20}, {25} - //Non-Numeric - Limit != 0 & Offset =, and no Offset param - - //Numeric and Non-Numeric Limit & Offset Edge Cases - //Numeric - Limit = {0}, {20}, {25} & Offset = {0}, {20}, {25} - //Non-Numeric - Limit=&Offset=, and no Limit and Offset params - - /*@DataProvider(name = "nonNumericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider") - public Object[][] nonNumericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider() { - return new Object[][]{ - {5, 0}, - {5, 5}, - {5, 20}, - {5, 25}, - {0, 5}, - {5, 5}, - {20, 5}, - {25, 5} - }; - }*/ - @Test(dependsOnMethods = "testAddEmailDomainsToOrganization") public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffsetAndOffsetWithLimit() { @@ -1192,12 +1135,12 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffset validateHttpStatusCode(response1, HttpStatus.SC_OK); - Assert.assertEquals(response1.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); - Assert.assertEquals(response1.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); - Assert.assertEquals(response1.jsonPath().getInt("count"), 0, "Count mismatch."); + Assert.assertEquals(response1.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); + Assert.assertEquals(response1.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); + Assert.assertEquals(response1.jsonPath().getInt(COUNT_PATH_PARAM), 0, COUNT_MISMATCH_ERROR); - List> links1 = response1.jsonPath().getList("links"); - String nextLink1 = getLink(links1, "next"); + List> links1 = response1.jsonPath().getList(LINKS_PATH_PARAM); + String nextLink1 = getLink(links1, LINK_REL_NEXT); Assert.assertNotNull(nextLink1, "Next link should be present."); // Case 2: When offset param is present (limit = 5) @@ -1207,12 +1150,12 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffset validateHttpStatusCode(response2, HttpStatus.SC_OK); - Assert.assertEquals(response2.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); - Assert.assertEquals(response2.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); - Assert.assertEquals(response2.jsonPath().getInt("count"), 5, "Count mismatch."); + Assert.assertEquals(response2.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); + Assert.assertEquals(response2.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); + Assert.assertEquals(response2.jsonPath().getInt(COUNT_PATH_PARAM), 5, COUNT_MISMATCH_ERROR); - List> links2 = response2.jsonPath().getList("links"); - String nextLink2 = getLink(links2, "next"); + List> links2 = response2.jsonPath().getList(LINKS_PATH_PARAM); + String nextLink2 = getLink(links2, LINK_REL_NEXT); Assert.assertNotNull(nextLink2, "Next link should be present."); // Case 3: When offset param is present (limit = NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) @@ -1222,12 +1165,12 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffset validateHttpStatusCode(response3, HttpStatus.SC_OK); - Assert.assertEquals(response3.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); - Assert.assertEquals(response3.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); - Assert.assertEquals(response3.jsonPath().getInt("count"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Count mismatch."); + Assert.assertEquals(response3.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); + Assert.assertEquals(response3.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); + Assert.assertEquals(response3.jsonPath().getInt(COUNT_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, COUNT_MISMATCH_ERROR); - List> links3 = response3.jsonPath().getList("links"); - String nextLink3 = getLink(links3, "next"); + List> links3 = response3.jsonPath().getList(LINKS_PATH_PARAM); + String nextLink3 = getLink(links3, LINK_REL_NEXT); Assert.assertNull(nextLink3, "Next link should be present."); // Case 4: When offset param is present (limit > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) @@ -1237,12 +1180,12 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffset validateHttpStatusCode(response4, HttpStatus.SC_OK); - Assert.assertEquals(response4.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); - Assert.assertEquals(response4.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); - Assert.assertEquals(response4.jsonPath().getInt("count"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Count mismatch."); + Assert.assertEquals(response4.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); + Assert.assertEquals(response4.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); + Assert.assertEquals(response4.jsonPath().getInt(COUNT_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, COUNT_MISMATCH_ERROR); - List> links4 = response4.jsonPath().getList("links"); - String nextLink4 = getLink(links4, "next"); + List> links4 = response4.jsonPath().getList(LINKS_PATH_PARAM); + String nextLink4 = getLink(links4, LINK_REL_NEXT); Assert.assertNull(nextLink4, "Next link should be present."); // Case 5: When offset param is not present (limit = 0) @@ -1252,12 +1195,12 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffset validateHttpStatusCode(response5, HttpStatus.SC_OK); - Assert.assertEquals(response5.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); - Assert.assertEquals(response5.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); - Assert.assertEquals(response5.jsonPath().getInt("count"), 0, "Count mismatch."); + Assert.assertEquals(response5.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); + Assert.assertEquals(response5.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); + Assert.assertEquals(response5.jsonPath().getInt(COUNT_PATH_PARAM), 0, COUNT_MISMATCH_ERROR); - List> links5 = response5.jsonPath().getList("links"); - String nextLink5 = getLink(links5, "next"); + List> links5 = response5.jsonPath().getList(LINKS_PATH_PARAM); + String nextLink5 = getLink(links5, LINK_REL_NEXT); Assert.assertNotNull(nextLink5, "Links should not be null."); // Case 6: When offset param is not present (limit = 5) @@ -1267,12 +1210,12 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffset validateHttpStatusCode(response6, HttpStatus.SC_OK); - Assert.assertEquals(response6.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); - Assert.assertEquals(response6.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); - Assert.assertEquals(response6.jsonPath().getInt("count"), 5, "Count mismatch."); + Assert.assertEquals(response6.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); + Assert.assertEquals(response6.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); + Assert.assertEquals(response6.jsonPath().getInt(COUNT_PATH_PARAM), 5, COUNT_MISMATCH_ERROR); - List> links6 = response6.jsonPath().getList("links"); - String nextLink6 = getLink(links6, "next"); + List> links6 = response6.jsonPath().getList(LINKS_PATH_PARAM); + String nextLink6 = getLink(links6, LINK_REL_NEXT); Assert.assertNotNull(nextLink6, "Links should not be null."); // Case 7: When offset param is not present (limit = NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) @@ -1282,11 +1225,11 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffset validateHttpStatusCode(response7, HttpStatus.SC_OK); - Assert.assertEquals(response7.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); - Assert.assertEquals(response7.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); - Assert.assertEquals(response7.jsonPath().getInt("count"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Count mismatch."); + Assert.assertEquals(response7.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); + Assert.assertEquals(response7.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); + Assert.assertEquals(response7.jsonPath().getInt(COUNT_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, COUNT_MISMATCH_ERROR); - List> links7 = response7.jsonPath().getList("links"); + List> links7 = response7.jsonPath().getList(LINKS_PATH_PARAM); Assert.assertTrue(links7.isEmpty(), "Links should be empty."); // Case 8: When offset param is not present (limit > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) @@ -1296,11 +1239,11 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffset validateHttpStatusCode(response8, HttpStatus.SC_OK); - Assert.assertEquals(response8.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); - Assert.assertEquals(response8.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); - Assert.assertEquals(response8.jsonPath().getInt("count"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Count mismatch."); + Assert.assertEquals(response8.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); + Assert.assertEquals(response8.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); + Assert.assertEquals(response8.jsonPath().getInt(COUNT_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, COUNT_MISMATCH_ERROR); - List> links8 = response8.jsonPath().getList("links"); + List> links8 = response8.jsonPath().getList(LINKS_PATH_PARAM); Assert.assertTrue(links8.isEmpty(), "Links should be empty."); // Case 9: Offset= and limit= @@ -1310,18 +1253,18 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffset validateHttpStatusCode(response9, HttpStatus.SC_OK); - Assert.assertEquals(response9.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); - Assert.assertEquals(response9.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); - Assert.assertEquals(response9.jsonPath().getInt("count"), Math.min(DEFAULT_ORG_LIMIT, + Assert.assertEquals(response9.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); + Assert.assertEquals(response9.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); + Assert.assertEquals(response9.jsonPath().getInt(COUNT_PATH_PARAM), Math.min(DEFAULT_ORG_LIMIT, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS), - "Count mismatch."); + COUNT_MISMATCH_ERROR); - List> links9 = response9.jsonPath().getList("links"); + List> links9 = response9.jsonPath().getList(LINKS_PATH_PARAM); if (NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS > DEFAULT_ORG_LIMIT) { - Assert.assertNotNull(getLink(links9, "next"), + Assert.assertNotNull(getLink(links9, LINK_REL_NEXT), "'next' link should be present when organizations exceed default limit."); } else { - Assert.assertNull(getLink(links9, "next"), + Assert.assertNull(getLink(links9, LINK_REL_NEXT), "'next' link should not be present when organizations are within default limit."); } @@ -1332,17 +1275,17 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffset validateHttpStatusCode(response10, HttpStatus.SC_OK); - Assert.assertEquals(response10.jsonPath().getInt("totalResults"), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, "Total results mismatch."); - Assert.assertEquals(response10.jsonPath().getInt("startIndex"), 1, "Start index mismatch."); - Assert.assertEquals(response10.jsonPath().getInt("count"), Math.min(DEFAULT_ORG_LIMIT, - NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS), "Count mismatch."); + Assert.assertEquals(response10.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); + Assert.assertEquals(response10.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); + Assert.assertEquals(response10.jsonPath().getInt(COUNT_PATH_PARAM), Math.min(DEFAULT_ORG_LIMIT, + NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS), COUNT_MISMATCH_ERROR); - List> links10 = response10.jsonPath().getList("links"); + List> links10 = response10.jsonPath().getList(LINKS_PATH_PARAM); if (NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS > DEFAULT_ORG_LIMIT) { - Assert.assertNotNull(getLink(links10, "next"), + Assert.assertNotNull(getLink(links10, LINK_REL_NEXT), "'next' link should be present when organizations exceed default limit."); } else { - Assert.assertNull(getLink(links10, "next"), + Assert.assertNull(getLink(links10, LINK_REL_NEXT), "'next' link should not be present when organizations are within default limit."); } @@ -1488,9 +1431,9 @@ private void validateOrgNamesOfOrganizationDiscoveryGet(List private void validateResponseForOrganizationDiscoveryLDefaultCases(Response response) { - int actualCount = response.jsonPath().getInt("count"); - int totalResults = response.jsonPath().getInt("totalResults"); - int startIndex = response.jsonPath().getInt("startIndex"); + int actualCount = response.jsonPath().getInt(COUNT_PATH_PARAM); + int totalResults = response.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM); + int startIndex = response.jsonPath().getInt(START_INDEX_PATH_PARAM); List> links = response.jsonPath().getList(LINKS_PATH_PARAM); List> returnedOrganizations = response.jsonPath().getList("organizations"); From fad2b2daaf048a1d1f9ea925003c48805152ba47 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sun, 1 Sep 2024 22:04:33 +0530 Subject: [PATCH 08/15] Restructure succes tests for organization discovery --- .../v1/OrganizationManagementSuccessTest.java | 369 ++++++++---------- 1 file changed, 169 insertions(+), 200 deletions(-) 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 5faa2f91248..448354a8d93 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 @@ -977,7 +977,7 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfLimit( Response responseWithEmptyLimit = getResponseOfGetWithOAuth2(endpointURLWithEmptyLimit, m2mToken); validateHttpStatusCode(responseWithEmptyLimit, HttpStatus.SC_OK); - validateResponseForOrganizationDiscoveryLDefaultCases(responseWithEmptyLimit); + validateResponseForOrganizationDiscoveryLimitDefaultCases(responseWithEmptyLimit); // Test case 2: URL without LIMIT_QUERY_PARAM. String endpointURLWithoutLimit = @@ -987,7 +987,7 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfLimit( Response responseWithoutLimit = getResponseOfGetWithOAuth2(endpointURLWithoutLimit, m2mToken); validateHttpStatusCode(responseWithoutLimit, HttpStatus.SC_OK); - validateResponseForOrganizationDiscoveryLDefaultCases(responseWithoutLimit); + validateResponseForOrganizationDiscoveryLimitDefaultCases(responseWithoutLimit); } @DataProvider(name = "organizationDiscoveryOffsetValidationDataProvider") @@ -1025,48 +1025,9 @@ public void testGetPaginatedOrganizationsDiscoveryWithOffset(int offset, int lim validateOrganizationDiscoveryOffsetLinks(links, limit, offset); } - private void validateOrganizationDiscoveryOffsetLinks(List> links, int limit, - int offset) { - - String nextLink = getLink(links, LINK_REL_NEXT); - if (offset + limit < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { - Assert.assertNotNull(nextLink, "The 'next' link should be present in first/middle pages."); - int expectedOffset = offset + limit; - validateOrganizationDiscoveryOffsetIsInLinks(nextLink, expectedOffset); - } else { - Assert.assertNull(nextLink, "The 'next' link should not be present in the last page."); - } - - String previousLink = getLink(links, LINK_REL_PREVIOUS); - if (offset > 0) { - Assert.assertNotNull(previousLink, "The 'previous' link should be present in last/middle pages."); - int expectedOffset = Math.max((offset - limit), 0); - validateOrganizationDiscoveryOffsetIsInLinks(previousLink, expectedOffset); - } else { - Assert.assertNull(previousLink, "The 'previous' link should not be present in the first page."); - } - } - - private void validateOrganizationDiscoveryOffsetIsInLinks(String link, int expectedOffset) { - - int offsetStartIndex = link.indexOf(OFFSET_QUERY_PARAM + EQUAL); - - if (offsetStartIndex != -1) { - offsetStartIndex += (OFFSET_QUERY_PARAM + EQUAL).length(); - int offsetEndIndex = link.indexOf(AMPERSAND, offsetStartIndex); - - if (offsetEndIndex == -1) offsetEndIndex = link.length(); - - int actualOffset = Integer.parseInt(link.substring(offsetStartIndex, offsetEndIndex)); - - Assert.assertEquals(actualOffset, expectedOffset, "Offset in the link is incorrect."); - } else { - Assert.fail("Offset parameter is missing in the link."); - } - } - @DataProvider(name = "numericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider") public Object[][] numericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider() { + return new Object[][]{ {20, 5}, {20, 17}, @@ -1081,14 +1042,15 @@ public Object[][] numericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider() { }; } - @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "numericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider") + @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", + dataProvider = "numericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider") public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfOffsetAndOffsetWithLimit(int offset, - int limit) { + int limit) { String queryUrl = buildQueryUrl(offset, limit); Response response = getResponseOfGetWithOAuth2(queryUrl, m2mToken); - validateHttpStatusCode(response, HttpStatus.SC_OK); + validateHttpStatusCode(response, HttpStatus.SC_OK); int totalResults = response.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM); int startIndex = response.jsonPath().getInt(START_INDEX_PATH_PARAM); @@ -1110,188 +1072,68 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfOffsetAnd validateOrganizationDiscoveryOffsetIsInLinks(previousLink, expectedOffset); } - - private int getExpectedOffsetInLinksForOffsetAndLimitEdgeCases(int offset, int limit) { - - if (offset == NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { - return Math.max(0, offset - limit); - } else if (offset > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { - int left = offset - limit; - while (left >= NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) left -= limit; - - return Math.max(0, left); - } else { - return 0; - } - } - + @Test(dependsOnMethods = "testAddEmailDomainsToOrganization") public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffsetAndOffsetWithLimit() { // Case 1: When offset param is present (limit = 0) - String queryUrl1 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + - OFFSET_QUERY_PARAM + EQUAL + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL + ZERO; - Response response1 = getResponseOfGetWithOAuth2(queryUrl1, m2mToken); - - validateHttpStatusCode(response1, HttpStatus.SC_OK); - - Assert.assertEquals(response1.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); - Assert.assertEquals(response1.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); - Assert.assertEquals(response1.jsonPath().getInt(COUNT_PATH_PARAM), 0, COUNT_MISMATCH_ERROR); - - List> links1 = response1.jsonPath().getList(LINKS_PATH_PARAM); - String nextLink1 = getLink(links1, LINK_REL_NEXT); - Assert.assertNotNull(nextLink1, "Next link should be present."); + validatePaginationScenarioWithOffsetAndLimit(0, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, 0, true); // Case 2: When offset param is present (limit = 5) - String queryUrl2 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + - OFFSET_QUERY_PARAM + EQUAL + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL + 5; - Response response2 = getResponseOfGetWithOAuth2(queryUrl2, m2mToken); - - validateHttpStatusCode(response2, HttpStatus.SC_OK); - - Assert.assertEquals(response2.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); - Assert.assertEquals(response2.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); - Assert.assertEquals(response2.jsonPath().getInt(COUNT_PATH_PARAM), 5, COUNT_MISMATCH_ERROR); - - List> links2 = response2.jsonPath().getList(LINKS_PATH_PARAM); - String nextLink2 = getLink(links2, LINK_REL_NEXT); - Assert.assertNotNull(nextLink2, "Next link should be present."); + validatePaginationScenarioWithOffsetAndLimit(5, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, 5, true); // Case 3: When offset param is present (limit = NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) - String queryUrl3 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + - OFFSET_QUERY_PARAM + EQUAL + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL + NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS; - Response response3 = getResponseOfGetWithOAuth2(queryUrl3, m2mToken); - - validateHttpStatusCode(response3, HttpStatus.SC_OK); - - Assert.assertEquals(response3.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); - Assert.assertEquals(response3.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); - Assert.assertEquals(response3.jsonPath().getInt(COUNT_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, COUNT_MISMATCH_ERROR); - - List> links3 = response3.jsonPath().getList(LINKS_PATH_PARAM); - String nextLink3 = getLink(links3, LINK_REL_NEXT); - Assert.assertNull(nextLink3, "Next link should be present."); + validatePaginationScenarioWithOffsetAndLimit(NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, + NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, false); // Case 4: When offset param is present (limit > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) - String queryUrl4 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + - OFFSET_QUERY_PARAM + EQUAL + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL + 25; - Response response4 = getResponseOfGetWithOAuth2(queryUrl4, m2mToken); - - validateHttpStatusCode(response4, HttpStatus.SC_OK); - - Assert.assertEquals(response4.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); - Assert.assertEquals(response4.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); - Assert.assertEquals(response4.jsonPath().getInt(COUNT_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, COUNT_MISMATCH_ERROR); - - List> links4 = response4.jsonPath().getList(LINKS_PATH_PARAM); - String nextLink4 = getLink(links4, LINK_REL_NEXT); - Assert.assertNull(nextLink4, "Next link should be present."); + validatePaginationScenarioWithOffsetAndLimit(25, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, + NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, false); // Case 5: When offset param is not present (limit = 0) - String queryUrl5 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + - LIMIT_QUERY_PARAM + EQUAL + ZERO; - Response response5 = getResponseOfGetWithOAuth2(queryUrl5, m2mToken); - - validateHttpStatusCode(response5, HttpStatus.SC_OK); - - Assert.assertEquals(response5.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); - Assert.assertEquals(response5.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); - Assert.assertEquals(response5.jsonPath().getInt(COUNT_PATH_PARAM), 0, COUNT_MISMATCH_ERROR); - - List> links5 = response5.jsonPath().getList(LINKS_PATH_PARAM); - String nextLink5 = getLink(links5, LINK_REL_NEXT); - Assert.assertNotNull(nextLink5, "Links should not be null."); + validatePaginationScenarioWithLimitOnly(0, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, 0, true); // Case 6: When offset param is not present (limit = 5) - String queryUrl6 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + - LIMIT_QUERY_PARAM + EQUAL + 5; - Response response6 = getResponseOfGetWithOAuth2(queryUrl6, m2mToken); - - validateHttpStatusCode(response6, HttpStatus.SC_OK); - - Assert.assertEquals(response6.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); - Assert.assertEquals(response6.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); - Assert.assertEquals(response6.jsonPath().getInt(COUNT_PATH_PARAM), 5, COUNT_MISMATCH_ERROR); - - List> links6 = response6.jsonPath().getList(LINKS_PATH_PARAM); - String nextLink6 = getLink(links6, LINK_REL_NEXT); - Assert.assertNotNull(nextLink6, "Links should not be null."); + validatePaginationScenarioWithLimitOnly(5, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, 5, true); // Case 7: When offset param is not present (limit = NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) - String queryUrl7 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + - LIMIT_QUERY_PARAM + EQUAL + NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS; - Response response7 = getResponseOfGetWithOAuth2(queryUrl7, m2mToken); - - validateHttpStatusCode(response7, HttpStatus.SC_OK); - - Assert.assertEquals(response7.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); - Assert.assertEquals(response7.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); - Assert.assertEquals(response7.jsonPath().getInt(COUNT_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, COUNT_MISMATCH_ERROR); - - List> links7 = response7.jsonPath().getList(LINKS_PATH_PARAM); - Assert.assertTrue(links7.isEmpty(), "Links should be empty."); + validatePaginationScenarioWithLimitOnly(NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, + NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, false); // Case 8: When offset param is not present (limit > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) - String queryUrl8 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + - LIMIT_QUERY_PARAM + EQUAL + 25; - Response response8 = getResponseOfGetWithOAuth2(queryUrl8, m2mToken); - - validateHttpStatusCode(response8, HttpStatus.SC_OK); - - Assert.assertEquals(response8.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); - Assert.assertEquals(response8.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); - Assert.assertEquals(response8.jsonPath().getInt(COUNT_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, COUNT_MISMATCH_ERROR); - - List> links8 = response8.jsonPath().getList(LINKS_PATH_PARAM); - Assert.assertTrue(links8.isEmpty(), "Links should be empty."); + validatePaginationScenarioWithLimitOnly(25, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, + NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, false); // Case 9: Offset= and limit= - String queryUrl9 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + - OFFSET_QUERY_PARAM + EQUAL + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL; - Response response9 = getResponseOfGetWithOAuth2(queryUrl9, m2mToken); + validatePaginationScenarioWithOffsetAndLimitAndDefaultLimit(); - validateHttpStatusCode(response9, HttpStatus.SC_OK); + // Case 10: Offset is not present and limit is not present + validatePaginationScenarioWithNoOffsetAndLimit(); + } - Assert.assertEquals(response9.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); - Assert.assertEquals(response9.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); - Assert.assertEquals(response9.jsonPath().getInt(COUNT_PATH_PARAM), Math.min(DEFAULT_ORG_LIMIT, - NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS), - COUNT_MISMATCH_ERROR); + private void validateNextLink(Response response, boolean expectNextLink) { - List> links9 = response9.jsonPath().getList(LINKS_PATH_PARAM); - if (NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS > DEFAULT_ORG_LIMIT) { - Assert.assertNotNull(getLink(links9, LINK_REL_NEXT), - "'next' link should be present when organizations exceed default limit."); + List> links = response.jsonPath().getList(LINKS_PATH_PARAM); + String nextLink = getLink(links, LINK_REL_NEXT); + if (expectNextLink) { + Assert.assertNotNull(nextLink, "Next link should be present."); } else { - Assert.assertNull(getLink(links9, LINK_REL_NEXT), - "'next' link should not be present when organizations are within default limit."); + Assert.assertNull(nextLink, "Next link should not be present."); } + } - // Case 10: Offset is not present and limit is not present - String queryUrl10 = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + - FILTER_QUERY_PARAM + EQUAL; - Response response10 = getResponseOfGetWithOAuth2(queryUrl10, m2mToken); - - validateHttpStatusCode(response10, HttpStatus.SC_OK); - - Assert.assertEquals(response10.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); - Assert.assertEquals(response10.jsonPath().getInt(START_INDEX_PATH_PARAM), 1, START_INDEX_MISMATCH_ERROR); - Assert.assertEquals(response10.jsonPath().getInt(COUNT_PATH_PARAM), Math.min(DEFAULT_ORG_LIMIT, - NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS), COUNT_MISMATCH_ERROR); + private void validateNextLinkBasedOnOrganizationCount(Response response) { - List> links10 = response10.jsonPath().getList(LINKS_PATH_PARAM); + List> links = response.jsonPath().getList(LINKS_PATH_PARAM); if (NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS > DEFAULT_ORG_LIMIT) { - Assert.assertNotNull(getLink(links10, LINK_REL_NEXT), + Assert.assertNotNull(getLink(links, LINK_REL_NEXT), "'next' link should be present when organizations exceed default limit."); } else { - Assert.assertNull(getLink(links10, LINK_REL_NEXT), + Assert.assertNull(getLink(links, LINK_REL_NEXT), "'next' link should not be present when organizations are within default limit."); } - } - private void validateOrganizationsOnPage(Response response, int pageNum, int totalOrganizations, int limit) { // Validate the organization count. @@ -1373,7 +1215,8 @@ private void validatePaginationLinksForOrganizationDiscovery(boolean isFirstPage } } - private void validateOrganizationDiscoveryLimitEdgeCaseLinks(List> links, int limit, int offset) { + private void validateOrganizationDiscoveryLimitEdgeCaseLinks(List> links, int limit, + int offset) { if (limit == 0) { if (offset == 0) { @@ -1398,7 +1241,7 @@ private void validateOrganizationDiscoveryLimitEdgeCaseLinks(List> organizations, - int limit, int offset) { + int limit, int offset) { if (limit == 0) { Assert.assertNull(organizations, @@ -1429,7 +1272,7 @@ private void validateOrgNamesOfOrganizationDiscoveryGet(List validateOrgNamesForOrganizationDiscoveryGet(accumulatedOrganizationNames); } - private void validateResponseForOrganizationDiscoveryLDefaultCases(Response response) { + private void validateResponseForOrganizationDiscoveryLimitDefaultCases(Response response) { int actualCount = response.jsonPath().getInt(COUNT_PATH_PARAM); int totalResults = response.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM); @@ -1452,6 +1295,100 @@ private void validateResponseForOrganizationDiscoveryLDefaultCases(Response resp "Number of organizations in the response does not match the expected count."); } + private void validateOrganizationDiscoveryOffsetLinks(List> links, int limit, + int offset) { + + String nextLink = getLink(links, LINK_REL_NEXT); + if (offset + limit < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { + Assert.assertNotNull(nextLink, "The 'next' link should be present in first/middle pages."); + int expectedOffset = offset + limit; + validateOrganizationDiscoveryOffsetIsInLinks(nextLink, expectedOffset); + } else { + Assert.assertNull(nextLink, "The 'next' link should not be present in the last page."); + } + + String previousLink = getLink(links, LINK_REL_PREVIOUS); + if (offset > 0) { + Assert.assertNotNull(previousLink, "The 'previous' link should be present in last/middle pages."); + int expectedOffset = Math.max((offset - limit), 0); + validateOrganizationDiscoveryOffsetIsInLinks(previousLink, expectedOffset); + } else { + Assert.assertNull(previousLink, "The 'previous' link should not be present in the first page."); + } + } + + private void validateOrganizationDiscoveryOffsetIsInLinks(String link, int expectedOffset) { + + int offsetStartIndex = link.indexOf(OFFSET_QUERY_PARAM + EQUAL); + + if (offsetStartIndex != -1) { + offsetStartIndex += (OFFSET_QUERY_PARAM + EQUAL).length(); + int offsetEndIndex = link.indexOf(AMPERSAND, offsetStartIndex); + + if (offsetEndIndex == -1) offsetEndIndex = link.length(); + + int actualOffset = Integer.parseInt(link.substring(offsetStartIndex, offsetEndIndex)); + + Assert.assertEquals(actualOffset, expectedOffset, "Offset in the link is incorrect."); + } else { + Assert.fail("Offset parameter is missing in the link."); + } + } + + private void validatePaginationScenarioWithOffsetAndLimit(int limit, int expectedTotalResults, + int expectedStartIndex, int expectedCount, + boolean expectNextLink) { + + String queryUrl = buildQueryUrlWithOffsetAndLimit(limit); + Response response = getResponseOfGetWithOAuth2(queryUrl, m2mToken); + + validateCommonAssertions(response, expectedTotalResults, expectedStartIndex, expectedCount); + validateNextLink(response, expectNextLink); + } + + private void validatePaginationScenarioWithLimitOnly(int limit, int expectedTotalResults, int expectedStartIndex, + int expectedCount, boolean expectNextLink) { + + String queryUrl = buildQueryUrlWithLimit(limit); + Response response = getResponseOfGetWithOAuth2(queryUrl, m2mToken); + + validateCommonAssertions(response, expectedTotalResults, expectedStartIndex, expectedCount); + validateNextLink(response, expectNextLink); + } + + private void validatePaginationScenarioWithOffsetAndLimitAndDefaultLimit() { + + String queryUrl = buildQueryUrlWithOffsetAndLimitAndDefaultLimit(); + Response response = getResponseOfGetWithOAuth2(queryUrl, m2mToken); + + validateCommonAssertions(response, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, + Math.min(DEFAULT_ORG_LIMIT, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS)); + validateNextLinkBasedOnOrganizationCount(response); + } + + private void validatePaginationScenarioWithNoOffsetAndLimit() { + + String queryUrl = buildQueryUrlWithNoOffsetAndLimit(); + Response response = getResponseOfGetWithOAuth2(queryUrl, m2mToken); + + validateCommonAssertions(response, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, + Math.min(DEFAULT_ORG_LIMIT, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS)); + validateNextLinkBasedOnOrganizationCount(response); + } + + private void validateCommonAssertions(Response response, int expectedTotalResults, int expectedStartIndex, + int expectedCount) { + + validateHttpStatusCode(response, HttpStatus.SC_OK); + + Assert.assertEquals(response.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM), expectedTotalResults, + TOTAL_RESULT_MISMATCH_ERROR); + Assert.assertEquals(response.jsonPath().getInt(START_INDEX_PATH_PARAM), expectedStartIndex, + START_INDEX_MISMATCH_ERROR); + Assert.assertEquals(response.jsonPath().getInt(COUNT_PATH_PARAM), expectedCount, + COUNT_MISMATCH_ERROR); + } + private String getLink(List> links, String rel) { for (Map link : links) { @@ -1488,6 +1425,20 @@ private List> getPaginationLinksForOrganizationDiscovery( return response.jsonPath().getList(LINKS_PATH_PARAM); } + private int getExpectedOffsetInLinksForOffsetAndLimitEdgeCases(int offset, int limit) { + + if (offset == NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { + return Math.max(0, offset - limit); + } else if (offset > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { + int left = offset - limit; + while (left >= NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) left -= limit; + + return Math.max(0, left); + } else { + return 0; + } + } + private void addEmailDomainsToOrganization(String organizationId, String... domains) { String addDomainsPayload = String.format( @@ -1557,9 +1508,27 @@ private String buildNewQueryUrl(String link, String queryUrl) { ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH)) : queryUrl; } + private String buildQueryUrlWithOffsetAndLimit(int limit) { + + return ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + OFFSET_QUERY_PARAM + EQUAL + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL + limit; + } + + private String buildQueryUrlWithLimit(int limit) { - //OFFSET= LIMIT=10 - //OFFSET= (NO LIMIT) - //LIMIT=OFFSET= - //LIMIT= OFFSET=n (ntotal) + return ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + LIMIT_QUERY_PARAM + EQUAL + limit; + } + + private String buildQueryUrlWithOffsetAndLimitAndDefaultLimit() { + + return ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + OFFSET_QUERY_PARAM + EQUAL + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL; + } + + private String buildQueryUrlWithNoOffsetAndLimit() { + + return ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + FILTER_QUERY_PARAM + EQUAL; + } } From e63c0b7c7396d206eed47c6cb3ee57c032abaf19 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Mon, 2 Sep 2024 09:43:07 +0530 Subject: [PATCH 09/15] Add faluire tests for Organization Discovery --- .../v1/OrganizationManagementFailureTest.java | 57 +++++++++++++++++-- 1 file changed, 52 insertions(+), 5 deletions(-) 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 e2c6a071262..4e77c5da846 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 @@ -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 organizationIDs = new ArrayList<>(); private String applicationID; @@ -380,7 +381,8 @@ 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); } @@ -388,8 +390,9 @@ public void testGetPaginatedOrganizationsWithInvalidLimit() { @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); } @@ -397,9 +400,53 @@ public void testGetPaginatedOrganizationsWithInvalidAfterCursor() { @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); + } + + @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); + } + } From f6d333fb344d5651005b522d8a5e521a1d2b9166 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Mon, 2 Sep 2024 11:55:02 +0530 Subject: [PATCH 10/15] Disable Email Domain Discovery --- .../v1/OrganizationManagementSuccessTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 448354a8d93..3628eada05d 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 @@ -1111,6 +1111,28 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffset validatePaginationScenarioWithNoOffsetAndLimit(); } + @Test(dependsOnMethods = "testEnableEmailDomainDiscovery") + public void testDisableEmailDomainDiscovery() { + + String emailDomainIsEnabled = "properties.find { it.key == 'emailDomain.enable' }?.value ?: false"; + + // Send DELETE request to disable email domain discovery + Response response = getResponseOfDeleteWithOAuth2( + ORGANIZATION_CONFIGS_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH, + m2mToken); + + validateHttpStatusCode(response, HttpStatus.SC_NO_CONTENT); + + // Send a GET request to validate that the email domain discovery is disabled + Response getResponse = getResponseOfGetWithOAuth2( + ORGANIZATION_CONFIGS_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH, + m2mToken); + + boolean isEnabled = getResponse.jsonPath().getBoolean(emailDomainIsEnabled); + Assert.assertFalse(isEnabled, "Email domain discovery was not successfully disabled."); + } + + private void validateNextLink(Response response, boolean expectNextLink) { List> links = response.jsonPath().getList(LINKS_PATH_PARAM); From 4be92ffe0267810af454fc227d2fd6aca9e9bf60 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Mon, 2 Sep 2024 12:31:01 +0530 Subject: [PATCH 11/15] Add a TODO to remove test method after fixing issue #21025 --- .../management/v1/OrganizationManagementFailureTest.java | 5 +++++ 1 file changed, 5 insertions(+) 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 4e77c5da846..38c78db84d4 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 @@ -428,6 +428,11 @@ public void testGetPaginatedOrganizationsDiscoveryWithInvalidLimitAndOffset(Stri 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() { From 075c7a14c0def3e2b499554ef1245135574da7db Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Mon, 2 Sep 2024 23:46:18 +0530 Subject: [PATCH 12/15] Delete Organizations for pagination and group pagination tests --- .../v1/OrganizationManagementSuccessTest.java | 53 +++++++++++++------ 1 file changed, 37 insertions(+), 16 deletions(-) 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 3628eada05d..a309509b6b0 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 @@ -89,7 +89,6 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertSame; import static org.wso2.identity.integration.test.restclients.RestBaseClient.API_SERVER_PATH; import static org.wso2.identity.integration.test.restclients.RestBaseClient.CONTENT_TYPE_ATTRIBUTE; import static org.wso2.identity.integration.test.restclients.RestBaseClient.ORGANIZATION_PATH; @@ -613,7 +612,7 @@ private void deleteApplication(String applicationId) throws Exception { oAuth2RestClient.deleteApplication(applicationId); } - @Test(dependsOnMethods = "testDeleteOrganization") + @Test(groups = "paginationTests", dependsOnMethods = "testDeleteOrganization") public void createOrganizationsForPaginationTests() throws JSONException { organizations = createOrganizations(NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS); @@ -630,7 +629,7 @@ public Object[][] organizationLimitValidationDataProvider() { }; } - @Test(dependsOnMethods = "createOrganizationsForPaginationTests", + @Test(groups = "paginationTests", dependsOnMethods = "createOrganizationsForPaginationTests", dataProvider = "organizationLimitValidationDataProvider") public void testGetPaginatedOrganizationsWithLimit(int limit) { @@ -669,7 +668,7 @@ public Object[][] organizationPaginationValidationProvider() { }; } - @Test(dependsOnMethods = "createOrganizationsForPaginationTests", + @Test(groups = "paginationTests", dependsOnMethods = "createOrganizationsForPaginationTests", dataProvider = "organizationPaginationValidationProvider") public void testGetPaginatedOrganizations(int limit) { @@ -743,7 +742,7 @@ public Object[][] organizationPaginationNumericEdgeCasesOfLimitDataProvider() { }; } - @Test(dependsOnMethods = "createOrganizationsForPaginationTests", + @Test(groups = "paginationTests", dependsOnMethods = "createOrganizationsForPaginationTests", dataProvider = "organizationPaginationNumericEdgeCasesOfLimitDataProvider") public void testGetPaginatedOrganizationsForNumericEdgeCasesOfLimit(int limit) { @@ -762,7 +761,7 @@ public void testGetPaginatedOrganizationsForNumericEdgeCasesOfLimit(int limit) { validateOrganizationsOnPage(response, 1, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, limit); } - @Test(dependsOnMethods = "createOrganizationsForPaginationTests") + @Test(groups = "paginationTests", dependsOnMethods = "createOrganizationsForPaginationTests") public void testGetPaginatedOrganizationsForNonNumericEdgeCasesOfLimit() { // Test case 1: URL with LIMIT_QUERY_PARAM but no value. @@ -787,7 +786,7 @@ public void testGetPaginatedOrganizationsForNonNumericEdgeCasesOfLimit() { validateOrganizationsForDefaultLimit(responseWithoutLimit, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS); } - @Test(dependsOnMethods = "createOrganizationsForPaginationTests") + @Test(groups = "paginationTests", dependsOnMethods = "createOrganizationsForPaginationTests") public void testEnableEmailDomainDiscovery() { String enableDiscoveryPayload = "{\"properties\":[{\"key\":\"emailDomain.enable\",\"value\":true}]}"; @@ -807,7 +806,7 @@ public void testEnableEmailDomainDiscovery() { Assert.assertTrue(isEnabled, "Email domain discovery was not successfully enabled."); } - @Test(dependsOnMethods = "testEnableEmailDomainDiscovery") + @Test(groups = "paginationTests", dependsOnMethods = "testEnableEmailDomainDiscovery") public void testAddEmailDomainsToOrganization() { for (int i = 0; i < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS; i++) { @@ -826,7 +825,7 @@ public Object[][] organizationDiscoveryLimitValidationDataProvider() { }; } - @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", + @Test(groups = "paginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "organizationDiscoveryLimitValidationDataProvider") public void testGetPaginatedOrganizationsDiscoveryWithLimit(int limit) { @@ -874,7 +873,7 @@ public Object[][] organizationDiscoveryPaginationValidationProvider() { }; } - @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", + @Test(groups = "paginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "organizationDiscoveryPaginationValidationProvider") public void testGetPaginatedOrganizationsDiscovery(int limit) { @@ -935,7 +934,7 @@ public Object[][] organizationDiscoveryPaginationNumericEdgeCasesOfLimitDataProv }; } - @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", + @Test(groups = "paginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "organizationDiscoveryPaginationNumericEdgeCasesOfLimitDataProvider") public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int offset, int limit) { @@ -965,7 +964,7 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int validateOrganizationDiscoveryLimitEdgeCaseOrganizations(returnedOrganizations, limit, offset); } - @Test(dependsOnMethods = "testAddEmailDomainsToOrganization") + @Test(groups = "paginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization") public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfLimit() { // Test case 1: URL with LIMIT_QUERY_PARAM but no value. @@ -1000,7 +999,7 @@ public Object[][] organizationDiscoveryOffsetValidationDataProvider() { }; } - @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", + @Test(groups = "paginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "organizationDiscoveryOffsetValidationDataProvider") public void testGetPaginatedOrganizationsDiscoveryWithOffset(int offset, int limit) { @@ -1042,7 +1041,7 @@ public Object[][] numericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider() { }; } - @Test(dependsOnMethods = "testAddEmailDomainsToOrganization", + @Test(groups = "paginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "numericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider") public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfOffsetAndOffsetWithLimit(int offset, int limit) { @@ -1073,7 +1072,7 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfOffsetAnd } - @Test(dependsOnMethods = "testAddEmailDomainsToOrganization") + @Test(groups = "paginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization") public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffsetAndOffsetWithLimit() { // Case 1: When offset param is present (limit = 0) @@ -1111,7 +1110,7 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffset validatePaginationScenarioWithNoOffsetAndLimit(); } - @Test(dependsOnMethods = "testEnableEmailDomainDiscovery") + @Test(groups = "paginationTests", dependsOnMethods = "testEnableEmailDomainDiscovery") public void testDisableEmailDomainDiscovery() { String emailDomainIsEnabled = "properties.find { it.key == 'emailDomain.enable' }?.value ?: false"; @@ -1132,6 +1131,15 @@ public void testDisableEmailDomainDiscovery() { Assert.assertFalse(isEnabled, "Email domain discovery was not successfully disabled."); } + @Test(dependsOnGroups = "paginationTests") + public void testDeleteOrganizationsForPagination() { + + for (Map org : new ArrayList<>(organizations)) { + deleteSingleOrganization(org); + } + + Assert.assertTrue(organizations.isEmpty(), "All organizations should be deleted, but the list is not empty."); + } private void validateNextLink(Response response, boolean expectNextLink) { @@ -1517,6 +1525,19 @@ private List> createOrganizations(int numberOfOrganizations) return newOrganizations; } + private void deleteSingleOrganization(Map org) { + + String organizationId = org.get(ORGANIZATION_ID); + String deleteEndpointURL = ORGANIZATION_MANAGEMENT_API_BASE_PATH + "/" + organizationId; + + Response response = getResponseOfDelete(deleteEndpointURL); + + validateHttpStatusCode(response, HttpStatus.SC_NO_CONTENT); + + // Remove the organization from the list after successful deletion + organizations.remove(org); + } + private String buildQueryUrl(int offset, int limit) { return ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + From 3f5ef236f3d17a1e71a0098e7efcf1870b2597d9 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Mon, 2 Sep 2024 23:59:09 +0530 Subject: [PATCH 13/15] Resturcture dependsOnGroups for succsess tests --- .../v1/OrganizationManagementSuccessTest.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) 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 a309509b6b0..d367ce5ceea 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 @@ -612,7 +612,7 @@ private void deleteApplication(String applicationId) throws Exception { oAuth2RestClient.deleteApplication(applicationId); } - @Test(groups = "paginationTests", dependsOnMethods = "testDeleteOrganization") + @Test(groups = "organizationPaginationTests", dependsOnMethods = "testDeleteOrganization") public void createOrganizationsForPaginationTests() throws JSONException { organizations = createOrganizations(NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS); @@ -629,7 +629,7 @@ public Object[][] organizationLimitValidationDataProvider() { }; } - @Test(groups = "paginationTests", dependsOnMethods = "createOrganizationsForPaginationTests", + @Test(groups = "organizationPaginationTests", dependsOnMethods = "createOrganizationsForPaginationTests", dataProvider = "organizationLimitValidationDataProvider") public void testGetPaginatedOrganizationsWithLimit(int limit) { @@ -668,7 +668,7 @@ public Object[][] organizationPaginationValidationProvider() { }; } - @Test(groups = "paginationTests", dependsOnMethods = "createOrganizationsForPaginationTests", + @Test(groups = "organizationPaginationTests", dependsOnMethods = "createOrganizationsForPaginationTests", dataProvider = "organizationPaginationValidationProvider") public void testGetPaginatedOrganizations(int limit) { @@ -742,7 +742,7 @@ public Object[][] organizationPaginationNumericEdgeCasesOfLimitDataProvider() { }; } - @Test(groups = "paginationTests", dependsOnMethods = "createOrganizationsForPaginationTests", + @Test(groups = "organizationPaginationTests", dependsOnMethods = "createOrganizationsForPaginationTests", dataProvider = "organizationPaginationNumericEdgeCasesOfLimitDataProvider") public void testGetPaginatedOrganizationsForNumericEdgeCasesOfLimit(int limit) { @@ -761,7 +761,7 @@ public void testGetPaginatedOrganizationsForNumericEdgeCasesOfLimit(int limit) { validateOrganizationsOnPage(response, 1, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, limit); } - @Test(groups = "paginationTests", dependsOnMethods = "createOrganizationsForPaginationTests") + @Test(groups = "organizationPaginationTests", dependsOnMethods = "createOrganizationsForPaginationTests") public void testGetPaginatedOrganizationsForNonNumericEdgeCasesOfLimit() { // Test case 1: URL with LIMIT_QUERY_PARAM but no value. @@ -786,7 +786,7 @@ public void testGetPaginatedOrganizationsForNonNumericEdgeCasesOfLimit() { validateOrganizationsForDefaultLimit(responseWithoutLimit, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS); } - @Test(groups = "paginationTests", dependsOnMethods = "createOrganizationsForPaginationTests") + @Test(groups = "organizationDiscoveryPaginationTests", dependsOnGroups = "organizationPaginationTests") public void testEnableEmailDomainDiscovery() { String enableDiscoveryPayload = "{\"properties\":[{\"key\":\"emailDomain.enable\",\"value\":true}]}"; @@ -806,7 +806,7 @@ public void testEnableEmailDomainDiscovery() { Assert.assertTrue(isEnabled, "Email domain discovery was not successfully enabled."); } - @Test(groups = "paginationTests", dependsOnMethods = "testEnableEmailDomainDiscovery") + @Test(groups = "organizationDiscoveryPaginationTests", dependsOnMethods = "testEnableEmailDomainDiscovery") public void testAddEmailDomainsToOrganization() { for (int i = 0; i < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS; i++) { @@ -825,7 +825,7 @@ public Object[][] organizationDiscoveryLimitValidationDataProvider() { }; } - @Test(groups = "paginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", + @Test(groups = "organizationDiscoveryPaginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "organizationDiscoveryLimitValidationDataProvider") public void testGetPaginatedOrganizationsDiscoveryWithLimit(int limit) { @@ -873,7 +873,7 @@ public Object[][] organizationDiscoveryPaginationValidationProvider() { }; } - @Test(groups = "paginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", + @Test(groups = "organizationDiscoveryPaginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "organizationDiscoveryPaginationValidationProvider") public void testGetPaginatedOrganizationsDiscovery(int limit) { @@ -934,7 +934,7 @@ public Object[][] organizationDiscoveryPaginationNumericEdgeCasesOfLimitDataProv }; } - @Test(groups = "paginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", + @Test(groups = "organizationDiscoveryPaginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "organizationDiscoveryPaginationNumericEdgeCasesOfLimitDataProvider") public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int offset, int limit) { @@ -964,7 +964,7 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int validateOrganizationDiscoveryLimitEdgeCaseOrganizations(returnedOrganizations, limit, offset); } - @Test(groups = "paginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization") + @Test(groups = "organizationDiscoveryPaginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization") public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfLimit() { // Test case 1: URL with LIMIT_QUERY_PARAM but no value. @@ -999,7 +999,7 @@ public Object[][] organizationDiscoveryOffsetValidationDataProvider() { }; } - @Test(groups = "paginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", + @Test(groups = "organizationDiscoveryPaginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "organizationDiscoveryOffsetValidationDataProvider") public void testGetPaginatedOrganizationsDiscoveryWithOffset(int offset, int limit) { @@ -1041,7 +1041,7 @@ public Object[][] numericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider() { }; } - @Test(groups = "paginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", + @Test(groups = "organizationDiscoveryPaginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", dataProvider = "numericEdgeCasesOfOffsetAndOffsetWithLimitDataProvider") public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfOffsetAndOffsetWithLimit(int offset, int limit) { @@ -1072,7 +1072,7 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfOffsetAnd } - @Test(groups = "paginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization") + @Test(groups = "organizationDiscoveryPaginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization") public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffsetAndOffsetWithLimit() { // Case 1: When offset param is present (limit = 0) @@ -1110,7 +1110,7 @@ public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffset validatePaginationScenarioWithNoOffsetAndLimit(); } - @Test(groups = "paginationTests", dependsOnMethods = "testEnableEmailDomainDiscovery") + @Test(groups = "organizationDiscoveryPaginationTests", dependsOnMethods = "testEnableEmailDomainDiscovery") public void testDisableEmailDomainDiscovery() { String emailDomainIsEnabled = "properties.find { it.key == 'emailDomain.enable' }?.value ?: false"; @@ -1131,7 +1131,7 @@ public void testDisableEmailDomainDiscovery() { Assert.assertFalse(isEnabled, "Email domain discovery was not successfully disabled."); } - @Test(dependsOnGroups = "paginationTests") + @Test(dependsOnGroups = "organizationDiscoveryPaginationTests") public void testDeleteOrganizationsForPagination() { for (Map org : new ArrayList<>(organizations)) { From 7629f4c85aa7707952c2962016ec9bcd46e868a8 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Tue, 3 Sep 2024 23:52:18 +0530 Subject: [PATCH 14/15] Format Comments --- .../v1/OrganizationManagementFailureTest.java | 6 +-- .../v1/OrganizationManagementSuccessTest.java | 54 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) 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 38c78db84d4..b9757a4066a 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 @@ -411,9 +411,9 @@ public void testGetPaginatedOrganizationsWithInvalidBeforeCursor() { 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 + {"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. }; } 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 d367ce5ceea..1fdc44c3671 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 @@ -792,16 +792,16 @@ public void testEnableEmailDomainDiscovery() { String enableDiscoveryPayload = "{\"properties\":[{\"key\":\"emailDomain.enable\",\"value\":true}]}"; String emailDomainIsEnabled = "properties.find { it.key == 'emailDomain.enable' }.value"; - // Send POST request to enable email domain discovery + // Send POST request to enable email domain discovery. Response response = getResponseOfPostWithOAuth2( ORGANIZATION_CONFIGS_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH, enableDiscoveryPayload, m2mToken); - // Validate that the request was successful + // Validate that the request was successful. validateHttpStatusCode(response, HttpStatus.SC_CREATED); - // Validate the response content + // Validate the response content. boolean isEnabled = response.jsonPath().getBoolean(emailDomainIsEnabled); Assert.assertTrue(isEnabled, "Email domain discovery was not successfully enabled."); } @@ -832,7 +832,7 @@ public void testGetPaginatedOrganizationsDiscoveryWithLimit(int limit) { int offset = 0; List accumulatedOrganizationNames = new ArrayList<>(); - // Loop through each page to test the organization discovery GET API limit + // Loop through each page to test the organization discovery GET API limit. while (offset < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) { String queryUrl = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + @@ -847,7 +847,7 @@ public void testGetPaginatedOrganizationsDiscoveryWithLimit(int limit) { Assert.assertEquals(returnedOrganizations.size(), Math.min(limit, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS - offset)); - // Validate no duplicate organization names + // Validate no duplicate organization names. for (Map org : returnedOrganizations) { String orgName = org.get(ORGANIZATION_NAME_ATTRIBUTE); assertFalse(accumulatedOrganizationNames.contains(orgName), @@ -858,10 +858,10 @@ public void testGetPaginatedOrganizationsDiscoveryWithLimit(int limit) { offset += limit; } - // Sort the list based on the numeric part of the organization name + // Sort the list based on the numeric part of the organization name. accumulatedOrganizationNames.sort(Comparator.comparingInt(s -> Integer.parseInt(s.split("-")[1]))); - // Compare accumulated organization names with the original list (order does not matter) + // Compare accumulated organization names with the original list (order does not matter). validateOrgNamesForOrganizationDiscoveryGet(accumulatedOrganizationNames); } @@ -886,7 +886,7 @@ public void testGetPaginatedOrganizationsDiscovery(int limit) { List forwardAccumulatedOrganizationNames = new ArrayList<>(); List backwardAccumulatedOrganizationNames = new ArrayList<>(); - // Forward Pagination + // Forward Pagination. do { links = getPaginationLinksForOrganizationDiscovery(queryUrl, offset, limit, forwardAccumulatedOrganizationNames, true); @@ -902,7 +902,7 @@ public void testGetPaginatedOrganizationsDiscovery(int limit) { } while (nextLink != null); - // Backward Pagination + // Backward Pagination. do { links = getPaginationLinksForOrganizationDiscovery(queryUrl, offset, limit, backwardAccumulatedOrganizationNames, false); @@ -944,7 +944,7 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int validateHttpStatusCode(response, HttpStatus.SC_OK); - // Validate the response content + // Validate the response content. int actualCount = response.jsonPath().getInt(COUNT_PATH_PARAM); int totalResults = response.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM); int startIndex = response.jsonPath().getInt(START_INDEX_PATH_PARAM); @@ -1009,7 +1009,7 @@ public void testGetPaginatedOrganizationsDiscoveryWithOffset(int offset, int lim validateHttpStatusCode(response, HttpStatus.SC_OK); - // Validate the response content + // Validate the response content. int totalResults = response.jsonPath().getInt(TOTAL_RESULTS_PATH_PARAM); int startIndex = response.jsonPath().getInt(START_INDEX_PATH_PARAM); int count = response.jsonPath().getInt(COUNT_PATH_PARAM); @@ -1056,12 +1056,12 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfOffsetAnd int count = response.jsonPath().getInt(COUNT_PATH_PARAM); List> links = response.jsonPath().getList(LINKS_PATH_PARAM); - // Validate based on the offset and limit + // Validate based on the offset and limit. Assert.assertEquals(totalResults, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, TOTAL_RESULT_MISMATCH_ERROR); Assert.assertEquals(startIndex, offset + 1, START_INDEX_MISMATCH_ERROR); Assert.assertEquals(count, 0, COUNT_MISMATCH_ERROR); - // Validate links + // Validate links. String nextLink = getLink(links, LINK_REL_NEXT); String previousLink = getLink(links, LINK_REL_PREVIOUS); Assert.assertNull(nextLink, "Next link should be null."); @@ -1075,38 +1075,38 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfOffsetAnd @Test(groups = "organizationDiscoveryPaginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization") public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfOffsetAndOffsetWithLimit() { - // Case 1: When offset param is present (limit = 0) + // Case 1: When offset param is present (limit = 0). validatePaginationScenarioWithOffsetAndLimit(0, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, 0, true); - // Case 2: When offset param is present (limit = 5) + // Case 2: When offset param is present (limit = 5). validatePaginationScenarioWithOffsetAndLimit(5, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, 5, true); - // Case 3: When offset param is present (limit = NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) + // Case 3: When offset param is present (limit = NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS). validatePaginationScenarioWithOffsetAndLimit(NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, false); - // Case 4: When offset param is present (limit > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) + // Case 4: When offset param is present (limit > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS). validatePaginationScenarioWithOffsetAndLimit(25, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, false); - // Case 5: When offset param is not present (limit = 0) + // Case 5: When offset param is not present (limit = 0). validatePaginationScenarioWithLimitOnly(0, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, 0, true); - // Case 6: When offset param is not present (limit = 5) + // Case 6: When offset param is not present (limit = 5). validatePaginationScenarioWithLimitOnly(5, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, 5, true); - // Case 7: When offset param is not present (limit = NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) + // Case 7: When offset param is not present (limit = NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS). validatePaginationScenarioWithLimitOnly(NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, false); - // Case 8: When offset param is not present (limit > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS) + // Case 8: When offset param is not present (limit > NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS). validatePaginationScenarioWithLimitOnly(25, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, 1, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, false); - // Case 9: Offset= and limit= + // Case 9: Offset= and limit= are equal to no value. validatePaginationScenarioWithOffsetAndLimitAndDefaultLimit(); - // Case 10: Offset is not present and limit is not present + // Case 10: Offset is not present and limit is not present. validatePaginationScenarioWithNoOffsetAndLimit(); } @@ -1115,14 +1115,14 @@ public void testDisableEmailDomainDiscovery() { String emailDomainIsEnabled = "properties.find { it.key == 'emailDomain.enable' }?.value ?: false"; - // Send DELETE request to disable email domain discovery + // Send DELETE request to disable email domain discovery. Response response = getResponseOfDeleteWithOAuth2( ORGANIZATION_CONFIGS_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH, m2mToken); validateHttpStatusCode(response, HttpStatus.SC_NO_CONTENT); - // Send a GET request to validate that the email domain discovery is disabled + // Send a GET request to validate that the email domain discovery is disabled. Response getResponse = getResponseOfGetWithOAuth2( ORGANIZATION_CONFIGS_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH, m2mToken); @@ -1222,7 +1222,7 @@ private void validateOrganizationsForDefaultLimit(Response response, int totalOr private void validateOrgNamesForOrganizationDiscoveryGet(List accumulatedOrganizationNames) { - // Ensure both sets contain the same organization names + // Ensure both sets contain the same organization names. for (int i = 0; i < NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS; i++) { assertEquals(accumulatedOrganizationNames.get(i), organizations.get(i).get(ORGANIZATION_NAME), "Organization names do not match."); @@ -1534,7 +1534,7 @@ private void deleteSingleOrganization(Map org) { validateHttpStatusCode(response, HttpStatus.SC_NO_CONTENT); - // Remove the organization from the list after successful deletion + // Remove the organization from the list after successful deletion. organizations.remove(org); } From 6ce4d2238cbc4e98ef8071dd6fa6ec098d6f9ba2 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Wed, 4 Sep 2024 00:34:27 +0530 Subject: [PATCH 15/15] Refactor pagination tests to use data providers for non-numeric edge cases of LIMIT query parameter and rename data providers adhering to a consistent format --- .../v1/OrganizationManagementSuccessTest.java | 76 +++++++++---------- 1 file changed, 35 insertions(+), 41 deletions(-) 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 1fdc44c3671..947d2508d37 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 @@ -660,7 +660,7 @@ public void testGetPaginatedOrganizationsWithLimit(int limit) { } } - @DataProvider(name = "organizationPaginationValidationProvider") + @DataProvider(name = "organizationPaginationValidationDataProvider") public Object[][] organizationPaginationValidationProvider() { return new Object[][]{ @@ -669,7 +669,7 @@ public Object[][] organizationPaginationValidationProvider() { } @Test(groups = "organizationPaginationTests", dependsOnMethods = "createOrganizationsForPaginationTests", - dataProvider = "organizationPaginationValidationProvider") + dataProvider = "organizationPaginationValidationDataProvider") public void testGetPaginatedOrganizations(int limit) { String after; @@ -761,29 +761,26 @@ public void testGetPaginatedOrganizationsForNumericEdgeCasesOfLimit(int limit) { validateOrganizationsOnPage(response, 1, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS, limit); } - @Test(groups = "organizationPaginationTests", dependsOnMethods = "createOrganizationsForPaginationTests") - public void testGetPaginatedOrganizationsForNonNumericEdgeCasesOfLimit() { - - // Test case 1: URL with LIMIT_QUERY_PARAM but no value. - String endpointURLWithEmptyLimit = - ORGANIZATION_MANAGEMENT_API_BASE_PATH + QUESTION_MARK + LIMIT_QUERY_PARAM + EQUAL + AMPERSAND + - RECURSIVE_QUERY_PARAM + EQUAL + FALSE; - - Response responseWithEmptyLimit = getResponseOfGetWithOAuth2(endpointURLWithEmptyLimit, m2mToken); - - validateHttpStatusCode(responseWithEmptyLimit, HttpStatus.SC_OK); + @DataProvider(name = "organizationPaginationNonNumericEdgeCasesOfLimitDataProvider") + public Object[][] organizationPaginationNonNumericEdgeCasesOfLimitProvider() { + return new Object[][] { + {AMPERSAND + LIMIT_QUERY_PARAM + EQUAL}, // Test case 1: URL with LIMIT_QUERY_PARAM but no value. + {""} // Test case 2: URL without LIMIT_QUERY_PARAM. + }; + } - validateOrganizationsForDefaultLimit(responseWithEmptyLimit, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS); + @Test(groups = "organizationPaginationTests", dependsOnMethods = "createOrganizationsForPaginationTests", + dataProvider = "organizationPaginationNonNumericEdgeCasesOfLimitDataProvider") + public void testGetPaginatedOrganizationsForNonNumericEdgeCasesOfLimit(String limitQueryParam) { - // Test case 2: URL without LIMIT_QUERY_PARAM. - String endpointURLWithoutLimit = - ORGANIZATION_MANAGEMENT_API_BASE_PATH + QUESTION_MARK + RECURSIVE_QUERY_PARAM + EQUAL + FALSE; + String endpointURL = ORGANIZATION_MANAGEMENT_API_BASE_PATH + QUESTION_MARK + RECURSIVE_QUERY_PARAM + EQUAL + FALSE + + limitQueryParam; - Response responseWithoutLimit = getResponseOfGetWithOAuth2(endpointURLWithoutLimit, m2mToken); + Response response = getResponseOfGetWithOAuth2(endpointURL, m2mToken); - validateHttpStatusCode(responseWithoutLimit, HttpStatus.SC_OK); + validateHttpStatusCode(response, HttpStatus.SC_OK); - validateOrganizationsForDefaultLimit(responseWithoutLimit, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS); + validateOrganizationsForDefaultLimit(response, NUM_OF_ORGANIZATIONS_FOR_PAGINATION_TESTS); } @Test(groups = "organizationDiscoveryPaginationTests", dependsOnGroups = "organizationPaginationTests") @@ -865,7 +862,7 @@ public void testGetPaginatedOrganizationsDiscoveryWithLimit(int limit) { validateOrgNamesForOrganizationDiscoveryGet(accumulatedOrganizationNames); } - @DataProvider(name = "organizationDiscoveryPaginationValidationProvider") + @DataProvider(name = "organizationDiscoveryPaginationValidationDataProvider") public Object[][] organizationDiscoveryPaginationValidationProvider() { return new Object[][]{ @@ -874,7 +871,7 @@ public Object[][] organizationDiscoveryPaginationValidationProvider() { } @Test(groups = "organizationDiscoveryPaginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", - dataProvider = "organizationDiscoveryPaginationValidationProvider") + dataProvider = "organizationDiscoveryPaginationValidationDataProvider") public void testGetPaginatedOrganizationsDiscovery(int limit) { int offset = 0; @@ -964,29 +961,26 @@ public void testGetPaginatedOrganizationsDiscoveryForNumericEdgeCasesOfLimit(int validateOrganizationDiscoveryLimitEdgeCaseOrganizations(returnedOrganizations, limit, offset); } - @Test(groups = "organizationDiscoveryPaginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization") - public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfLimit() { - - // Test case 1: URL with LIMIT_QUERY_PARAM but no value. - String endpointURLWithEmptyLimit = - ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + - FILTER_QUERY_PARAM + EQUAL + AMPERSAND + LIMIT_QUERY_PARAM + EQUAL + AMPERSAND + - OFFSET_QUERY_PARAM + EQUAL + ZERO; - - Response responseWithEmptyLimit = getResponseOfGetWithOAuth2(endpointURLWithEmptyLimit, m2mToken); - validateHttpStatusCode(responseWithEmptyLimit, HttpStatus.SC_OK); + @DataProvider(name = "organizationDiscoveryPaginationNonNumericEdgeCasesOfLimitDataProvider") + public Object[][] organizationDiscoveryPaginationNonNumericEdgeCasesOfLimitProvider() { + return new Object[][] { + {AMPERSAND + LIMIT_QUERY_PARAM + EQUAL}, // Test case 1: URL with LIMIT_QUERY_PARAM but no value. + {""} // Test case 2: URL without LIMIT_QUERY_PARAM. + }; + } - validateResponseForOrganizationDiscoveryLimitDefaultCases(responseWithEmptyLimit); + @Test(groups = "organizationDiscoveryPaginationTests", dependsOnMethods = "testAddEmailDomainsToOrganization", + dataProvider = "organizationDiscoveryPaginationNonNumericEdgeCasesOfLimitDataProvider") + public void testGetPaginatedOrganizationsDiscoveryForNonNumericEdgeCasesOfLimit(String limitQueryParam) { - // Test case 2: URL without LIMIT_QUERY_PARAM. - String endpointURLWithoutLimit = - ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + - FILTER_QUERY_PARAM + EQUAL + AMPERSAND + OFFSET_QUERY_PARAM + EQUAL + ZERO; + String endpointURL = ORGANIZATION_MANAGEMENT_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH + QUESTION_MARK + + FILTER_QUERY_PARAM + EQUAL + AMPERSAND + OFFSET_QUERY_PARAM + EQUAL + ZERO + + limitQueryParam; - Response responseWithoutLimit = getResponseOfGetWithOAuth2(endpointURLWithoutLimit, m2mToken); - validateHttpStatusCode(responseWithoutLimit, HttpStatus.SC_OK); + Response response = getResponseOfGetWithOAuth2(endpointURL, m2mToken); + validateHttpStatusCode(response, HttpStatus.SC_OK); - validateResponseForOrganizationDiscoveryLimitDefaultCases(responseWithoutLimit); + validateResponseForOrganizationDiscoveryLimitDefaultCases(response); } @DataProvider(name = "organizationDiscoveryOffsetValidationDataProvider")