Search in sources :

Example 31 with Device

use of org.wso2.carbon.device.mgt.common.Device in project product-iots by wso2.

the class VirtualFireAlarmTestCase method testPolicyPublishing.

@Test(description = "Test whether the policy publishing from the server to device works", dependsOnMethods = { "testEventPublishing" })
public void testPolicyPublishing() throws Exception {
    String deviceId2 = userMode == TestUserMode.TENANT_ADMIN ? tenantDeviceId2 : VirtualFireAlarmTestCase.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, 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. ", 2, mqttMessages.size());
}
Also used : JsonArray(com.google.gson.JsonArray) MqttMessage(org.eclipse.paho.client.mqttv3.MqttMessage) JsonPrimitive(com.google.gson.JsonPrimitive) HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) JsonObject(com.google.gson.JsonObject) MqttSubscriberClient(org.wso2.iot.integration.common.MqttSubscriberClient) JsonParser(com.google.gson.JsonParser) Test(org.testng.annotations.Test)

Example 32 with Device

use of org.wso2.carbon.device.mgt.common.Device in project product-iots by wso2.

the class VirtualFireAlarmTestCase method testBatchDataPersistence.

// 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 = { "testPolicyPublishing" })
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 = restClient.get(url);
// TODO:Need to verify this testcase
// 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.assertTrue(
// "Published event for the device with the id " + deviceId1 + " is not inserted to analytics table",
// jsonArray.size() > 0);
// 
// url = Constants.VirtualFireAlarmConstants.STATS_ENDPOINT + "/" + deviceId2;
// url += "?from=" + (VirtualFireAlarmTestCase.currentTime - 300000)/1000 + "&to=" + System.currentTimeMillis()
// /1000;
// response = restClient.get(url);
// log.info("PAYLOADXX : " + response.getData());
// 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.assertTrue(
// "Published event for the device with the id " + deviceId2 + " is not inserted to analytics table",
// jsonArray.size() > 0);
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Example 33 with Device

use of org.wso2.carbon.device.mgt.common.Device in project product-iots by wso2.

the class AndroidDeviceManagementAPIJmeterTestCase method listServices.

@Test(description = "Testing the basic android device management API calls", dependsOnMethods = { "permutationTest" })
public void listServices() throws AutomationFrameworkException {
    URL url = Thread.currentThread().getContextClassLoader().getResource("jmeter-scripts" + File.separator + "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);
}
Also used : JMeterTest(org.wso2.carbon.automation.extensions.jmeter.JMeterTest) File(java.io.File) URL(java.net.URL) JMeterTestManager(org.wso2.carbon.automation.extensions.jmeter.JMeterTestManager) JMeterTest(org.wso2.carbon.automation.extensions.jmeter.JMeterTest) Test(org.testng.annotations.Test)

Example 34 with Device

use of org.wso2.carbon.device.mgt.common.Device in project product-iots by wso2.

the class AndroidOperation method testLock.

@Test(groups = { Constants.AndroidOperations.OPERATIONS_GROUP }, description = "Test Android device lock operation.")
public void testLock() throws MalformedURLException, AutomationFrameworkException {
    HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.LOCK_ENDPOINT, Constants.AndroidOperations.LOCK_OPERATION_PAYLOAD);
    Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Example 35 with Device

use of org.wso2.carbon.device.mgt.common.Device in project product-iots by wso2.

the class AndroidOperation method testClearPassword.

@Test(groups = { Constants.AndroidOperations.OPERATIONS_GROUP }, description = "Test Android device clear password " + "operation.")
public void testClearPassword() throws Exception {
    HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.CLEAR_PASSWORD_ENDPOINT, Constants.AndroidOperations.CLEAR_PASSWORD_PAYLOAD);
    Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)20 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)17 DeviceManagementException (org.wso2.carbon.device.mgt.common.DeviceManagementException)13 DeviceMgtPluginException (org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException)11 JsonParser (com.google.gson.JsonParser)10 SQLException (java.sql.SQLException)8 JsonObject (com.google.gson.JsonObject)7 Connection (java.sql.Connection)7 PreparedStatement (java.sql.PreparedStatement)7 HashMap (java.util.HashMap)6 ConnectedCupDeviceMgtPluginException (org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException)6 Device (org.wso2.carbon.device.mgt.common.Device)6 JsonArray (com.google.gson.JsonArray)5 JsonElement (com.google.gson.JsonElement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 JSONObject (org.json.simple.JSONObject)4 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)4 DeviceIdentifier (org.wso2.carbon.device.mgt.common.DeviceIdentifier)4