mirror of
https://repository.entgra.net/community/product-iots.git
synced 2025-09-16 23:32:19 +00:00
Merge pull request #483 from Megala21/test_case_fixes
Adding test cases for virtual fire-alarm
This commit is contained in:
commit
cadfba3c05
@ -140,6 +140,10 @@
|
||||
<artifactId>org.wso2.carbon.integration.common.utils</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@ -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,16 @@ 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";
|
||||
public static final String POLICY_DATA = "POLICY_DATA";
|
||||
public static final String ACTIVATE_POLICY_ENDPOINT = "/api/device-mgt/v1.0/policies/activate-policy";
|
||||
public static final String APPLY_CHANGES_ENDPOINT = "/api/device-mgt/v1.0/policies/apply-changes";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
|
||||
import org.eclipse.paho.client.mqttv3.MqttCallback;
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* This is a mqtt subscriber client to receive .
|
||||
*/
|
||||
public class MqttSubscriberClient implements MqttCallback {
|
||||
private ArrayList<MqttMessage> mqttMessages;
|
||||
|
||||
@Override
|
||||
public void connectionLost(Throwable throwable) {
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
||||
mqttMessages.add(mqttMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param serverAddress Mqtt broker address
|
||||
* @param clientId Client ID
|
||||
* @param topicName Topic Name
|
||||
* @throws MqttException Mqtt Exception
|
||||
*/
|
||||
public MqttSubscriberClient(String serverAddress, String clientId, String topicName, String accessToken) throws
|
||||
MqttException {
|
||||
mqttMessages = new ArrayList<>();
|
||||
MemoryPersistence persistence = new MemoryPersistence();
|
||||
MqttClient client = new MqttClient(serverAddress, clientId, persistence);
|
||||
MqttConnectOptions connectOptions = new MqttConnectOptions();
|
||||
client.setCallback(this);
|
||||
connectOptions.setUserName(accessToken);
|
||||
connectOptions.setPassword("".toCharArray());
|
||||
connectOptions.setCleanSession(true);
|
||||
connectOptions.setKeepAliveInterval(300);
|
||||
client.connect(connectOptions);
|
||||
client.subscribe(topicName);
|
||||
}
|
||||
|
||||
public ArrayList<MqttMessage> getMqttMessages() {
|
||||
return mqttMessages;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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,201 @@
|
||||
/*
|
||||
* 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 com.google.gson.JsonPrimitive;
|
||||
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.MqttSubscriberClient;
|
||||
import org.wso2.iot.integration.common.PayloadGenerator;
|
||||
import org.wso2.iot.integration.common.RestClient;
|
||||
import org.wso2.iot.integration.common.TestBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* 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 String tenantDeviceId1;
|
||||
public static String tenantDeviceId2;
|
||||
public static long currentTime;
|
||||
private String broker = "tcp://localhost:1886";
|
||||
private String DEVICE_TYPE = "virtual_firealarm";
|
||||
private RestClient restClient;
|
||||
|
||||
@Factory(dataProvider = "userModeProvider")
|
||||
public VirtualFireAlarmTestCase(TestUserMode userMode) {
|
||||
this.userMode = userMode;
|
||||
}
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void initTest() throws Exception {
|
||||
super.init(userMode);
|
||||
restClient = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
|
||||
if (userMode == TestUserMode.TENANT_ADMIN) {
|
||||
HttpResponse response = restClient
|
||||
.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());
|
||||
|
||||
if (userMode != TestUserMode.TENANT_ADMIN) {
|
||||
deviceId1 = jsonArray.get(0).getAsJsonObject().getAsJsonPrimitive("deviceIdentifier").getAsString();
|
||||
deviceId2 = jsonArray.get(1).getAsJsonObject().getAsJsonPrimitive("deviceIdentifier").getAsString();
|
||||
} else {
|
||||
tenantDeviceId1 = jsonArray.get(0).getAsJsonObject().getAsJsonPrimitive("deviceIdentifier").getAsString();
|
||||
tenantDeviceId2 = 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 deviceId1 = userMode == TestUserMode.TENANT_ADMIN ? tenantDeviceId1 : VirtualFireAlarmTestCase.deviceId1;
|
||||
String deviceId2 = userMode == TestUserMode.TENANT_ADMIN ? tenantDeviceId2 : VirtualFireAlarmTestCase.deviceId2;
|
||||
// Publishing message as a device with simple agent (device 1)
|
||||
String topic = automationContext.getContextTenant().getDomain() + "/" + DEVICE_TYPE + "/" + deviceId1 +
|
||||
"/temperature";
|
||||
int qos = 2;
|
||||
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();
|
||||
}
|
||||
|
||||
@Test(description = "Test whether the policy publishing from the server to device works", dependsOnMethods =
|
||||
{"testEnrollment"} )
|
||||
public void testPolicyPublishing() throws Exception {
|
||||
String deviceId2 = userMode == TestUserMode.TENANT_ADMIN ? tenantDeviceId2 : VirtualFireAlarmTestCase.deviceId2;
|
||||
String topic = automationContext.getContextTenant().getDomain() + "/" + DEVICE_TYPE + "/" + deviceId2 + "/#";
|
||||
String clientId = deviceId2 + ":" + DEVICE_TYPE;
|
||||
HttpResponse response = restClient.post("/api/device-mgt/v1.0/policies", PayloadGenerator
|
||||
.getJsonPayload(Constants.VirtualFireAlarmConstants.PAYLOAD_FILE,
|
||||
Constants.VirtualFireAlarmConstants.POLICY_DATA).toString());
|
||||
Assert.assertEquals("Policy creation for virtual fire alarm failed", HttpStatus.SC_CREATED,
|
||||
response.getResponseCode());
|
||||
JsonObject jsonObject = new JsonParser().parse(response.getData()).getAsJsonObject();
|
||||
String policyId = jsonObject.getAsJsonPrimitive("id").getAsString();
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
jsonArray.add(new JsonPrimitive(policyId));
|
||||
response = restClient.post(Constants.VirtualFireAlarmConstants.ACTIVATE_POLICY_ENDPOINT,
|
||||
jsonArray.toString());
|
||||
Assert.assertEquals("Policy activation for virtual fire alarm failed", HttpStatus.SC_OK,
|
||||
response.getResponseCode());
|
||||
MqttSubscriberClient mqttSubscriberClient = new MqttSubscriberClient(broker, clientId, topic, accessToken);
|
||||
response = restClient.put(Constants.VirtualFireAlarmConstants.APPLY_CHANGES_ENDPOINT, "");
|
||||
Assert.assertEquals("Applying changes to policy for virtual fire alarm failed", HttpStatus.SC_OK,
|
||||
response.getResponseCode());
|
||||
// Allow some time for message delivery
|
||||
Thread.sleep(20000);
|
||||
ArrayList<MqttMessage> mqttMessages = mqttSubscriberClient.getMqttMessages();
|
||||
Assert.assertEquals("Policy published message is not received by the mqtt listener. ", 1, mqttMessages.size());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -33,6 +33,8 @@ 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 static org.wso2.iot.integration.samples.VirtualFireAlarmTestCase.*;
|
||||
|
||||
/**
|
||||
* This class contains integration tests for user management backend services.
|
||||
@ -164,8 +166,47 @@ 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 {
|
||||
String deviceId1 =
|
||||
this.userMode == TestUserMode.TENANT_ADMIN ? tenantDeviceId1 : VirtualFireAlarmTestCase.deviceId1;
|
||||
String deviceId2 =
|
||||
this.userMode == TestUserMode.TENANT_ADMIN ? tenantDeviceId2 : VirtualFireAlarmTestCase.deviceId2;
|
||||
|
||||
long MilliSecondDifference = System.currentTimeMillis() - VirtualFireAlarmTestCase.currentTime;
|
||||
if (MilliSecondDifference < 300000) {
|
||||
Thread.sleep(300000 - MilliSecondDifference);
|
||||
}
|
||||
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,30 @@
|
||||
{
|
||||
"PUBLISH_DATA": {
|
||||
"event": {
|
||||
"metaData": {
|
||||
"owner": "admin",
|
||||
"deviceId": "AS101",
|
||||
"time": 1494315475
|
||||
},
|
||||
"payloadData": {
|
||||
"temperature": 30
|
||||
}
|
||||
}
|
||||
},
|
||||
"POLICY_DATA" : {
|
||||
"policyName":"testpolicy",
|
||||
"description":"","compliance":"enforce","ownershipType":null,"active":true,
|
||||
"profile":{
|
||||
"profileName":"dvdv",
|
||||
"deviceType":"virtual_firealarm",
|
||||
"profileFeaturesList":[{
|
||||
"featureCode":"CONFIG",
|
||||
"deviceType":"virtual_firealarm",
|
||||
"content":{
|
||||
"policyDefinition":"define stream fireAlarmEventStream (deviceID string, temp int);\nfrom fireAlarmEventStream#window.time(30 sec)\nselect deviceID, max(temp) as maxValue\ngroup by deviceID\ninsert into analyzeStream for expired-events;\nfrom analyzeStream[maxValue > 50]\nselect maxValue\ninsert into bulbOnStream;\nfrom fireAlarmEventStream[temp < 50]\nselect deviceID, temp\ninsert into bulbOffStream;"
|
||||
}
|
||||
}]
|
||||
},
|
||||
"roles":["ANY"]
|
||||
}
|
||||
}
|
||||
@ -28,79 +28,23 @@
|
||||
<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.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.samples.VirtualFireAlarmTestCase"/>
|
||||
<class name="org.wso2.iot.integration.device.enrollment.AndroidEnrollment"/>
|
||||
<class name="org.wso2.iot.integration.device.operation.AndroidOperation"/>
|
||||
<class name="org.wso2.iot.integration.device.configuration.AndroidConfigurationManagement"/>
|
||||
<class name="org.wso2.iot.integration.role.RoleManagement"/>
|
||||
<class name="org.wso2.iot.integration.jmeter.GroupManagementJMeterTestCase"/>
|
||||
<class name="org.wso2.iot.integration.jmeter.DeviceManagementAPINegativeTestCase"/>
|
||||
<class name="org.wso2.iot.integration.jmeter.NotificationManagementAPIJMeterTestCase"/>
|
||||
<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>
|
||||
|
||||
4
pom.xml
4
pom.xml
@ -1512,7 +1512,7 @@
|
||||
|
||||
<!-- Carbon Device Management -->
|
||||
|
||||
<carbon.device.mgt.version>2.0.65</carbon.device.mgt.version>
|
||||
<carbon.device.mgt.version>2.0.68</carbon.device.mgt.version>
|
||||
<carbon.device.mgt.version.range>[2.0.0, 3.0.0)</carbon.device.mgt.version.range>
|
||||
|
||||
<!-- IOT Device Management -->
|
||||
@ -1520,7 +1520,7 @@
|
||||
|
||||
<!-- Carbon Device Management Plugins-->
|
||||
|
||||
<carbon.device.mgt.plugin.version>3.0.35</carbon.device.mgt.plugin.version>
|
||||
<carbon.device.mgt.plugin.version>3.0.36</carbon.device.mgt.plugin.version>
|
||||
|
||||
<!-- API Management -->
|
||||
<carbon.api.mgt.version>6.1.80</carbon.api.mgt.version>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user