Improving android test cases

merge-requests/1/head
megala21 8 years ago
parent 477536aa68
commit 1a80b27cd5

@ -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();
}

@ -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();
}
}

@ -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}
};
}
}

@ -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);
}*/
}

@ -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}
};
}
}

@ -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());
}

@ -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" : []
}

@ -14,7 +14,7 @@
"install_apps": {
"operation": {
"appIdentifier": "package_name",
"type": "enterprise/public/webapp",
"type": "enterprise",
"url": "https://www.youtube.com",
"name": "youtube"
},

@ -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"]
}

@ -1596,7 +1596,7 @@
<equinox.jsp.jasper.version>1.0.400.v20120522-2049</equinox.jsp.jasper.version>
<selenium.version>2.40.0</selenium.version>
<operadriver.version>0.8.1</operadriver.version>
<carbon.automationutils.version>4.4.1</carbon.automationutils.version>
<carbon.automationutils.version>4.4.2</carbon.automationutils.version>
<xfer.version>3.3.0</xfer.version>
<jacoco.agent.version>0.7.4.201502262128</jacoco.agent.version>
<commons.logging.version>1.1.1</commons.logging.version>

Loading…
Cancel
Save