From 1a80b27cd5a06fd74734f1b4461dba1a7e325d54 Mon Sep 17 00:00:00 2001 From: megala21 Date: Tue, 18 Apr 2017 17:29:03 +0530 Subject: [PATCH 1/3] Improving android test cases --- .../iot/integration/common/Constants.java | 16 ++- .../integration/common/PayloadGenerator.java | 8 ++ .../device/enrollment/AndroidEnrollment.java | 74 +++++++++- .../device/mgt/AndroidDeviceManagement.java | 10 -- .../device/operation/AndroidOperation.java | 135 +++++++++++------- .../iot/integration/role/RoleManagement.java | 40 +++++- .../payloads/android-enrollment-payloads.json | 46 ++++++ .../payloads/android-operation-payloads.json | 2 +- .../resources/payloads/role-payloads.json | 10 +- pom.xml | 2 +- 10 files changed, 255 insertions(+), 88 deletions(-) diff --git a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java index 8eba5498..b0b2552c 100644 --- a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java +++ b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java @@ -58,7 +58,8 @@ public final class Constants { public static final String API_APP_REGISTRATION_ENDPOINT = "/api-application-registration/register"; public static final String TOKEN_ENDPOINT = "/token"; public static final String MULTI_TENANT_OAUTH_TOKEN_PAYLOAD = "&grant_type=password&scope=perm:android:enroll" - + " perm:android:wipe perm:android:ring perm:android:lock-devices perm:android:configure-vpn perm:android:configure-wifi perm:android:enroll perm:android:uninstall-application perm:android:manage-configuration perm:android:location perm:android:install-application perm:android:mute perm:android:change-lock-code perm:android:blacklist-applications perm:android:set-password-policy perm:android:encrypt-storage perm:android:clear-password perm:android:enterprise-wipe perm:android:info perm:android:view-configuration perm:android:upgrade-firmware perm:android:set-webclip perm:android:send-notification perm:android:disenroll perm:android:update-application perm:android:unlock-devices perm:android:control-camera perm:android:reboot perm:android:logcat appm:subscribe perm:sign-csr perm:admin:devices:view perm:roles:add perm:roles:add-users perm:roles:update perm:roles:permissions perm:roles:details perm:roles:view perm:roles:create-combined-role perm:roles:delete perm:dashboard:vulnerabilities perm:dashboard:non-compliant-count perm:dashboard:non-compliant perm:dashboard:by-groups perm:dashboard:device-counts perm:dashboard:feature-non-compliant perm:dashboard:count-overview perm:dashboard:filtered-count perm:dashboard:details perm:get-activity perm:devices:delete perm:devices:applications perm:devices:effective-policy perm:devices:compliance-data perm:devices:features perm:devices:operations perm:devices:search perm:devices:details perm:devices:update perm:devices:view perm:view-configuration perm:manage-configuration perm:policies:remove perm:policies:priorities perm:policies:deactivate perm:policies:get-policy-details perm:policies:manage perm:policies:activate perm:policies:update perm:policies:changes perm:policies:get-details perm:users:add perm:users:details perm:users:count perm:users:delete perm:users:roles perm:users:user-details perm:users:credentials perm:users:search perm:users:is-exist perm:users:update perm:users:send-invitation perm:admin-users:view perm:groups:devices perm:groups:update perm:groups:add perm:groups:device perm:groups:devices-count perm:groups:remove perm:groups:groups perm:groups:groups-view perm:groups:share perm:groups:count perm:groups:roles perm:groups:devices-remove perm:groups:devices-add perm:groups:assign perm:device-types:features perm:device-types:types perm:applications:install perm:applications:uninstall perm:admin-groups:count perm:admin-groups:view perm:notifications:mark-checked perm:notifications:view perm:admin:certificates:delete perm:admin:certificates:details perm:admin:certificates:view perm:admin:certificates:add perm:admin:certificates:verify perm:ios:enroll perm:ios:view-device perm:ios:apn perm:ios:ldap perm:ios:enterprise-app perm:ios:store-application perm:ios:remove-application perm:ios:app-list perm:ios:profile-list perm:ios:lock perm:ios:enterprise-wipe perm:ios:device-info perm:ios:restriction perm:ios:email perm:ios:cellular perm:ios:applications perm:ios:wifi perm:ios:ring perm:ios:location perm:ios:notification perm:ios:airplay perm:ios:caldav perm:ios:cal-subscription perm:ios:passcode-policy perm:ios:webclip perm:ios:vpn perm:ios:per-app-vpn perm:ios:app-to-per-app-vpn perm:ios:app-lock perm:ios:clear-passcode perm:ios:remove-profile perm:ios:get-restrictions perm:ios:wipe-data perm:admin"; + + " perm:android:wipe perm:android:ring perm:android:lock-devices perm:android:configure-vpn " + + "perm:android:configure-wifi perm:android:enroll perm:android:uninstall-application perm:android:manage-configuration perm:android:location perm:android:install-application perm:android:mute perm:android:change-lock-code perm:android:blacklist-applications perm:android:set-password-policy perm:android:encrypt-storage perm:android:clear-password perm:android:enterprise-wipe perm:android:info perm:android:view-configuration perm:android:upgrade-firmware perm:android:set-webclip perm:android:send-notification perm:android:disenroll perm:android:update-application perm:android:unlock-devices perm:android:control-camera perm:android:reboot perm:android:logcat appm:subscribe perm:sign-csr perm:admin:devices:view perm:roles:add perm:roles:add-users perm:roles:update perm:roles:permissions perm:roles:details perm:roles:view perm:roles:create-combined-role perm:roles:delete perm:dashboard:vulnerabilities perm:dashboard:non-compliant-count perm:dashboard:non-compliant perm:dashboard:by-groups perm:dashboard:device-counts perm:dashboard:feature-non-compliant perm:dashboard:count-overview perm:dashboard:filtered-count perm:dashboard:details perm:get-activity perm:devices:delete perm:devices:applications perm:devices:effective-policy perm:devices:compliance-data perm:devices:features perm:devices:operations perm:devices:search perm:devices:details perm:devices:update perm:devices:view perm:view-configuration perm:manage-configuration perm:policies:remove perm:policies:priorities perm:policies:deactivate perm:policies:get-policy-details perm:policies:manage perm:policies:activate perm:policies:update perm:policies:changes perm:policies:get-details perm:users:add perm:users:details perm:users:count perm:users:delete perm:users:roles perm:users:user-details perm:users:credentials perm:users:search perm:users:is-exist perm:users:update perm:users:send-invitation perm:admin-users:view perm:groups:devices perm:groups:update perm:groups:add perm:groups:device perm:groups:devices-count perm:groups:remove perm:groups:groups perm:groups:groups-view perm:groups:share perm:groups:count perm:groups:roles perm:groups:devices-remove perm:groups:devices-add perm:groups:assign perm:device-types:features perm:device-types:types perm:applications:install perm:applications:uninstall perm:admin-groups:count perm:admin-groups:view perm:notifications:mark-checked perm:notifications:view perm:admin:certificates:delete perm:admin:certificates:details perm:admin:certificates:view perm:admin:certificates:add perm:admin:certificates:verify perm:ios:enroll perm:ios:view-device perm:ios:apn perm:ios:ldap perm:ios:enterprise-app perm:ios:store-application perm:ios:remove-application perm:ios:app-list perm:ios:profile-list perm:ios:lock perm:ios:enterprise-wipe perm:ios:device-info perm:ios:restriction perm:ios:email perm:ios:cellular perm:ios:applications perm:ios:wifi perm:ios:ring perm:ios:location perm:ios:notification perm:ios:airplay perm:ios:caldav perm:ios:cal-subscription perm:ios:passcode-policy perm:ios:webclip perm:ios:vpn perm:ios:per-app-vpn perm:ios:app-to-per-app-vpn perm:ios:app-lock perm:ios:clear-passcode perm:ios:remove-profile perm:ios:get-restrictions perm:ios:wipe-data perm:admin perm:android:applications"; public static final String OAUTH_TOKEN_PAYLOAD = "username=admin&password=admin" + MULTI_TENANT_OAUTH_TOKEN_PAYLOAD; @@ -104,7 +105,9 @@ public final class Constants { public static final String ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME = "android-enrollment-response-payloads.json"; public static final String ENROLLMENT_ENDPOINT = "/api/device-mgt/android/v1.0/devices"; public static final String ENROLLMENT_GROUP = "android-enrollment"; - + public static final String UPDATE_APPLICATION_METHOD = "UPDATE_APPLICATIONS"; + public static final String ANDROID_DEVICE_TYPE = "android"; + public static final String GET_PENDING_OPERATIONS_METHOD = "GET_PENDING_OPERATIONS"; private AndroidEnrollment() { throw new AssertionError(); } @@ -145,7 +148,7 @@ public final class Constants { } public static final class AndroidOperations { - private static final String PAYLOAD_COMMON = "[" + DEVICE_ID + "]"; + public static final String PAYLOAD_COMMON = "[" + DEVICE_ID + "]"; public static final String OPERATION_PAYLOAD_FILE_NAME = "android-operation-payloads.json"; public static final String OPERATIONS_GROUP = "operations"; @@ -179,9 +182,11 @@ public final class Constants { public static final String CLEAR_PASSWORD_ENDPOINT = "clear-password"; public static final String CLEAR_PASSWORD_PAYLOAD = PAYLOAD_COMMON; - public static final String DEVICE_INFO_ENDPOINT = "/info"; + public static final String DEVICE_INFO_ENDPOINT = "info"; public static final String DEVICE_INFO_PAYLOAD = "[\"" + DEVICE_ID + "\"]"; + public static final String DEVICE_LOGCAT_ENDPOINT = "logcat"; + public static final String ENTERPRISE_WIPE_ENDPOINT = "enterprise-wipe"; public static final String ENTERPRISE_WIPE_PAYLOAD = PAYLOAD_COMMON; @@ -254,7 +259,7 @@ public final class Constants { public static final String DEVICE_MANAGEMENT_GROUP = "device-mgt"; public static final String KEY_DEVICE_ID = "deviceIdentifier"; public static final String KEY_DEVICE_NAME = "name"; - public static final String DEVICE_MGT_ENDPOINT = "/mdm-android-agent/device/"; + public static final String DEVICE_MGT_ENDPOINT = "/api/device-mgt/android/v1.0/devices"; public static final String LICENSE_SECTION = "This"; public static final String LICENSE_ENDPOINT = DEVICE_MGT_ENDPOINT + "license"; public static final String APP_LIST_ENDPOINT = DEVICE_MGT_ENDPOINT + "appList/" + @@ -330,6 +335,7 @@ public final class Constants { public static final String ROLE_PAYLOAD_FILE_NAME = "role-payloads.json"; public static final String ROLE_RESPONSE_PAYLOAD_FILE_NAME = "role-response-payloads.json"; public static final String GET_FILTERED_ROLED_METHOD = "GET_FILTERED_ROLES"; + public static final String UPDATE_ROLES_METHOD = "UPDATE_USERS"; private RoleManagement() { throw new AssertionError(); } diff --git a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/PayloadGenerator.java b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/PayloadGenerator.java index c7c82e59..b1d3e3cf 100644 --- a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/PayloadGenerator.java +++ b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/PayloadGenerator.java @@ -18,6 +18,7 @@ package org.wso2.iot.integration.common; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import org.apache.commons.io.IOUtils; @@ -46,4 +47,11 @@ public class PayloadGenerator { String returnString = IOUtils.toString(fisTargetFile, Constants.UTF8); return returnString; } + + public static JsonArray getJsonArray(String fileName, String method) + throws FileNotFoundException { + URL url = PayloadGenerator.class.getClassLoader().getResource(PAYLOAD_LOCATION + fileName); + JsonObject jsonObject = parser.parse(new FileReader(url.getPath())).getAsJsonObject(); + return jsonObject.get(method).getAsJsonArray(); + } } \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java index 4687ad44..03fb3733 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java @@ -17,16 +17,26 @@ */ package org.wso2.iot.integration.device.enrollment; +import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import junit.framework.Assert; import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.net.util.Base64; import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Factory; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.engine.context.beans.User; import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; -import org.wso2.iot.integration.common.*; +import org.wso2.iot.integration.common.AssertUtil; +import org.wso2.iot.integration.common.Constants; +import org.wso2.iot.integration.common.OAuthUtil; +import org.wso2.iot.integration.common.PayloadGenerator; +import org.wso2.iot.integration.common.RestClient; +import org.wso2.iot.integration.common.TestBase; /** * This contains testing of Android device enrollment which is necessary to run prior to all other Android related @@ -35,12 +45,23 @@ import org.wso2.iot.integration.common.*; public class AndroidEnrollment extends TestBase { private RestClient client; private String deviceId; + private TestUserMode userMode; - @BeforeClass(alwaysRun = true, groups = { Constants.AndroidEnrollment.ENROLLMENT_GROUP}, dependsOnGroups = - Constants.MobileDeviceManagement.MOBILE_DEVICE_MANAGEMENT_GROUP) + @Factory(dataProvider = "userModeProvider") + public AndroidEnrollment(TestUserMode userMode) { + this.userMode = userMode; + } + + @BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP}) public void initTest() throws Exception { - super.init(TestUserMode.SUPER_TENANT_ADMIN); - String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL); + super.init(userMode); + User currentUser = getAutomationContext().getContextTenant().getContextUser(); + byte[] bytesEncoded = Base64 + .encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes()); + String encoded = new String(bytesEncoded); + String accessTokenString = "Bearer " + OAuthUtil + .getOAuthTokenPair(encoded, backendHTTPSURL, backendHTTPSURL, currentUser.getUserName(), + currentUser.getPassword()); this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); } @@ -81,7 +102,40 @@ public class AndroidEnrollment extends TestBase { Constants.HTTP_METHOD_PUT).toString(), response.getData(), true); } - @Test(description = "Test disEnrollment.", dependsOnMethods = {"testModifyEnrollment"}) + @Test(description = "Test update applications", dependsOnMethods = {"testModifyEnrollment"}) + public void testUpdateApplications() throws Exception { + JsonArray updateApplicationData = PayloadGenerator.getJsonArray( + Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, + Constants.AndroidEnrollment.UPDATE_APPLICATION_METHOD); + HttpResponse response = client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId + + "/applications", updateApplicationData.toString()); + Assert.assertEquals("Update of applications for the device id " + deviceId + " failed", HttpStatus + .SC_ACCEPTED, response.getResponseCode()); + response = client.get(Constants.MobileDeviceManagement.CHANGE_DEVICE_STATUS_ENDPOINT + Constants + .AndroidEnrollment.ANDROID_DEVICE_TYPE + "/" + deviceId + "/applications"); + Assert.assertEquals("Error while getting application list for the device with the id " + deviceId + " failed", + HttpStatus.SC_OK, response.getResponseCode()); + JsonArray jsonArray = new JsonParser().parse(response.getData()).getAsJsonArray(); + Assert.assertEquals("Installed applications for the device with the device id " + deviceId + " has not been " + + "updated yet", 3, jsonArray.size()); + + } + + @Test(description = "Test get pending operations", dependsOnMethods = {"testModifyEnrollment"}) + public void testGetPendingOperations() throws Exception { + JsonArray pendingOperationsData = PayloadGenerator.getJsonArray( + Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, + Constants.AndroidEnrollment.GET_PENDING_OPERATIONS_METHOD); + HttpResponse response = client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId + + "/pending-operations", pendingOperationsData.toString()); + JsonArray pendingOperations = new JsonParser().parse(response.getData()).getAsJsonArray(); + Assert.assertEquals("Error while getting pending operations for android device with the id " + deviceId, + HttpStatus.SC_CREATED, response.getResponseCode()); + Assert.assertTrue("Pending operation count is 0. Periodic monitoring tasks are not running.", 0 < + pendingOperations.size()); + + } + @Test(description = "Test disEnrollment.", dependsOnMethods = {"testGetPendingOperations"}) public void testDisEnrollDevice() throws Exception { HttpResponse response = client.delete(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); @@ -89,4 +143,12 @@ public class AndroidEnrollment extends TestBase { Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_DELETE).toString(), response.getData(), true); } + + @DataProvider + private static Object[][] userModeProvider() { + return new TestUserMode[][]{ + new TestUserMode[]{TestUserMode.SUPER_TENANT_ADMIN}, + new TestUserMode[]{TestUserMode.TENANT_ADMIN} + }; + } } diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/mgt/AndroidDeviceManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/mgt/AndroidDeviceManagement.java index 5b20f691..7aae9173 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/mgt/AndroidDeviceManagement.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/mgt/AndroidDeviceManagement.java @@ -81,15 +81,5 @@ public class AndroidDeviceManagement extends TestBase { Assert.assertTrue(response.getData().contains(sequence)); } - /* - @Test(description = "Test update android device applist.", groups = Constants.DeviceManagement.DEVICE_MANAGEMENT_GROUP, - dependsOnMethods = {"testGetDevice"} ) - public void testUpdateAppList() throws Exception { - HttpResponse response = client.post(Constants.DeviceManagement.APP_LIST_ENDPOINT, - Constants.DeviceManagement.APPLIST_PAYLOAD); - Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); - AssertUtil.jsonPayloadCompare(Constants.DeviceManagement.REQUEST_MODIFY_DEVICE_EXPECTED, - response.getData().toString(), true); - }*/ } diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java index 43e4fa12..f01bc303 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java @@ -20,22 +20,45 @@ package org.wso2.iot.integration.device.operation; import com.google.gson.JsonObject; import junit.framework.Assert; import org.apache.commons.httpclient.HttpStatus; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; +import org.apache.commons.net.util.Base64; +import org.testng.annotations.*; import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.engine.context.beans.User; +import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException; import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; -import org.wso2.iot.integration.common.*; +import org.wso2.iot.integration.common.Constants; +import org.wso2.iot.integration.common.OAuthUtil; +import org.wso2.iot.integration.common.PayloadGenerator; +import org.wso2.iot.integration.common.RestClient; +import org.wso2.iot.integration.common.TestBase; + +import java.io.File; +import java.io.FileNotFoundException; +import java.net.MalformedURLException; +import java.net.URL; /** * This contain tests to check operations supported by Android. Test are executed against a previously enrolled device */ public class AndroidOperation extends TestBase { private RestClient client; + private TestUserMode userMode; + + @Factory(dataProvider = "userModeProvider") + public AndroidOperation(TestUserMode userMode) { + this.userMode = userMode; + } - @BeforeTest(alwaysRun = true, groups = { Constants.AndroidOperations.OPERATIONS_GROUP}) + @BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP}) public void initTest() throws Exception { - super.init(TestUserMode.SUPER_TENANT_ADMIN); - String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL); + super.init(userMode); + User currentUser = getAutomationContext().getContextTenant().getContextUser(); + byte[] bytesEncoded = Base64 + .encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes()); + String encoded = new String(bytesEncoded); + String accessTokenString = "Bearer " + OAuthUtil + .getOAuthTokenPair(encoded, backendHTTPSURL, backendHTTPSURL, currentUser.getUserName(), + currentUser.getPassword()); this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); //Enroll a device JsonObject enrollmentData = PayloadGenerator.getJsonPayload( @@ -45,20 +68,21 @@ public class AndroidOperation extends TestBase { } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device lock operation.") - public void testLock() throws Exception { + public void testLock() throws MalformedURLException, AutomationFrameworkException { HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.LOCK_ENDPOINT, Constants.AndroidOperations.LOCK_OPERATION_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } -/* - @Test(groups = Constants.AndroidOperations.OPERATIONS_GROUP, description = "Test Android getPendingOperations.") - public void testGetPendingOperations() throws Exception { - HttpResponse response = client.put(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.DEVICE_ID, - "[]"); - Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_CREATED); - }*/ + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device un-lock " + + "operation.") + public void testUnLock() throws MalformedURLException, AutomationFrameworkException { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.UNLOCK_ENDPOINT, Constants.AndroidOperations.UNLOCK_OPERATION_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device location " + "operation.") @@ -87,16 +111,20 @@ public class AndroidOperation extends TestBase { Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } -// //404 -// @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device information " -// + "operation.") -// public void testDeviceInfo() throws Exception { -// -// HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + -// Constants.AndroidOperations.DEVICE_INFO_ENDPOINT, -// Constants.AndroidOperations.DEVICE_INFO_PAYLOAD); -// Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); -// } + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android get info operation") + public void testGetInfo() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.DEVICE_INFO_ENDPOINT, Constants.AndroidOperations.DEVICE_INFO_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android logcat operation") + public void testLogcat() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.DEVICE_LOGCAT_ENDPOINT, Constants.AndroidOperations.PAYLOAD_COMMON); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android enterprise-wipe " + "operation.") @@ -115,15 +143,29 @@ public class AndroidOperation extends TestBase { Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } -// //400 -// @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android application list " -// + "operation.") -// public void testApplicationList() throws Exception { -// HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + -// Constants.AndroidOperations.APPLICATION_LIST_ENDPOINT, -// Constants.AndroidOperations.APPLICATION_LIST_PAYLOAD); -// Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); -// } + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android get applications " + + "operation.") + public void testGetApplications() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.APPLICATION_LIST_ENDPOINT, Constants.AndroidOperations.PAYLOAD_COMMON); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android app install operation") + public void testInstallApplication() throws Exception { + JsonObject installApplicationPayload = PayloadGenerator.getJsonPayload(Constants.AndroidOperations + .OPERATION_PAYLOAD_FILE_NAME, Constants.AndroidOperations.INSTALL_APPS_OPERATION); + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.INSTALL_APPS_ENDPOINT, installApplicationPayload.toString()); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android reboot operation") + public void testReboot() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.REBOOT_ENDPOINT, Constants.AndroidOperations.PAYLOAD_COMMON); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android ring operation.") public void testRing() throws Exception { @@ -141,25 +183,6 @@ public class AndroidOperation extends TestBase { Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } -// //400 -// @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android install apps operation.") -// public void testInstallApps() throws Exception { -// HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + -// Constants.AndroidOperations.INSTALL_APPS_ENDPOINT, -// Constants.AndroidOperations.INSTALL_APPS_PAYLOAD); -// Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); -// } - -// //400 -// @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android uninstall apps " -// + "operation.") -// public void testUninstallApps() throws Exception { -// HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + -// Constants.AndroidOperations.UNINSTALL_APPS_ENDPOINT, -// Constants.AndroidOperations.UNINSTALL_APPS_PAYLOAD); -// Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); -// } - @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android notification operation.") public void testNotification() throws Exception { HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + @@ -207,4 +230,12 @@ public class AndroidOperation extends TestBase { Constants.AndroidOperations.WEB_CLIP_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } + + @DataProvider + private static Object[][] userModeProvider() { + return new TestUserMode[][]{ + new TestUserMode[]{TestUserMode.SUPER_TENANT_ADMIN}, + new TestUserMode[]{TestUserMode.TENANT_ADMIN} + }; + } } \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java index 9e6c8deb..0b6e9feb 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java @@ -17,6 +17,8 @@ */ package org.wso2.iot.integration.role; +import com.google.gson.JsonArray; +import com.google.gson.JsonParser; import junit.framework.Assert; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.net.util.Base64; @@ -26,7 +28,13 @@ import org.testng.annotations.Factory; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.carbon.automation.engine.context.beans.User; -import org.wso2.iot.integration.common.*; +import org.wso2.iot.integration.common.AssertUtil; +import org.wso2.iot.integration.common.Constants; +import org.wso2.iot.integration.common.IOTHttpClient; +import org.wso2.iot.integration.common.IOTResponse; +import org.wso2.iot.integration.common.OAuthUtil; +import org.wso2.iot.integration.common.PayloadGenerator; +import org.wso2.iot.integration.common.TestBase; import javax.xml.xpath.XPathExpressionException; import java.io.FileNotFoundException; @@ -37,6 +45,7 @@ import java.io.FileNotFoundException; public class RoleManagement extends TestBase { private IOTHttpClient client; private TestUserMode userMode; + private static final String ROLE_NAME = "administration"; @Factory(dataProvider = "userModeProvider") public RoleManagement(TestUserMode userMode) { @@ -66,7 +75,7 @@ public class RoleManagement extends TestBase { @Test(description = "Test update permission role.", dependsOnMethods = {"testAddRole"}) public void testUpdateRolePermission() throws FileNotFoundException { - IOTResponse response = client.put(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/administration", + IOTResponse response = client.put(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/" + ROLE_NAME, PayloadGenerator.getJsonPayload(Constants.RoleManagement.ROLE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_PUT).toString()); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); @@ -94,20 +103,39 @@ public class RoleManagement extends TestBase { @Test(description = "Test getting permissions of a role.", dependsOnMethods = {"testGetFilteredRoles"}) public void testGetRolePermissions() throws FileNotFoundException { IOTResponse response = client - .get(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/administration/permissions"); + .get(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/" + ROLE_NAME + "/permissions"); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); } @Test(description = "Test getting role details.", dependsOnMethods = {"testGetRolePermissions"}) public void testGetRole() throws FileNotFoundException { IOTResponse response = client.get(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + - "/administration"); + "/" + ROLE_NAME); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); } - @Test(description = "Test remove user.", dependsOnMethods = {"testGetRole"}) + @Test(description = "Test updating users with a given role.", dependsOnMethods = {"testGetRole"}) + public void testUpdateRolesOfUser() throws FileNotFoundException, XPathExpressionException { + IOTResponse response = client + .put(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/administration/users", PayloadGenerator.getJsonArray( + Constants.RoleManagement.ROLE_PAYLOAD_FILE_NAME, + Constants.RoleManagement.UPDATE_ROLES_METHOD).toString()); + + Assert.assertEquals("Error while updating the user list for the role administration", HttpStatus.SC_OK, + response.getStatus()); + String url = Constants.UserManagement.USER_ENDPOINT + "/" + automationContext.getContextTenant() + .getContextUser().getUserNameWithoutDomain() + "/roles"; + response = client.get(url); + + JsonArray jsonArray = new JsonParser().parse(response.getBody()).getAsJsonObject().get("roles").getAsJsonArray(); + Assert.assertEquals("Error while retrieving the role details", HttpStatus.SC_OK, response.getStatus()); + Assert.assertEquals("The user is not updated with the roles list", "\"" + ROLE_NAME + "\"", + jsonArray.get(0).toString()); + } + + @Test(description = "Test remove user.", dependsOnMethods = {"testUpdateRolesOfUser"}) public void testRemoveRole() throws Exception { - IOTResponse response = client.delete(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT +"/administration"); + IOTResponse response = client.delete(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT +"/" + ROLE_NAME); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); } diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-enrollment-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/android-enrollment-payloads.json index ca0c8a6b..9b73a322 100644 --- a/modules/integration/tests-integration/src/test/resources/payloads/android-enrollment-payloads.json +++ b/modules/integration/tests-integration/src/test/resources/payloads/android-enrollment-payloads.json @@ -182,5 +182,51 @@ "memoryUsage": 0 } ] + }, +"UPDATE_APPLICATIONS": [ + { + "id": 1, + "platform": "string", + "category": "string", + "name": "string", + "locationUrl": "string", + "imageUrl": "string", + "version": "string", + "type": "string", + "appProperties": { + }, + "applicationIdentifier": "string", + "memoryUsage": 0 + }, + { + "id": 2, + "platform": "string", + "category": "string", + "name": "string", + "locationUrl": "string", + "imageUrl": "string", + "version": "string", + "type": "string", + "appProperties": { + }, + "applicationIdentifier": "string", + "memoryUsage": 0 + }, + { + "id": 3, + "platform": "string", + "category": "string", + "name": "string", + "locationUrl": "string", + "imageUrl": "string", + "version": "string", + "type": "string", + "appProperties": { + }, + "applicationIdentifier": "string", + "memoryUsage": 0 } +], + "GET_PENDING_OPERATIONS" : [] } + diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-operation-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/android-operation-payloads.json index b6bd861c..dc1b8f9e 100644 --- a/modules/integration/tests-integration/src/test/resources/payloads/android-operation-payloads.json +++ b/modules/integration/tests-integration/src/test/resources/payloads/android-operation-payloads.json @@ -14,7 +14,7 @@ "install_apps": { "operation": { "appIdentifier": "package_name", - "type": "enterprise/public/webapp", + "type": "enterprise", "url": "https://www.youtube.com", "name": "youtube" }, diff --git a/modules/integration/tests-integration/src/test/resources/payloads/role-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/role-payloads.json index 3ca61531..e6dc97c3 100644 --- a/modules/integration/tests-integration/src/test/resources/payloads/role-payloads.json +++ b/modules/integration/tests-integration/src/test/resources/payloads/role-payloads.json @@ -1,17 +1,13 @@ { "POST": { "roleName": "administration", - "users": [ - "admin" - ] + "users": [] }, "PUT": { "roleName": "administration", - "users": [ - "admin" - ], "permissions": [ "/permission/admin/device-mgt/admin/groups" ] - } + }, + "UPDATE_USERS": ["admin", "testuser11"] } \ No newline at end of file diff --git a/pom.xml b/pom.xml index ba9c41ec..01441639 100644 --- a/pom.xml +++ b/pom.xml @@ -1596,7 +1596,7 @@ 1.0.400.v20120522-2049 2.40.0 0.8.1 - 4.4.1 + 4.4.2 3.3.0 0.7.4.201502262128 1.1.1 From 23c385a7be54bfb71ef48dcf88d32cb026942d84 Mon Sep 17 00:00:00 2001 From: megala21 Date: Wed, 19 Apr 2017 14:31:17 +0530 Subject: [PATCH 2/3] Improving android test cases --- .../iot/integration/common/Constants.java | 66 +++++++------- .../wso2/iot/integration/common/TestBase.java | 20 +++++ .../AndroidConfigurationManagement.java | 74 ++++++++-------- .../device/enrollment/AndroidEnrollment.java | 19 ----- .../device/mgt/AndroidDeviceManagement.java | 85 ------------------- .../device/operation/AndroidOperation.java | 85 +++++++++++++------ .../MobileDeviceManagementWithNoDevices.java | 27 ++++-- .../iot/integration/role/RoleManagement.java | 22 +---- .../iot/integration/user/UserManagement.java | 20 ----- .../android-config-response-payloads.json | 1 + .../payloads/android-operation-payloads.json | 31 ++++++- .../src/test/resources/testng.xml | 23 ++--- 12 files changed, 212 insertions(+), 261 deletions(-) delete mode 100644 modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/mgt/AndroidDeviceManagement.java diff --git a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java index b0b2552c..7a7442c2 100644 --- a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java +++ b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java @@ -68,32 +68,32 @@ public final class Constants { + " \"applicationName\":\"app_123456\",\n" + " \"isAllowedToAllDomains\":false,\n" + " \"tags\":[\"android\", \"device_management\"],\n" + " \"isMappingAnExistingOAuthApp\":false\n" + "}").toString(); - public static final String PERMISSION_LIST = "default perm:admin-groups:count perm:admin-groups:view " + - "perm:admin-users:view perm:admin:certificates:add perm:admin:certificates:delete " + - "perm:admin:certificates:details perm:admin:certificates:verify perm:admin:certificates:view " + - "perm:admin:devices:view perm:android:blacklist-applications perm:android:change-lock-code " + - "perm:android:clear-password perm:android:configure-vpn perm:android:configure-wifi " + - "perm:android:control-camera perm:android:disenroll perm:android:encrypt-storage " + - "perm:android:enroll perm:android:enterprise-wipe perm:android:info perm:android:install-application " + - "perm:android:location perm:android:lock-devices perm:android:logcat perm:android:manage-configuration " + - "perm:android:mute perm:android:reboot perm:android:ring perm:android:send-notification " + - "perm:android:set-password-policy perm:android:set-webclip perm:android:uninstall-application " + - "perm:android:unlock-devices perm:android:update-application perm:android:upgrade-firmware " + - "perm:android:view-configuration perm:android:wipe perm:applications:install perm:applications:uninstall " + - "perm:device-types:features perm:device-types:types perm:devices:applications " + - "perm:devices:compliance-data perm:devices:delete perm:devices:details perm:devices:effective-policy " + - "perm:devices:features perm:devices:operations perm:devices:search perm:devices:update " + - "perm:devices:view perm:get-activity perm:groups:add perm:groups:assign perm:groups:count " + - "perm:groups:device perm:groups:devices perm:groups:devices-add perm:groups:devices-count " + - "perm:groups:devices-remove perm:groups:groups perm:groups:groups-view perm:groups:remove " + - "perm:groups:roles perm:groups:share perm:groups:update perm:manage-configuration " + - "perm:notifications:mark-checked perm:notifications:view perm:policies:activate " + - "perm:policies:changes perm:policies:deactivate perm:policies:get-details perm:policies:get-policy-details " + - "perm:policies:manage perm:policies:priorities perm:policies:remove perm:policies:update perm:roles:add" + - " perm:roles:add-users perm:roles:create-combined-role perm:roles:delete perm:roles:details " + - "perm:roles:permissions perm:roles:update perm:roles:view perm:users:add perm:users:count " + - "perm:users:credentials perm:users:delete perm:users:details perm:users:is-exist perm:users:roles " + - "perm:users:search perm:users:send-invitation perm:users:update perm:users:user-details perm:view-configuration"; + public static final String PERMISSION_LIST = "default perm:admin-groups:count perm:admin-groups:view " + + "perm:admin-users:view perm:admin:certificates:add perm:admin:certificates:delete " + + "perm:admin:certificates:details perm:admin:certificates:verify perm:admin:certificates:view " + + "perm:admin:devices:view perm:android:applications perm:android:blacklist-applications " + + "perm:android:change-lock-code perm:android:clear-password perm:android:configure-vpn perm:android:configure-wifi " + + "perm:android:control-camera perm:android:disenroll perm:android:encrypt-storage " + + "perm:android:enroll perm:android:enterprise-wipe perm:android:info perm:android:install-application " + + "perm:android:location perm:android:lock-devices perm:android:logcat perm:android:manage-configuration " + + "perm:android:mute perm:android:reboot perm:android:ring perm:android:send-notification " + + "perm:android:set-password-policy perm:android:set-webclip perm:android:uninstall-application " + + "perm:android:unlock-devices perm:android:update-application perm:android:upgrade-firmware " + + "perm:android:view-configuration perm:android:wipe perm:applications:install perm:applications:uninstall " + + "perm:device-types:features perm:device-types:types perm:devices:applications " + + "perm:devices:compliance-data perm:devices:delete perm:devices:details perm:devices:effective-policy " + + "perm:devices:features perm:devices:operations perm:devices:search perm:devices:update " + + "perm:devices:view perm:get-activity perm:groups:add perm:groups:assign perm:groups:count " + + "perm:groups:device perm:groups:devices perm:groups:devices-add perm:groups:devices-count " + + "perm:groups:devices-remove perm:groups:groups perm:groups:groups-view perm:groups:remove " + + "perm:groups:roles perm:groups:share perm:groups:update perm:manage-configuration " + + "perm:notifications:mark-checked perm:notifications:view perm:policies:activate " + + "perm:policies:changes perm:policies:deactivate perm:policies:get-details perm:policies:get-policy-details " + + "perm:policies:manage perm:policies:priorities perm:policies:remove perm:policies:update perm:roles:add" + + " perm:roles:add-users perm:roles:create-combined-role perm:roles:delete perm:roles:details " + + "perm:roles:permissions perm:roles:update perm:roles:view perm:users:add perm:users:count " + + "perm:users:credentials perm:users:delete perm:users:details perm:users:is-exist perm:users:roles " + + "perm:users:search perm:users:send-invitation perm:users:update perm:users:user-details perm:view-configuration"; private APIApplicationRegistration() { throw new AssertionError(); @@ -204,6 +204,7 @@ public final class Constants { public static final String MUTE_PAYLOAD = PAYLOAD_COMMON; public static final String INSTALL_APPS_ENDPOINT = "install-application"; + public static final String UPDATE_APPS_ENDPOINT = "update-application"; public static final String INSTALL_APPS_PAYLOAD = "{\n" + " \"deviceIDs\": [\n" + " \"" + DEVICE_ID + "\"\n" + " ],\n" + " \"operation\": {\n" + " \"appIdentifier\": \"string\",\n" + " \"type\": \"string\",\n" + " \"url\": \"string\"\n" + " }\n" + "}"; @@ -211,10 +212,16 @@ public final class Constants { public static final String UNINSTALL_APPS_ENDPOINT = "uninstall-application"; public static final String UNINSTALL_APPS_PAYLOAD = "{\n" + " \"deviceIDs\": [\n" + " \"" + DEVICE_ID + "\"\n" + " ],\n" + " \"operation\": {\n" - + " \"appIdentifier\": \"string\",\n" + " \"type\": \"string\",\n" + " \"url\": \"string\",\n" - + " \"name\": \"string\"\n" + " }\n" + "}"; + + " \"appIdentifier\": \"string\",\n" + " \"type\": \"enterprise\"} }"; public static final String BLACKLIST_APPS_ENDPOINT = "blacklist-applications"; + public static final String BLACKLIST_OPERATION = "black_list_application"; + + public static final String UPGRADE_FIRMWARE_ENDPOINT = "upgrade-firmware"; + public static final String UPGRADE_FIRMWARE_OPERATION = "upgrade-firmware"; + + public static final String VPN_ENDPOINT = "configure-vpn"; + public static final String VPN_OPERATION = "vpn"; public static final String NOTIFICATION_ENDPOINT = "send-notification"; public static final String NOTIFICATION_PAYLOAD = "{\n" + " \"deviceIDs\": [\n" + " \"" + DEVICE_ID + "\"\n" @@ -278,7 +285,8 @@ public final class Constants { public static final class AndroidConfigurationManagement { public static final String DEVICE_CONFIGURATION_GROUP = "android-config-mgt"; - public static final String CONFIG_MGT_ENDPOINT = "/mdm-android-agent/configuration/"; + public static final String CONFIG_MGT_ENDPOINT = "/api/device-mgt/android/v1.0/configuration/"; + public static final String LICENSE_ENDPOINT = "license"; public static final String PAYLOAD_FILE_NAME = "android-configuration-payloads.json"; public static final String RESPONSE_PAYLOAD_FILE_NAME = "android-config-response-payloads.json"; diff --git a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/TestBase.java b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/TestBase.java index e092cbb9..8915356a 100644 --- a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/TestBase.java +++ b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/TestBase.java @@ -17,8 +17,11 @@ */ package org.wso2.iot.integration.common; +import org.apache.commons.net.util.Base64; +import org.testng.annotations.DataProvider; import org.wso2.carbon.automation.engine.context.AutomationContext; import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.engine.context.beans.User; import org.wso2.carbon.automation.engine.frameworkutils.FrameworkPathUtil; import org.wso2.carbon.integration.common.utils.LoginLogoutClient; @@ -31,6 +34,8 @@ public class TestBase { protected AutomationContext automationContext; protected String backendHTTPSURL; protected String backendHTTPURL; + protected String accessTokenString; + protected TestUserMode userMode; protected void init(TestUserMode userMode) throws Exception { automationContext = new AutomationContext(Constants.AUTOMATION_CONTEXT, userMode); @@ -39,6 +44,13 @@ public class TestBase { .HTTPS_GATEWAY_PORT)).replace("/t/" + tenantDomain , ""); backendHTTPURL = automationContext.getContextUrls().getWebAppURL().replace("9763", String.valueOf(Constants .HTTP_GATEWAY_PORT)).replace("/t/" + tenantDomain , ""); + User currentUser = getAutomationContext().getContextTenant().getContextUser(); + byte[] bytesEncoded = Base64 + .encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes()); + String encoded = new String(bytesEncoded); + accessTokenString = "Bearer " + OAuthUtil + .getOAuthTokenPair(encoded, backendHTTPSURL, backendHTTPSURL, currentUser.getUserName(), + currentUser.getPassword()); } protected void initPublisher(String productGroupName, String instanceName, @@ -76,4 +88,12 @@ public class TestBase { protected String getTestArtifactLocation() { return FrameworkPathUtil.getSystemResourceLocation(); } + + @DataProvider + public static Object[][] userModeProvider() { + return new TestUserMode[][]{ + new TestUserMode[]{TestUserMode.SUPER_TENANT_ADMIN}, + new TestUserMode[]{TestUserMode.TENANT_ADMIN} + }; + } } diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/configuration/AndroidConfigurationManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/configuration/AndroidConfigurationManagement.java index 11d8ca8a..e9758754 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/configuration/AndroidConfigurationManagement.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/configuration/AndroidConfigurationManagement.java @@ -20,9 +20,13 @@ package org.wso2.iot.integration.device.configuration; import junit.framework.Assert; import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.net.util.Base64; import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Factory; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.engine.context.beans.User; import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; import org.wso2.iot.integration.common.*; @@ -30,55 +34,45 @@ import org.wso2.iot.integration.common.*; * This class contains integration tests for Android configuration management backend services. */ public class AndroidConfigurationManagement extends TestBase { - private RestClient client; - @BeforeClass(alwaysRun = true, groups = { Constants.AndroidConfigurationManagement.DEVICE_CONFIGURATION_GROUP}) - public void initTest() throws Exception { - super.init(TestUserMode.SUPER_TENANT_ADMIN); - String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL); - this.client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON, accessTokenString); + @Factory(dataProvider = "userModeProvider") + public AndroidConfigurationManagement(TestUserMode testUserMode) { + this.userMode = testUserMode; } - @Test(description = "Test add android platform configuration.") - public void testAddConfiguration() throws Exception { - HttpResponse response = client.post(Constants.AndroidConfigurationManagement.CONFIG_MGT_ENDPOINT, - PayloadGenerator.getJsonPayload( - Constants.AndroidConfigurationManagement.PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_POST).toString() - ); - Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); - AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( - Constants.AndroidConfigurationManagement.RESPONSE_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_POST).toString(), - response.getData().toString(), true - ); + @BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP}) + public void initTest() throws Exception { + super.init(userMode); + this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); } - @Test(description = "Test update android configuration.", dependsOnMethods = {"testAddConfiguration"}) + @Test(description = "Test update android configuration.") public void testModifyConfiguration() throws Exception { HttpResponse response = client.put(Constants.AndroidConfigurationManagement.CONFIG_MGT_ENDPOINT, - PayloadGenerator.getJsonPayload( - Constants.AndroidConfigurationManagement.PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_PUT).toString() - ); + PayloadGenerator.getJsonPayload(Constants.AndroidConfigurationManagement.PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_PUT).toString()); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); - AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( - Constants.AndroidConfigurationManagement.RESPONSE_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_PUT).toString(), - response.getData().toString(), true - ); + Assert.assertEquals("Android configuration update message is not received properly", + "Android platform " + "configuration has been updated successfully.", + response.getData().replaceAll("\"", "")); } -// @Test(description = "Test get android configuration.", -// dependsOnMethods = { "testAddConfiguration", "testModifyConfiguration" }) -// public void testGetConfiguration() throws Exception { -// HttpResponse response = client.get(Constants.AndroidConfigurationManagement.CONFIG_MGT_ENDPOINT); -// Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); -// AssertUtil.jsonPayloadCompare( -// PayloadGenerator.getJsonPayload(Constants.AndroidConfigurationManagement.PAYLOAD_FILE_NAME, -// Constants.HTTP_METHOD_PUT).toString(), -// response.getData().toString(), true -// ); -// } + @Test(description = "Test get android configuration.", dependsOnMethods = { "testModifyConfiguration" }) + public void testGetConfiguration() throws Exception { + HttpResponse response = client.get(Constants.AndroidConfigurationManagement.CONFIG_MGT_ENDPOINT); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator + .getJsonPayload(Constants.AndroidConfigurationManagement.PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_PUT) + .toString(), response.getData(), true); + } + + @Test(description = "Test get android license.", dependsOnMethods = { "testModifyConfiguration" }) + public void testGetLicense() throws Exception { + HttpResponse response = client.get(Constants.AndroidConfigurationManagement.CONFIG_MGT_ENDPOINT + + Constants.AndroidConfigurationManagement.LICENSE_ENDPOINT); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + Assert.assertEquals("Expected android license agreement is not received", + "This End User License Agreement is " + "Eula.", response.getData()); + } } diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java index 03fb3733..671e5122 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java @@ -23,17 +23,13 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import junit.framework.Assert; import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.net.util.Base64; import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; -import org.wso2.carbon.automation.engine.context.beans.User; import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; import org.wso2.iot.integration.common.AssertUtil; import org.wso2.iot.integration.common.Constants; -import org.wso2.iot.integration.common.OAuthUtil; import org.wso2.iot.integration.common.PayloadGenerator; import org.wso2.iot.integration.common.RestClient; import org.wso2.iot.integration.common.TestBase; @@ -45,7 +41,6 @@ import org.wso2.iot.integration.common.TestBase; public class AndroidEnrollment extends TestBase { private RestClient client; private String deviceId; - private TestUserMode userMode; @Factory(dataProvider = "userModeProvider") public AndroidEnrollment(TestUserMode userMode) { @@ -55,13 +50,6 @@ public class AndroidEnrollment extends TestBase { @BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP}) public void initTest() throws Exception { super.init(userMode); - User currentUser = getAutomationContext().getContextTenant().getContextUser(); - byte[] bytesEncoded = Base64 - .encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes()); - String encoded = new String(bytesEncoded); - String accessTokenString = "Bearer " + OAuthUtil - .getOAuthTokenPair(encoded, backendHTTPSURL, backendHTTPSURL, currentUser.getUserName(), - currentUser.getPassword()); this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); } @@ -144,11 +132,4 @@ public class AndroidEnrollment extends TestBase { Constants.HTTP_METHOD_DELETE).toString(), response.getData(), true); } - @DataProvider - private static Object[][] userModeProvider() { - return new TestUserMode[][]{ - new TestUserMode[]{TestUserMode.SUPER_TENANT_ADMIN}, - new TestUserMode[]{TestUserMode.TENANT_ADMIN} - }; - } } diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/mgt/AndroidDeviceManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/mgt/AndroidDeviceManagement.java deleted file mode 100644 index 7aae9173..00000000 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/mgt/AndroidDeviceManagement.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2015, 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.iot.integration.device.mgt; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import junit.framework.Assert; -import org.apache.commons.httpclient.HttpStatus; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.wso2.carbon.automation.engine.context.TestUserMode; -import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; -import org.wso2.iot.integration.common.*; - -/** - * This class contains integration tests for Android device management backend services. - */ -public class AndroidDeviceManagement extends TestBase { - private RestClient client; - private JsonObject device; - - @BeforeClass(alwaysRun = true, groups = {Constants.AndroidDeviceManagement.DEVICE_MANAGEMENT_GROUP}) - public void initTest() throws Exception { - super.init(TestUserMode.SUPER_TENANT_ADMIN); - String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL); - this.client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON, accessTokenString); - } - - @Test(description = "Test get all android devices.", groups = Constants.AndroidDeviceManagement.DEVICE_MANAGEMENT_GROUP) - public void testGetAllDevices() throws Exception { - HttpResponse response = client.get(Constants.AndroidDeviceManagement.DEVICE_MGT_ENDPOINT); - JsonArray jsonArray = new JsonParser().parse(response.getData()).getAsJsonArray(); - Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); - Assert.assertEquals(jsonArray.size(), 1); - } - - @Test(description = "Test get android device.", groups = Constants.AndroidDeviceManagement.DEVICE_MANAGEMENT_GROUP) - public void testGetDevice() throws Exception { - HttpResponse response = client.get(Constants.AndroidDeviceManagement.DEVICE_MGT_ENDPOINT + Constants.DEVICE_ID); - device = new JsonParser().parse(response.getData()).getAsJsonObject(); - Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); - Assert.assertEquals(device.get(Constants.AndroidDeviceManagement.KEY_DEVICE_ID).getAsString(), Constants.DEVICE_ID); - } - - @Test(description = "Test update android device.", groups = Constants.AndroidDeviceManagement.DEVICE_MANAGEMENT_GROUP, - dependsOnMethods = {"testGetDevice"}) - public void testUpdateDevice() throws Exception { - device.addProperty(Constants.AndroidDeviceManagement.KEY_DEVICE_NAME, "UpdatedName"); - HttpResponse response = client.put(Constants.AndroidDeviceManagement.DEVICE_MGT_ENDPOINT + Constants.DEVICE_ID, - device.toString()); - Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); - AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( - Constants.AndroidDeviceManagement.RESPONSE_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_PUT).toString(), - response.getData().toString(), true); - } - - - @Test(description = "Test get android license.", groups = Constants.AndroidDeviceManagement.DEVICE_MANAGEMENT_GROUP) - public void testGetLicense() throws Exception { - HttpResponse response = client.get(Constants.AndroidDeviceManagement.LICENSE_ENDPOINT); - CharSequence sequence = Constants.AndroidDeviceManagement.LICENSE_SECTION; - Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); - Assert.assertTrue(response.getData().contains(sequence)); - } - - -} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java index f01bc303..5195fb4d 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java @@ -20,29 +20,25 @@ package org.wso2.iot.integration.device.operation; import com.google.gson.JsonObject; import junit.framework.Assert; import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.net.util.Base64; -import org.testng.annotations.*; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Factory; +import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; -import org.wso2.carbon.automation.engine.context.beans.User; import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException; import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; import org.wso2.iot.integration.common.Constants; -import org.wso2.iot.integration.common.OAuthUtil; import org.wso2.iot.integration.common.PayloadGenerator; import org.wso2.iot.integration.common.RestClient; import org.wso2.iot.integration.common.TestBase; -import java.io.File; import java.io.FileNotFoundException; import java.net.MalformedURLException; -import java.net.URL; /** * This contain tests to check operations supported by Android. Test are executed against a previously enrolled device */ public class AndroidOperation extends TestBase { private RestClient client; - private TestUserMode userMode; @Factory(dataProvider = "userModeProvider") public AndroidOperation(TestUserMode userMode) { @@ -52,13 +48,6 @@ public class AndroidOperation extends TestBase { @BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP}) public void initTest() throws Exception { super.init(userMode); - User currentUser = getAutomationContext().getContextTenant().getContextUser(); - byte[] bytesEncoded = Base64 - .encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes()); - String encoded = new String(bytesEncoded); - String accessTokenString = "Bearer " + OAuthUtil - .getOAuthTokenPair(encoded, backendHTTPSURL, backendHTTPSURL, currentUser.getUserName(), - currentUser.getPassword()); this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); //Enroll a device JsonObject enrollmentData = PayloadGenerator.getJsonPayload( @@ -69,9 +58,9 @@ public class AndroidOperation extends TestBase { @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device lock operation.") public void testLock() throws MalformedURLException, AutomationFrameworkException { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.LOCK_ENDPOINT, - Constants.AndroidOperations.LOCK_OPERATION_PAYLOAD); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.LOCK_ENDPOINT, + Constants.AndroidOperations.LOCK_OPERATION_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @@ -160,6 +149,58 @@ public class AndroidOperation extends TestBase { Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android app update operation") + public void testUpdateApplication() + throws FileNotFoundException, MalformedURLException, AutomationFrameworkException { + JsonObject installApplicationPayload = PayloadGenerator.getJsonPayload(Constants.AndroidOperations + .OPERATION_PAYLOAD_FILE_NAME, Constants.AndroidOperations.INSTALL_APPS_OPERATION); + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.UPDATE_APPS_ENDPOINT, installApplicationPayload.toString()); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android app un-install " + + "operation") + public void testUninstallApplication() throws MalformedURLException, AutomationFrameworkException { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.UNINSTALL_APPS_ENDPOINT, + Constants.AndroidOperations.UNINSTALL_APPS_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test black list application " + + "operation") + public void testBlackListApplication() + throws FileNotFoundException, MalformedURLException, AutomationFrameworkException { + JsonObject blackListApplicationPayload = PayloadGenerator.getJsonPayload(Constants.AndroidOperations + .OPERATION_PAYLOAD_FILE_NAME, Constants.AndroidOperations.BLACKLIST_OPERATION); + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.BLACKLIST_APPS_ENDPOINT, blackListApplicationPayload.toString()); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test upgrade firmware operation") + public void testUpgradeFirmware() + throws FileNotFoundException, MalformedURLException, AutomationFrameworkException { + JsonObject upgradeFirmWarePayload = PayloadGenerator + .getJsonPayload(Constants.AndroidOperations.OPERATION_PAYLOAD_FILE_NAME, + Constants.AndroidOperations.UPGRADE_FIRMWARE_OPERATION); + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.UPGRADE_FIRMWARE_ENDPOINT, upgradeFirmWarePayload.toString()); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test configure VPN operation") + public void testConfigureVPN() + throws FileNotFoundException, MalformedURLException, AutomationFrameworkException { + JsonObject configureVPNPayload = PayloadGenerator + .getJsonPayload(Constants.AndroidOperations.OPERATION_PAYLOAD_FILE_NAME, + Constants.AndroidOperations.VPN_OPERATION); + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.VPN_ENDPOINT, configureVPNPayload.toString()); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android reboot operation") public void testReboot() throws Exception { HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + @@ -230,12 +271,4 @@ public class AndroidOperation extends TestBase { Constants.AndroidOperations.WEB_CLIP_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } - - @DataProvider - private static Object[][] userModeProvider() { - return new TestUserMode[][]{ - new TestUserMode[]{TestUserMode.SUPER_TENANT_ADMIN}, - new TestUserMode[]{TestUserMode.TENANT_ADMIN} - }; - } -} \ No newline at end of file +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java index eeaa37a9..d4c40827 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java @@ -20,12 +20,16 @@ package org.wso2.iot.integration.mobileDevice; import junit.framework.Assert; import org.apache.commons.httpclient.HttpStatus; -import org.junit.experimental.theories.Theories; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Factory; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; -import org.wso2.iot.integration.common.*; +import org.wso2.iot.integration.common.Constants; +import org.wso2.iot.integration.common.IOTHttpClient; +import org.wso2.iot.integration.common.IOTResponse; +import org.wso2.iot.integration.common.OAuthUtil; +import org.wso2.iot.integration.common.TestBase; import java.util.concurrent.TimeUnit; @@ -35,26 +39,35 @@ import java.util.concurrent.TimeUnit; public class MobileDeviceManagementWithNoDevices extends TestBase { private IOTHttpClient client; + @Factory(dataProvider = "userModeProvider") + public MobileDeviceManagementWithNoDevices(TestUserMode userMode) { + this.userMode = userMode; + } + /** * @BeforeSuite annotation is added to run this verification before the test suite starts. * As in IoT server, apis are published after the server startup. Due to that the generated token doesn't get * required scope. * This method delays test suit startup until the tokens get required scopes. - * @throws Exception + * @throws Exception Exception */ @BeforeSuite public void verifyApiPublishing() throws Exception { super.init(TestUserMode.SUPER_TENANT_ADMIN); + long startTime = System.currentTimeMillis(); while (!checkScopes(Constants.APIApplicationRegistration.PERMISSION_LIST)) { TimeUnit.SECONDS.sleep(5); + long WAIT_TIME = 30000; + if (System.currentTimeMillis() - startTime > WAIT_TIME) { + Assert.fail("Required APIs are not deployed after waiting for " + WAIT_TIME + " time-out has happened"); + } } } - @BeforeClass(alwaysRun = true, groups = { Constants.MobileDeviceManagement.MOBILE_DEVICE_MANAGEMENT_GROUP}) + @BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP}) public void initTest() throws Exception { - - String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL); + super.init(userMode); this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); } @@ -70,4 +83,6 @@ public class MobileDeviceManagementWithNoDevices extends TestBase { return tokenString.contains(permissionsList); } + + } diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java index 0b6e9feb..7c266812 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java @@ -21,18 +21,14 @@ import com.google.gson.JsonArray; import com.google.gson.JsonParser; import junit.framework.Assert; import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.net.util.Base64; import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; -import org.wso2.carbon.automation.engine.context.beans.User; import org.wso2.iot.integration.common.AssertUtil; import org.wso2.iot.integration.common.Constants; import org.wso2.iot.integration.common.IOTHttpClient; import org.wso2.iot.integration.common.IOTResponse; -import org.wso2.iot.integration.common.OAuthUtil; import org.wso2.iot.integration.common.PayloadGenerator; import org.wso2.iot.integration.common.TestBase; @@ -44,7 +40,6 @@ import java.io.FileNotFoundException; */ public class RoleManagement extends TestBase { private IOTHttpClient client; - private TestUserMode userMode; private static final String ROLE_NAME = "administration"; @Factory(dataProvider = "userModeProvider") @@ -55,13 +50,6 @@ public class RoleManagement extends TestBase { @BeforeClass(alwaysRun = true, groups = { Constants.RoleManagement.ROLE_MANAGEMENT_GROUP}) public void initTest() throws Exception { super.init(userMode); - User currentUser = getAutomationContext().getContextTenant().getContextUser(); - byte[] bytesEncoded = Base64 - .encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes()); - String encoded = new String(bytesEncoded); - String accessTokenString = "Bearer " + OAuthUtil - .getOAuthTokenPair(encoded, backendHTTPSURL, backendHTTPSURL, currentUser.getUserName(), - currentUser.getPassword()); this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); } @@ -138,12 +126,4 @@ public class RoleManagement extends TestBase { IOTResponse response = client.delete(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT +"/" + ROLE_NAME); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); } - - @DataProvider - private static Object[][] userModeProvider() { - return new TestUserMode[][]{ - new TestUserMode[]{TestUserMode.SUPER_TENANT_ADMIN}, - new TestUserMode[]{TestUserMode.TENANT_ADMIN} - }; - } -} \ No newline at end of file +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/user/UserManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/user/UserManagement.java index bee86d5e..ef00d78b 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/user/UserManagement.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/user/UserManagement.java @@ -23,17 +23,13 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import junit.framework.Assert; import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.net.util.Base64; import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; -import org.wso2.carbon.automation.engine.context.beans.User; import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; import org.wso2.iot.integration.common.AssertUtil; import org.wso2.iot.integration.common.Constants; -import org.wso2.iot.integration.common.OAuthUtil; import org.wso2.iot.integration.common.PayloadGenerator; import org.wso2.iot.integration.common.RestClient; import org.wso2.iot.integration.common.TestBase; @@ -44,7 +40,6 @@ import org.wso2.iot.integration.common.TestBase; public class UserManagement extends TestBase { private String NON_EXISTING_USERNAME = "non_exiting"; private RestClient client; - private TestUserMode userMode; @Factory(dataProvider = "userModeProvider") public UserManagement(TestUserMode userMode) { @@ -54,13 +49,6 @@ public class UserManagement extends TestBase { @BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP}) public void initTest() throws Exception { super.init(userMode); - User currentUser = getAutomationContext().getContextTenant().getContextUser(); - byte[] bytesEncoded = Base64 - .encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes()); - String encoded = new String(bytesEncoded); - String accessTokenString = "Bearer " + OAuthUtil - .getOAuthTokenPair(encoded, backendHTTPSURL, backendHTTPSURL, currentUser.getUserName(), - currentUser.getPassword()); this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); } @@ -186,12 +174,4 @@ public class UserManagement extends TestBase { Assert.assertEquals("Password of the user cannot be changed", "\"UserImpl password by " + "username: admin was successfully changed.\"", response.getData()); } - - @DataProvider - private static Object[][] userModeProvider() { - return new TestUserMode[][]{ - new TestUserMode[]{TestUserMode.SUPER_TENANT_ADMIN}, - new TestUserMode[]{TestUserMode.TENANT_ADMIN} - }; - } } diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-config-response-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/android-config-response-payloads.json index 5e8353b5..693c0e85 100644 --- a/modules/integration/tests-integration/src/test/resources/payloads/android-config-response-payloads.json +++ b/modules/integration/tests-integration/src/test/resources/payloads/android-config-response-payloads.json @@ -1,3 +1,4 @@ + { "POST": { "responseCode": "Created", diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-operation-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/android-operation-payloads.json index dc1b8f9e..655c0318 100644 --- a/modules/integration/tests-integration/src/test/resources/payloads/android-operation-payloads.json +++ b/modules/integration/tests-integration/src/test/resources/payloads/android-operation-payloads.json @@ -18,7 +18,7 @@ "url": "https://www.youtube.com", "name": "youtube" }, - "deviceIDs": [] + "deviceIDs": ["d24f870f390352a41234"] }, "notification": { "operation": { @@ -64,5 +64,34 @@ "type": "install" }, "deviceIDs": [] + }, + "black_list_application": { + "operation": { + "appIdentifiers": ["com.google", "android.studio"] + }, + "deviceIDs": [ + "d24f870f390352a41234" + ] + }, + "upgrade-firmware" : { + "operation": { + "schedule": "", + "server" : "http://www.google.lk" + }, + "deviceIDs": [ + "d24f870f390352a41234" + ] + }, + "vpn" : { + "operation": { + "serverAddress": "localhost", + "serverPort" : "9763", + "sharedSecret" : "helloWorld", + "dnsServer" : "testserver.com" + }, + "deviceIDs": [ + "d24f870f390352a41234" + ] + } } \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/testng.xml b/modules/integration/tests-integration/src/test/resources/testng.xml index fb3c0230..b1c4252f 100644 --- a/modules/integration/tests-integration/src/test/resources/testng.xml +++ b/modules/integration/tests-integration/src/test/resources/testng.xml @@ -43,20 +43,15 @@ + + + + + - - - - - - - - - - - - - + + + @@ -108,4 +103,4 @@ - \ No newline at end of file + From b0ab301004c5c8afec2f05dd918cd0dd44b399cb Mon Sep 17 00:00:00 2001 From: megala21 Date: Wed, 19 Apr 2017 14:47:13 +0530 Subject: [PATCH 3/3] Reformatting code --- .../iot/integration/common/Constants.java | 20 --- .../integration/common/PayloadGenerator.java | 7 + .../device/enrollment/AndroidEnrollment.java | 78 +++++----- .../device/operation/AndroidOperation.java | 138 +++++++++--------- .../MobileDeviceManagementWithNoDevices.java | 3 - .../iot/integration/role/RoleManagement.java | 33 +++-- .../iot/integration/user/UserManagement.java | 11 +- 7 files changed, 141 insertions(+), 149 deletions(-) diff --git a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java index 7a7442c2..fffc9021 100644 --- a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java +++ b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java @@ -262,26 +262,6 @@ public final class Constants { } } - public static final class AndroidDeviceManagement { - public static final String DEVICE_MANAGEMENT_GROUP = "device-mgt"; - public static final String KEY_DEVICE_ID = "deviceIdentifier"; - public static final String KEY_DEVICE_NAME = "name"; - public static final String DEVICE_MGT_ENDPOINT = "/api/device-mgt/android/v1.0/devices"; - public static final String LICENSE_SECTION = "This"; - public static final String LICENSE_ENDPOINT = DEVICE_MGT_ENDPOINT + "license"; - public static final String APP_LIST_ENDPOINT = DEVICE_MGT_ENDPOINT + "appList/" + - Constants.DEVICE_ID; - public static final String REQUEST_MODIFY_DEVICE_EXPECTED = "{\"responseMessage\":\"Device information " + - "has modified successfully.\"}"; - public static final String APPLIST_PAYLOAD = "{\"id\":\"1\"," + - "\"applicationIdentifier\": \"appid\",\"\"platform\": \"android\"," + - "\"name\": \"testapp\"}"; - public static final String RESPONSE_PAYLOAD_FILE_NAME = "android-device-mgt-response-payloads.json"; - - private AndroidDeviceManagement() { - throw new AssertionError(); - } - } public static final class AndroidConfigurationManagement { public static final String DEVICE_CONFIGURATION_GROUP = "android-config-mgt"; diff --git a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/PayloadGenerator.java b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/PayloadGenerator.java index b1d3e3cf..51ce51e1 100644 --- a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/PayloadGenerator.java +++ b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/PayloadGenerator.java @@ -48,6 +48,13 @@ public class PayloadGenerator { return returnString; } + /** + * Create a Json Array from a specific method in the file + * @param fileName Name of the file + * @param method Method name + * @return Json Arry created from the specific method in the file + * @throws FileNotFoundException File Not found exception + */ public static JsonArray getJsonArray(String fileName, String method) throws FileNotFoundException { URL url = PayloadGenerator.class.getClassLoader().getResource(PAYLOAD_LOCATION + fileName); diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java index 671e5122..2ac6e9a1 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java @@ -55,8 +55,9 @@ public class AndroidEnrollment extends TestBase { @Test(description = "Test an Android device enrollment.") public void testEnrollment() throws Exception { - String enrollmentData = PayloadGenerator.getJsonPayload(Constants.AndroidEnrollment - .ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST).toString(); + String enrollmentData = PayloadGenerator + .getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST) + .toString(); HttpResponse response = client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData); JsonParser jsonParser = new JsonParser(); JsonElement element = jsonParser.parse(response.getData()); @@ -64,72 +65,73 @@ public class AndroidEnrollment extends TestBase { JsonElement msg = jsonObject.get("responseMessage"); deviceId = msg.getAsString().split("\'")[1].split("\'")[0]; Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); - AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( - Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_POST).toString(), response.getData(), true); + AssertUtil.jsonPayloadCompare(PayloadGenerator + .getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST).toString(), response.getData(), true); } @Test(description = "Test an Android device is enrolled.", dependsOnMethods = {"testEnrollment"}) public void testIsEnrolled() throws Exception { - HttpResponse response = client.get(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId + "/status"); + HttpResponse response = client + .get(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId + "/status"); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); - AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( - Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_GET).toString(), response.getData(), true); + AssertUtil.jsonPayloadCompare(PayloadGenerator + .getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_GET).toString(), response.getData(), true); } @Test(description = "Test modify enrollment.", dependsOnMethods = {"testIsEnrolled"}) public void testModifyEnrollment() throws Exception { - JsonObject enrollmentData = PayloadGenerator.getJsonPayload( - Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_PUT); - HttpResponse response = client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId, - enrollmentData.toString()); - AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( - Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_PUT).toString(), response.getData(), true); + JsonObject enrollmentData = PayloadGenerator + .getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_PUT); + HttpResponse response = client + .put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId, enrollmentData.toString()); + AssertUtil.jsonPayloadCompare(PayloadGenerator + .getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_PUT).toString(), response.getData(), true); } @Test(description = "Test update applications", dependsOnMethods = {"testModifyEnrollment"}) public void testUpdateApplications() throws Exception { - JsonArray updateApplicationData = PayloadGenerator.getJsonArray( - Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, - Constants.AndroidEnrollment.UPDATE_APPLICATION_METHOD); - HttpResponse response = client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId + - "/applications", updateApplicationData.toString()); - Assert.assertEquals("Update of applications for the device id " + deviceId + " failed", HttpStatus - .SC_ACCEPTED, response.getResponseCode()); - response = client.get(Constants.MobileDeviceManagement.CHANGE_DEVICE_STATUS_ENDPOINT + Constants - .AndroidEnrollment.ANDROID_DEVICE_TYPE + "/" + deviceId + "/applications"); + JsonArray updateApplicationData = PayloadGenerator + .getJsonArray(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, + Constants.AndroidEnrollment.UPDATE_APPLICATION_METHOD); + HttpResponse response = client + .put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId + "/applications", + updateApplicationData.toString()); + Assert.assertEquals("Update of applications for the device id " + deviceId + " failed", HttpStatus.SC_ACCEPTED, + response.getResponseCode()); + response = client.get(Constants.MobileDeviceManagement.CHANGE_DEVICE_STATUS_ENDPOINT + + Constants.AndroidEnrollment.ANDROID_DEVICE_TYPE + "/" + deviceId + "/applications"); Assert.assertEquals("Error while getting application list for the device with the id " + deviceId + " failed", HttpStatus.SC_OK, response.getResponseCode()); JsonArray jsonArray = new JsonParser().parse(response.getData()).getAsJsonArray(); Assert.assertEquals("Installed applications for the device with the device id " + deviceId + " has not been " + "updated yet", 3, jsonArray.size()); - } @Test(description = "Test get pending operations", dependsOnMethods = {"testModifyEnrollment"}) public void testGetPendingOperations() throws Exception { - JsonArray pendingOperationsData = PayloadGenerator.getJsonArray( - Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, - Constants.AndroidEnrollment.GET_PENDING_OPERATIONS_METHOD); - HttpResponse response = client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId + - "/pending-operations", pendingOperationsData.toString()); + JsonArray pendingOperationsData = PayloadGenerator + .getJsonArray(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, + Constants.AndroidEnrollment.GET_PENDING_OPERATIONS_METHOD); + HttpResponse response = client + .put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId + "/pending-operations", + pendingOperationsData.toString()); JsonArray pendingOperations = new JsonParser().parse(response.getData()).getAsJsonArray(); Assert.assertEquals("Error while getting pending operations for android device with the id " + deviceId, HttpStatus.SC_CREATED, response.getResponseCode()); - Assert.assertTrue("Pending operation count is 0. Periodic monitoring tasks are not running.", 0 < - pendingOperations.size()); - + Assert.assertTrue("Pending operation count is 0. Periodic monitoring tasks are not running.", + 0 < pendingOperations.size()); } + @Test(description = "Test disEnrollment.", dependsOnMethods = {"testGetPendingOperations"}) public void testDisEnrollDevice() throws Exception { HttpResponse response = client.delete(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); - AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( - Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_DELETE).toString(), response.getData(), true); + AssertUtil.jsonPayloadCompare(PayloadGenerator + .getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_DELETE).toString(), response.getData(), true); } } diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java index 5195fb4d..575c869c 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java @@ -50,9 +50,8 @@ public class AndroidOperation extends TestBase { super.init(userMode); this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); //Enroll a device - JsonObject enrollmentData = PayloadGenerator.getJsonPayload( - Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_POST); + JsonObject enrollmentData = PayloadGenerator + .getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST); client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData.toString()); } @@ -67,8 +66,9 @@ public class AndroidOperation extends TestBase { @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device un-lock " + "operation.") public void testUnLock() throws MalformedURLException, AutomationFrameworkException { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.UNLOCK_ENDPOINT, Constants.AndroidOperations.UNLOCK_OPERATION_PAYLOAD); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.UNLOCK_ENDPOINT, + Constants.AndroidOperations.UNLOCK_OPERATION_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @@ -76,41 +76,42 @@ public class AndroidOperation extends TestBase { @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device location " + "operation.") public void testLocation() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.LOCATION_ENDPOINT, - Constants.AndroidOperations.LOCATION_PAYLOAD); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.LOCATION_ENDPOINT, + Constants.AndroidOperations.LOCATION_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device clear password " + "operation.") public void testClearPassword() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.CLEAR_PASSWORD_ENDPOINT, - Constants.AndroidOperations.CLEAR_PASSWORD_PAYLOAD); + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.CLEAR_PASSWORD_ENDPOINT, + Constants.AndroidOperations.CLEAR_PASSWORD_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device camera " + "operation.") public void testCamera() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.CAMERA_OPERATION, - Constants.AndroidOperations.CAMERA_OPERATION_PAYLOAD); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.CAMERA_OPERATION, + Constants.AndroidOperations.CAMERA_OPERATION_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android get info operation") public void testGetInfo() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.DEVICE_INFO_ENDPOINT, Constants.AndroidOperations.DEVICE_INFO_PAYLOAD); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.DEVICE_INFO_ENDPOINT, + Constants.AndroidOperations.DEVICE_INFO_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android logcat operation") public void testLogcat() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.DEVICE_LOGCAT_ENDPOINT, Constants.AndroidOperations.PAYLOAD_COMMON); + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.DEVICE_LOGCAT_ENDPOINT, Constants.AndroidOperations.PAYLOAD_COMMON); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @@ -118,44 +119,47 @@ public class AndroidOperation extends TestBase { @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android enterprise-wipe " + "operation.") public void testEnterpriseWipe() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.ENTERPRISE_WIPE_ENDPOINT, - Constants.AndroidOperations.ENTERPRISE_WIPE_PAYLOAD); + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.ENTERPRISE_WIPE_ENDPOINT, + Constants.AndroidOperations.ENTERPRISE_WIPE_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android wipe data operation.") public void testWipeData() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.WIPE_DATA_ENDPOINT, - Constants.AndroidOperations.WIPE_DATA_PAYLOAD); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.WIPE_DATA_ENDPOINT, + Constants.AndroidOperations.WIPE_DATA_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android get applications " + "operation.") public void testGetApplications() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.APPLICATION_LIST_ENDPOINT, Constants.AndroidOperations.PAYLOAD_COMMON); + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.APPLICATION_LIST_ENDPOINT, Constants.AndroidOperations.PAYLOAD_COMMON); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android app install operation") public void testInstallApplication() throws Exception { - JsonObject installApplicationPayload = PayloadGenerator.getJsonPayload(Constants.AndroidOperations - .OPERATION_PAYLOAD_FILE_NAME, Constants.AndroidOperations.INSTALL_APPS_OPERATION); - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.INSTALL_APPS_ENDPOINT, installApplicationPayload.toString()); + JsonObject installApplicationPayload = PayloadGenerator + .getJsonPayload(Constants.AndroidOperations.OPERATION_PAYLOAD_FILE_NAME, + Constants.AndroidOperations.INSTALL_APPS_OPERATION); + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.INSTALL_APPS_ENDPOINT, installApplicationPayload.toString()); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android app update operation") public void testUpdateApplication() throws FileNotFoundException, MalformedURLException, AutomationFrameworkException { - JsonObject installApplicationPayload = PayloadGenerator.getJsonPayload(Constants.AndroidOperations - .OPERATION_PAYLOAD_FILE_NAME, Constants.AndroidOperations.INSTALL_APPS_OPERATION); - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.UPDATE_APPS_ENDPOINT, installApplicationPayload.toString()); + JsonObject installApplicationPayload = PayloadGenerator + .getJsonPayload(Constants.AndroidOperations.OPERATION_PAYLOAD_FILE_NAME, + Constants.AndroidOperations.INSTALL_APPS_OPERATION); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.UPDATE_APPS_ENDPOINT, + installApplicationPayload.toString()); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @@ -172,10 +176,11 @@ public class AndroidOperation extends TestBase { + "operation") public void testBlackListApplication() throws FileNotFoundException, MalformedURLException, AutomationFrameworkException { - JsonObject blackListApplicationPayload = PayloadGenerator.getJsonPayload(Constants.AndroidOperations - .OPERATION_PAYLOAD_FILE_NAME, Constants.AndroidOperations.BLACKLIST_OPERATION); - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.BLACKLIST_APPS_ENDPOINT, blackListApplicationPayload.toString()); + JsonObject blackListApplicationPayload = PayloadGenerator + .getJsonPayload(Constants.AndroidOperations.OPERATION_PAYLOAD_FILE_NAME, + Constants.AndroidOperations.BLACKLIST_OPERATION); + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.BLACKLIST_APPS_ENDPOINT, blackListApplicationPayload.toString()); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @@ -196,79 +201,80 @@ public class AndroidOperation extends TestBase { JsonObject configureVPNPayload = PayloadGenerator .getJsonPayload(Constants.AndroidOperations.OPERATION_PAYLOAD_FILE_NAME, Constants.AndroidOperations.VPN_OPERATION); - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT - + Constants.AndroidOperations.VPN_ENDPOINT, configureVPNPayload.toString()); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.VPN_ENDPOINT, + configureVPNPayload.toString()); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android reboot operation") public void testReboot() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.REBOOT_ENDPOINT, Constants.AndroidOperations.PAYLOAD_COMMON); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.REBOOT_ENDPOINT, + Constants.AndroidOperations.PAYLOAD_COMMON); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android ring operation.") public void testRing() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.RING_ENDPOINT, - Constants.AndroidOperations.RING_PAYLOAD); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.RING_ENDPOINT, + Constants.AndroidOperations.RING_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android mute operation.") public void testMute() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.MUTE_ENDPOINT, - Constants.AndroidOperations.MUTE_PAYLOAD); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.MUTE_ENDPOINT, + Constants.AndroidOperations.MUTE_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android notification operation.") public void testNotification() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.NOTIFICATION_ENDPOINT, - Constants.AndroidOperations.NOTIFICATION_PAYLOAD); + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.NOTIFICATION_ENDPOINT, Constants.AndroidOperations.NOTIFICATION_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android WiFi operation.") public void testWiFi() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.WIFI_ENDPOINT, - Constants.AndroidOperations.WIFI_PAYLOAD); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.WIFI_ENDPOINT, + Constants.AndroidOperations.WIFI_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android encrypt operation.") public void testEncrypt() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.ENCRYPT_ENDPOINT, - Constants.AndroidOperations.ENCRYPT_PAYLOAD); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.ENCRYPT_ENDPOINT, + Constants.AndroidOperations.ENCRYPT_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android change lock operation.") public void testChangeLock() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.CHANGE_LOCK_ENDPOINT, - Constants.AndroidOperations.CHANGE_LOCK_PAYLOAD); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.CHANGE_LOCK_ENDPOINT, + Constants.AndroidOperations.CHANGE_LOCK_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android password policy operation.") public void testPasswordPolicy() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.PASSWORD_POLICY_ENDPOINT, - Constants.AndroidOperations.PASSWORD_POLICY_PAYLOAD); + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.PASSWORD_POLICY_ENDPOINT, + Constants.AndroidOperations.PASSWORD_POLICY_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android web clip operation.") public void testWebClip() throws Exception { - HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + - Constants.AndroidOperations.WEB_CLIP_ENDPOINT, - Constants.AndroidOperations.WEB_CLIP_PAYLOAD); + HttpResponse response = client + .post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.WEB_CLIP_ENDPOINT, + Constants.AndroidOperations.WEB_CLIP_PAYLOAD); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } } diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java index d4c40827..9202331b 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java @@ -82,7 +82,4 @@ public class MobileDeviceManagementWithNoDevices extends TestBase { String tokenString = OAuthUtil.getScopes(backendHTTPSURL, backendHTTPSURL); return tokenString.contains(permissionsList); } - - - } diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java index 7c266812..9ab7e675 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java @@ -55,17 +55,18 @@ public class RoleManagement extends TestBase { @Test(description = "Test add role.") public void testAddRole() throws FileNotFoundException { - IOTResponse response = client.post(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT, - PayloadGenerator.getJsonPayload(Constants.RoleManagement.ROLE_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_POST).toString()); + IOTResponse response = client.post(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT, PayloadGenerator + .getJsonPayload(Constants.RoleManagement.ROLE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST) + .toString()); Assert.assertEquals(HttpStatus.SC_CREATED, response.getStatus()); } @Test(description = "Test update permission role.", dependsOnMethods = {"testAddRole"}) public void testUpdateRolePermission() throws FileNotFoundException { IOTResponse response = client.put(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/" + ROLE_NAME, - PayloadGenerator.getJsonPayload(Constants.RoleManagement.ROLE_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_PUT).toString()); + PayloadGenerator + .getJsonPayload(Constants.RoleManagement.ROLE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_PUT) + .toString()); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); } @@ -80,8 +81,8 @@ public class RoleManagement extends TestBase { @Test(description = "Test getting roles that has particular prefix.", dependsOnMethods = {"testGetRoles"}) public void testGetFilteredRoles() throws FileNotFoundException { - IOTResponse response = client.get(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + - "/filter/administ?offset=0&limit=2"); + IOTResponse response = client + .get(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/filter/administ?offset=0&limit=2"); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); AssertUtil.jsonPayloadCompare(PayloadGenerator .getJsonPayload(Constants.RoleManagement.ROLE_RESPONSE_PAYLOAD_FILE_NAME, @@ -97,25 +98,25 @@ public class RoleManagement extends TestBase { @Test(description = "Test getting role details.", dependsOnMethods = {"testGetRolePermissions"}) public void testGetRole() throws FileNotFoundException { - IOTResponse response = client.get(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + - "/" + ROLE_NAME); + IOTResponse response = client.get(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/" + ROLE_NAME); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); } @Test(description = "Test updating users with a given role.", dependsOnMethods = {"testGetRole"}) public void testUpdateRolesOfUser() throws FileNotFoundException, XPathExpressionException { - IOTResponse response = client - .put(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/administration/users", PayloadGenerator.getJsonArray( - Constants.RoleManagement.ROLE_PAYLOAD_FILE_NAME, + IOTResponse response = client.put(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/administration/users", + PayloadGenerator.getJsonArray(Constants.RoleManagement.ROLE_PAYLOAD_FILE_NAME, Constants.RoleManagement.UPDATE_ROLES_METHOD).toString()); Assert.assertEquals("Error while updating the user list for the role administration", HttpStatus.SC_OK, response.getStatus()); - String url = Constants.UserManagement.USER_ENDPOINT + "/" + automationContext.getContextTenant() - .getContextUser().getUserNameWithoutDomain() + "/roles"; + String url = + Constants.UserManagement.USER_ENDPOINT + "/" + automationContext.getContextTenant().getContextUser() + .getUserNameWithoutDomain() + "/roles"; response = client.get(url); - JsonArray jsonArray = new JsonParser().parse(response.getBody()).getAsJsonObject().get("roles").getAsJsonArray(); + JsonArray jsonArray = new JsonParser().parse(response.getBody()).getAsJsonObject().get("roles") + .getAsJsonArray(); Assert.assertEquals("Error while retrieving the role details", HttpStatus.SC_OK, response.getStatus()); Assert.assertEquals("The user is not updated with the roles list", "\"" + ROLE_NAME + "\"", jsonArray.get(0).toString()); @@ -123,7 +124,7 @@ public class RoleManagement extends TestBase { @Test(description = "Test remove user.", dependsOnMethods = {"testUpdateRolesOfUser"}) public void testRemoveRole() throws Exception { - IOTResponse response = client.delete(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT +"/" + ROLE_NAME); + IOTResponse response = client.delete(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/" + ROLE_NAME); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); } } diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/user/UserManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/user/UserManagement.java index ef00d78b..5f4e469e 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/user/UserManagement.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/user/UserManagement.java @@ -101,8 +101,8 @@ public class UserManagement extends TestBase { @Test(description = "Test the API that checks whether user exist.", dependsOnMethods = {"testGetUserRoles"}) public void testIsUserExist() throws Exception { - String url = Constants.UserManagement.USER_ENDPOINT + "/checkUser?username=" + Constants.UserManagement - .USER_NAME; + String url = + Constants.UserManagement.USER_ENDPOINT + "/checkUser?username=" + Constants.UserManagement.USER_NAME; HttpResponse response = client.get(url); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); Assert.assertEquals( @@ -145,20 +145,19 @@ public class UserManagement extends TestBase { 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()); + 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()); + + "non-existing username", 0, jsonArray.size()); } @Test(description = "Test remove user.", dependsOnMethods = {"testSearchUserNames"}) public void testRemoveUser() throws Exception { - String url = Constants.UserManagement.USER_ENDPOINT + "/" + Constants.UserManagement.USER_NAME ; + String url = Constants.UserManagement.USER_ENDPOINT + "/" + Constants.UserManagement.USER_NAME; HttpResponse response = client.delete(url); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); }