Search in sources :

Example 26 with Device

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());
}
Also used : RestClient(org.wso2.iot.integration.common.RestClient) JsonObject(com.google.gson.JsonObject) BeforeClass(org.testng.annotations.BeforeClass)

Example 27 with Device

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");
}
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) Test(org.testng.annotations.Test) JMeterTest(org.wso2.carbon.automation.extensions.jmeter.JMeterTest)

Example 28 with Device

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);
}
Also used : MqttClient(org.eclipse.paho.client.mqttv3.MqttClient) JsonArray(com.google.gson.JsonArray) MqttMessage(org.eclipse.paho.client.mqttv3.MqttMessage) MemoryPersistence(org.eclipse.paho.client.mqttv3.persist.MemoryPersistence) MqttConnectOptions(org.eclipse.paho.client.mqttv3.MqttConnectOptions) HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Timestamp(java.sql.Timestamp) JsonParser(com.google.gson.JsonParser) Test(org.testng.annotations.Test)

Example 29 with Device

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);
}
Also used : JsonElement(com.google.gson.JsonElement) HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Test(org.testng.annotations.Test)

Example 30 with Device

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);
}
Also used : DeviceAddGroupPage(org.wso2.iot.integration.ui.pages.groups.DeviceAddGroupPage) 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