forked from community/product-iots
Merge pull request #453 from Megala21/test_case_fixes
Adding test cases for android sense and mobile-qsg script execution.application-manager-new
commit
fa21f8cfd6
@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
* 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.device.enrollment;
|
||||||
|
|
||||||
|
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.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.commons.net.util.Base64;
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||||
|
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||||
|
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.engine.context.beans.User;
|
||||||
|
import org.wso2.carbon.automation.test.utils.http.client.HttpResponse;
|
||||||
|
import org.wso2.iot.integration.common.Constants;
|
||||||
|
import org.wso2.iot.integration.common.PayloadGenerator;
|
||||||
|
import org.wso2.iot.integration.common.RestClient;
|
||||||
|
import org.wso2.iot.integration.common.TestBase;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class tests the android sense enrollment.
|
||||||
|
*/
|
||||||
|
public class AndroidSenseEnrollment extends TestBase {
|
||||||
|
private static Log log = LogFactory.getLog(AndroidSenseEnrollment.class);
|
||||||
|
private RestClient client;
|
||||||
|
private String DEVICE_ID = "AS101";
|
||||||
|
private RestClient analyticsClient;
|
||||||
|
|
||||||
|
@Factory(dataProvider = "userModeProvider")
|
||||||
|
public AndroidSenseEnrollment(TestUserMode userMode) {
|
||||||
|
this.userMode = userMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP})
|
||||||
|
public void initTest() throws Exception {
|
||||||
|
super.init(userMode);
|
||||||
|
User currentUser = getAutomationContext().getContextTenant().getContextUser();
|
||||||
|
byte[] bytesEncoded = Base64
|
||||||
|
.encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes());
|
||||||
|
String encoded = new String(bytesEncoded);
|
||||||
|
String auth_string = "Basic " + encoded;
|
||||||
|
String anaytics_https_url = automationContext.getContextUrls().getWebAppURLHttps()
|
||||||
|
.replace("9443", String.valueOf(Constants.HTTPS_ANALYTICS_PORT))
|
||||||
|
.replace("/t/" + automationContext.getContextTenant().getDomain(), "") + "/";
|
||||||
|
this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
|
||||||
|
this.analyticsClient = new RestClient(anaytics_https_url, Constants.APPLICATION_JSON, auth_string);
|
||||||
|
if (this.userMode == TestUserMode.TENANT_ADMIN) {
|
||||||
|
HttpResponse response = client
|
||||||
|
.post(Constants.AndroidSenseEnrollment.ANALYTICS_ARTIFACTS_DEPLOYMENT_ENDPOINT, "");
|
||||||
|
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
|
||||||
|
// Time for deploying the carbon apps
|
||||||
|
Thread.sleep(30000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test an Android sense device enrollment.")
|
||||||
|
public void testEnrollment() throws Exception {
|
||||||
|
HttpResponse response = client.post(Constants.AndroidSenseEnrollment.ENROLLMENT_ENDPOINT + DEVICE_ID
|
||||||
|
+ "/register?deviceName=android_sense_test", "");
|
||||||
|
// Time for deploying the carbon apps
|
||||||
|
Thread.sleep(30000);
|
||||||
|
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
|
||||||
|
JsonElement jsonElement = new JsonParser().parse(response.getData());
|
||||||
|
JsonObject expectedPayloadObject = jsonElement.getAsJsonObject();
|
||||||
|
Assert.assertNotNull("Mqtt end-point is returned with the android sense enrollment " + "payload",
|
||||||
|
expectedPayloadObject.get("mqttEndpoint"));
|
||||||
|
Assert.assertNotNull("Tenant domain is returned with the android sense enrollment " + "payload",
|
||||||
|
expectedPayloadObject.get("tenantDomain"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Test an Android sense device data publishing.", dependsOnMethods = {"testEnrollment"} )
|
||||||
|
public void testEventPublishing() throws Exception {
|
||||||
|
String DEVICE_TYPE = "android_sense";
|
||||||
|
String topic = automationContext.getContextTenant().getDomain() + "/" + DEVICE_TYPE + "/" + DEVICE_ID + "/data";
|
||||||
|
int qos = 2;
|
||||||
|
String broker = "tcp://localhost:1886";
|
||||||
|
String clientId = DEVICE_ID + ":" + DEVICE_TYPE;
|
||||||
|
MemoryPersistence persistence = new MemoryPersistence();
|
||||||
|
MqttClient sampleClient = new MqttClient(broker, clientId, persistence);
|
||||||
|
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||||
|
connOpts.setUserName(accessToken);
|
||||||
|
connOpts.setPassword("".toCharArray());
|
||||||
|
connOpts.setKeepAliveInterval(120);
|
||||||
|
connOpts.setCleanSession(true);
|
||||||
|
log.info("Connecting to broker: " + broker);
|
||||||
|
sampleClient.connect(connOpts);
|
||||||
|
log.info("Connected");
|
||||||
|
MqttMessage message = new MqttMessage(PayloadGenerator
|
||||||
|
.getJsonArray(Constants.AndroidSenseEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME,
|
||||||
|
Constants.AndroidSenseEnrollment.PUBLISH_DATA_OPERATION).toString().getBytes());
|
||||||
|
message.setQos(qos);
|
||||||
|
sampleClient.publish(topic, message);
|
||||||
|
log.info("Message is published to Mqtt Client");
|
||||||
|
Thread.sleep(30000);
|
||||||
|
HttpResponse response = analyticsClient
|
||||||
|
.get(Constants.AndroidSenseEnrollment.IS_TABLE_EXIST_CHECK_URL + "?table="
|
||||||
|
+ Constants.AndroidSenseEnrollment.BATTERY_STATS_TABLE_NAME);
|
||||||
|
Assert.assertEquals("ORG_WSO2_IOT_ANDROID_BATTERY_STATS table does not exist. Problem with the android sense "
|
||||||
|
+ "analytics", HttpStatus.SC_OK, response.getResponseCode());
|
||||||
|
// Allow some time to perform the analytics tasks.
|
||||||
|
Thread.sleep(30000);
|
||||||
|
sampleClient.disconnect();
|
||||||
|
log.info("Mqtt Client is Disconnected");
|
||||||
|
|
||||||
|
String url = Constants.AndroidSenseEnrollment.RETRIEVER_ENDPOINT
|
||||||
|
+ Constants.AndroidSenseEnrollment.BATTERY_STATS_TABLE_NAME + "/";
|
||||||
|
Timestamp timestamp = new Timestamp(System.currentTimeMillis() - 3600000);
|
||||||
|
url += timestamp.getTime() + "/" + new Timestamp(System.currentTimeMillis()).getTime() + "/0/100";
|
||||||
|
response = analyticsClient.get(url);
|
||||||
|
JsonArray jsonArray = new JsonParser().parse(response.getData()).getAsJsonArray();
|
||||||
|
Assert.assertEquals(
|
||||||
|
"Published event for the device with the id " + DEVICE_ID + " is not inserted to analytics table",
|
||||||
|
HttpStatus.SC_OK, response.getResponseCode());
|
||||||
|
Assert.assertEquals(
|
||||||
|
"Published event for the device with the id " + DEVICE_ID + " is not inserted to analytics table", 1,
|
||||||
|
jsonArray.size());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* 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.samples;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
|
import org.testng.annotations.AfterClass;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.automation.engine.context.TestUserMode;
|
||||||
|
import org.wso2.carbon.automation.engine.frameworkutils.FrameworkPathUtil;
|
||||||
|
import org.wso2.carbon.automation.test.utils.http.client.HttpResponse;
|
||||||
|
import org.wso2.iot.integration.common.Constants;
|
||||||
|
import org.wso2.iot.integration.common.RestClient;
|
||||||
|
import org.wso2.iot.integration.common.TestBase;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class tests the functionality of the mobile qsg.
|
||||||
|
*/
|
||||||
|
public class MobileQSGTestCase extends TestBase {
|
||||||
|
private RestClient client;
|
||||||
|
private String username1;
|
||||||
|
private String username2;
|
||||||
|
|
||||||
|
@BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP})
|
||||||
|
public void initTest() throws Exception {
|
||||||
|
super.init(TestUserMode.SUPER_TENANT_ADMIN);
|
||||||
|
backendHTTPSURL = automationContext.getContextUrls().getWebAppURLHttps();
|
||||||
|
this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
|
||||||
|
username1 = "alex";
|
||||||
|
username2 = "chris";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests the execution of QSG script, whether it executes without any exceptions")
|
||||||
|
public void executeQSGScript() throws IOException, InterruptedException {
|
||||||
|
String scriptPath =
|
||||||
|
FrameworkPathUtil.getCarbonHome() + File.separator + "samples" + File.separator + "mobile-qsg";
|
||||||
|
File scriptFile = new File(scriptPath);
|
||||||
|
String[] cmdArray = new String[] { "sh", "mobile-qsg.sh" };
|
||||||
|
Runtime.getRuntime().exec(cmdArray, null, scriptFile);
|
||||||
|
// Allow some time to finish its execution
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests whether user and roles are created as expected", dependsOnMethods =
|
||||||
|
{"executeQSGScript"})
|
||||||
|
public void testUserRoleCreation() throws Exception {
|
||||||
|
// Two users will be created with the quick start script, check whether those two users are created
|
||||||
|
// successfully,
|
||||||
|
String url = Constants.UserManagement.USER_ENDPOINT + "/" + username1;
|
||||||
|
HttpResponse response = client.get(url);
|
||||||
|
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
|
||||||
|
url = Constants.UserManagement.USER_ENDPOINT + "/" + username2;
|
||||||
|
response = client.get(url);
|
||||||
|
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
|
||||||
|
|
||||||
|
// A single role will be created with the quick start script, checking whether that role creation happens
|
||||||
|
// without problem
|
||||||
|
String rolename = "iotMobileUser";
|
||||||
|
response = client.get(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/" + rolename);
|
||||||
|
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests whether app-catalogue is created from qsg script", dependsOnMethods =
|
||||||
|
{"executeQSGScript"})
|
||||||
|
public void testMobileApp() throws Exception {
|
||||||
|
RestClient appManagerRestClient = new RestClient(automationContext.getContextUrls().getWebAppURLHttps(),
|
||||||
|
Constants.APPLICATION_JSON, accessTokenString);
|
||||||
|
HttpResponse response = appManagerRestClient.get(Constants.QSGManagement.GET_MOBILE_APPS_ENDPONT);
|
||||||
|
Assert.assertEquals("Catalog mobile app is not uploaded successfully", HttpStatus.SC_OK,
|
||||||
|
response.getResponseCode());
|
||||||
|
Assert.assertTrue("Catalog app addition through script is not successful",
|
||||||
|
response.getData().contains("Catalog"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This test case tests the policy creation through qsg script", dependsOnMethods = {"executeQSGScript"})
|
||||||
|
public void testPolicyCreation() throws Exception {
|
||||||
|
HttpResponse response = client.get(Constants.PolicyManagement.VIEW_POLICY_LIST_ENDPOINT + "?offset=0&limit=10");
|
||||||
|
Assert.assertEquals("Policy upload view mobile-qsg script failed", HttpStatus.SC_OK,
|
||||||
|
response.getResponseCode());
|
||||||
|
Assert.assertTrue("Android pass-code policy is not added from qsg script",
|
||||||
|
response.getData().contains("android-passcode-policy1"));
|
||||||
|
Assert.assertTrue("Windows pass-code policy is not added from qsg script",
|
||||||
|
response.getData().contains("windows-passcode-policy1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass(alwaysRun = true)
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
String url = Constants.UserManagement.USER_ENDPOINT + "/" + username1;
|
||||||
|
client.delete(url);
|
||||||
|
url = Constants.UserManagement.USER_ENDPOINT + "/" + username2;
|
||||||
|
client.delete(url);
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,63 @@
|
|||||||
|
{
|
||||||
|
"PUBLISH_DATA": [{
|
||||||
|
"event": {
|
||||||
|
"metaData": {
|
||||||
|
"owner": "admin",
|
||||||
|
"deviceId": "AS101",
|
||||||
|
"type": "battery",
|
||||||
|
"timestamp": 1494315475
|
||||||
|
},
|
||||||
|
"payloadData": {
|
||||||
|
"battery": 4,
|
||||||
|
"battery_state": "abc",
|
||||||
|
"battery_status": 90,
|
||||||
|
"battery_temperature": 100,
|
||||||
|
"gps_lat": 4.504343,
|
||||||
|
"gps_long": 4.504343,
|
||||||
|
"accelerometer_x": 6.6,
|
||||||
|
"accelerometer_y": 2.3,
|
||||||
|
"accelerometer_z": 4.5,
|
||||||
|
"speed_limit": 9.8,
|
||||||
|
"turn_way": "data5",
|
||||||
|
"magnetic_x": 8.9,
|
||||||
|
"magnetic_y": 6.6,
|
||||||
|
"magnetic_z": 6.6,
|
||||||
|
"gyroscope_x": 6.6,
|
||||||
|
"gyroscope_y": 8.9,
|
||||||
|
"gyroscope_z": 9.8,
|
||||||
|
"light": 2.3,
|
||||||
|
"pressure": 8.9,
|
||||||
|
"proximity": 6.6,
|
||||||
|
"gravity_x": 2.3,
|
||||||
|
"gravity_y": 6.6,
|
||||||
|
"gravity_z": 2.3,
|
||||||
|
"rotation_x": 6.6,
|
||||||
|
"rotation_y": 4.5,
|
||||||
|
"rotation_z": 6.6,
|
||||||
|
"word": "data1",
|
||||||
|
"word_sessionId": "data2",
|
||||||
|
"word_status": "data1",
|
||||||
|
"beacon_major": 70,
|
||||||
|
"beacon_minor": 45,
|
||||||
|
"beacon_proximity": "data4",
|
||||||
|
"beacon_uuid": 4,
|
||||||
|
"call_number": "data3",
|
||||||
|
"call_type": "data3",
|
||||||
|
"call_start_time": 4354643,
|
||||||
|
"call_end_time": 4354643,
|
||||||
|
"screen_state": "data1",
|
||||||
|
"audio_playing": true,
|
||||||
|
"headset_on": true,
|
||||||
|
"music_volume": 4,
|
||||||
|
"activity_type": 50,
|
||||||
|
"confidence": 45,
|
||||||
|
"sms_number": "data2",
|
||||||
|
"application_name": "data1",
|
||||||
|
"action": "data5",
|
||||||
|
"data_type": "data3",
|
||||||
|
"data_sent": 323232,
|
||||||
|
"data_received": 645565
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
Loading…
Reference in new issue