Merge pull request #374 from Megala21/test_case_fixes

Adding initial test cases with j-meter scripts
merge-requests/1/head
Ayyoob Hamza 8 years ago committed by GitHub
commit 66be42a9ba

@ -207,6 +207,6 @@
</repository> </repository>
</repositories> </repositories>
<properties> <properties>
<carbon.device.mgt.plugin.version>3.0.22</carbon.device.mgt.plugin.version> <carbon.device.mgt.plugin.version>3.0.23</carbon.device.mgt.plugin.version>
</properties> </properties>
</project> </project>

@ -291,7 +291,12 @@ public final class Constants {
public static final String GET_DEVICE_COUNT_ENDPOINT = "/api/device-mgt/v1.0/devices"; public static final String GET_DEVICE_COUNT_ENDPOINT = "/api/device-mgt/v1.0/devices";
public static final String CHANGE_DEVICE_STATUS_ENDPOINT = "/api/device-mgt/v1.0/devices/"; public static final String CHANGE_DEVICE_STATUS_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 = "/api/device-mgt/v1.0/devices/";
public static final String USER_DEVICE_ENDPOINT = "user-devices";
public static final String ADVANCE_SEARCH_ENDPOINT = "search-devices";
public static final String ADVANCE_SEARCH_OPERATION = "ADVANCE_SEARCH";
public static final String REQUEST_PAYLOAD_FILE_NAME = "mobile-device-mgt-payloads.json";
public static final String UPDATE_PAYLOAD_OPERATION = "UPDATE_DEVICE_INFO";
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";

@ -265,6 +265,10 @@
<groupId>org.wso2.iot</groupId> <groupId>org.wso2.iot</groupId>
<artifactId>org.wso2.carbon.iot.integration.common</artifactId> <artifactId>org.wso2.carbon.iot.integration.common</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon.automation</groupId>
<artifactId>org.wso2.carbon.automation.extensions</artifactId>
</dependency>
</dependencies> </dependencies>
<properties> <properties>

@ -0,0 +1,58 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.iot.integration.jmeter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException;
import org.wso2.carbon.automation.extensions.jmeter.JMeterTest;
import org.wso2.carbon.automation.extensions.jmeter.JMeterTestManager;
import java.io.File;
import java.net.URL;
/**
* JMeter Test cases for AndroidDeviceManagement API.
*/
public class AndroidDeviceManagementAPIJmeterTestCase {
private static Log log = LogFactory.getLog(AndroidDeviceManagementAPIJmeterTestCase.class);
@Test()
public void permutationTest() throws AutomationFrameworkException {
URL url = Thread.currentThread().getContextClassLoader().getResource(
"jmeter-scripts/AndroidDeviceManagementAPIAdditionalPermutations.jmx");
JMeterTest script = new JMeterTest(
new File(url.getPath()));
JMeterTestManager manager = new JMeterTestManager();
log.info("Running permutation test using jmeter scripts");
manager.runTest(script);
}
@Test(dependsOnMethods = {"permutationTest"})
public void listServices() throws AutomationFrameworkException {
URL url = Thread.currentThread().getContextClassLoader().getResource(
"jmeter-scripts/NewAndroidDeviceManagementAPI.jmx");
JMeterTest script = new JMeterTest(
new File(url.getPath()));
JMeterTestManager manager = new JMeterTestManager();
log.info("Running API service test using jmeter scripts");
manager.runTest(script);
}
}

@ -17,67 +17,89 @@
*/ */
package org.wso2.iot.integration.mobileDevice; package org.wso2.iot.integration.mobileDevice;
import com.google.gson.JsonArray;
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;
import org.testng.annotations.Factory;
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.carbon.automation.test.utils.http.client.HttpResponse;
import org.wso2.iot.integration.common.*; import org.wso2.iot.integration.common.*;
/** /**
* This class contains integration tests for API Device management backend services. * This class contains integration tests for API Device management backend services.
*/ */
public class MobileDeviceManagement extends TestBase { public class MobileDeviceManagement extends TestBase {
private IOTHttpClient client; private RestClient client;
@BeforeClass(alwaysRun = true, groups = { Constants.MobileDeviceManagement.MOBILE_DEVICE_MANAGEMENT_GROUP}) @Factory(dataProvider = "userModeProvider")
public void initTest() throws Exception { public MobileDeviceManagement(TestUserMode userMode) {
super.init(TestUserMode.SUPER_TENANT_ADMIN); this.userMode = userMode;
String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL);
this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
} }
@Test(description = "Add an Android device.") @BeforeClass(alwaysRun = true, groups = { Constants.MobileDeviceManagement.MOBILE_DEVICE_MANAGEMENT_GROUP})
public void addEnrollment() throws Exception { public void initTest() throws Exception {
JsonObject enrollmentData = PayloadGenerator.getJsonPayload( super.init(userMode);
Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST); this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
JsonObject enrollmentData = PayloadGenerator
.getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, 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()); client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData.toString());
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(
Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME,
Constants.HTTP_METHOD_POST).toString(), response.getBody(), true);
}
@Test(dependsOnMethods = {"addEnrollment"}, description = "Test count devices")
public void testCountDevices() throws Exception {
IOTResponse response = client.get(Constants.MobileDeviceManagement.GET_DEVICE_COUNT_ENDPOINT);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
Assert.assertTrue(response.getBody().equals(Constants.MobileDeviceManagement.NO_OF_DEVICES));
} }
@Test(dependsOnMethods = {"addEnrollment"}, description = "Test view devices") @Test(description = "Test getting devices")
public void testViewDevices() throws Exception { public void testViewDevices() throws Exception {
IOTResponse response = client.get(Constants.MobileDeviceManagement.GET_ALL_DEVICES_ENDPOINT); int expectedCount = this.userMode == TestUserMode.TENANT_ADMIN ? 1 : 23;
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); HttpResponse response = client.get(Constants.MobileDeviceManagement.GET_ALL_DEVICES_ENDPOINT);
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
JsonObject devices = new JsonParser().parse(response.getData()).getAsJsonObject();
Assert.assertEquals("Expected device count is not received", expectedCount, devices.get("count").getAsInt());
} }
@Test(dependsOnMethods = {"addEnrollment"}, description = "Test view device types") @Test(description = "Test getting devices")
public void testViewDeviceTypes() throws Exception { public void testGetUserDevices() throws Exception {
IOTResponse response = client.get(Constants.MobileDeviceManagement.VIEW_DEVICE_TYPES_ENDPOINT); int expectedCount = this.userMode == TestUserMode.TENANT_ADMIN ? 1 : 13;
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); HttpResponse response = client.get(Constants.MobileDeviceManagement.GET_ALL_DEVICES_ENDPOINT
Assert.assertEquals(PayloadGenerator.getJsonPayloadToString + Constants.MobileDeviceManagement.USER_DEVICE_ENDPOINT);
(Constants.MobileDeviceManagement.VIEW_DEVICE_RESPONSE_PAYLOAD_FILE_NAME), response.getBody()); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
//Response has two device types, because in windows enrollment a windows device is previously enrolled. JsonObject devices = new JsonParser().parse(response.getData()).getAsJsonObject();
Assert.assertEquals("Expected device count is not received", expectedCount, devices.get("count").getAsInt());
} }
@Test(description = "Change device status") @Test(description = "Test Advance search")
public void testRemoveDevices() throws Exception { public void testAdvancedSearch() throws Exception {
String endpointUrl = Constants.MobileDeviceManagement.CHANGE_DEVICE_STATUS_ENDPOINT + Constants.ANDROID_DEVICE_TYPE JsonArray pendingOperationsData = PayloadGenerator
+ "/" + Constants.DEVICE_ID + "/changestatus?newStatus=" + Constants.INACTIVE; .getJsonArray(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME,
IOTResponse response = client.put(endpointUrl, ""); Constants.AndroidEnrollment.GET_PENDING_OPERATIONS_METHOD);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); JsonArray newPayload = new JsonArray();
HttpResponse response = client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + Constants.DEVICE_ID
+ "/pending-operations", pendingOperationsData.toString());
JsonArray pendingOperations = new JsonParser().parse(response.getData()).getAsJsonArray();
for (JsonElement pendingOperation : pendingOperations) {
JsonObject jsonObject = pendingOperation.getAsJsonObject();
if (jsonObject.get("code").getAsString().equals("DEVICE_INFO")) {
jsonObject.addProperty("operationResponse", PayloadGenerator
.getJsonPayload(Constants.MobileDeviceManagement.REQUEST_PAYLOAD_FILE_NAME,
Constants.MobileDeviceManagement.UPDATE_PAYLOAD_OPERATION).toString());
jsonObject.addProperty("status", "COMPLETED");
newPayload.add(jsonObject);
break;
}
}
client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + Constants.DEVICE_ID + "/pending-operations",
newPayload.toString());
response = client.post(Constants.MobileDeviceManagement.GET_ALL_DEVICES_ENDPOINT
+ Constants.MobileDeviceManagement.ADVANCE_SEARCH_ENDPOINT, PayloadGenerator
.getJsonPayload(Constants.MobileDeviceManagement.REQUEST_PAYLOAD_FILE_NAME,
Constants.MobileDeviceManagement.ADVANCE_SEARCH_OPERATION).toString());
JsonObject devices = new JsonParser().parse(response.getData()).getAsJsonObject();
Assert.assertEquals("Expected device count is not received", 1, devices.get("devices").getAsJsonArray().size());
} }
} }

@ -118,23 +118,25 @@ public class UserManagement extends TestBase {
@Test(description = "Test whether correct user count is returned.", dependsOnMethods = {"testIsUserExist"}) @Test(description = "Test whether correct user count is returned.", dependsOnMethods = {"testIsUserExist"})
public void testUserCount() throws Exception { public void testUserCount() throws Exception {
int expectedCount = this.userMode == TestUserMode.TENANT_ADMIN ? 4 : 15;
String url = Constants.UserManagement.USER_ENDPOINT + "/count"; String url = Constants.UserManagement.USER_ENDPOINT + "/count";
HttpResponse response = client.get(url); HttpResponse response = client.get(url);
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
JsonObject jsonElement = new JsonParser().parse(response.getData()).getAsJsonObject(); JsonObject jsonElement = new JsonParser().parse(response.getData()).getAsJsonObject();
Assert.assertEquals("Actual user count does not match with the returned user count", 4, Assert.assertEquals("Actual user count does not match with the returned user count", expectedCount,
jsonElement.get("count").getAsInt()); jsonElement.get("count").getAsInt());
} }
@Test(description = "Test whether the API that is used to get the users returns all the user details.", @Test(description = "Test whether the API that is used to get the users returns all the user details.",
dependsOnMethods = {"testUserCount"}) dependsOnMethods = {"testUserCount"})
public void testGetUsers() throws Exception { public void testGetUsers() throws Exception {
int expectedCount = this.userMode == TestUserMode.TENANT_ADMIN ? 4 : 15;
String url = Constants.UserManagement.USER_ENDPOINT + "/?offset=0&limit=100"; String url = Constants.UserManagement.USER_ENDPOINT + "/?offset=0&limit=100";
HttpResponse response = client.get(url); HttpResponse response = client.get(url);
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
JsonObject jsonElement = new JsonParser().parse(response.getData()).getAsJsonObject(); JsonObject jsonElement = new JsonParser().parse(response.getData()).getAsJsonObject();
Assert.assertEquals("All the users list is not returned", 4, jsonElement.get("users").getAsJsonArray().size()); Assert.assertEquals("All the users list is not returned", expectedCount,
jsonElement.get("users").getAsJsonArray().size());
} }
@Test(description = "Test whether the API that is used to get the users with particular filter returns all the " @Test(description = "Test whether the API that is used to get the users with particular filter returns all the "

@ -0,0 +1,106 @@
{
"ADVANCE_SEARCH" : {
"conditions" : [{
"key" : "deviceModel",
"value" : "S8",
"operator" : "=",
"state" : "OR"
}]
},
"UPDATE_DEVICE_INFO": {
"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": "newfeature1",
"description": "this is the new feature 1",
"deviceType": "android",
"metadataEntries": [
{
"id": 10,
"value": {
}
}
]
}
],
"properties": [
{
"name": "DEVICE_MODEL",
"value": "S8"
},
{
"name" : "VENDOR",
"value" : "SAMSUNG"
}
],
"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
}
]
}
}

@ -33,6 +33,16 @@
<class name="org.wso2.iot.integration.mobileDevice.MobileDeviceManagementWithNoDevices"/> <class name="org.wso2.iot.integration.mobileDevice.MobileDeviceManagementWithNoDevices"/>
</classes> </classes>
</test> </test>
<test name="android-jmeter" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.jmeter.AndroidDeviceManagementAPIJmeterTestCase"/>
</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="android-enrollment" preserve-order="true" parallel="false"> <test name="android-enrollment" preserve-order="true" parallel="false">
<classes> <classes>
<class name="org.wso2.iot.integration.device.enrollment.AndroidEnrollment"/> <class name="org.wso2.iot.integration.device.enrollment.AndroidEnrollment"/>
@ -63,11 +73,6 @@
<!--<class name="org.wso2.iot.integration.operation.OperationManagement"/>--> <!--<class name="org.wso2.iot.integration.operation.OperationManagement"/>-->
<!--</classes>--> <!--</classes>-->
<!--</test>--> <!--</test>-->
<!--<test name="mobile-device-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.mobileDevice.MobileDeviceManagement"/>-->
<!--</classes>-->
<!--</test>-->
<test name="role-mgt" preserve-order="true" parallel="false"> <test name="role-mgt" preserve-order="true" parallel="false">
<classes> <classes>
<class name="org.wso2.iot.integration.role.RoleManagement"/> <class name="org.wso2.iot.integration.role.RoleManagement"/>

@ -156,10 +156,6 @@
<groupId>com.opera</groupId> <groupId>com.opera</groupId>
<artifactId>operadriver</artifactId> <artifactId>operadriver</artifactId>
</exclusion> </exclusion>
<exclusion>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_core</artifactId>
</exclusion>
<exclusion> <exclusion>
<groupId>com.saucelabs.selenium</groupId> <groupId>com.saucelabs.selenium</groupId>
<artifactId>sauce-ondemand-driver</artifactId> <artifactId>sauce-ondemand-driver</artifactId>
@ -890,7 +886,6 @@
<scope>test</scope> <scope>test</scope>
<version>${junit.version}</version> <version>${junit.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.wso2.carbon.devicemgt</groupId> <groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.dynamic.client.registration</artifactId> <artifactId>org.wso2.carbon.dynamic.client.registration</artifactId>
@ -1467,7 +1462,7 @@
<testng.version>6.8</testng.version> <testng.version>6.8</testng.version>
<automation.utils.version>4.4.1</automation.utils.version> <automation.utils.version>4.4.1</automation.utils.version>
<test.automation.emm.ui.version>1.1.0</test.automation.emm.ui.version> <test.automation.emm.ui.version>1.1.0</test.automation.emm.ui.version>
<platform.integration.utils.version>4.4.2</platform.integration.utils.version> <platform.integration.utils.version>4.4.3</platform.integration.utils.version>
<!--Eclipse Osgi--> <!--Eclipse Osgi-->
<eclipse.equinox.common.version>3.6.100.v20120522-1841</eclipse.equinox.common.version> <eclipse.equinox.common.version>3.6.100.v20120522-1841</eclipse.equinox.common.version>
@ -1518,7 +1513,7 @@
<!-- Carbon Device Management --> <!-- Carbon Device Management -->
<carbon.device.mgt.version>2.0.43</carbon.device.mgt.version> <carbon.device.mgt.version>2.0.46</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 -->
@ -1526,7 +1521,7 @@
<!-- Carbon Device Management Plugins--> <!-- Carbon Device Management Plugins-->
<carbon.device.mgt.plugin.version>3.0.22</carbon.device.mgt.plugin.version> <carbon.device.mgt.plugin.version>3.0.23</carbon.device.mgt.plugin.version>
<!-- API Management --> <!-- API Management -->
<carbon.api.mgt.version>6.1.80</carbon.api.mgt.version> <carbon.api.mgt.version>6.1.80</carbon.api.mgt.version>
@ -1597,6 +1592,7 @@
<selenium.version>2.40.0</selenium.version> <selenium.version>2.40.0</selenium.version>
<operadriver.version>0.8.1</operadriver.version> <operadriver.version>0.8.1</operadriver.version>
<carbon.automationutils.version>4.4.2</carbon.automationutils.version> <carbon.automationutils.version>4.4.2</carbon.automationutils.version>
<carbon.automation.jmeter.version>4.2.7</carbon.automation.jmeter.version>
<xfer.version>3.3.0</xfer.version> <xfer.version>3.3.0</xfer.version>
<jacoco.agent.version>0.7.4.201502262128</jacoco.agent.version> <jacoco.agent.version>0.7.4.201502262128</jacoco.agent.version>
<commons.logging.version>1.1.1</commons.logging.version> <commons.logging.version>1.1.1</commons.logging.version>

Loading…
Cancel
Save