Skip to content

Commit

Permalink
Merge pull request #444 from Pushpalanka/IDENTITY-3287
Browse files Browse the repository at this point in the history
Test case user store count feature
  • Loading branch information
Pushpalanka Jayawardhana committed Mar 17, 2016
2 parents e73d687 + f40bfe0 commit f1277d6
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 1 deletion.
4 changes: 4 additions & 0 deletions modules/integration/tests-common/admin-clients/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.user.store.configuration.stub</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.user.store.count.stub</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.scim.common.stub</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.identity.integration.common.clients.user.store.count;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.apache.axis2.AxisFault;
import org.wso2.carbon.identity.user.store.count.stub.UserStoreCountServiceStub;
import org.wso2.carbon.identity.user.store.count.stub.dto.PairDTO;
import org.wso2.carbon.integration.common.admin.client.utils.AuthenticateStubUtil;

public class UserStoreCountServiceClient {
private UserStoreCountServiceStub stub;
private String service = "UserStoreCountService";

/**
* Constructor UserStoreCountServiceClient
*
* @param sessionCookie - session cookie
* @param backendServerURL - backend server URL
*/
public UserStoreCountServiceClient(String backendServerURL, String sessionCookie) throws AxisFault {
String serviceURL = backendServerURL + service;
stub = new UserStoreCountServiceStub(serviceURL);
AuthenticateStubUtil.authenticateStub(sessionCookie, stub);

}

/**
* Constructor UserStoreCountServiceClient
*
* @param userName - user name
* @param backendServerURL - backend server URL
*/
public UserStoreCountServiceClient(String backendServerURL, String userName, String password) throws AxisFault {
String serviceURL = backendServerURL + service;
stub = new UserStoreCountServiceStub(serviceURL);
AuthenticateStubUtil.authenticateStub(userName, password, stub);

}

public Map<String, String> countUsers(String filter) throws Exception {
return convertArrayToMap(stub.countUsers(filter));
}

public Map<String, String> countRoles(String filter) throws Exception {
return convertArrayToMap(stub.countRoles(filter));

}

public Map<String, String> countByClaim(String claimURI, String value) throws Exception {
return convertArrayToMap(stub.countClaim(claimURI, value));
}

public Map<String, String> countByClaims(Map<String, String> claims) throws Exception {
return convertArrayToMap(stub.countClaims(convertMapToArray(claims)));

}

public long countUsersInDomain(String filter, String domain) throws Exception {
return stub.countUsersInDomain(filter, domain);
}

public long countRolesInDomain(String filter, String domain) throws Exception {
return stub.countRolesInDomain(filter, domain);
}

public long countByClaimInDomain(String claimURI, String filter, String domain) throws Exception {
return stub.countByClaimInDomain(claimURI, filter, domain);
}

public long countByClaimsInDomain(PairDTO[] pairDTOs, String domain) throws Exception {
return stub.countByClaimsInDomain(pairDTOs, domain);
}

public Set<String> getCountableUserStores() throws Exception {
return new HashSet<String>(Arrays.asList(stub.getCountEnabledUserStores()));

}

/**
* Converts a given array of PairDTOs to a Map
*
* @param pairDTOs
* @return
*/
private Map<String, String> convertArrayToMap(PairDTO[] pairDTOs) {
Map<String, String> map = new HashMap<>();
for (PairDTO pairDTO : pairDTOs) {
map.put(pairDTO.getKey(), pairDTO.getValue());
}
return map;
}

/**
* Converts a given Map to an array of PairDTOs
*
* @param claims
* @return
*/
private PairDTO[] convertMapToArray(Map<String, String> claims) {
PairDTO[] pairs = new PairDTO[claims.size()];
Iterator iterator = claims.entrySet().iterator();
int i = 0;
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next();
PairDTO pair = new PairDTO();
pair.setKey((String) entry.getKey());
pair.setValue((String) entry.getValue());
pairs[i] = pair;
i++;
}

return pairs;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,25 @@
import org.wso2.carbon.identity.user.store.configuration.stub.dto.PropertyDTO;
import org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO;
import org.wso2.carbon.integration.common.admin.client.AuthenticatorClient;
import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager;
import org.wso2.carbon.user.core.UserCoreConstants;
import org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException;
import org.wso2.identity.integration.common.clients.UserManagementClient;
import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager;
import org.wso2.identity.integration.common.clients.user.store.config.UserStoreConfigAdminServiceClient;
import org.wso2.identity.integration.common.clients.user.store.count.UserStoreCountServiceClient;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
import org.wso2.identity.integration.common.utils.UserStoreConfigUtils;
import org.wso2.identity.integration.test.util.Utils;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class JDBCUserStoreAddingTestCase extends ISIntegrationTest{
private static final String PERMISSION_LOGIN = "/permission/admin/login";
private UserStoreConfigAdminServiceClient userStoreConfigAdminServiceClient;
private UserStoreCountServiceClient userStoreCountServiceClient;
private UserStoreConfigUtils userStoreConfigUtils = new UserStoreConfigUtils();
private final String jdbcClass = "org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager";
private final String rwLDAPClass = "org.wso2.carbon.user.core.ldap.ReadWriteLDAPUserStoreManager";
Expand All @@ -62,6 +66,7 @@ public class JDBCUserStoreAddingTestCase extends ISIntegrationTest{
public void init() throws Exception {
super.init();
userStoreConfigAdminServiceClient = new UserStoreConfigAdminServiceClient(backendURL, sessionCookie);
userStoreCountServiceClient = new UserStoreCountServiceClient(backendURL, sessionCookie);
}

@AfterClass(alwaysRun = true)
Expand Down Expand Up @@ -124,6 +129,9 @@ private void testAddJDBCUserStore() throws Exception {
propertyDTOs[9].setName("SCIMEnabled");
propertyDTOs[9].setValue("true");

propertyDTOs[9].setName("CountRetrieverClass");
propertyDTOs[9].setValue("org.wso2.carbon.identity.user.store.count.jdbc.JDBCUserStoreCountRetriever");


UserStoreDTO userStoreDTO = userStoreConfigAdminServiceClient.createUserStoreDTO(jdbcClass, domainId, propertyDTOs);
userStoreConfigAdminServiceClient.addUserStore(userStoreDTO);
Expand Down Expand Up @@ -200,8 +208,37 @@ public void changePassWordByUserTest() throws Exception {

}

@Test(groups = "wso2.is", dependsOnMethods = "addUserIntoJDBCUserStore")
public void getCountEnabledUserStores() throws Exception {
Assert.assertTrue(userStoreCountServiceClient.getCountableUserStores().contains(domainId), "no count enabled " +
"user stores");
}

@Test(groups = "wso2.is", dependsOnMethods = "addUserIntoJDBCUserStore")
public void countUsersInDomain() throws Exception {
Assert.assertEquals(1, userStoreCountServiceClient.countUsersInDomain("%",domainId), "user count failed");
}

@Test(groups = "wso2.is", dependsOnMethods = "addUserIntoJDBCUserStore")
public void countRolesInDomain() throws Exception {
Assert.assertEquals(1, userStoreCountServiceClient.countRolesInDomain("%", domainId), "role count failed");
}

@Test(groups = "wso2.is", dependsOnMethods = "addUserIntoJDBCUserStore")
public void countUsers() throws Exception {
Map<String, String> users = userStoreCountServiceClient.countUsers("%");
Assert.assertEquals(Long.valueOf(1), Long.valueOf(users.get(domainId)));
Assert.assertEquals(Long.valueOf(-1), Long.valueOf(users.get(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME)));
}

@Test(groups = "wso2.is", dependsOnMethods = "addUserIntoJDBCUserStore")
public void countRoles() throws Exception {
Map<String, String> roles = userStoreCountServiceClient.countRoles("%");
Assert.assertEquals(Long.valueOf(1), Long.valueOf(roles.get(domainId)));
Assert.assertEquals(Long.valueOf(-1), Long.valueOf(roles.get(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME)));
}

@Test(groups = "wso2.is", dependsOnMethods = {"countRoles" , "countUsers" , "countRolesInDomain" , "countUsersInDomain"})
public void deleteUserFromJDBCUserStore() throws Exception {
userMgtClient.deleteUser(newUserName);
Assert.assertFalse(Utils.nameExists(userMgtClient.listAllUsers(newUserName, 10)
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,12 @@
<version>${carbon.identity.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.user.store.count.stub</artifactId>
<version>${carbon.identity.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.core</artifactId>
Expand Down

0 comments on commit f1277d6

Please sign in to comment.