Skip to content

Commit

Permalink
Merge pull request #16301 from ThaminduDilshan/thamindu-fix-filter
Browse files Browse the repository at this point in the history
Update integration tests for user discoverable applications
  • Loading branch information
ThaminduDilshan committed Jul 26, 2023
2 parents a856f12 + cfc8903 commit 935fd5f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ public void testGetApplicationWithInvalidApplicationId() {
validateErrorResponse(response, HttpStatus.SC_NOT_FOUND, "APP-10001", "randomApp");
}

@Test
public void testFilterApplicationsWithInvalidFilterOperation() {

Map<String, Object> params = new HashMap<String, Object>() {{
put("filter", "name equal APP_1 ");

}};
Response response = getResponseOfGet(USER_APPLICATION_ENDPOINT_URI, params);
validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, "APP-10002", "equal");
}

@Test
public void testFilterApplicationsWithInvalidFilterAttribute() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,8 @@ public void testMethodEnd() {
private void createServiceProviders() throws Exception {

for (int i = 1; i <= TOTAL_DISCOVERABLE_APP_COUNT; i++) {

ServiceProvider serviceProvider = new ServiceProvider();
serviceProvider.setApplicationName(APP_NAME_PREFIX + i);
serviceProvider.setDescription(APP_DESC_PREFIX + i);
appMgtclient.createApplication(serviceProvider);

serviceProvider = appMgtclient.getApplication(APP_NAME_PREFIX + i);
ServiceProvider serviceProvider = createServiceProvider(APP_NAME_PREFIX + i, APP_DESC_PREFIX + i);
if (serviceProvider != null) {
serviceProvider.setDiscoverable(true);
serviceProvider.setImageUrl(APP_IMAGE_URL);
serviceProvider.setAccessUrl(APP_ACCESS_URL);
appMgtclient.updateApplicationData(serviceProvider);
serviceProviders.add(serviceProvider);
}
}
Expand All @@ -122,4 +112,23 @@ private void deleteServiceProviders() throws Exception {
serviceProviders.clear();
}

protected ServiceProvider createServiceProvider(String appName, String appDescription) throws Exception {

ServiceProvider serviceProvider = new ServiceProvider();
serviceProvider.setApplicationName(appName);
serviceProvider.setDescription(appDescription);
appMgtclient.createApplication(serviceProvider);

serviceProvider = appMgtclient.getApplication(appName);
if (serviceProvider != null) {
serviceProvider.setDiscoverable(true);
serviceProvider.setImageUrl(APP_IMAGE_URL);
serviceProvider.setAccessUrl(APP_ACCESS_URL);
appMgtclient.updateApplicationData(serviceProvider);

return serviceProvider;
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.http.HttpStatus;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
Expand All @@ -40,6 +41,7 @@
public class UserDiscoverableApplicationSuccessTest extends UserDiscoverableApplicationServiceTestBase {

private static final String PAGINATION_LINK_QUERY_PARAM_STRING = "?offset=%d&limit=%d";
private static final String APP_NAME_WITH_SPACES = "APP_SPACES IN NAME";

@Factory(dataProvider = "restAPIUserConfigProvider")
public UserDiscoverableApplicationSuccessTest(TestUserMode userMode) throws Exception {
Expand Down Expand Up @@ -186,6 +188,59 @@ public void testFilteringApplicationsByNameForEW() {
assertForApplication(serviceProviders.get(0), response);
}

@Test(description = "Test filtering applications by name with eq operator when name contains spaces.")
public void testFilterApplicationsByNameWithSpacesForEQ() throws Exception {

// Create a discoverable SP with spaces in the name.
ServiceProvider serviceProvider = createServiceProvider(
APP_NAME_WITH_SPACES, "This is " + APP_NAME_WITH_SPACES);
Assert.assertNotNull(serviceProvider, "Failed to create service provider with spaces in name.");

Map<String, Object> params = new HashMap<String, Object>() {{
put("filter", "name eq " + APP_NAME_WITH_SPACES);
}};
Response response = getResponseOfGet(USER_APPLICATION_ENDPOINT_URI, params);
response.then().log().ifValidationFails().assertThat().body("totalResults", equalTo(1));
response.then().log().ifValidationFails().assertThat().body("startIndex", equalTo(1));
response.then().log().ifValidationFails().assertThat().body("count", equalTo(1));

assertForApplication(serviceProvider, response);

// Remove the discoverable SP with spaces in the name.
ServiceProvider serviceProviderCreated = appMgtclient.getApplication(APP_NAME_WITH_SPACES);
if (serviceProviderCreated != null) {
appMgtclient.deleteApplication(serviceProviderCreated.getApplicationName());
log.info("############## " + "Deleted app: " + serviceProviderCreated.getApplicationName());
}
}

@Test(description = "Test filtering applications by name with co operator when name contains spaces.")
public void testFilterApplicationsByNameWithSpacesForCO() throws Exception {

// Create a discoverable SP with spaces in the name.
ServiceProvider serviceProvider = createServiceProvider(
APP_NAME_WITH_SPACES, "This is " + APP_NAME_WITH_SPACES);
Assert.assertNotNull(serviceProvider, "Failed to create service provider with spaces in name.");

Map<String, Object> params = new HashMap<String, Object>() {{
put("filter", "name co " + APP_NAME_WITH_SPACES);

}};
Response response = getResponseOfGet(USER_APPLICATION_ENDPOINT_URI, params);
response.then().log().ifValidationFails().assertThat().body("totalResults", equalTo(1));
response.then().log().ifValidationFails().assertThat().body("startIndex", equalTo(1));
response.then().log().ifValidationFails().assertThat().body("count", equalTo(1));

assertForApplication(serviceProvider, response);

// Remove the discoverable SP with spaces in the name.
ServiceProvider serviceProviderCreated = appMgtclient.getApplication(APP_NAME_WITH_SPACES);
if (serviceProviderCreated != null) {
appMgtclient.deleteApplication(serviceProviderCreated.getApplicationName());
log.info("############## " + "Deleted app: " + serviceProviderCreated.getApplicationName());
}
}

@Test(description = "Test get application.")
public void testGetApplication() {

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2352,7 +2352,7 @@

<!-- Identity REST API feature -->
<identity.api.dispatcher.version>2.0.13</identity.api.dispatcher.version>
<identity.user.api.version>1.3.16</identity.user.api.version>
<identity.user.api.version>1.3.17</identity.user.api.version>
<identity.server.api.version>1.2.66</identity.server.api.version>

<identity.agent.sso.version>5.5.9</identity.agent.sso.version>
Expand Down

0 comments on commit 935fd5f

Please sign in to comment.