Merge pull request #272 from menakaj/master

Integration Tests : Fixed Android Enrollment flow.
application-manager-new
Ayyoob Hamza 8 years ago committed by GitHub
commit 83f4b392a8

@ -24,7 +24,7 @@ import java.io.File;
*/ */
public final class Constants { 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 NUMBER_NOT_EQUAL_TO_DEVICE_ID = "1111";
public static final String DEVICE_IMEI = "123123123"; public static final String DEVICE_IMEI = "123123123";
public static final String AUTOMATION_CONTEXT = "IOT"; public static final String AUTOMATION_CONTEXT = "IOT";
@ -33,6 +33,7 @@ public final class Constants {
public static final String OAUTH_CLIENT_ID = "client_id"; public static final String OAUTH_CLIENT_ID = "client_id";
public static final String OAUTH_CLIENT_SECRET = "client_secret"; public static final String OAUTH_CLIENT_SECRET = "client_secret";
public static final String OAUTH_ACCESS_TOKEN = "access_token"; public static final String OAUTH_ACCESS_TOKEN = "access_token";
public static final String SCOPE = "scope";
public static final String ANDROID_DEVICE_TYPE = "android"; public static final String ANDROID_DEVICE_TYPE = "android";
public static final String HTTP_METHOD_POST = "POST"; public static final String HTTP_METHOD_POST = "POST";
public static final String HTTP_METHOD_PUT = "PUT"; public static final String HTTP_METHOD_PUT = "PUT";
@ -61,6 +62,36 @@ public final class Constants {
+ " \"applicationName\":\"app_12345\",\n" + " \"isAllowedToAllDomains\":false,\n" + " \"applicationName\":\"app_12345\",\n" + " \"isAllowedToAllDomains\":false,\n"
+ " \"tags\":[\"android\", \"device_management\"],\n" + " \"isMappingAnExistingOAuthApp\":false\n" + " \"tags\":[\"android\", \"device_management\"],\n" + " \"isMappingAnExistingOAuthApp\":false\n"
+ "}").toString(); + "}").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:dashboard:by-groups "
+ "perm:dashboard:count-overview perm:dashboard:details perm:dashboard:device-counts "
+ "perm:dashboard:feature-non-compliant perm:dashboard:filtered-count perm:dashboard:non-compliant "
+ "perm:dashboard:non-compliant-count perm:dashboard:vulnerabilities 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() { private APIApplicationRegistration() {
throw new AssertionError(); throw new AssertionError();
@ -202,6 +233,7 @@ public final class Constants {
public static final String VIEW_DEVICE_TYPES_ENDPOINT = "/mdm-admin/devices/types"; public static final String VIEW_DEVICE_TYPES_ENDPOINT = "/mdm-admin/devices/types";
public static final String VIEW_DEVICE_RESPONSE_PAYLOAD_FILE_NAME = public static final String VIEW_DEVICE_RESPONSE_PAYLOAD_FILE_NAME =
"mobile-device-mgt-view-device-types-response-payloads.json"; "mobile-device-mgt-view-device-types-response-payloads.json";
public static final String NO_DEVICE = "{\"devices\":[],\"count\":0}";
private MobileDeviceManagement() { private MobileDeviceManagement() {
throw new AssertionError(); throw new AssertionError();

@ -27,10 +27,17 @@ import org.wso2.carbon.automation.test.utils.http.client.HttpResponse;
*/ */
public class OAuthUtil { public class OAuthUtil {
public static String getOAuthToken(String backendHTTPURL, String backendHTTPSURL) public static String getScopes(String backendHTTPURL, String backendHTTPSURL) throws Exception {
throws Exception { return getOAuthTokenPair(backendHTTPURL, backendHTTPSURL).get(Constants.SCOPE).toString();
RestClient client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON); }
client.setHttpHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
public static String getOAuthToken(String backendHTTPURL, String backendHTTPSURL) throws Exception {
return getOAuthTokenPair(backendHTTPURL, backendHTTPSURL).get(Constants.OAUTH_ACCESS_TOKEN).toString();
}
public static JSONObject getOAuthTokenPair(String backendHTTPURL, String backendHTTPSURL) throws Exception {
String AuthString = "Basic YWRtaW46YWRtaW4=";
RestClient client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON, AuthString);
HttpResponse oAuthData = client.post(Constants.APIApplicationRegistration.API_APP_REGISTRATION_ENDPOINT, HttpResponse oAuthData = client.post(Constants.APIApplicationRegistration.API_APP_REGISTRATION_ENDPOINT,
Constants.APIApplicationRegistration.API_APP_REGISTRATION_PAYLOAD); Constants.APIApplicationRegistration.API_APP_REGISTRATION_PAYLOAD);
JSONObject jsonObj = new JSONObject(oAuthData.getData()); JSONObject jsonObj = new JSONObject(oAuthData.getData());
@ -44,6 +51,6 @@ public class OAuthUtil {
Constants.APIApplicationRegistration.OAUTH_TOKEN_PAYLOAD); Constants.APIApplicationRegistration.OAUTH_TOKEN_PAYLOAD);
System.out.println(oAuthData.getData()); System.out.println(oAuthData.getData());
jsonObj = new JSONObject(oAuthData.getData()); jsonObj = new JSONObject(oAuthData.getData());
return jsonObj.get(Constants.OAUTH_ACCESS_TOKEN).toString(); return jsonObj;
} }
} }

@ -17,11 +17,13 @@
*/ */
package org.wso2.iot.integration.common; package org.wso2.iot.integration.common;
import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException;
import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil;
import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; import org.wso2.carbon.automation.test.utils.http.client.HttpResponse;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException; import java.net.ProtocolException;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -73,7 +75,7 @@ public class RestClient {
this.requestHeaders.remove(headerName); this.requestHeaders.remove(headerName);
} }
public HttpResponse post(String endpoint, String body) throws Exception { public HttpResponse post(String endpoint, String body) throws MalformedURLException, AutomationFrameworkException {
return HttpRequestUtil.doPost(new URL(backEndUrl + endpoint), body, requestHeaders); return HttpRequestUtil.doPost(new URL(backEndUrl + endpoint), body, requestHeaders);
} }

@ -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.AutomationContext;
import org.wso2.carbon.automation.engine.context.TestUserMode; 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.automation.engine.frameworkutils.FrameworkPathUtil;
import org.wso2.carbon.integration.common.utils.LoginLogoutClient; 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. * This is the base test class that provides common details necessary for other test cases.
*/ */
public class TestBase { public class TestBase {
static String accessToken;
protected AutomationContext automationContext; protected AutomationContext automationContext;
protected String backendHTTPSURL; protected String backendHTTPSURL;
protected String backendHTTPURL; protected String backendHTTPURL;

@ -17,7 +17,9 @@
*/ */
package org.wso2.iot.integration.device.enrollment; package org.wso2.iot.integration.device.enrollment;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import junit.framework.Assert; import junit.framework.Assert;
import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.HttpStatus;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
@ -32,8 +34,10 @@ import org.wso2.iot.integration.common.*;
*/ */
public class AndroidEnrollment extends TestBase { public class AndroidEnrollment extends TestBase {
private RestClient client; 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 { public void initTest() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN); super.init(TestUserMode.SUPER_TENANT_ADMIN);
String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL); String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL);
@ -42,17 +46,23 @@ public class AndroidEnrollment extends TestBase {
@Test(description = "Test an Android device enrollment.") @Test(description = "Test an Android device enrollment.")
public void testEnrollment() throws Exception { public void testEnrollment() throws Exception {
String enrollmentData = PayloadGenerator.getJsonPayloadToString(Constants.AndroidEnrollment String enrollmentData = PayloadGenerator.getJsonPayload(Constants.AndroidEnrollment
.ENROLLMENT_PAYLOAD_FILE_NAME); .ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST).toString();
HttpResponse response = client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData); 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()); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayloadToString( AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(
Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME), response.getData(), true); 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"}) @Test(description = "Test an Android device is enrolled.", dependsOnMethods = {"testEnrollment"})
public void testIsEnrolled() throws Exception { 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()); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(
Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME,
@ -64,21 +74,19 @@ public class AndroidEnrollment extends TestBase {
JsonObject enrollmentData = PayloadGenerator.getJsonPayload( JsonObject enrollmentData = PayloadGenerator.getJsonPayload(
Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME,
Constants.HTTP_METHOD_PUT); Constants.HTTP_METHOD_PUT);
enrollmentData.addProperty(Constants.DEVICE_IDENTIFIER_KEY, Constants.DEVICE_ID); HttpResponse response = client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId,
HttpResponse response = client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + Constants.DEVICE_ID,
enrollmentData.toString()); enrollmentData.toString());
AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(
Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME,
Constants.HTTP_METHOD_PUT).toString(), response.getData(), true); 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 { 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()); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(
Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME,
Constants.HTTP_METHOD_DELETE).toString(), Constants.HTTP_METHOD_DELETE).toString(), response.getData(), true);
response.getData(), true);
} }
} }

@ -41,8 +41,7 @@ public class MobileDeviceManagement extends TestBase {
@Test(description = "Add an Android device.") @Test(description = "Add an Android device.")
public void addEnrollment() throws Exception { public void addEnrollment() throws Exception {
JsonObject enrollmentData = PayloadGenerator.getJsonPayload( JsonObject enrollmentData = PayloadGenerator.getJsonPayload(
Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST);
Constants.HTTP_METHOD_POST);
enrollmentData.addProperty(Constants.DEVICE_IDENTIFIER_KEY, Constants.DEVICE_ID); enrollmentData.addProperty(Constants.DEVICE_IDENTIFIER_KEY, Constants.DEVICE_ID);
IOTResponse response = client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData.toString()); IOTResponse response = client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData.toString());
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
@ -55,7 +54,7 @@ public class MobileDeviceManagement extends TestBase {
public void testCountDevices() throws Exception { public void testCountDevices() throws Exception {
IOTResponse response = client.get(Constants.MobileDeviceManagement.GET_DEVICE_COUNT_ENDPOINT); IOTResponse response = client.get(Constants.MobileDeviceManagement.GET_DEVICE_COUNT_ENDPOINT);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
Assert.assertTrue(response.getBody().toString().equals(Constants.MobileDeviceManagement.NO_OF_DEVICES)); Assert.assertTrue(response.getBody().equals(Constants.MobileDeviceManagement.NO_OF_DEVICES));
} }

@ -20,20 +20,40 @@ package org.wso2.iot.integration.mobileDevice;
import junit.framework.Assert; import junit.framework.Assert;
import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.HttpStatus;
import org.junit.experimental.theories.Theories;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.iot.integration.common.*; 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. * This class contains integration tests for API Mobile Device Management with No Devices Enrolled.
*/ */
public class MobileDeviceManagementWithNoDevices extends TestBase { public class MobileDeviceManagementWithNoDevices extends TestBase {
private IOTHttpClient client; private IOTHttpClient client;
/**
* @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
*/
@BeforeSuite
public void verifyApiPublishing() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
while (!checkScopes(Constants.APIApplicationRegistration.PERMISSION_LIST)) {
TimeUnit.SECONDS.sleep(5);
}
}
@BeforeClass(alwaysRun = true, groups = { Constants.MobileDeviceManagement.MOBILE_DEVICE_MANAGEMENT_GROUP}) @BeforeClass(alwaysRun = true, groups = { Constants.MobileDeviceManagement.MOBILE_DEVICE_MANAGEMENT_GROUP})
public void initTest() throws Exception { public void initTest() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL); String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL);
this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
} }
@ -42,14 +62,12 @@ public class MobileDeviceManagementWithNoDevices extends TestBase {
public void testCountDevicesWithNoDevices() throws Exception { public void testCountDevicesWithNoDevices() throws Exception {
IOTResponse response = client.get(Constants.MobileDeviceManagement.GET_DEVICE_COUNT_ENDPOINT); IOTResponse response = client.get(Constants.MobileDeviceManagement.GET_DEVICE_COUNT_ENDPOINT);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); 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") private boolean checkScopes(String permissionsList) throws Exception {
// public void testViewDevicesWithNoDevices() throws Exception { String tokenString = OAuthUtil.getScopes(backendHTTPSURL, backendHTTPSURL);
// IOTResponse response = client.get(Constants.MobileDeviceManagement.GET_ALL_DEVICES_ENDPOINT); return tokenString.contains(permissionsList);
// 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 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 Change this to standalone|platform|all to execute test on specific environment
--> -->

@ -1,4 +1,5 @@
{ {
"POST": {
"id": 101234, "id": 101234,
"name": "androiddevice1234", "name": "androiddevice1234",
"type": "android", "type": "android",
@ -89,4 +90,97 @@
"memoryUsage": 0 "memoryUsage": 0
} }
] ]
},
"PUT": {
"id": 101234,
"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"
},
"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 @@
{ {
"POST": {
"responseCode": "OK", "responseCode": "OK",
"responseMessage": "Android device, which carries the id \u0027d24f870f390352a41\u0027 has successfully been enrolled" "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"
}
} }

@ -0,0 +1,3 @@
{
"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:dashboard:by-groups perm:dashboard:count-overview perm:dashboard:details perm:dashboard:device-counts perm:dashboard:feature-non-compliant perm:dashboard:filtered-count perm:dashboard:non-compliant perm:dashboard:non-compliant-count perm:dashboard:vulnerabilities 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"
}

@ -18,24 +18,16 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="mdm-suite-initializer"> <suite name="iot-suite-initializer">
<parameter name="useDefaultListeners" value="false"/> <parameter name="useDefaultListeners" value="false"/>
<listeners> <listeners>
<listener <listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestExecutionListener"/>
class-name="org.wso2.carbon.automation.engine.testlisteners.TestExecutionListener"/>
<listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestManagerListener"/> <listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestManagerListener"/>
<listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestReportListener"/> <listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestReportListener"/>
<listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestSuiteListener"/> <listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestSuiteListener"/>
<listener <listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestTransformerListener"/>
class-name="org.wso2.carbon.automation.engine.testlisteners.TestTransformerListener"/>
</listeners> </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"> <test name="mobile-device-mgt-no-devices" preserve-order="true" parallel="false">
<classes> <classes>
<class name="org.wso2.iot.integration.mobileDevice.MobileDeviceManagementWithNoDevices"/> <class name="org.wso2.iot.integration.mobileDevice.MobileDeviceManagementWithNoDevices"/>

@ -1529,14 +1529,14 @@
<carbon.governance.version>4.7.0</carbon.governance.version> <carbon.governance.version>4.7.0</carbon.governance.version>
<!-- Carbon Device Management --> <!-- Carbon Device Management -->
<carbon.device.mgt.version>2.0.11-SNAPSHOT</carbon.device.mgt.version> <carbon.device.mgt.version>2.0.11</carbon.device.mgt.version>
<carbon.device.mgt.version.range>[2.0.0, 3.0.0)</carbon.device.mgt.version.range> <carbon.device.mgt.version.range>[2.0.0, 3.0.0)</carbon.device.mgt.version.range>
<!-- IOT Device Management --> <!-- IOT Device Management -->
<product.iot.version>3.1.0-SNAPSHOT</product.iot.version> <product.iot.version>3.1.0-SNAPSHOT</product.iot.version>
<!-- Carbon Device Management Plugins--> <!-- Carbon Device Management Plugins-->
<carbon.device.mgt.plugin.version>3.0.9-SNAPSHOT</carbon.device.mgt.plugin.version> <carbon.device.mgt.plugin.version>3.0.8</carbon.device.mgt.plugin.version>
<!-- API Management --> <!-- API Management -->
<carbon.api.mgt.version>6.1.35</carbon.api.mgt.version> <carbon.api.mgt.version>6.1.35</carbon.api.mgt.version>

Loading…
Cancel
Save