Adding initial test cases for virtual fire alarm

merge-requests/1/head
megala21 8 years ago
parent fa21f8cfd6
commit 1aadd2b171

@ -28,6 +28,7 @@ public final class Constants {
public static final String DEVICE_IMEI = "123123123";
public static final String AUTOMATION_CONTEXT = "IOT";
public static final String APPLICATION_JSON = "application/json";
public static final String APPLICATION_ZIP = "application/zip";
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_SECRET = "client_secret";
@ -89,7 +90,8 @@ public final class Constants {
+ "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 perm:android:applications perm:devicetype:deployment perm:android-sense:enroll";
+ "perm:ios:wipe-data perm:admin perm:android:applications perm:devicetype:deployment "
+ "perm:android-sense:enroll perm:firealarm:enroll";
public static final String OAUTH_TOKEN_PAYLOAD = "username=admin&password=admin" +
MULTI_TENANT_OAUTH_TOKEN_PAYLOAD;
@ -114,11 +116,11 @@ public final class Constants {
+ "perm:device-types:features perm:device-types:types perm:devices:applications "
+ "perm:devices:compliance-data perm:devices:delete perm:devices:details perm:devices:effective-policy "
+ "perm:devices:features perm:devices:operations perm:devices:search perm:devices:update "
+ "perm:devices:view perm:devicetype:deployment perm:get-activity perm:groups:add perm:groups:assign "
+ "perm:groups:count perm:groups:device perm:groups:devices perm:groups:devices-add perm:groups:devices-count "
+ "perm:groups:devices-remove perm:groups:groups perm:groups:groups-view perm:groups:remove "
+ "perm:groups:roles perm:groups:share perm:groups:update perm:manage-configuration "
+ "perm:notifications:mark-checked perm:notifications:view perm:policies:activate "
+ "perm:devices:view perm:devicetype:deployment perm:firealarm:enroll perm:get-activity "
+ "perm:groups:add perm:groups:assign perm:groups:count perm:groups:device perm:groups:devices "
+ "perm:groups:devices-add perm:groups:devices-count perm:groups:devices-remove perm:groups:groups "
+ "perm:groups:groups-view perm:groups:remove perm:groups:roles perm:groups:share perm:groups:update "
+ "perm:manage-configuration perm:notifications:mark-checked perm:notifications:view perm:policies:activate "
+ "perm:policies:changes perm:policies:deactivate perm:policies:get-details perm:policies:get-policy-details "
+ "perm:policies:manage perm:policies:priorities perm:policies:remove perm:policies:update perm:roles:add"
+ " perm:roles:add-users perm:roles:create-combined-role perm:roles:delete perm:roles:details "
@ -442,4 +444,13 @@ public final class Constants {
throw new AssertionError();
}
}
public static final class VirtualFireAlarmConstants {
public static final String ENROLLMENT_ENDPOINT = "/virtual_firealarm/1.0.0/device/download";
public static final String STATS_ENDPOINT = "/virtual_firealarm/1.0.0/device/stats";
public static final String PAYLOAD_FILE = "virtual-fire-alarm-enrollment-payloads.json";
public static final String ANALYTICS_ARTIFACTS_DEPLOYMENT_ENDPOINT =
"/api/device-mgt/v1.0/admin/devicetype/1.0.0/deploy/virtual_firealarm";
}
}

@ -99,7 +99,7 @@ public class CustomTestServerManager {
* Carbon server
*/
public synchronized String startServer(String server)
throws AutomationFrameworkException, IOException, XPathExpressionException {
throws AutomationFrameworkException, IOException, XPathExpressionException, InterruptedException {
if (carbonHome == null) {
if (carbonZip == null) {
carbonZip = System.getProperty(FrameworkConstants.SYSTEM_PROPERTY_CARBON_ZIP_LOCATION);
@ -114,6 +114,10 @@ public class CustomTestServerManager {
} else {
carbonHome = extractedDir;
}
// Deploy the plugins.
String[] cmdArray = new String[] { "mvn", "clean", "install", "-f", "plugins-deployer.xml"};
Runtime.getRuntime().exec(cmdArray, null, new File(carbonHome + File.separator + "plugins"));
Thread.sleep(15000);
} else if (server.equalsIgnoreCase("analytics") || server.equalsIgnoreCase("broker")) {
if (extractedDir == null) {
carbonHome = carbonServer.setUpCarbonHome(carbonZip) + File.separator + "wso2" + File.separator + server;
@ -131,6 +135,7 @@ public class CustomTestServerManager {
} else {
this.portOffset = 0;
}
carbonServer.startServerUsingCarbonHome(carbonHome, commandMap);
return carbonHome;
}

@ -96,7 +96,8 @@ public class AndroidSenseEnrollment extends TestBase {
}
@Test(description = "Test an Android sense device data publishing.", dependsOnMethods = {"testEnrollment"} )
@Test(description = "Test an Android sense device data publishing.", dependsOnMethods = {"testEnrollment"},
groups = {"androidSense"})
public void testEventPublishing() throws Exception {
String DEVICE_TYPE = "android_sense";
String topic = automationContext.getContextTenant().getDomain() + "/" + DEVICE_TYPE + "/" + DEVICE_ID + "/data";

@ -41,11 +41,9 @@ public class MobileQSGTestCase extends TestBase {
private String username1;
private String username2;
@BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP})
@BeforeClass(alwaysRun = true)
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";
}
@ -59,6 +57,7 @@ public class MobileQSGTestCase extends TestBase {
Runtime.getRuntime().exec(cmdArray, null, scriptFile);
// Allow some time to finish its execution
Thread.sleep(10000);
this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
}
@Test(description = "This test case tests whether user and roles are created as expected", dependsOnMethods =

@ -0,0 +1,157 @@
/*
* 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 com.google.gson.JsonArray;
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.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.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;
/**
* This class tests the functionality of the virtual fire alarm.
*/
public class VirtualFireAlarmTestCase extends TestBase {
private static Log log = LogFactory.getLog(VirtualFireAlarmTestCase.class);
public static String deviceId1;
public static String deviceId2;
public static long currentTime;
@Factory(dataProvider = "userModeProvider")
public VirtualFireAlarmTestCase(TestUserMode userMode) {
this.userMode = userMode;
}
@BeforeClass(alwaysRun = true)
public void initTest() throws Exception {
super.init(userMode);;
RestClient client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
if (userMode == TestUserMode.TENANT_ADMIN) {
HttpResponse response = client
.post(Constants.VirtualFireAlarmConstants.ANALYTICS_ARTIFACTS_DEPLOYMENT_ENDPOINT, "");
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
// Time for deploying the carbon apps
Thread.sleep(30000);
}
}
@Test(description = "This test case tests the virtual fire alarm enrollment")
public void testEnrollment() throws Exception {
RestClient client = new RestClient(backendHTTPSURL, Constants.APPLICATION_ZIP, accessTokenString);
// Enroll an advanced agent and check whether that enrollment succeeds without issues.
HttpResponse response = client.get(Constants.VirtualFireAlarmConstants.ENROLLMENT_ENDPOINT
+ "?deviceName=advanced&sketchType=virtual_firealarm_advanced");
Assert.assertEquals("Advance fire alarm advance agent enrollment failed", HttpStatus.SC_OK,
response.getResponseCode());
// Enroll an simple agent and check whether that enrollment succeeds without issues.
response = client.get(Constants.VirtualFireAlarmConstants.ENROLLMENT_ENDPOINT
+ "?deviceName=simple&sketchType=virtual_firealarm");
Assert.assertEquals("Advance fire alarm advance agent enrollment failed", HttpStatus.SC_OK,
response.getResponseCode());
response = client.get(Constants.MobileDeviceManagement.GET_DEVICE_COUNT_ENDPOINT + "?type=virtual_firealarm");
JsonArray jsonArray = new JsonParser().parse(response.getData()).getAsJsonObject().getAsJsonArray("devices");
Assert.assertEquals("Virtual fire alarm enrollment failed ", 2, jsonArray.size());
deviceId1 = jsonArray.get(0).getAsJsonObject().getAsJsonPrimitive("deviceIdentifier").getAsString();
deviceId2 = jsonArray.get(1).getAsJsonObject().getAsJsonPrimitive("deviceIdentifier").getAsString();
}
@Test(description = "Test whether the publishing to a mqtt broker works fine without exceptions", dependsOnMethods =
{"testEnrollment"} )
public void testEventPublishing() throws Exception {
String DEVICE_TYPE = "virtual_firealarm";
// Publishing message as a device with simple agent (device 1)
String topic = automationContext.getContextTenant().getDomain() + "/" + DEVICE_TYPE + "/" + deviceId1 +
"/temperature";
int qos = 2;
String broker = "tcp://localhost:1886";
String clientId = deviceId1 + ":" + 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");
JsonObject fireAlarmPayload = PayloadGenerator.getJsonPayload(Constants.VirtualFireAlarmConstants
.PAYLOAD_FILE, Constants.AndroidSenseEnrollment.PUBLISH_DATA_OPERATION);
JsonObject eventPayload = fireAlarmPayload.getAsJsonObject("event");
JsonObject metaDataPayload = eventPayload.getAsJsonObject("metaData");
metaDataPayload.addProperty("deviceId", deviceId1);
eventPayload.add("metaData", metaDataPayload);
fireAlarmPayload.add("event", eventPayload);
MqttMessage message = new MqttMessage(fireAlarmPayload.toString().getBytes());
message.setQos(qos);
sampleClient.publish(topic, message);
log.info("Message is published to Mqtt Client");
sampleClient.disconnect();
log.info("Mqtt Client is Disconnected");
// Publishing message as a device with simple agent (device 2)
topic = automationContext.getContextTenant().getDomain() + "/" + DEVICE_TYPE + "/" + deviceId2 +
"/temperature";
clientId = deviceId2 + ":" + DEVICE_TYPE;
persistence = new MemoryPersistence();
sampleClient = new MqttClient(broker, clientId, persistence);
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");
fireAlarmPayload = PayloadGenerator.getJsonPayload(Constants.VirtualFireAlarmConstants
.PAYLOAD_FILE, Constants.AndroidSenseEnrollment.PUBLISH_DATA_OPERATION);
eventPayload = fireAlarmPayload.getAsJsonObject("event");
metaDataPayload = eventPayload.getAsJsonObject("metaData");
metaDataPayload.addProperty("deviceId", deviceId2);
eventPayload.add("metaData", metaDataPayload);
fireAlarmPayload.add("event", eventPayload);
message = new MqttMessage(fireAlarmPayload.toString().getBytes());
message.setQos(qos);
sampleClient.publish(topic, message);
log.info("Message is published to Mqtt Client");
sampleClient.disconnect();
log.info("Mqtt Client is Disconnected");
currentTime = System.currentTimeMillis();
}
}

@ -33,6 +33,12 @@ 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 org.wso2.iot.integration.samples.VirtualFireAlarmTestCase;
import java.sql.Timestamp;
import static org.wso2.iot.integration.samples.VirtualFireAlarmTestCase.deviceId1;
import static org.wso2.iot.integration.samples.VirtualFireAlarmTestCase.deviceId2;
/**
* This class contains integration tests for user management backend services.
@ -164,8 +170,43 @@ public class UserManagement extends TestBase {
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
}
// Test case related to virtual fire alarm added here as the batch cron runs for every 5 minutes and rather than
// waiting for that we can check them in a latter test cases
@Test(description = "Test whether data that is published is stored in analytics event table", dependsOnMethods =
{"testRemoveUser"} )
public void testBatchDataPersistence() throws Exception {
long MilliSecondDifference = System.currentTimeMillis() - VirtualFireAlarmTestCase.currentTime;
if (MilliSecondDifference < 300000) {
Thread.sleep(300000 - MilliSecondDifference);
}
Timestamp timestamp = new Timestamp(System.currentTimeMillis() - 7200000);
String url = Constants.VirtualFireAlarmConstants.STATS_ENDPOINT + "/" + deviceId1;
url += "?from=" + (VirtualFireAlarmTestCase.currentTime - 300000)/1000 + "&to=" + System.currentTimeMillis()
/1000;
HttpResponse response = client.get(url);
JsonArray jsonArray = new JsonParser().parse(response.getData()).getAsJsonArray();
Assert.assertEquals(
"Published event for the device with the id " + deviceId1 + " is not inserted to "
+ "analytics table", HttpStatus.SC_OK, response.getResponseCode());
Assert.assertEquals(
"Published event for the device with the id " + deviceId1 + " is not inserted to analytics table", 1,
jsonArray.size());
url = Constants.VirtualFireAlarmConstants.STATS_ENDPOINT + "/" + deviceId2;
url += "?from=" + (VirtualFireAlarmTestCase.currentTime - 300000)/1000 + "&to=" + System.currentTimeMillis()
/1000;
response = client.get(url);
jsonArray = new JsonParser().parse(response.getData()).getAsJsonArray();
Assert.assertEquals(
"Published event for the device with the id " + deviceId2 + " is not inserted to "
+ "analytics table", HttpStatus.SC_OK, response.getResponseCode());
Assert.assertEquals(
"Published event for the device with the id " + deviceId2 + " is not inserted to analytics table", 1,
jsonArray.size());
}
@Test(description = "Test whether the API that is used to change the password works as expected.",
dependsOnMethods = {"testRemoveUser"})
dependsOnMethods = {"testBatchDataPersistence"})
public void testChangePassword() throws Exception {
String url = Constants.UserManagement.USER_ENDPOINT + "/credentials";
HttpResponse response = client.put(url, PayloadGenerator

@ -0,0 +1,14 @@
{
"PUBLISH_DATA": {
"event": {
"metaData": {
"owner": "admin",
"deviceId": "AS101",
"time": 1494315475
},
"payloadData": {
"temperature": 30
}
}
}
}

@ -28,80 +28,100 @@
<listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestTransformerListener"/>
</listeners>
<test name="mobile-device-mgt-no-devices" preserve-order="true" parallel="false">
<test name="iot-test-cases" preserve-order="true" parallel="false">
<classes>
<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.samples.VirtualFireAlarmTestCase"/>
<class name="org.wso2.iot.integration.device.enrollment.AndroidEnrollment"/>
</classes>
</test>
<test name="android-operation" preserve-order="false" parallel="true">
<classes>
<class name="org.wso2.iot.integration.device.operation.AndroidOperation"/>
</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="role-mgt" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.role.RoleManagement"/>
</classes>
</test>
<test name="group-mgt" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.jmeter.GroupManagementJMeterTestCase"/>
</classes>
</test>
<test name="negative-test" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.jmeter.DeviceManagementAPINegativeTestCase"/>
</classes>
</test>
<test name="notification-mgt" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.jmeter.NotificationManagementAPIJMeterTestCase"/>
</classes>
</test>
<test name="policy-mgt" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.jmeter.PolicyManagementJMeterTestCase"/>
</classes>
</test>
<test name="app-mgt" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.jmeter.AppManagerJmeterTestCase"/>
</classes>
</test>
<test name="android-sense-enrollment" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.device.enrollment.AndroidSenseEnrollment"/>
</classes>
</test>
<test name="mobile-qsg" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.samples.MobileQSGTestCase"/>
</classes>
</test>
<test name="user-mgt" preserve-order="true" parallel="false">
<classes>
<class name="org.wso2.iot.integration.user.UserManagement"/>
</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="virtual-fire-alarm" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.samples.VirtualFireAlarmTestCase"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="android-enrollment" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.device.enrollment.AndroidEnrollment"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="android-operation" preserve-order="false" parallel="true">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.device.operation.AndroidOperation"/>-->
<!--</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="role-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.role.RoleManagement"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="group-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.jmeter.GroupManagementJMeterTestCase"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="negative-test" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.jmeter.DeviceManagementAPINegativeTestCase"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="notification-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.jmeter.NotificationManagementAPIJMeterTestCase"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="policy-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.jmeter.PolicyManagementJMeterTestCase"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="app-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.jmeter.AppManagerJmeterTestCase"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="android-sense-enrollment" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.device.enrollment.AndroidSenseEnrollment"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="mobile-qsg" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.samples.MobileQSGTestCase"/>-->
<!--</classes>-->
<!--</test>-->
<!--<test name="user-mgt" preserve-order="true" parallel="false">-->
<!--<classes>-->
<!--<class name="org.wso2.iot.integration.user.UserManagement"/>-->
<!--</classes>-->
<!--</test>-->
</suite>

Loading…
Cancel
Save