Skip to content

Commit

Permalink
Merge pull request #21486 from hwupathum/tenant-filter
Browse files Browse the repository at this point in the history
Add integration tests for tenant filter API
  • Loading branch information
hwupathum authored Oct 25, 2024
2 parents 96f8d59 + d7a90e5 commit c3f3d31
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import java.io.IOException;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.core.IsNull.notNullValue;

/**
Expand Down Expand Up @@ -148,5 +149,32 @@ public void updateTenantOwnerWithInvalidOwnerId() throws IOException {
validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, "TM-60020", tenantId);
}

@Test
public void testGetTenantsInvalidFilterFormat() {

Response response = getResponseOfGet(TENANT_API_BASE_PATH + "?filter=invalid format");
validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, "TM-60022");
}

@Test
public void testGetTenantsUnsupportedFilterAttribute() {

Response response = getResponseOfGet(TENANT_API_BASE_PATH + "?filter=username eq mail.com");
validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, "TM-60023", "username");
}

@Test
public void testGetTenantsInvalidFilterOperation() {

Response response = getResponseOfGet(TENANT_API_BASE_PATH + "?filter=domainName invalid_op abc.com");
validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, "TM-60024", "domainName");
}

@Test
public void testGetTenantsFilterIllegalDomain() {

Response response = getResponseOfGet(TENANT_API_BASE_PATH + "?filter=domainName eq abc*");
validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, "TM-60007");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void testGetTenant() throws IOException {
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("id", equalTo(tenantId))
.body("domain", equalTo("abc1.com"))
.body("domain", equalTo(TENANT_DOMAIN_NAME))
.body(baseIdentifier, notNullValue());
TenantResponseModel tenantResponseModel = response.getBody().as(TenantResponseModel.class);
userId = tenantResponseModel.getOwners().get(0).getId();
Expand Down Expand Up @@ -183,4 +183,42 @@ public void testGetOwner() {
.body( "lastname", equalTo("lee"))
.body(claimsIdentifier + ".value", equalTo("+94 77 123 4568"));
}

@Test(dependsOnMethods = {"testGetTenant"})
public void testGetFilteredTenantsEqual() {

String baseIdentifier = "tenants.find{ it.id == '" + tenantId + "' }.";
String activeStatusIdentifier = "owners.find{ it.id == '" + userId + "' }.";
Response response = getResponseOfGet(TENANT_API_BASE_PATH + "?filter=domainName eq "
+ TENANT_DOMAIN_NAME);
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("totalResults", equalTo(1))
.body(baseIdentifier + "domain", equalTo("abc1.com"))
.body(baseIdentifier + activeStatusIdentifier + "username", equalTo("kim"));
}

@Test(dependsOnMethods = {"testAddTenant"})
public void testGetFilteredTenantsContains() {

Response response = getResponseOfGet(TENANT_API_BASE_PATH + "?filter=domainName co abc1");
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("totalResults", equalTo(1));
}

@Test
public void testGetFilteredTenantsNotAvailable() {

Response response = getResponseOfGet(TENANT_API_BASE_PATH + "?filter=domainName eq abc99.com");
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("totalResults", equalTo(0));
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2478,7 +2478,7 @@

<!-- Identity REST API feature -->
<identity.api.dispatcher.version>2.0.17</identity.api.dispatcher.version>
<identity.server.api.version>1.2.241</identity.server.api.version>
<identity.server.api.version>1.2.243</identity.server.api.version>
<identity.user.api.version>1.3.43</identity.user.api.version>

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

0 comments on commit c3f3d31

Please sign in to comment.