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());
}
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);
}
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);
}
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());
}
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());
}
Aggregations