Package: UserManagementUtils

UserManagementUtils

nameinstructionbranchcomplexitylinemethod
UserManagementUtils()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
addUser(String, String, String, String[], String, String, String)
M: 43 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
signupUser(String, String, String, String)
M: 88 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
signupUser(String, String, String, String, String)
M: 92 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package org.wso2.am.integration.test.utils;
2:
3: import org.apache.commons.httpclient.HttpStatus;
4: import org.apache.commons.logging.Log;
5: import org.apache.commons.logging.LogFactory;
6: import org.apache.http.client.methods.CloseableHttpResponse;
7: import org.apache.http.client.methods.HttpPost;
8: import org.apache.http.entity.StringEntity;
9: import org.apache.http.impl.client.CloseableHttpClient;
10: import org.wso2.am.admin.clients.client.utils.AuthenticateStub;
11: import org.wso2.am.integration.test.utils.base.APIMIntegrationConstants;
12: import org.wso2.am.integration.test.utils.http.HTTPSClientUtils;
13: import org.wso2.carbon.automation.engine.context.beans.User;
14: import org.wso2.carbon.user.mgt.stub.UserAdminStub;
15: import org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException;
16: import org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue;
17:
18: import java.io.IOException;
19: import java.rmi.RemoteException;
20:
21: import static org.wso2.am.integration.test.Constants.APPLICATION_JSON;
22: import static org.wso2.am.integration.test.utils.generic.APIMTestCaseUtils.encodeCredentials;
23:
24: public class UserManagementUtils {
25:
26: private static UserAdminStub userAdminStub;
27: private static final String serviceName = "UserAdmin";
28: private static final Log log = LogFactory.getLog(UserManagementUtils.class);
29:
30: public static void addUser(String userName, String password, String backendURL, String[] roleList,
31: String adminUsername, String adminPassword, String email)
32: throws RemoteException, UserAdminUserAdminException {
33:
34: String endPoint = backendURL + serviceName;
35: userAdminStub = new UserAdminStub(endPoint);
36: AuthenticateStub.authenticateStub(adminUsername, adminPassword, userAdminStub);
37: ClaimValue claimValue = new ClaimValue();
38: claimValue.setClaimURI("email");
39: claimValue.setValue(email);
40:
41: ClaimValue[] claims = {claimValue};
42:
43: userAdminStub.addUser(userName, password, roleList, claims, null);
44: }
45:
46: /**
47: * Self Sign-up a new user with minimal properties
48: *
49: * @throws IOException
50: * @throws APIManagerIntegrationTestException
51: */
52: public static void signupUser(String userName, String password, String firstName,
53: String organization) throws IOException, APIManagerIntegrationTestException {
54: CloseableHttpClient client = HTTPSClientUtils.getHttpsClient();
55: HttpPost postRequest = new HttpPost("https://localhost:9943/api/identity/user/v1.0/me");
56: postRequest.addHeader(APIMIntegrationConstants.AUTHORIZATION_HEADER,
57: "Basic " + encodeCredentials("admin", "admin".toCharArray()));
58: postRequest.addHeader("Content-Type", APPLICATION_JSON);
59:
60: StringEntity payload = new StringEntity(
61: "{\"user\":" +
62: "{\"username\": \"" + userName + "\"," +
63: " \"password\": \"" + password + "\"," +
64: "\"claims\": " +
65: "[{\"uri\": \"http://wso2.org/claims/givenname\",\"value\": \""+ firstName +"\" }," +
66: "{\"uri\": \"http://wso2.org/claims/organization\",\"value\": \""+ organization + "\"" +
67: "}]}, " +
68: "\"properties\": []}");
69: postRequest.setEntity(payload);
70: CloseableHttpResponse response = client.execute(postRequest);
71:
72:• if (!(response.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED)) {
73: log.error("Error occurred in self sing up a new user with user name " + userName);
74: throw new APIManagerIntegrationTestException("Error occurred in self sign-up a new user. Expected " +
75: "response code " + HttpStatus.SC_CREATED + ", but returned " + response.getStatusLine().getStatusCode());
76: }
77: }
78:
79:
80: /**
81: * Self Sign-up a new user with minimal properties
82: *
83: * @throws IOException
84: * @throws APIManagerIntegrationTestException
85: */
86: public static void signupUser(String userName, String password, String firstName,
87: String organization, String email) throws IOException, APIManagerIntegrationTestException {
88: CloseableHttpClient client = HTTPSClientUtils.getHttpsClient();
89: HttpPost postRequest = new HttpPost("https://localhost:9943/api/identity/user/v1.0/me");
90: postRequest.addHeader(APIMIntegrationConstants.AUTHORIZATION_HEADER,
91: "Basic " + encodeCredentials("admin", "admin".toCharArray()));
92: postRequest.addHeader("Content-Type", APPLICATION_JSON);
93:
94: StringEntity payload = new StringEntity(
95: "{\"user\":" +
96: "{\"username\": \"" + userName + "\"," +
97: " \"password\": \"" + password + "\"," +
98: "\"claims\": " +
99: "[{\"uri\": \"http://wso2.org/claims/givenname\",\"value\": \""+ firstName +"\" }," +
100: "{\"uri\": \"http://wso2.org/claims/emailaddress\",\"value\": \""+ email +"\" }," +
101: "{\"uri\": \"http://wso2.org/claims/organization\",\"value\": \""+ organization + "\"" +
102: "}]}, " +
103: "\"properties\": []}");
104: postRequest.setEntity(payload);
105: CloseableHttpResponse response = client.execute(postRequest);
106:
107:• if (!(response.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED)) {
108: log.error("Error occurred in self sing up a new user with user name " + userName);
109: throw new APIManagerIntegrationTestException("Error occurred in self sign-up a new user. Expected " +
110: "response code " + HttpStatus.SC_CREATED + ", but returned " + response.getStatusLine().getStatusCode());
111: }
112: }
113: }