Merge branch 'backend-integration'

# Conflicts:
#	modules/integration/tests-integration-old/src/test/java/org/wso2/mdm/integration/common/MDMHttpClient.java
#	modules/integration/tests-integration-old/src/test/java/org/wso2/mdm/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java
#	modules/integration/tests-integration/src/test/resources/automation.xml
#	modules/integration/tests-integration/src/test/resources/testng.xml
merge-requests/1/head
Menaka Jayawardena 8 years ago
commit 5d41fe313b

@ -21,7 +21,7 @@
<parent> <parent>
<groupId>org.wso2.iot</groupId> <groupId>org.wso2.iot</groupId>
<artifactId>wso2iot-parent</artifactId> <artifactId>wso2iot-parent</artifactId>
<version>3.1.0-SNAPSHOT</version> <version>3.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>

@ -21,7 +21,7 @@
<parent> <parent>
<groupId>org.wso2.iot</groupId> <groupId>org.wso2.iot</groupId>
<artifactId>wso2iot-integration</artifactId> <artifactId>wso2iot-integration</artifactId>
<version>3.1.0-SNAPSHOT</version> <version>3.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

@ -21,7 +21,7 @@
<parent> <parent>
<groupId>org.wso2.iot</groupId> <groupId>org.wso2.iot</groupId>
<artifactId>wso2iot-integration</artifactId> <artifactId>wso2iot-integration</artifactId>
<version>3.1.0-SNAPSHOT</version> <version>3.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

@ -22,7 +22,7 @@
<parent> <parent>
<groupId>org.wso2.iot</groupId> <groupId>org.wso2.iot</groupId>
<artifactId>tests-common</artifactId> <artifactId>tests-common</artifactId>
<version>3.1.0-SNAPSHOT</version> <version>3.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

@ -27,7 +27,7 @@ public final class Constants {
public static final String DEVICE_ID = "1234"; public static final String DEVICE_ID = "1234";
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 = "MDM"; public static final String AUTOMATION_CONTEXT = "IOT";
public static final String APPLICATION_JSON = "application/json"; public static final String APPLICATION_JSON = "application/json";
public static final String APPLICATION_URL_ENCODED = "application/x-www-form-urlencoded"; public static final String APPLICATION_URL_ENCODED = "application/x-www-form-urlencoded";
public static final String OAUTH_CLIENT_ID = "client_id"; public static final String OAUTH_CLIENT_ID = "client_id";
@ -46,16 +46,23 @@ public final class Constants {
public static final String ZERO = "0"; public static final String ZERO = "0";
public static final String NULL = "[]"; public static final String NULL = "[]";
public static final class DynamicClientAuthentication { public static final String HTTPS = "https";
public static final String REGISTRATION_ENDPOINT = "/dynamic-client-web/register"; public static final String HTTP = "http";
public static final String TOKEN_ENDPOINT = "/oauth2/token";
public static final String OAUTH_TOKEN_PAYLOAD = "grant_type=password&username=admin&password=admin&scope=prod"; public static final int HTTPS_GATEWAY_PORT = 8243;
public static final int HTTP_GATEWAY_PORT = 8280;
public static final class APIApplicationRegistration {
public static final String API_APP_REGISTRATION_ENDPOINT = "/api-application-registration/register";
public static final String TOKEN_ENDPOINT = "/token";
public static final String OAUTH_TOKEN_PAYLOAD = "username=admin&password=admin&grant_type=password&scope=perm:android:enroll perm:android:wipe perm:android:ring perm:android:lock-devices perm:android:configure-vpn perm:android:configure-wifi perm:android:enroll perm:android:uninstall-application perm:android:manage-configuration perm:android:location perm:android:install-application perm:android:mute perm:android:change-lock-code perm:android:blacklist-applications perm:android:set-password-policy perm:android:encrypt-storage perm:android:clear-password perm:android:enterprise-wipe perm:android:info perm:android:view-configuration perm:android:upgrade-firmware perm:android:set-webclip perm:android:send-notification perm:android:disenroll perm:android:update-application perm:android:unlock-devices perm:android:control-camera perm:android:reboot perm:android:logcat appm:subscribe perm:sign-csr perm:admin:devices:view perm:roles:add perm:roles:add-users perm:roles:update perm:roles:permissions perm:roles:details perm:roles:view perm:roles:create-combined-role perm:roles:delete perm:dashboard:vulnerabilities perm:dashboard:non-compliant-count perm:dashboard:non-compliant perm:dashboard:by-groups perm:dashboard:device-counts perm:dashboard:feature-non-compliant perm:dashboard:count-overview perm:dashboard:filtered-count perm:dashboard:details perm:get-activity perm:devices:delete perm:devices:applications perm:devices:effective-policy perm:devices:compliance-data perm:devices:features perm:devices:operations perm:devices:search perm:devices:details perm:devices:update perm:devices:view perm:view-configuration perm:manage-configuration perm:policies:remove perm:policies:priorities perm:policies:deactivate perm:policies:get-policy-details perm:policies:manage perm:policies:activate perm:policies:update perm:policies:changes perm:policies:get-details perm:users:add perm:users:details perm:users:count perm:users:delete perm:users:roles perm:users:user-details perm:users:credentials perm:users:search perm:users:is-exist perm:users:update perm:users:send-invitation perm:admin-users:view perm:groups:devices perm:groups:update perm:groups:add perm:groups:device perm:groups:devices-count perm:groups:remove perm:groups:groups perm:groups:groups-view perm:groups:share perm:groups:count perm:groups:roles perm:groups:devices-remove perm:groups:devices-add perm:groups:assign perm:device-types:features perm:device-types:types perm:applications:install perm:applications:uninstall perm:admin-groups:count perm:admin-groups:view perm:notifications:mark-checked perm:notifications:view perm:admin:certificates:delete perm:admin:certificates:details perm:admin:certificates:view perm:admin:certificates:add perm:admin:certificates:verify perm:ios:enroll perm:ios:view-device perm:ios:apn perm:ios:ldap perm:ios:enterprise-app perm:ios:store-application perm:ios:remove-application perm:ios:app-list perm:ios:profile-list perm:ios:lock perm:ios:enterprise-wipe perm:ios:device-info perm:ios:restriction perm:ios:email perm:ios:cellular perm:ios:applications perm:ios:wifi perm:ios:ring perm:ios:location perm:ios:notification perm:ios:airplay perm:ios:caldav perm:ios:cal-subscription perm:ios:passcode-policy perm:ios:webclip perm:ios:vpn perm:ios:per-app-vpn perm:ios:app-to-per-app-vpn perm:ios:app-lock perm:ios:clear-passcode perm:ios:remove-profile perm:ios:get-restrictions perm:ios:wipe-data perm:admin";
private static StringBuffer dynamicClientPayloadBuffer = new StringBuffer(); private static StringBuffer dynamicClientPayloadBuffer = new StringBuffer();
public static final String DYNAMIC_CLIENT_REGISTRATION_PAYLOAD = dynamicClientPayloadBuffer.append("{\"clientName\":"). public static final String API_APP_REGISTRATION_PAYLOAD = dynamicClientPayloadBuffer.append("{ \n"
append(" \"device\",\"owner\": \"admin\",\"grantType\": \"password\",\"callbackUrl\": \"www.google.lk\"," + + " \"applicationName\":\"app_12345\",\n" + " \"isAllowedToAllDomains\":false,\n"
"\"saasApp\": \"" + true + "\"}").toString(); + " \"tags\":[\"android\", \"device_management\"],\n" + " \"isMappingAnExistingOAuthApp\":false\n"
+ "}").toString();
private DynamicClientAuthentication() { private APIApplicationRegistration() {
throw new AssertionError(); throw new AssertionError();
} }
} }
@ -63,7 +70,7 @@ public final class Constants {
public static final class AndroidEnrollment { public static final class AndroidEnrollment {
public static final String ENROLLMENT_PAYLOAD_FILE_NAME = "android-enrollment-payloads.json"; public static final String ENROLLMENT_PAYLOAD_FILE_NAME = "android-enrollment-payloads.json";
public static final String ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME = "android-enrollment-response-payloads.json"; public static final String ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME = "android-enrollment-response-payloads.json";
public static final String ENROLLMENT_ENDPOINT = "/mdm-android-agent/enrollment/"; public static final String ENROLLMENT_ENDPOINT = "/api/device-mgt/android/v1.0/devices";
public static final String ENROLLMENT_GROUP = "android-enrollment"; public static final String ENROLLMENT_GROUP = "android-enrollment";
private AndroidEnrollment() { private AndroidEnrollment() {
@ -189,7 +196,7 @@ public final class Constants {
public static final class MobileDeviceManagement { public static final class MobileDeviceManagement {
public static final String MOBILE_DEVICE_MANAGEMENT_GROUP = "mobile-device-mgt"; public static final String MOBILE_DEVICE_MANAGEMENT_GROUP = "mobile-device-mgt";
public static final String GET_DEVICE_COUNT_ENDPOINT = "/mdm-admin/devices/count"; public static final String GET_DEVICE_COUNT_ENDPOINT = "/api/device-mgt/v1.0/devices";
public static final String NO_OF_DEVICES = "1"; public static final String NO_OF_DEVICES = "1";
public static final String GET_ALL_DEVICES_ENDPOINT = "/mdm-admin/devices"; public static final String GET_ALL_DEVICES_ENDPOINT = "/mdm-admin/devices";
public static final String VIEW_DEVICE_TYPES_ENDPOINT = "/mdm-admin/devices/types"; public static final String VIEW_DEVICE_TYPES_ENDPOINT = "/mdm-admin/devices/types";

@ -15,7 +15,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.wso2.mdm.integration.common; package org.wso2.iot.integration.common;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
@ -27,42 +27,39 @@ import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.automation.engine.context.AutomationContext;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import java.io.IOException; import java.io.IOException;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
/** /**
* This class creates a customised Http Client Class * This class creates a customised Http Client Class
*/ */
public class MDMHttpClient { public class IOTHttpClient {
private static final String AUTHORIZATION = "Authorization"; private static final String AUTHORIZATION = "Authorization";
private static Log log = LogFactory.getLog(MDMHttpClient.class); private static Log log = LogFactory.getLog(IOTHttpClient.class);
private String backEndUrl; private String backEndUrl;
private String authrizationString; private String authorizationString;
private Map<String, String> requestHeaders = new HashMap<String, String>(); private Map<String, String> requestHeaders = new HashMap<String, String>();
public MDMHttpClient(String backEndUrl, String contentType, String authorization) { public IOTHttpClient(String backEndUrl, String contentType, String authorization) {
this.backEndUrl = backEndUrl; this.backEndUrl = backEndUrl;
this.requestHeaders.put(Constants.CONTENT_TYPE, contentType); this.requestHeaders.put(Constants.CONTENT_TYPE, contentType);
if (authorization != null || !authorization.isEmpty()) { if (authorization != null || !authorization.isEmpty()) {
this.authrizationString = authorization; this.authorizationString = authorization;
this.requestHeaders.put(AUTHORIZATION, authorization); this.requestHeaders.put(AUTHORIZATION, authorization);
} }
} }
public String getAuthrizationString() { public String getAuthorizationString() {
return authrizationString; return authorizationString;
} }
public void setAuthrizationString(String authrizationString) { public void setAuthorizationString(String authorizationString) {
this.authrizationString = authrizationString; this.authorizationString = authorizationString;
} }
public void setHttpHeader(String headerName, String value) { public void setHttpHeader(String headerName, String value) {
@ -77,108 +74,108 @@ public class MDMHttpClient {
this.requestHeaders.remove(headerName); this.requestHeaders.remove(headerName);
} }
public MDMResponse post(String endpoint, String body) { public IOTResponse post(String endpoint, String body) {
HttpClient client = new HttpClient(); HttpClient client = new HttpClient();
try { try {
ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory(); ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
Protocol https = new Protocol("https", socketFactory, 9443); Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT);
Protocol.registerProtocol("https", https); Protocol.registerProtocol(Constants.HTTPS, https);
String url = backEndUrl + endpoint; String url = backEndUrl + endpoint;
PostMethod method = new PostMethod(url); PostMethod method = new PostMethod(url);
method.setRequestHeader(AUTHORIZATION, authrizationString); method.setRequestHeader(AUTHORIZATION, authorizationString);
StringRequestEntity requestEntity = new StringRequestEntity(body, StringRequestEntity requestEntity = new StringRequestEntity(body,
requestHeaders.get(Constants.CONTENT_TYPE), Constants.UTF8); requestHeaders.get(Constants.CONTENT_TYPE), Constants.UTF8);
method.setRequestEntity(requestEntity); method.setRequestEntity(requestEntity);
MDMResponse mdmResponse = new MDMResponse(); IOTResponse iotResponse = new IOTResponse();
mdmResponse.setStatus(client.executeMethod(method)); iotResponse.setStatus(client.executeMethod(method));
mdmResponse.setBody(method.getResponseBodyAsString()); iotResponse.setBody(method.getResponseBodyAsString());
return mdmResponse; return iotResponse;
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
log.error("Failure occurred at MDMResponse post for GeneralSecurityException", e); log.error("Failure occurred at IOTResponse post for GeneralSecurityException", e);
} catch (IOException e) { } catch (IOException e) {
log.error("Failure occured at MDMResponse post for IOException", e); log.error("Failure occurred at IOTResponse post for IOException", e);
} }
return null; return null;
} }
public MDMResponse put(String endpoint, String body) { public IOTResponse put(String endpoint, String body) {
HttpClient client = new HttpClient(); HttpClient client = new HttpClient();
try { try {
ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory(); ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
Protocol https = new Protocol("https", socketFactory, 9443); Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT);
Protocol.registerProtocol("https", https); Protocol.registerProtocol(Constants.HTTPS, https);
String url = backEndUrl + endpoint; String url = backEndUrl + endpoint;
PutMethod method = new PutMethod(url); PutMethod method = new PutMethod(url);
method.setRequestHeader(AUTHORIZATION, authrizationString); method.setRequestHeader(AUTHORIZATION, authorizationString);
StringRequestEntity requestEntity = new StringRequestEntity( StringRequestEntity requestEntity = new StringRequestEntity(
body, requestHeaders.get(Constants.CONTENT_TYPE), Constants.UTF8); body, requestHeaders.get(Constants.CONTENT_TYPE), Constants.UTF8);
method.setRequestEntity(requestEntity); method.setRequestEntity(requestEntity);
MDMResponse mdmResponse = new MDMResponse(); IOTResponse iotResponse = new IOTResponse();
mdmResponse.setStatus(client.executeMethod(method)); iotResponse.setStatus(client.executeMethod(method));
mdmResponse.setBody(method.getResponseBodyAsString()); iotResponse.setBody(method.getResponseBodyAsString());
return mdmResponse; return iotResponse;
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
log.error("Failure occurred at MDMResponse put for GeneralSecurityException", e); log.error("Failure occurred at IOTResponse put for GeneralSecurityException", e);
} catch (IOException e) { } catch (IOException e) {
log.error("Failure occurred at MDMResponse put for IO Exception", e); log.error("Failure occurred at IOTResponse put for IO Exception", e);
} }
return null; return null;
} }
public MDMResponse get(String endpoint) { public IOTResponse get(String endpoint) {
HttpClient client = new HttpClient(); HttpClient client = new HttpClient();
try { try {
ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory(); ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
Protocol https = new Protocol("https", socketFactory, 9443); Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT);
Protocol.registerProtocol("https", https); Protocol.registerProtocol(Constants.HTTPS, https);
String url = backEndUrl + endpoint; String url = backEndUrl + endpoint;
GetMethod method = new GetMethod(url); GetMethod method = new GetMethod(url);
method.setRequestHeader(AUTHORIZATION, authrizationString); method.setRequestHeader(AUTHORIZATION, authorizationString);
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false)); new DefaultHttpMethodRetryHandler(3, false));
MDMResponse mdmResponse = new MDMResponse(); IOTResponse iotResponse = new IOTResponse();
mdmResponse.setStatus(client.executeMethod(method)); iotResponse.setStatus(client.executeMethod(method));
mdmResponse.setBody(new String(method.getResponseBody())); iotResponse.setBody(new String(method.getResponseBody()));
return mdmResponse; return iotResponse;
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
log.error("Failure occurred at MDMResponse get for GeneralSecurityException", e); log.error("Failure occurred at IOTResponse get for GeneralSecurityException", e);
} catch (IOException e) { } catch (IOException e) {
log.error("Failure occurred at MDMResponse get for IOException", e); log.error("Failure occurred at IOTResponse get for IOException", e);
} }
return null; return null;
} }
public MDMResponse delete(String endpoint) { public IOTResponse delete(String endpoint) {
HttpClient client = new HttpClient(); HttpClient client = new HttpClient();
try { try {
ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory(); ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
Protocol https = new Protocol("https", socketFactory, 9443); Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT);
Protocol.registerProtocol("https", https); Protocol.registerProtocol(Constants.HTTPS, https);
String url = backEndUrl + endpoint; String url = backEndUrl + endpoint;
DeleteMethod method = new DeleteMethod(url); DeleteMethod method = new DeleteMethod(url);
method.setRequestHeader(AUTHORIZATION, authrizationString); method.setRequestHeader(AUTHORIZATION, authorizationString);
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false)); new DefaultHttpMethodRetryHandler(3, false));
MDMResponse mdmResponse = new MDMResponse(); IOTResponse iotResponse = new IOTResponse();
mdmResponse.setStatus(client.executeMethod(method)); iotResponse.setStatus(client.executeMethod(method));
mdmResponse.setBody(method.getResponseBodyAsString()); iotResponse.setBody(method.getResponseBodyAsString());
return mdmResponse; return iotResponse;
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
log.error("Failure occurred at MDMResponse delete for GeneralSecurityException", e); log.error("Failure occurred at IOTResponse delete for GeneralSecurityException", e);
} catch (IOException e) { } catch (IOException e) {
log.error("Failure occurred at MDMResponse delete for IOException", e); log.error("Failure occurred at IOTResponse delete for IOException", e);
} }
return null; return null;
} }

@ -30,8 +30,9 @@ public class OAuthUtil {
public static String getOAuthToken(String backendHTTPURL, String backendHTTPSURL) public static String getOAuthToken(String backendHTTPURL, String backendHTTPSURL)
throws Exception { throws Exception {
RestClient client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON); RestClient client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON);
HttpResponse oAuthData = client.post(Constants.DynamicClientAuthentication.REGISTRATION_ENDPOINT, client.setHttpHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
Constants.DynamicClientAuthentication.DYNAMIC_CLIENT_REGISTRATION_PAYLOAD); HttpResponse oAuthData = client.post(Constants.APIApplicationRegistration.API_APP_REGISTRATION_ENDPOINT,
Constants.APIApplicationRegistration.API_APP_REGISTRATION_PAYLOAD);
JSONObject jsonObj = new JSONObject(oAuthData.getData()); JSONObject jsonObj = new JSONObject(oAuthData.getData());
String clientId = jsonObj.get(Constants.OAUTH_CLIENT_ID).toString(); String clientId = jsonObj.get(Constants.OAUTH_CLIENT_ID).toString();
String clientSecret = jsonObj.get(Constants.OAUTH_CLIENT_SECRET).toString(); String clientSecret = jsonObj.get(Constants.OAUTH_CLIENT_SECRET).toString();
@ -39,8 +40,9 @@ public class OAuthUtil {
String basicAuthString = "Basic " + new String(bytesEncoded); String basicAuthString = "Basic " + new String(bytesEncoded);
//Initiate a RestClient to get OAuth token //Initiate a RestClient to get OAuth token
client = new RestClient(backendHTTPSURL, Constants.APPLICATION_URL_ENCODED, basicAuthString); client = new RestClient(backendHTTPSURL, Constants.APPLICATION_URL_ENCODED, basicAuthString);
oAuthData = client.post(Constants.DynamicClientAuthentication.TOKEN_ENDPOINT, oAuthData = client.post(Constants.APIApplicationRegistration.TOKEN_ENDPOINT,
Constants.DynamicClientAuthentication.OAUTH_TOKEN_PAYLOAD); Constants.APIApplicationRegistration.OAUTH_TOKEN_PAYLOAD);
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.get(Constants.OAUTH_ACCESS_TOKEN).toString();
} }

@ -35,7 +35,7 @@ public class PayloadGenerator {
public static JsonObject getJsonPayload(String fileName, String method) public static JsonObject getJsonPayload(String fileName, String method)
throws FileNotFoundException { throws FileNotFoundException {
URL url = Thread.currentThread().getContextClassLoader().getResource(PAYLOAD_LOCATION + fileName); URL url = PayloadGenerator.class.getClassLoader().getResource(PAYLOAD_LOCATION + fileName);
JsonObject jsonObject = parser.parse(new FileReader(url.getPath())).getAsJsonObject(); JsonObject jsonObject = parser.parse(new FileReader(url.getPath())).getAsJsonObject();
return jsonObject.get(method).getAsJsonObject(); return jsonObject.get(method).getAsJsonObject();
} }

@ -19,6 +19,7 @@ package org.wso2.mdm.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;
@ -35,8 +36,10 @@ public class TestBase {
protected void init(TestUserMode userMode) throws Exception { protected void init(TestUserMode userMode) throws Exception {
automationContext = new AutomationContext(Constants.AUTOMATION_CONTEXT, userMode); automationContext = new AutomationContext(Constants.AUTOMATION_CONTEXT, userMode);
backendHTTPSURL = automationContext.getContextUrls().getWebAppURLHttps(); backendHTTPSURL = automationContext.getContextUrls().getWebAppURLHttps().replace("9443", String.valueOf(Constants
backendHTTPURL = automationContext.getContextUrls().getWebAppURL(); .HTTPS_GATEWAY_PORT));
backendHTTPURL = automationContext.getContextUrls().getWebAppURL().replace("9763", String.valueOf(Constants
.HTTP_GATEWAY_PORT));
} }
protected void initPublisher(String productGroupName, String instanceName, protected void initPublisher(String productGroupName, String instanceName,
@ -55,7 +58,7 @@ public class TestBase {
} }
protected String getBackendHTTPSURL() throws XPathExpressionException { protected String getBackendHTTPSURL() throws XPathExpressionException {
return automationContext.getContextUrls().getBackEndUrl(); return backendHTTPSURL;
} }
protected String getSessionCookie() throws Exception { protected String getSessionCookie() throws Exception {

@ -42,15 +42,12 @@ 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 {
JsonObject enrollmentData = PayloadGenerator.getJsonPayload( String enrollmentData = PayloadGenerator.getJsonPayloadToString(Constants.AndroidEnrollment
Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, .ENROLLMENT_PAYLOAD_FILE_NAME);
Constants.HTTP_METHOD_POST); HttpResponse response = client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData);
enrollmentData.addProperty(Constants.DEVICE_IDENTIFIER_KEY, Constants.DEVICE_ID);
HttpResponse response = client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData.toString());
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayloadToString(
Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME), response.getData(), true);
Constants.HTTP_METHOD_POST).toString(), response.getData().toString(), true);
} }
@Test(description = "Test an Android device is enrolled.", dependsOnMethods = {"testEnrollment"}) @Test(description = "Test an Android device is enrolled.", dependsOnMethods = {"testEnrollment"})
@ -59,7 +56,7 @@ public class AndroidEnrollment extends TestBase {
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_GET).toString(), response.getData().toString(), true); Constants.HTTP_METHOD_GET).toString(), response.getData(), true);
} }
@Test(description = "Test modify enrollment.", dependsOnMethods = {"testIsEnrolled"}) @Test(description = "Test modify enrollment.", dependsOnMethods = {"testIsEnrolled"})
@ -72,7 +69,7 @@ public class AndroidEnrollment extends TestBase {
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().toString(), true); Constants.HTTP_METHOD_PUT).toString(), response.getData(), true);
} }
@Test(description = "Test disenrollment.", dependsOnMethods = {"testModifyEnrollment"}) @Test(description = "Test disenrollment.", dependsOnMethods = {"testModifyEnrollment"})
@ -82,6 +79,6 @@ public class AndroidEnrollment extends TestBase {
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().toString(), true); response.getData(), true);
} }
} }

@ -1,45 +1,92 @@
{ {
"POST": { "id": 101234,
"name": "milan", "name": "androiddevice1234",
"type": "android", "type": "android",
"description": "milan123", "description": "this is an android device",
"deviceIdentifier": "1234", "deviceIdentifier": "d24f870f390352a41234",
"enrolmentInfo": { "enrolmentInfo": {
"ownership": "BYOD", "id": 101234,
"status": "ACTIVE", "device": {
"owner": "admin"
}, },
"properties": [ "dateOfEnrolment": 0,
{ "dateOfLastUpdate": 0,
"name": "IMEI", "ownership": "BYOD",
"value": "123123123" "status": "CREATED",
}, "owner": "admin"
{
"name": "IMSI",
"value": "123123123"
}
]
}, },
"PUT": { "features": [
"name": "milan123", {
"type": "android", "id": 10,
"description": "updatedDescription", "code": "aaaa1111",
"deviceIdentifier": "1234", "name": "newfeature1",
"enrolmentInfo": { "description": "this is the new feature 1",
"ownership": "BYOD", "deviceType": "android",
"status": "ACTIVE", "metadataEntries": [
"owner": "admin", {
"dateOfEnrolment": "1445438864650" "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"
},
"latitude": 0,
"longitude": 0,
"street1": "string",
"street2": "string",
"city": "string",
"state": "string",
"zip": "string",
"country": "string"
}, },
"properties": [ "deviceDetailsMap": {
{ },
"name": "IMEI", "imei": "string",
"value": "123123123" "imsi": "string"
},
"applications": [
{
"id": 0,
"platform": "string",
"category": "string",
"name": "string",
"locationUrl": "string",
"imageUrl": "string",
"version": "string",
"type": "string",
"appProperties": {
}, },
{ "applicationIdentifier": "string",
"name": "IMSI", "memoryUsage": 0
"value": "123123123" }
} ]
]
}
} }

@ -1,18 +1,4 @@
{ {
"POST": { "responseCode": "OK",
"responseCode": "Created", "responseMessage": "Android device, which carries the id \u0027d24f870f390352a41\u0027 has successfully been enrolled"
"responseMessage": "Device enrollment succeeded."
},
"PUT": {
"responseCode": "Accepted",
"responseMessage": "Device enrollment has updated successfully"
},
"GET": {
"responseCode": "Accepted",
"responseMessage": "Device has already enrolled"
},
"DELETE": {
"responseCode": "Accepted",
"responseMessage": "Device has removed successfully"
}
} }

@ -0,0 +1,4 @@
package org.wso2.iot.integration.util;
public class ServerRestart {
}

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. ~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ ~
~ WSO2 Inc. licenses this file to you under the Apache License, ~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except ~ Version 2.0 (the "License"); you may not use this file except
@ -16,8 +16,7 @@
~ specific language governing permissions and limitations ~ specific language governing permissions and limitations
~ under the License. ~ under the License.
--> -->
<automation xmlns="automationXMLSchema.xsd">
<automation xmlns="automationSchema.xsd">
<!-- ================================================= --> <!-- ================================================= -->
<!-- Parameters --> <!-- Parameters -->
<!-- ================================================= --> <!-- ================================================= -->
@ -25,15 +24,11 @@
<!-- <!--
Change this to edit wait time for test artifact deployment Change this to edit wait time for test artifact deployment
--> -->
<deploymentDelay>60000</deploymentDelay> <deploymentDelay>300000</deploymentDelay>
<!-- <!--
Change this to product|platform/cloud to execute test on specific environment Change this to standalone|platform|all to execute test on specific environment
--> -->
<executionEnvironment>standalone</executionEnvironment> <executionEnvironment>standalone</executionEnvironment>
<!--
Change this to user/tenant to execute test with user mode or tenant mode
-->
<multiTenantMode>false</multiTenantMode>
<!-- <!--
Change this to true if you want to generate coverage statistics Change this to true if you want to generate coverage statistics
--> -->
@ -50,7 +45,7 @@
<selenium> <selenium>
<!-- Change to enable remote webDriver --> <!-- Change to enable remote webDriver -->
<!-- URL of remote webDriver server --> <!-- URL of remote webDriver server -->
<remoteDriverUrl enable="true">http://10.100.2.51:4444/wd/hub/</remoteDriverUrl> <remoteDriverUrl enable="false">http://10.100.2.51:4444/wd/hub/</remoteDriverUrl>
<!-- Type of the browser selenium tests are running" --> <!-- Type of the browser selenium tests are running" -->
<browser> <browser>
@ -169,39 +164,35 @@
<!-- <!--
cluster instance details to be used to platform test execution cluster instance details to be used to platform test execution
--> -->
<productGroup name="MDM" clusteringEnabled="false" default="true"> <productGroup name="IOT" clusteringEnabled="false" default="true">
<instance name="mdm" type="standalone" nonBlockingTransportEnabled="false"> <instance name="iot001" type="standalone" nonBlockingTransportEnabled="false">
<hosts> <hosts>
<host type="default">localhost</host> <host type="default">localhost</host>
</hosts> </hosts>
<ports> <ports>
<port type="http">10863</port> <port type="http">9763</port>
<port type="https">10543</port> <!--<port type="https">9446</port>-->
<port type="https">9443</port>
<!--<port type="https">9445</port>-->
</ports> </ports>
<properties>
<properties>
<!--<property name="webContext">admin</property>-->
</properties> </properties>
</instance> </instance>
</productGroup> </productGroup>
</platform> </platform>
<listenerExtensions> <listenerExtensions>
<!--<className>org.wso2.carbon.automation.extentions.servers.wso2server.Wso2ServerExtention</className>-->
<platformExecutionManager> <platformExecutionManager>
<extentionClasses> <extentionClasses>
<class> <class>
<name> <!--<name>org.wso2.iot.integration.extensions.BrokerServerExtension</name>-->
org.wso2.carbon.automation.extensions.servers.carbonserver.CarbonServerExtension <name>org.wso2.iot.integration.extensions.IOTServerExtension</name>
</name> <!--<name>org.wso2.iot.integration.extensions.AnalyticsServerExtension</name>-->
<parameter name="-DportOffset" value="1100"/> <name>org.wso2.carbon.integration.common.extensions.usermgt.UserPopulateExtension</name>
<!--<parameter name="cmdArg" value="debug 5005" />-->
</class>
<class>
<name>
org.wso2.carbon.integration.common.extensions.usermgt.UserPopulateExtension
</name>
</class> </class>
</extentionClasses> </extentionClasses>
</platformExecutionManager> </platformExecutionManager>
@ -209,13 +200,13 @@
<PlatformSuiteManager> <PlatformSuiteManager>
<extentionClasses> <extentionClasses>
<!--<className>org.wso2.carbon.automation.extentions.servers.wso2server.Wso2ServerExtention</className>--> <!--<className>org.wso2.carbon.automation.extensions.servers.carbonserver.CarbonServerExtension</className>-->
</extentionClasses> </extentionClasses>
</PlatformSuiteManager> </PlatformSuiteManager>
<PlatformAnnotationTransferManager> <PlatformAnnotationTransferManager>
<extentionClasses> <extentionClasses>
<!--<className>org.wso2.carbon.automation.extentions.servers.wso2server.Wso2ServerExtention</className>--> <!--<className>org.wso2.carbon.automation.extensions.servers.carbonserver.CarbonServerExtension</className>-->
</extentionClasses> </extentionClasses>
</PlatformAnnotationTransferManager> </PlatformAnnotationTransferManager>

@ -1,5 +1,5 @@
<!-- <!--
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. ~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ ~
~ WSO2 Inc. licenses this file to you under the Apache License, ~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except ~ Version 2.0 (the "License"); you may not use this file except
@ -18,21 +18,95 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="DssTestSuite" parallel="false"> <suite name="mdm-suite-initializer">
<parameter name="useDefaultListeners" value="false"/> <parameter name="useDefaultListeners" value="false"/>
<listeners> <listeners>
<listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestExecutionListener"/> <listener
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 class-name="org.wso2.carbon.automation.engine.testlisteners.TestTransformerListener"/> <listener
class-name="org.wso2.carbon.automation.engine.testlisteners.TestTransformerListener"/>
</listeners> </listeners>
<test name="mobile-device-mgt-no-devices" preserve-order="true" parallel="false">
<test name="IOT-Integration-Test" parallel="false" verbose="2">
<classes> <classes>
<class name="org.wso2.iot.integration.mobileDevice.MobileDeviceManagementWithNoDevices"/>
</classes>
</test>
<test name="android-enrollment" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.device.enrollment.AndroidEnrollment"/>
</classes> </classes>
</test> </test>
<!--<test name="android-operation" preserve-order="false" parallel="true">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.device.operation.AndroidOperation"/>-->
<!--</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>-->
<!--</test>-->
<!--<test name="android-policy" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.device.policy.AndroidPolicy"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="operation-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.operation.OperationManagement"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="mobile-device-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.mobileDevice.MobileDeviceManagement"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="user-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.user.UserManagement"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="role-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.role.RoleManagement"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="policy-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.policy.PolicyManagement"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="feature-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.feature.FeatureManagement"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="license-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.license.LicenseManagement"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="configuration-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.configuration.ConfigurationManagement"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="notification-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.notification.NotificationManagement"/>-->
<!--</classes>-->
<!--</test>-->
</suite> </suite>

@ -20,7 +20,7 @@
<parent> <parent>
<groupId>org.wso2.iot</groupId> <groupId>org.wso2.iot</groupId>
<artifactId>wso2iot-integration</artifactId> <artifactId>wso2iot-integration</artifactId>
<version>3.1.0-SNAPSHOT</version> <version>3.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

Loading…
Cancel
Save