Fixed Mobile device management and Android Enrollment test flows.

application-manager-new
Menaka Jayawardena 8 years ago committed by susinda
parent cffb96bc93
commit 962623f257

@ -24,7 +24,7 @@ import java.io.File;
*/
public final class Constants {
public static final String DEVICE_ID = "1234";
public static final String DEVICE_ID = "24f870f390352a41234";
public static final String NUMBER_NOT_EQUAL_TO_DEVICE_ID = "1111";
public static final String DEVICE_IMEI = "123123123";
public static final String AUTOMATION_CONTEXT = "IOT";
@ -202,6 +202,7 @@ public final class Constants {
public static final String VIEW_DEVICE_TYPES_ENDPOINT = "/mdm-admin/devices/types";
public static final String VIEW_DEVICE_RESPONSE_PAYLOAD_FILE_NAME =
"mobile-device-mgt-view-device-types-response-payloads.json";
public static final String NO_DEVICE = "{\"devices\":[],\"count\":0}";
private MobileDeviceManagement() {
throw new AssertionError();

@ -29,8 +29,9 @@ public class OAuthUtil {
public static String getOAuthToken(String backendHTTPURL, String backendHTTPSURL)
throws Exception {
RestClient client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON);
client.setHttpHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
Thread.sleep(10000);
String AuthString = "Basic YWRtaW46YWRtaW4=";
RestClient client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON, AuthString);
HttpResponse oAuthData = client.post(Constants.APIApplicationRegistration.API_APP_REGISTRATION_ENDPOINT,
Constants.APIApplicationRegistration.API_APP_REGISTRATION_PAYLOAD);
JSONObject jsonObj = new JSONObject(oAuthData.getData());

@ -19,7 +19,6 @@ package org.wso2.iot.integration.common;
import org.wso2.carbon.automation.engine.context.AutomationContext;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.automation.engine.frameworkutils.CodeCoverageUtils;
import org.wso2.carbon.automation.engine.frameworkutils.FrameworkPathUtil;
import org.wso2.carbon.integration.common.utils.LoginLogoutClient;
@ -29,7 +28,6 @@ import javax.xml.xpath.XPathExpressionException;
* This is the base test class that provides common details necessary for other test cases.
*/
public class TestBase {
static String accessToken;
protected AutomationContext automationContext;
protected String backendHTTPSURL;
protected String backendHTTPURL;

@ -17,7 +17,9 @@
*/
package org.wso2.iot.integration.device.enrollment;
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.testng.annotations.BeforeClass;
@ -32,8 +34,10 @@ import org.wso2.iot.integration.common.*;
*/
public class AndroidEnrollment extends TestBase {
private RestClient client;
private String deviceId;
@BeforeClass(alwaysRun = true, groups = { Constants.AndroidEnrollment.ENROLLMENT_GROUP})
@BeforeClass(alwaysRun = true, groups = { Constants.AndroidEnrollment.ENROLLMENT_GROUP}, dependsOnGroups =
Constants.MobileDeviceManagement.MOBILE_DEVICE_MANAGEMENT_GROUP)
public void initTest() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL);
@ -42,17 +46,23 @@ public class AndroidEnrollment extends TestBase {
@Test(description = "Test an Android device enrollment.")
public void testEnrollment() throws Exception {
String enrollmentData = PayloadGenerator.getJsonPayloadToString(Constants.AndroidEnrollment
.ENROLLMENT_PAYLOAD_FILE_NAME);
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());
JsonObject jsonObject = element.getAsJsonObject();
JsonElement msg = jsonObject.get("responseMessage");
deviceId = msg.getAsString().split("\'")[1].split("\'")[0];
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayloadToString(
Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME), 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 + Constants.DEVICE_ID);
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,
@ -64,21 +74,19 @@ public class AndroidEnrollment extends TestBase {
JsonObject enrollmentData = PayloadGenerator.getJsonPayload(
Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME,
Constants.HTTP_METHOD_PUT);
enrollmentData.addProperty(Constants.DEVICE_IDENTIFIER_KEY, Constants.DEVICE_ID);
HttpResponse response = client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + Constants.DEVICE_ID,
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 disenrollment.", dependsOnMethods = {"testModifyEnrollment"})
@Test(description = "Test disEnrollment.", dependsOnMethods = {"testModifyEnrollment"})
public void testDisEnrollDevice() throws Exception {
HttpResponse response = client.delete(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + Constants.DEVICE_ID);
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);
Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME,
Constants.HTTP_METHOD_DELETE).toString(), response.getData(), true);
}
}

@ -20,11 +20,14 @@ 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.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.iot.integration.common.*;
import java.util.concurrent.TimeUnit;
/**
* This class contains integration tests for API Mobile Device Management with No Devices Enrolled.
*/
@ -34,6 +37,7 @@ public class MobileDeviceManagementWithNoDevices extends TestBase {
@BeforeClass(alwaysRun = true, groups = { Constants.MobileDeviceManagement.MOBILE_DEVICE_MANAGEMENT_GROUP})
public void initTest() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
Thread.sleep(10000);
String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL);
this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
}
@ -42,14 +46,8 @@ public class MobileDeviceManagementWithNoDevices extends TestBase {
public void testCountDevicesWithNoDevices() throws Exception {
IOTResponse response = client.get(Constants.MobileDeviceManagement.GET_DEVICE_COUNT_ENDPOINT);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
Assert.assertEquals(Constants.ZERO, response.getBody());
Assert.assertEquals(Constants.MobileDeviceManagement.NO_DEVICE, response.getBody());
}
// @Test(description = "Test view devices with no added devices")
// public void testViewDevicesWithNoDevices() throws Exception {
// IOTResponse response = client.get(Constants.MobileDeviceManagement.GET_ALL_DEVICES_ENDPOINT);
// Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
// Assert.assertEquals(response.getBody(), Constants.NULL);
// }
}

@ -1,92 +0,0 @@
package org.wso2.iot.integration.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.BeforeClass;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.integration.common.admin.client.LogViewerClient;
import org.wso2.carbon.integration.common.utils.exceptions.AutomationUtilException;
import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager;
import org.wso2.carbon.logging.view.stub.LogViewerLogViewerException;
import org.wso2.carbon.logging.view.stub.types.carbon.LogEvent;
import org.wso2.iot.integration.common.TestBase;
import javax.xml.xpath.XPathExpressionException;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import java.util.concurrent.*;
public class RestartTest extends TestBase {
private Log log = LogFactory.getLog(RestartTest.class);
private LogViewerClient logViewerClient;
@BeforeClass
public void initTest() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
logViewerClient = new LogViewerClient(getBackendHTTPSURL(), getSessionCookie());
}
@Test(description = "Test restarting the server")
public void serverRestartTest() {
ServerConfigurationManager serverManager;
try {
serverManager = new ServerConfigurationManager(automationContext);
log.info("Restart Triggered -------------------------------------------------------------------");
serverManager.restartGracefully();
logViewerClient.getAllRemoteSystemLogs();
waitForRestart();
} catch (AutomationUtilException | XPathExpressionException | MalformedURLException e) {
log.error("Restart failed due to : " + e.getLocalizedMessage());
} catch (RemoteException | LogViewerLogViewerException e) {
log.error("Cannot get server log due to : " + e.getLocalizedMessage());
}
}
/**
* Wait until the server restarts.
* This method looks for "Mgt console URL:" to be appeared in the terminal.
* If it does not appear within the given timeout an Exception will be thrown.
*/
private void waitForRestart() {
ExecutorService service = Executors.newSingleThreadExecutor();
try {
Runnable r = new Runnable() {
@Override
public void run() {
try {
LogEvent[] logEvents = logViewerClient.getAllRemoteSystemLogs();
for (LogEvent event : logEvents) {
log.info(event.getMessage() + " @ " + event.getLogTime());
if (event.getMessage().contains("Mgt Console URL : " )){
log.info("Server restarted successfully");
Assert.assertTrue(true);
}
}
} catch (RemoteException | LogViewerLogViewerException e) {
log.error("Error reading logs. \n" + e.getMessage());
Assert.assertTrue(false);
}
}
};
Future<?> f = service.submit(r);
f.get(30, TimeUnit.MINUTES);
} catch (final InterruptedException e) {
log.error("Interrupted "+e.getMessage());
Assert.assertTrue(false);
} catch (final TimeoutException e) {
log.error("Timeout " + e.getMessage());
Assert.assertTrue(false);
} catch (final ExecutionException e) {
log.error("Execution failed " + e.getMessage());
Assert.assertTrue(false);
} finally {
service.shutdown();
}
}
}

@ -24,7 +24,7 @@
<!--
Change this to edit wait time for test artifact deployment
-->
<deploymentDelay>300000</deploymentDelay>
<deploymentDelay>100000</deploymentDelay>
<!--
Change this to standalone|platform|all to execute test on specific environment
-->

@ -1,92 +1,186 @@
{
"id": 101234,
"name": "androiddevice1234",
"type": "android",
"description": "this is an android device",
"deviceIdentifier": "d24f870f390352a41234",
"enrolmentInfo": {
"POST": {
"id": 101234,
"device": {
"name": "androiddevice1234",
"type": "android",
"description": "this is an android device",
"deviceIdentifier": "d24f870f390352a41234",
"enrolmentInfo": {
"id": 101234,
"device": {
},
"dateOfEnrolment": 0,
"dateOfLastUpdate": 0,
"ownership": "BYOD",
"status": "CREATED",
"owner": "admin"
},
"dateOfEnrolment": 0,
"dateOfLastUpdate": 0,
"ownership": "BYOD",
"status": "CREATED",
"owner": "admin"
},
"features": [
{
"id": 10,
"code": "aaaa1111",
"name": "newfeature1",
"description": "this is the new feature 1",
"deviceType": "android",
"metadataEntries": [
{
"id": 10,
"value": {
"features": [
{
"id": 10,
"code": "aaaa1111",
"name": "newfeature1",
"description": "this is the new feature 1",
"deviceType": "android",
"metadataEntries": [
{
"id": 10,
"value": {
}
}
}
]
}
],
"properties": [
{
"name": "property1",
"value": "value1"
}
],
"deviceInfo": {
"deviceModel": "S8",
"vendor": "SAMSUNG",
"osVersion": "5.1",
"batteryLevel": 1,
"internalTotalMemory": 32,
"internalAvailableMemory": 24,
"externalTotalMemory": 64,
"externalAvailableMemory": 60,
"operator": "dialog",
"connectionType": "GSM",
"mobileSignalStrength": 1,
"ssid": "picassowifi",
"cpuUsage": 0,
"totalRAMMemory": 2,
"availableRAMMemory": 1,
"pluggedIn": false,
"location": {
"deviceId": 0,
"deviceIdentifier": {
"id": "string",
"type": "string"
]
}
],
"properties": [
{
"name": "property1",
"value": "value1"
}
],
"deviceInfo": {
"deviceModel": "S8",
"vendor": "SAMSUNG",
"osVersion": "5.1",
"batteryLevel": 1,
"internalTotalMemory": 32,
"internalAvailableMemory": 24,
"externalTotalMemory": 64,
"externalAvailableMemory": 60,
"operator": "dialog",
"connectionType": "GSM",
"mobileSignalStrength": 1,
"ssid": "picassowifi",
"cpuUsage": 0,
"totalRAMMemory": 2,
"availableRAMMemory": 1,
"pluggedIn": false,
"location": {
"deviceId": 0,
"deviceIdentifier": {
"id": "string",
"type": "string"
},
"latitude": 0,
"longitude": 0,
"street1": "string",
"street2": "string",
"city": "string",
"state": "string",
"zip": "string",
"country": "string"
},
"latitude": 0,
"longitude": 0,
"street1": "string",
"street2": "string",
"city": "string",
"state": "string",
"zip": "string",
"country": "string"
},
"deviceDetailsMap": {
"deviceDetailsMap": {
},
"imei": "string",
"imsi": "string"
},
"imei": "string",
"imsi": "string"
"applications": [
{
"id": 0,
"platform": "string",
"category": "string",
"name": "string",
"locationUrl": "string",
"imageUrl": "string",
"version": "string",
"type": "string",
"appProperties": {
},
"applicationIdentifier": "string",
"memoryUsage": 0
}
]
},
"applications": [
{
"id": 0,
"platform": "string",
"category": "string",
"name": "string",
"locationUrl": "string",
"imageUrl": "string",
"version": "string",
"type": "string",
"appProperties": {
"PUT": {
"id": 101234,
"name": "androiddevice1234",
"type": "android",
"description": "this is an android device",
"deviceIdentifier": "d24f870f390352a41234",
"enrolmentInfo": {
"id": 101234,
"device": {
},
"applicationIdentifier": "string",
"memoryUsage": 0
}
]
"dateOfEnrolment": 0,
"dateOfLastUpdate": 0,
"ownership": "BYOD",
"status": "CREATED",
"owner": "admin"
},
"features": [
{
"id": 10,
"code": "aaaa1111",
"name": "newfeature2",
"description": "this is the new feature 2",
"deviceType": "android",
"metadataEntries": [
{
"id": 10,
"value": {
}
}
]
}
],
"properties": [
{
"name": "property2",
"value": "value2"
}
],
"deviceInfo": {
"deviceModel": "S8",
"vendor": "SAMSUNG",
"osVersion": "5.1",
"batteryLevel": 1,
"internalTotalMemory": 32,
"internalAvailableMemory": 24,
"externalTotalMemory": 64,
"externalAvailableMemory": 60,
"operator": "dialog",
"connectionType": "GSM",
"mobileSignalStrength": 1,
"ssid": "picassowifi",
"cpuUsage": 0,
"totalRAMMemory": 2,
"availableRAMMemory": 1,
"pluggedIn": false,
"location": {
"deviceId": 0,
"deviceIdentifier": {
"id": "string",
"type": "string"
},
"latitude": 0,
"longitude": 0,
"street1": "string",
"street2": "string",
"city": "string",
"state": "string",
"zip": "string",
"country": "string"
},
"deviceDetailsMap": {
},
"imei": "string",
"imsi": "string"
},
"applications": [
{
"id": 0,
"platform": "string",
"category": "string",
"name": "string",
"locationUrl": "string",
"imageUrl": "string",
"version": "string",
"type": "string",
"appProperties": {
},
"applicationIdentifier": "string",
"memoryUsage": 0
}
]
}
}

@ -1,4 +1,19 @@
{
"responseCode": "OK",
"responseMessage": "Android device, which carries the id \u0027d24f870f390352a41\u0027 has successfully been enrolled"
"POST": {
"responseCode": "OK",
"responseMessage": "Android device, which carries the id \u0027d24f870f390352a41234\u0027 has successfully been enrolled"
},
"GET": {
"responseCode": "OK",
"responseMessage": "Android device that carries the id \u0027d24f870f390352a41234\u0027 is enrolled"
},
"PUT": {
"responseCode": "Accepted",
"responseMessage": "Enrollment of Android device that carries the id \u0027d24f870f390352a41234\u0027 has successfully updated"
},
"DELETE" : {
"responseCode":"OK",
"responseMessage":"Android device that carries id \u0027d24f870f390352a41234\u0027 has successfully dis-enrolled"
}
}

@ -30,12 +30,6 @@
class-name="org.wso2.carbon.automation.engine.testlisteners.TestTransformerListener"/>
</listeners>
<test name="Server restart test" preserve-order="true">
<classes>
<class name="org.wso2.iot.integration.util.RestartTest"/>
</classes>
</test>
<test name="mobile-device-mgt-no-devices" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.mobileDevice.MobileDeviceManagementWithNoDevices"/>

Loading…
Cancel
Save