|
|
@ -20,22 +20,45 @@ package org.wso2.iot.integration.device.operation;
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import junit.framework.Assert;
|
|
|
|
import junit.framework.Assert;
|
|
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
|
|
import org.testng.annotations.BeforeTest;
|
|
|
|
import org.apache.commons.net.util.Base64;
|
|
|
|
import org.testng.annotations.Test;
|
|
|
|
import org.testng.annotations.*;
|
|
|
|
import org.wso2.carbon.automation.engine.context.TestUserMode;
|
|
|
|
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.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
|
|
|
|
* This contain tests to check operations supported by Android. Test are executed against a previously enrolled device
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class AndroidOperation extends TestBase {
|
|
|
|
public class AndroidOperation extends TestBase {
|
|
|
|
private RestClient client;
|
|
|
|
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 {
|
|
|
|
public void initTest() throws Exception {
|
|
|
|
super.init(TestUserMode.SUPER_TENANT_ADMIN);
|
|
|
|
super.init(userMode);
|
|
|
|
String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL);
|
|
|
|
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);
|
|
|
|
this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
|
|
|
|
//Enroll a device
|
|
|
|
//Enroll a device
|
|
|
|
JsonObject enrollmentData = PayloadGenerator.getJsonPayload(
|
|
|
|
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.")
|
|
|
|
@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 +
|
|
|
|
HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT +
|
|
|
|
Constants.AndroidOperations.LOCK_ENDPOINT,
|
|
|
|
Constants.AndroidOperations.LOCK_ENDPOINT,
|
|
|
|
Constants.AndroidOperations.LOCK_OPERATION_PAYLOAD);
|
|
|
|
Constants.AndroidOperations.LOCK_OPERATION_PAYLOAD);
|
|
|
|
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
|
|
|
|
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device un-lock "
|
|
|
|
@Test(groups = Constants.AndroidOperations.OPERATIONS_GROUP, description = "Test Android getPendingOperations.")
|
|
|
|
+ "operation.")
|
|
|
|
public void testGetPendingOperations() throws Exception {
|
|
|
|
public void testUnLock() throws MalformedURLException, AutomationFrameworkException {
|
|
|
|
HttpResponse response = client.put(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.DEVICE_ID,
|
|
|
|
HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT +
|
|
|
|
"[]");
|
|
|
|
Constants.AndroidOperations.UNLOCK_ENDPOINT, Constants.AndroidOperations.UNLOCK_OPERATION_PAYLOAD);
|
|
|
|
Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_CREATED);
|
|
|
|
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device location "
|
|
|
|
@Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device location "
|
|
|
|
+ "operation.")
|
|
|
|
+ "operation.")
|
|
|
@ -87,16 +111,20 @@ public class AndroidOperation extends TestBase {
|
|
|
|
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
|
|
|
|
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// //404
|
|
|
|
@Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android get info operation")
|
|
|
|
// @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device information "
|
|
|
|
public void testGetInfo() throws Exception {
|
|
|
|
// + "operation.")
|
|
|
|
HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT +
|
|
|
|
// public void testDeviceInfo() throws Exception {
|
|
|
|
Constants.AndroidOperations.DEVICE_INFO_ENDPOINT, Constants.AndroidOperations.DEVICE_INFO_PAYLOAD);
|
|
|
|
//
|
|
|
|
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
|
|
|
|
// HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT +
|
|
|
|
}
|
|
|
|
// Constants.AndroidOperations.DEVICE_INFO_ENDPOINT,
|
|
|
|
|
|
|
|
// Constants.AndroidOperations.DEVICE_INFO_PAYLOAD);
|
|
|
|
@Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android logcat operation")
|
|
|
|
// Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
|
|
|
|
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 "
|
|
|
|
@Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android enterprise-wipe "
|
|
|
|
+ "operation.")
|
|
|
|
+ "operation.")
|
|
|
@ -115,15 +143,29 @@ public class AndroidOperation extends TestBase {
|
|
|
|
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
|
|
|
|
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// //400
|
|
|
|
@Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android get applications "
|
|
|
|
// @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android application list "
|
|
|
|
+ "operation.")
|
|
|
|
// + "operation.")
|
|
|
|
public void testGetApplications() throws Exception {
|
|
|
|
// public void testApplicationList() throws Exception {
|
|
|
|
HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT +
|
|
|
|
// HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT +
|
|
|
|
Constants.AndroidOperations.APPLICATION_LIST_ENDPOINT, Constants.AndroidOperations.PAYLOAD_COMMON);
|
|
|
|
// Constants.AndroidOperations.APPLICATION_LIST_ENDPOINT,
|
|
|
|
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
|
|
|
|
// Constants.AndroidOperations.APPLICATION_LIST_PAYLOAD);
|
|
|
|
}
|
|
|
|
// 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.")
|
|
|
|
@Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android ring operation.")
|
|
|
|
public void testRing() throws Exception {
|
|
|
|
public void testRing() throws Exception {
|
|
|
@ -141,25 +183,6 @@ public class AndroidOperation extends TestBase {
|
|
|
|
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
|
|
|
|
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.")
|
|
|
|
@Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android notification operation.")
|
|
|
|
public void testNotification() throws Exception {
|
|
|
|
public void testNotification() throws Exception {
|
|
|
|
HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT +
|
|
|
|
HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT +
|
|
|
@ -207,4 +230,12 @@ public class AndroidOperation extends TestBase {
|
|
|
|
Constants.AndroidOperations.WEB_CLIP_PAYLOAD);
|
|
|
|
Constants.AndroidOperations.WEB_CLIP_PAYLOAD);
|
|
|
|
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
|
|
|
|
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}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|