use of org.wso2.carbon.device.mgt.common.Device in project product-iots by wso2.
the class AndroidOperation method initTest.
@BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP })
public void initTest() throws Exception {
super.init(userMode);
this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
// Enroll a device
JsonObject enrollmentData = PayloadGenerator.getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST);
client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData.toString());
}
use of org.wso2.carbon.device.mgt.common.Device in project product-iots by wso2.
the class DeviceTypeManagementJMeterTestCase method DeviceTypeManagementTest.
@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");
}
use of org.wso2.carbon.device.mgt.common.Device in project product-iots by wso2.
the class AndroidSenseEnrollment method testEventPublishing.
@Test(description = "Test an Android sense device data publishing.", dependsOnMethods = { "testEnrollment" })
public void testEventPublishing() throws Exception {
String DEVICE_TYPE = "android_sense";
String topic = automationContext.getContextTenant().getDomain() + "/" + DEVICE_TYPE + "/" + DEVICE_ID + "/data";
int qos = 2;
String broker = "tcp://localhost:1886";
String clientId = DEVICE_ID + ":" + 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");
MqttMessage message = new MqttMessage(PayloadGenerator.getJsonArray(Constants.AndroidSenseEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.AndroidSenseEnrollment.PUBLISH_DATA_OPERATION).toString().getBytes());
message.setQos(qos);
for (int i = 0; i < 100; i++) {
sampleClient.publish(topic, message);
log.info("Message is published to Mqtt Client");
Thread.sleep(1000);
}
sampleClient.disconnect();
HttpResponse response = analyticsClient.get(Constants.AndroidSenseEnrollment.IS_TABLE_EXIST_CHECK_URL + "?table=" + Constants.AndroidSenseEnrollment.BATTERY_STATS_TABLE_NAME);
Assert.assertEquals("ORG_WSO2_IOT_ANDROID_BATTERY_STATS table does not exist. Problem with the android sense " + "analytics", HttpStatus.SC_OK, response.getResponseCode());
// Allow some time to perform the analytics tasks.
log.info("Mqtt Client is Disconnected");
String url = Constants.AndroidSenseEnrollment.RETRIEVER_ENDPOINT + Constants.AndroidSenseEnrollment.BATTERY_STATS_TABLE_NAME + "/";
Timestamp timestamp = new Timestamp(System.currentTimeMillis() - 3600000);
url += timestamp.getTime() + "/" + new Timestamp(System.currentTimeMillis()).getTime() + "/0/100";
response = analyticsClient.get(url);
JsonArray jsonArray = new JsonParser().parse(response.getData()).getAsJsonArray();
// TODO: temporarily commenting out untill new changes are merged
// Assert.assertEquals(
// "Published event for the device with the id " + DEVICE_ID + " is not inserted to analytics table",
// HttpStatus.SC_OK, response.getResponseCode());
// Assert.assertTrue(
// "Published event for the device with the id " + DEVICE_ID + " 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 AndroidEnrollment method testEnrollment.
@Test(description = "Test an Android device enrollment.")
public void testEnrollment() throws Exception {
String enrollmentData = PayloadGenerator.getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST).toString();
HttpResponse response = client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData);
JsonParser jsonParser = new JsonParser();
JsonElement element = jsonParser.parse(response.getData());
JsonObject jsonObject = element.getAsJsonObject();
JsonElement msg = jsonObject.get("responseMessage");
deviceId = msg.getAsString().split("\'")[1].split("\'")[0];
Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST).toString(), response.getData(), true);
}
use of org.wso2.carbon.device.mgt.common.Device in project product-iots by wso2.
the class DeviceGroupTest method addNewGroupTest.
@Test(description = "Test for adding a new device group.")
public void addNewGroupTest() throws IOException {
DeviceAddGroupPage addGroupPage = adminDashboard.addGroup();
addGroupPage.addNewGroup(Constants.GROUP_NAME, Constants.GROUP_DESCRIPTION);
}
Aggregations