Search in sources :

Example 76 with HttpResponse

use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.

the class AndroidSenseEnrollment method testEnrollment.

@Test(description = "Test an Android sense device enrollment.")
public void testEnrollment() throws Exception {
    // Time for deploying the carbon apps
    Thread.sleep(30000);
    HttpResponse response = client.post(Constants.AndroidSenseEnrollment.ENROLLMENT_ENDPOINT + DEVICE_ID + "/register?deviceName=android_sense_test", "");
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    JsonElement jsonElement = new JsonParser().parse(response.getData());
    JsonObject expectedPayloadObject = jsonElement.getAsJsonObject();
    Assert.assertNotNull("Mqtt end-point is returned with the android sense enrollment " + "payload", expectedPayloadObject.get("mqttEndpoint"));
    Assert.assertNotNull("Tenant domain is returned with the android sense enrollment " + "payload", expectedPayloadObject.get("tenantDomain"));
}
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 77 with HttpResponse

use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.

the class AndroidSenseEnrollment method initTest.

@BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP })
public void initTest() throws Exception {
    super.init(userMode);
    User currentUser = getAutomationContext().getContextTenant().getContextUser();
    byte[] bytesEncoded = Base64.encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes());
    String encoded = new String(bytesEncoded);
    String auth_string = "Basic " + encoded;
    String anaytics_https_url = automationContext.getContextUrls().getWebAppURLHttps().replace("9443", String.valueOf(Constants.HTTPS_ANALYTICS_PORT)).replace("/t/" + automationContext.getContextTenant().getDomain(), "") + "/";
    this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
    this.analyticsClient = new RestClient(anaytics_https_url, Constants.APPLICATION_JSON, auth_string);
    if (this.userMode == TestUserMode.TENANT_ADMIN) {
        HttpResponse response = client.post(Constants.AndroidSenseEnrollment.ANALYTICS_ARTIFACTS_DEPLOYMENT_ENDPOINT, "");
        Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
    }
}
Also used : User(org.wso2.carbon.automation.engine.context.beans.User) RestClient(org.wso2.iot.integration.common.RestClient) HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) BeforeClass(org.testng.annotations.BeforeClass)

Example 78 with HttpResponse

use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.

the class ConfigurationManagement method testSaveConfiguration.

@Test(description = "Test save configuration.")
public void testSaveConfiguration() throws Exception {
    HttpResponse response = client.post(Constants.ConfigurationManagement.CONFIGURATION_ENDPOINT, PayloadGenerator.getJsonPayload(Constants.ConfigurationManagement.CONFIGURATION_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST).toString());
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.ConfigurationManagement.CONFIGURATION_RESPONSE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST).toString(), response.getData().toString(), true);
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Example 79 with HttpResponse

use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.

the class AndroidEnrollment method testIsEnrolled.

@Test(description = "Test an Android device is enrolled.", dependsOnMethods = { "testEnrollment" })
public void testIsEnrolled() throws Exception {
    HttpResponse response = client.get(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId + "/status");
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_GET).toString(), response.getData(), true);
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Example 80 with HttpResponse

use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.

the class AndroidEnrollment method testUpdateApplications.

@Test(description = "Test update applications", dependsOnMethods = { "testModifyEnrollment" })
public void testUpdateApplications() throws Exception {
    JsonArray updateApplicationData = PayloadGenerator.getJsonArray(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.AndroidEnrollment.UPDATE_APPLICATION_METHOD);
    HttpResponse response = client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId + "/applications", updateApplicationData.toString());
    Assert.assertEquals("Update of applications for the device id " + deviceId + " failed", HttpStatus.SC_ACCEPTED, response.getResponseCode());
    response = client.get(Constants.MobileDeviceManagement.CHANGE_DEVICE_STATUS_ENDPOINT + Constants.AndroidEnrollment.ANDROID_DEVICE_TYPE + "/" + deviceId + "/applications");
    Assert.assertEquals("Error while getting application list for the device with the id " + deviceId + " failed", HttpStatus.SC_OK, response.getResponseCode());
    JsonArray jsonArray = new JsonParser().parse(response.getData()).getAsJsonArray();
    Assert.assertEquals("Installed applications for the device with the device id " + deviceId + " has not been " + "updated yet", 3, jsonArray.size());
}
Also used : JsonArray(com.google.gson.JsonArray) HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) JsonParser(com.google.gson.JsonParser) Test(org.testng.annotations.Test)

Aggregations

HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)75 Test (org.testng.annotations.Test)72 JsonObject (com.google.gson.JsonObject)15 HTTPResponse (org.wso2.mdm.qsg.dto.HTTPResponse)15 JsonParser (com.google.gson.JsonParser)14 JSONObject (org.json.simple.JSONObject)11 HashMap (java.util.HashMap)9 JsonArray (com.google.gson.JsonArray)8 IOException (java.io.IOException)8 HttpURLConnection (java.net.HttpURLConnection)8 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)7 KeyManagementException (java.security.KeyManagementException)6 KeyStoreException (java.security.KeyStoreException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 HttpResponse (org.apache.http.HttpResponse)6 ClientProtocolException (org.apache.http.client.ClientProtocolException)6 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)6 HttpPost (org.apache.http.client.methods.HttpPost)5 JSONArray (org.json.simple.JSONArray)5 JsonElement (com.google.gson.JsonElement)4