Skip to content

Commit b07052b

Browse files
Merge pull request #23619 from sadilchamishka/add-integration-test-for-multiattribute-improvement
Add integration test for efficient filtering multi valued attributes
2 parents d381a75 + a9c1141 commit b07052b

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/claim/management/v1/model/LocalClaimRes.java

+14
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class LocalClaimRes {
4040
private String regEx = null;
4141
private Boolean required = null;
4242
private Boolean supportedByDefault = null;
43+
private Boolean multiValued = null;
4344

4445
public enum UniquenessScopeEnum {
4546
NONE, WITHIN_USERSTORE, ACROSS_USERSTORES,
@@ -209,6 +210,19 @@ public void setSupportedByDefault(Boolean supportedByDefault) {
209210
this.supportedByDefault = supportedByDefault;
210211
}
211212

213+
/**
214+
* Specifies if the claim can hold multiple values.
215+
**/
216+
@ApiModelProperty(value = "Specifies if the claim can hold multiple values.")
217+
@JsonProperty("multiValued")
218+
public Boolean getMultiValued() {
219+
return multiValued;
220+
}
221+
222+
public void setMultiValued(Boolean multiValued) {
223+
this.multiValued = multiValued;
224+
}
225+
212226
/**
213227
* Specifies the scope of uniqueness validation for the claim value.
214228
**/

modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/scim2/SCIM2BaseTestCase.java

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class SCIM2BaseTestCase extends ISIntegrationTest {
4242
public static final String GIVEN_NAME_ATTRIBUTE = "givenName";
4343
public static final String EMAIL_TYPE_WORK_ATTRIBUTE = "work";
4444
public static final String EMAIL_TYPE_HOME_ATTRIBUTE = "home";
45+
public static final String EMAIL_ADDRESSES_ATTRIBUTE = "emailAddresses";
4546
public static final String ID_ATTRIBUTE = "id";
4647
public static final String PASSWORD_ATTRIBUTE = "password";
4748
public static final String EMAILS_ATTRIBUTE = "emails";
@@ -59,6 +60,7 @@ public class SCIM2BaseTestCase extends ISIntegrationTest {
5960
public static final String LIST_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:ListResponse";
6061
public static final String RESOURCE_TYPE_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:ResourceType";
6162
public static final String ERROR_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:Error";
63+
public static final String USER_SYSTEM_SCHEMA = "urn:scim:wso2:schema";
6264

6365
private ServerConfigurationManager serverConfigurationManager;
6466

modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/scim2/SCIM2UserTestCase.java

+39-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.apache.http.HttpResponse;
2626
import org.apache.http.client.methods.HttpDelete;
2727
import org.apache.http.client.methods.HttpGet;
28-
import org.apache.http.client.methods.HttpPatch;
2928
import org.apache.http.client.methods.HttpPost;
3029
import org.apache.http.entity.StringEntity;
3130
import org.apache.http.impl.client.CloseableHttpClient;
@@ -41,7 +40,6 @@
4140
import org.testng.annotations.Test;
4241
import org.wso2.carbon.automation.engine.context.AutomationContext;
4342
import org.wso2.carbon.automation.engine.context.TestUserMode;
44-
import org.wso2.carbon.integration.common.utils.LoginLogoutClient;
4543
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
4644
import org.wso2.identity.integration.common.clients.claim.metadata.mgt.ClaimMetadataManagementServiceClient;
4745
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
@@ -51,7 +49,9 @@
5149
import static org.testng.Assert.assertEquals;
5250
import static org.testng.Assert.assertNotNull;
5351
import static org.testng.Assert.assertTrue;
52+
import static org.testng.Assert.fail;
5453
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.EMAILS_ATTRIBUTE;
54+
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.EMAIL_ADDRESSES_ATTRIBUTE;
5555
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.EMAIL_TYPE_HOME_ATTRIBUTE;
5656
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.EMAIL_TYPE_WORK_ATTRIBUTE;
5757
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.ERROR_SCHEMA;
@@ -69,6 +69,7 @@
6969
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.SERVER_URL;
7070
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.TYPE_PARAM;
7171
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.USER_NAME_ATTRIBUTE;
72+
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.USER_SYSTEM_SCHEMA;
7273
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.VALUE_PARAM;
7374

7475
public class SCIM2UserTestCase extends ISIntegrationTest {
@@ -160,6 +161,13 @@ public void testCreateUser() throws Exception {
160161

161162
rootObject.put(PASSWORD_ATTRIBUTE, PASSWORD);
162163

164+
JSONArray emailAddresses = new JSONArray();
165+
emailAddresses.add(EMAIL_TYPE_WORK_CLAIM_VALUE);
166+
emailAddresses.add(EMAIL_TYPE_HOME_CLAIM_VALUE);
167+
JSONObject emailAddressesObject = new JSONObject();
168+
emailAddressesObject.put(EMAIL_ADDRESSES_ATTRIBUTE, emailAddresses);
169+
rootObject.put(USER_SYSTEM_SCHEMA, emailAddressesObject);
170+
163171
StringEntity entity = new StringEntity(rootObject.toString());
164172
request.setEntity(entity);
165173

@@ -301,6 +309,7 @@ public void testFilterUser() throws Exception {
301309
validateFilteredUser(USER_NAME_ATTRIBUTE, CONTAINS, USERNAME.substring(2, 4));
302310
validateFilteredUser(USER_NAME_ATTRIBUTE, STARTWITH, USERNAME.substring(0, 3));
303311
validateFilteredUser(USER_NAME_ATTRIBUTE, ENDWITH, USERNAME.substring(4, USERNAME.length()));
312+
validateFilteredUserByEmailAddresses(EMAIL_ADDRESSES_ATTRIBUTE, CONTAINS, EMAIL_TYPE_HOME_CLAIM_VALUE);
304313
}
305314

306315
private void validateFilteredUser(String attributeName, String operator, String attributeValue) throws IOException {
@@ -325,6 +334,34 @@ private void validateFilteredUser(String attributeName, String operator, String
325334
assertEquals(userId, this.userId);
326335
}
327336

337+
private void validateFilteredUserByEmailAddresses(String attributeName, String operator, String attributeValue)
338+
throws IOException {
339+
340+
String userResourcePath = getPath() + "?filter=" + USER_SYSTEM_SCHEMA + ":" + attributeName + operator
341+
+ attributeValue;
342+
HttpGet request = new HttpGet(userResourcePath);
343+
request.addHeader(HttpHeaders.AUTHORIZATION, getAuthzHeader());
344+
request.addHeader(HttpHeaders.CONTENT_TYPE, "application/json");
345+
request.addHeader(HttpHeaders.ACCEPT, "application/scim+json");
346+
HttpResponse response = client.execute(request);
347+
assertEquals(response.getStatusLine().getStatusCode(), 200, "User " +
348+
"has not been retrieved successfully");
349+
350+
Object responseObj = JSONValue.parse(EntityUtils.toString(response.getEntity()));
351+
EntityUtils.consume(response.getEntity());
352+
353+
JSONObject userResources = ((JSONObject) ((JSONArray) ((JSONObject) responseObj)
354+
.get("Resources")).get(0));
355+
JSONArray emailsArray = (JSONArray) ((JSONObject) userResources.get(USER_SYSTEM_SCHEMA)).get(attributeName);
356+
357+
for (Object email: emailsArray) {
358+
if (email.equals(attributeValue)) {
359+
return;
360+
}
361+
}
362+
fail();
363+
}
364+
328365
@Test(dependsOnMethods = "testFilterUser")
329366
public void testDeleteUser() throws Exception {
330367
String userResourcePath = getPath() + "/" + userId;

0 commit comments

Comments
 (0)