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>
</repositories>
<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>
</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 CHANGE_DEVICE_STATUS_ENDPOINT = "/api/device-mgt/v1.0/devices/";
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_RESPONSE_PAYLOAD_FILE_NAME =
"mobile-device-mgt-view-device-types-response-payloads.json";

@ -265,6 +265,10 @@
<groupId>org.wso2.iot</groupId>
<artifactId>org.wso2.carbon.iot.integration.common</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.automation</groupId>
<artifactId>org.wso2.carbon.automation.extensions</artifactId>
</dependency>
</dependencies>
<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;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import junit.framework.Assert;
import org.apache.commons.httpclient.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.automation.test.utils.http.client.HttpResponse;
import org.wso2.iot.integration.common.*;
/**
* This class contains integration tests for API Device management backend services.
*/
public class MobileDeviceManagement extends TestBase {
private IOTHttpClient client;
private RestClient client;
@BeforeClass(alwaysRun = true, groups = { Constants.MobileDeviceManagement.MOBILE_DEVICE_MANAGEMENT_GROUP})
public void initTest() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL);
this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
@Factory(dataProvider = "userModeProvider")
public MobileDeviceManagement(TestUserMode userMode) {
this.userMode = userMode;
}
@Test(description = "Add an Android device.")
public void addEnrollment() throws Exception {
JsonObject enrollmentData = PayloadGenerator.getJsonPayload(
Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST);
@BeforeClass(alwaysRun = true, groups = { Constants.MobileDeviceManagement.MOBILE_DEVICE_MANAGEMENT_GROUP})
public void initTest() throws Exception {
super.init(userMode);
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);
IOTResponse response = 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));
client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData.toString());
}
@Test(dependsOnMethods = {"addEnrollment"}, description = "Test view devices")
@Test(description = "Test getting devices")
public void testViewDevices() throws Exception {
IOTResponse response = client.get(Constants.MobileDeviceManagement.GET_ALL_DEVICES_ENDPOINT);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
int expectedCount = this.userMode == TestUserMode.TENANT_ADMIN ? 1 : 23;
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")
public void testViewDeviceTypes() throws Exception {
IOTResponse response = client.get(Constants.MobileDeviceManagement.VIEW_DEVICE_TYPES_ENDPOINT);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
Assert.assertEquals(PayloadGenerator.getJsonPayloadToString
(Constants.MobileDeviceManagement.VIEW_DEVICE_RESPONSE_PAYLOAD_FILE_NAME), response.getBody());
//Response has two device types, because in windows enrollment a windows device is previously enrolled.
@Test(description = "Test getting devices")
public void testGetUserDevices() throws Exception {
int expectedCount = this.userMode == TestUserMode.TENANT_ADMIN ? 1 : 13;
HttpResponse response = client.get(Constants.MobileDeviceManagement.GET_ALL_DEVICES_ENDPOINT
+ Constants.MobileDeviceManagement.USER_DEVICE_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(description = "Change device status")
public void testRemoveDevices() throws Exception {
String endpointUrl = Constants.MobileDeviceManagement.CHANGE_DEVICE_STATUS_ENDPOINT + Constants.ANDROID_DEVICE_TYPE
+ "/" + Constants.DEVICE_ID + "/changestatus?newStatus=" + Constants.INACTIVE;
IOTResponse response = client.put(endpointUrl, "");
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
@Test(description = "Test Advance search")
public void testAdvancedSearch() throws Exception {
JsonArray pendingOperationsData = PayloadGenerator
.getJsonArray(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME,
Constants.AndroidEnrollment.GET_PENDING_OPERATIONS_METHOD);
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"})
public void testUserCount() throws Exception {
int expectedCount = this.userMode == TestUserMode.TENANT_ADMIN ? 4 : 15;
String url = Constants.UserManagement.USER_ENDPOINT + "/count";
HttpResponse response = client.get(url);
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
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());
}
@Test(description = "Test whether the API that is used to get the users returns all the user details.",
dependsOnMethods = {"testUserCount"})
public void testGetUsers() throws Exception {
int expectedCount = this.userMode == TestUserMode.TENANT_ADMIN ? 4 : 15;
String url = Constants.UserManagement.USER_ENDPOINT + "/?offset=0&limit=100";
HttpResponse response = client.get(url);
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
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 "

@ -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"/>
</classes>
</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">
<classes>
<class name="org.wso2.iot.integration.device.enrollment.AndroidEnrollment"/>
@ -63,11 +73,6 @@
<!--<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="role-mgt" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.role.RoleManagement"/>

@ -156,10 +156,6 @@
<groupId>com.opera</groupId>
<artifactId>operadriver</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_core</artifactId>
</exclusion>
<exclusion>
<groupId>com.saucelabs.selenium</groupId>
<artifactId>sauce-ondemand-driver</artifactId>
@ -890,7 +886,6 @@
<scope>test</scope>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.dynamic.client.registration</artifactId>
@ -1467,7 +1462,7 @@
<testng.version>6.8</testng.version>
<automation.utils.version>4.4.1</automation.utils.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.equinox.common.version>3.6.100.v20120522-1841</eclipse.equinox.common.version>
@ -1518,7 +1513,7 @@
<!-- 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>
<!-- IOT Device Management -->
@ -1526,7 +1521,7 @@
<!-- 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 -->
<carbon.api.mgt.version>6.1.80</carbon.api.mgt.version>
@ -1597,6 +1592,7 @@
<selenium.version>2.40.0</selenium.version>
<operadriver.version>0.8.1</operadriver.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>
<jacoco.agent.version>0.7.4.201502262128</jacoco.agent.version>
<commons.logging.version>1.1.1</commons.logging.version>

Loading…
Cancel
Save