added device type test case

application-manager-new
ayyoob 8 years ago
parent bf02c6ccb7
commit 5f80490332

@ -91,7 +91,9 @@ public final class Constants {
+ "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:firealarm:enroll";
+ "perm:android-sense:enroll perm:admin:device-type perm:device-types:events "
+ "perm:device-types:events:view perm:device-types:types perm:device:enroll perm:device:disenroll "
+ "perm:device:modify perm:device:operations perm:device:publish-event perm:devices:operations perm:devices:operations perm:firealarm:enroll ";
public static final String OAUTH_TOKEN_PAYLOAD = "username=admin&password=admin" +
MULTI_TENANT_OAUTH_TOKEN_PAYLOAD;
@ -126,7 +128,7 @@ public final class Constants {
+ " perm:roles:add-users perm:roles:create-combined-role perm:roles:delete perm:roles:details "
+ "perm:roles:permissions perm:roles:update perm:roles:view perm:users:add perm:users:count "
+ "perm:users:credentials perm:users:delete perm:users:details perm:users:is-exist perm:users:roles "
+ "perm:users:search perm:users:send-invitation perm:users:update perm:users:user-details perm:view-configuration";
+ "perm:users:search perm:users:send-invitation perm:users:update perm:users:user-details perm:device:publish-event perm:view-configuration";
private APIApplicationRegistration() {
throw new AssertionError();

@ -0,0 +1,126 @@
/*
* 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 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.engine.exceptions.AutomationFrameworkException;
import org.wso2.carbon.automation.extensions.jmeter.JMeterTest;
import org.wso2.carbon.automation.extensions.jmeter.JMeterTestManager;
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.io.File;
import java.net.URL;
import java.util.ArrayList;
/**
* This test case is used to run the jmeter test cases related with DeviceType Management APIs.
*/
public class DeviceTypeManagementJMeterTestCase extends TestBase {
private static Log log = LogFactory.getLog(DeviceTypeManagementJMeterTestCase.class);
private String broker = "tcp://localhost:1886";
private RestClient restClient;
@BeforeClass(alwaysRun = true)
public void initTest() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
restClient = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
}
@Test(description = "This test case tests the Device Type/Device Management/Device Agent APIs")
public void DeviceTypeManagementTest() throws AutomationFrameworkException {
URL url = Thread.currentThread().getContextClassLoader()
.getResource("jmeter-scripts" + File.separator + "DeviceTypeManagementAPI.jmx");
JMeterTest script = new JMeterTest(new File(url.getPath()));
JMeterTestManager manager = new JMeterTestManager();
log.info("Running Device Type/Device Management/Device Agent management api test cases using jmeter scripts");
manager.runTest(script);
log.info("Completed DeviceType API service test using jmeter scripts");
}
@Test(description = "Test whether the policy publishing from the server to device works", dependsOnMethods =
{"DeviceTypeManagementTest"} )
public void testMqttFlow() throws Exception {
String deviceId = "123422578912";
String deviceType = "firealarmmqtt";
String payload = "{\"deviceIdentifiers\":[123422578912],\"operation\":{\"code\":\"ring\",\"type\":\"CONFIG\"," +
"\"payLoad\":\"volume:30%\"}}";
String topic = automationContext.getContextTenant().getDomain() + "/"+deviceType+"/" + deviceId + "/operation/#";
String clientId = deviceId + ":firealarmmqtt";
MqttSubscriberClient mqttDeviceSubscriberClient = new MqttSubscriberClient(broker, clientId, topic, accessToken);
restClient.post("/api/device-mgt/v1.0/devices/" + deviceType + "/operations", payload);
// Allow some time for message delivery
Thread.sleep(10000);
ArrayList<MqttMessage> mqttMessages = mqttDeviceSubscriberClient.getMqttMessages();
Assert.assertEquals("listener did not recieve mqtt messages ", 1, mqttMessages.size());
String topicPub = automationContext.getContextTenant().getDomain() + "/"+deviceType+"/"+deviceId+"/events";
int qos = 2;
String clientIdPub = deviceId + ":firealarmmqttpub";
MemoryPersistence persistence = new MemoryPersistence();
MqttClient sampleClient = new MqttClient(broker, clientIdPub, persistence);
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setUserName(accessToken);
connOpts.setPassword("".toCharArray());
connOpts.setKeepAliveInterval(120);
connOpts.setCleanSession(false);
log.info("Connecting to broker: " + broker);
sampleClient.connect(connOpts);
log.info("Connected");
payload = "{\"temperature\":10,\"status\":\"workingh\",\"humidity\":20}";
String payload2 = "{\"temperature\":100,\"status\":\"workingh\",\"humidity\":20}";
MqttMessage message = new MqttMessage(payload.getBytes());
message.setQos(qos);
MqttMessage message2 = new MqttMessage(payload2.getBytes());
message.setQos(qos);
sampleClient.publish(topicPub, message2);
sampleClient.publish(topicPub, message2);
log.info("Message is published to Mqtt Client");
sampleClient.disconnect();
log.info("Mqtt Client is Disconnected");
// Allow some time for message delivery
Thread.sleep(20000);
HttpResponse response = restClient.get("/api/device-mgt/v1.0/events/last-known/"+deviceType+"/"+deviceId);
Assert.assertEquals("No published event found (mqtt)", HttpStatus.SC_OK,
response.getResponseCode());
Assert.assertTrue("Event count does not match published event count, " + response.getData() ,
response.getData().contains("\"count\":2"));
}
}

@ -172,7 +172,7 @@ public class VirtualFireAlarmTestCase extends TestBase {
{"testEnrollment"} )
public void testPolicyPublishing() throws Exception {
String deviceId2 = userMode == TestUserMode.TENANT_ADMIN ? tenantDeviceId2 : VirtualFireAlarmTestCase.deviceId2;
String topic = automationContext.getContextTenant().getDomain() + "/" + DEVICE_TYPE + "/" + deviceId2 + "/#";
String topic = automationContext.getContextTenant().getDomain() + "/" + DEVICE_TYPE + "/" + deviceId2 + "/operation/#";
String clientId = deviceId2 + ":" + DEVICE_TYPE;
HttpResponse response = restClient.post("/api/device-mgt/v1.0/policies", PayloadGenerator
.getJsonPayload(Constants.VirtualFireAlarmConstants.PAYLOAD_FILE,
@ -194,8 +194,7 @@ public class VirtualFireAlarmTestCase extends TestBase {
// 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());
Assert.assertEquals("Policy published message is not received by the mqtt listener. ", 2, mqttMessages.size());
}
}

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.9" jmeter="3.0 r1743807">
<jmeterTestPlan version="1.2" properties="2.8" jmeter="2.13 r1665067">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Android Device Management API" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
@ -304,6 +304,7 @@
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<threadCounts>true</threadCounts>
</value>
</objProp>
<stringProp name="filename">/home/ace/Desktop/results_multi_user_multi_tenancy.jtl</stringProp>
@ -2127,73 +2128,6 @@ GEL4ZNjZ+jnwSkzwBU5vh/QS&quot;,&#xd;
</HeaderManager>
<hashTree/>
</hashTree>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Android Device Management - PUT Pending Operations" enabled="true">
<boolProp name="HTTPSampler.postBodyRaw">true</boolProp>
<elementProp name="HTTPsampler.Arguments" elementType="Arguments">
<collectionProp name="Arguments.arguments">
<elementProp name="" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value">[&#xd;
{&#xd;
&quot;code&quot;: &quot;aaa&quot;,&#xd;
&quot;properties&quot;: {},&#xd;
&quot;type&quot;: &quot;CONFIG&quot;,&#xd;
&quot;id&quot;: 0,&#xd;
&quot;status&quot;: &quot;IN_PROGRESS&quot;,&#xd;
&quot;control&quot;: &quot;REPEAT&quot;,&#xd;
&quot;receivedTimeStamp&quot;: &quot;string&quot;,&#xd;
&quot;createdTimeStamp&quot;: &quot;string&quot;,&#xd;
&quot;payLoad&quot;: {},&#xd;
&quot;operationResponse&quot;: &quot;string&quot;,&#xd;
&quot;activityId&quot;: &quot;string&quot;,&#xd;
&quot;responses&quot;: [&#xd;
{&#xd;
&quot;response&quot;: &quot;string&quot;,&#xd;
&quot;receivedTimeStamp&quot;: &quot;string&quot;&#xd;
}&#xd;
],&#xd;
&quot;enabled&quot;: false&#xd;
}&#xd;
]</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</elementProp>
<stringProp name="HTTPSampler.domain">${host}</stringProp>
<stringProp name="HTTPSampler.port">${https_port}</stringProp>
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
<stringProp name="HTTPSampler.response_timeout"></stringProp>
<stringProp name="HTTPSampler.protocol">https</stringProp>
<stringProp name="HTTPSampler.contentEncoding">UTF-8</stringProp>
<stringProp name="HTTPSampler.path">/api/device-mgt/android/v1.0/devices/d24f870f390352a41000${DeviceID}/pending-operations</stringProp>
<stringProp name="HTTPSampler.method">PUT</stringProp>
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
<stringProp name="HTTPSampler.implementation">HttpClient4</stringProp>
<boolProp name="HTTPSampler.monitor">false</boolProp>
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
</HTTPSamplerProxy>
<hashTree>
<HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager" enabled="true">
<collectionProp name="HeaderManager.headers">
<elementProp name="" elementType="Header">
<stringProp name="Header.name">Authorization</stringProp>
<stringProp name="Header.value">Bearer ${access_token}</stringProp>
</elementProp>
<elementProp name="" elementType="Header">
<stringProp name="Header.name">Content-Type</stringProp>
<stringProp name="Header.value">application/json</stringProp>
</elementProp>
<elementProp name="" elementType="Header">
<stringProp name="Header.name">Accept</stringProp>
<stringProp name="Header.value">application/json</stringProp>
</elementProp>
</collectionProp>
</HeaderManager>
<hashTree/>
</hashTree>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Android Device Management - GET Status" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
@ -6400,73 +6334,6 @@ GEL4ZNjZ+jnwSkzwBU5vh/QS&quot;,&#xd;
</HeaderManager>
<hashTree/>
</hashTree>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Android Device Management - PUT Pending Operations" enabled="true">
<boolProp name="HTTPSampler.postBodyRaw">true</boolProp>
<elementProp name="HTTPsampler.Arguments" elementType="Arguments">
<collectionProp name="Arguments.arguments">
<elementProp name="" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value">[&#xd;
{&#xd;
&quot;code&quot;: &quot;aaa&quot;,&#xd;
&quot;properties&quot;: {},&#xd;
&quot;type&quot;: &quot;CONFIG&quot;,&#xd;
&quot;id&quot;: 0,&#xd;
&quot;status&quot;: &quot;IN_PROGRESS&quot;,&#xd;
&quot;control&quot;: &quot;REPEAT&quot;,&#xd;
&quot;receivedTimeStamp&quot;: &quot;string&quot;,&#xd;
&quot;createdTimeStamp&quot;: &quot;string&quot;,&#xd;
&quot;payLoad&quot;: {},&#xd;
&quot;operationResponse&quot;: &quot;string&quot;,&#xd;
&quot;activityId&quot;: &quot;string&quot;,&#xd;
&quot;responses&quot;: [&#xd;
{&#xd;
&quot;response&quot;: &quot;string&quot;,&#xd;
&quot;receivedTimeStamp&quot;: &quot;string&quot;&#xd;
}&#xd;
],&#xd;
&quot;enabled&quot;: false&#xd;
}&#xd;
]</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</elementProp>
<stringProp name="HTTPSampler.domain">${host}</stringProp>
<stringProp name="HTTPSampler.port">${https_port}</stringProp>
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
<stringProp name="HTTPSampler.response_timeout"></stringProp>
<stringProp name="HTTPSampler.protocol">https</stringProp>
<stringProp name="HTTPSampler.contentEncoding">UTF-8</stringProp>
<stringProp name="HTTPSampler.path">/api/device-mgt/android/v1.0/devices/d24f870f390352a41000${DeviceID}/pending-operations</stringProp>
<stringProp name="HTTPSampler.method">PUT</stringProp>
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
<stringProp name="HTTPSampler.implementation">HttpClient4</stringProp>
<boolProp name="HTTPSampler.monitor">false</boolProp>
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
</HTTPSamplerProxy>
<hashTree>
<HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager" enabled="true">
<collectionProp name="HeaderManager.headers">
<elementProp name="" elementType="Header">
<stringProp name="Header.name">Authorization</stringProp>
<stringProp name="Header.value">Bearer ${access_token}</stringProp>
</elementProp>
<elementProp name="" elementType="Header">
<stringProp name="Header.name">Content-Type</stringProp>
<stringProp name="Header.value">application/json</stringProp>
</elementProp>
<elementProp name="" elementType="Header">
<stringProp name="Header.name">Accept</stringProp>
<stringProp name="Header.value">application/json</stringProp>
</elementProp>
</collectionProp>
</HeaderManager>
<hashTree/>
</hashTree>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Android Device Management - GET Status" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>

@ -34,6 +34,7 @@
<class name="org.wso2.iot.integration.jmeter.AndroidDeviceManagementAPIJmeterTestCase"/>
<class name="org.wso2.iot.integration.mobileDevice.MobileDeviceManagement"/>
<class name="org.wso2.iot.integration.jmeter.PolicyManagementJMeterTestCase"/>
<class name="org.wso2.iot.integration.jmeter.DeviceTypeManagementJMeterTestCase"/>
<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"/>

@ -1511,7 +1511,7 @@
<carbon.governance.version>4.7.0</carbon.governance.version>
<!-- Carbon Device Management -->
<carbon.device.mgt.version>2.0.76-SNAPSHOT</carbon.device.mgt.version>
<carbon.device.mgt.version>3.0.0-SNAPSHOT</carbon.device.mgt.version>
<carbon.device.mgt.version.range>[2.0.0, 3.0.0)</carbon.device.mgt.version.range>
<!-- IOT Device Management -->

Loading…
Cancel
Save