Improving android test cases

application-manager-new
megala21 8 years ago
parent bb841f9a57
commit 23c385a7be

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

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

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

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

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

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

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

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

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

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

@ -43,20 +43,15 @@
<class name="org.wso2.iot.integration.device.operation.AndroidOperation"/>
</classes>
</test>
<test name="android-configuration" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.device.configuration.AndroidConfigurationManagement"/>
</classes>
</test>
<!--<test name="windows-enrollment" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.device.enrollment.WindowsEnrollment"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="android-device-mgt" preserve-order="false" parallel="true">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.device.mgt.AndroidDeviceManagement"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="android-configuration" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.device.configuration.AndroidConfigurationManagement"/>-->
<!--</classes>-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.device.enrollment.WindowsEnrollment"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="android-policy" preserve-order="true" parallel="false">-->
<!--<classes>-->
@ -108,4 +103,4 @@
<class name="org.wso2.iot.integration.user.UserManagement"/>
</classes>
</test>
</suite>
</suite>

Loading…
Cancel
Save