Search in sources :

Example 91 with HttpResponse

use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.

the class MobileQSGTestCase method testUserRoleCreation.

@Test(description = "This test case tests whether user and roles are created as expected", dependsOnMethods = { "executeQSGScript" })
public void testUserRoleCreation() throws Exception {
    // Two users will be created with the quick start script, check whether those two users are created
    // successfully,
    String url = Constants.UserManagement.USER_ENDPOINT + "/" + username1;
    HttpResponse response = client.get(url);
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    url = Constants.UserManagement.USER_ENDPOINT + "/" + username2;
    response = client.get(url);
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    // A single role will be created with the quick start script, checking whether that role creation happens
    // without problem
    String rolename = "iotMobileUser";
    response = client.get(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/" + rolename);
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Example 92 with HttpResponse

use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.

the class UserManagement method testGetUsers.

@Test(description = "Test whether the API that is used to get the users returns all the user details.", dependsOnMethods = { "testUserCount" })
public void testGetUsers() throws Exception {
    int expectedCount = this.userMode == TestUserMode.TENANT_ADMIN ? 4 : 15;
    String url = Constants.UserManagement.USER_ENDPOINT + "/?offset=0&limit=100";
    HttpResponse response = client.get(url);
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    JsonObject jsonElement = new JsonParser().parse(response.getData()).getAsJsonObject();
    Assert.assertEquals("All the users list is not returned", expectedCount, jsonElement.get("users").getAsJsonArray().size());
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Test(org.testng.annotations.Test)

Example 93 with HttpResponse

use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.

the class UserManagement method testUserCount.

@Test(description = "Test whether correct user count is returned.", dependsOnMethods = { "testIsUserExist" })
public void testUserCount() throws Exception {
    int expectedCount = this.userMode == TestUserMode.TENANT_ADMIN ? 4 : 15;
    String url = Constants.UserManagement.USER_ENDPOINT + "/count";
    HttpResponse response = client.get(url);
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    JsonObject jsonElement = new JsonParser().parse(response.getData()).getAsJsonObject();
    Assert.assertEquals("Actual user count does not match with the returned user count", expectedCount, jsonElement.get("count").getAsInt());
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Test(org.testng.annotations.Test)

Example 94 with HttpResponse

use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.

the class UserManagement method testChangePassword.

@Test(description = "Test whether the API that is used to change the password works as expected.", dependsOnMethods = { "testRemoveUser" })
public void testChangePassword() throws Exception {
    String url = Constants.UserManagement.USER_ENDPOINT + "/credentials";
    HttpResponse response = client.put(url, PayloadGenerator.getJsonPayload(Constants.UserManagement.USER_PAYLOAD_FILE_NAME, Constants.UserManagement.RESET_PASSWORD_PAYLOAD).toString());
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    Assert.assertEquals("Password of the user cannot be changed", "\"UserImpl password by " + "username: admin was successfully changed.\"", response.getData());
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Example 95 with HttpResponse

use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.

the class UserManagement method testSearchUserNames.

@Test(description = "Test whether the API that is used to get the users with particular filter returns all the " + "user details that satisfy particular filter.", dependsOnMethods = { "testGetUsers" })
public void testSearchUserNames() throws Exception {
    String url = Constants.UserManagement.USER_ENDPOINT + "/search/usernames?filter=" + Constants.UserManagement.USER_NAME;
    HttpResponse response = client.get(url);
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    JsonArray jsonArray = new JsonParser().parse(response.getData()).getAsJsonArray();
    Assert.assertEquals("Relevant filtered user list in not returned correctly.", 1, jsonArray.size());
    url = Constants.UserManagement.USER_ENDPOINT + "/search/usernames?filter=" + NON_EXISTING_USERNAME;
    response = client.get(url);
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    jsonArray = new JsonParser().parse(response.getData()).getAsJsonArray();
    Assert.assertEquals("Relevant filtered user list in not returned correctly. Return a list of users for " + "non-existing username", 0, jsonArray.size());
}
Also used : JsonArray(com.google.gson.JsonArray) HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) JsonParser(com.google.gson.JsonParser) Test(org.testng.annotations.Test)

Aggregations

HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)75 Test (org.testng.annotations.Test)72 JsonObject (com.google.gson.JsonObject)15 HTTPResponse (org.wso2.mdm.qsg.dto.HTTPResponse)15 JsonParser (com.google.gson.JsonParser)14 JSONObject (org.json.simple.JSONObject)11 HashMap (java.util.HashMap)9 JsonArray (com.google.gson.JsonArray)8 IOException (java.io.IOException)8 HttpURLConnection (java.net.HttpURLConnection)8 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)7 KeyManagementException (java.security.KeyManagementException)6 KeyStoreException (java.security.KeyStoreException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 HttpResponse (org.apache.http.HttpResponse)6 ClientProtocolException (org.apache.http.client.ClientProtocolException)6 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)6 HttpPost (org.apache.http.client.methods.HttpPost)5 JSONArray (org.json.simple.JSONArray)5 JsonElement (com.google.gson.JsonElement)4