Search in sources :

Example 11 with HTTPResponse

use of org.wso2.mdm.qsg.dto.HTTPResponse in project product-iots by wso2.

the class RestClient method delete.

public HttpResponse delete(String endpoint) throws Exception {
    HttpURLConnection conn = null;
    HttpResponse httpResponse1;
    try {
        URL url = new URL(backEndUrl + endpoint);
        conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("DELETE");
        conn.setDoOutput(true);
        conn.setReadTimeout(30000);
        Iterator entryIterator = this.requestHeaders.entrySet().iterator();
        while (entryIterator.hasNext()) {
            Map.Entry rd = (Map.Entry) entryIterator.next();
            conn.setRequestProperty((String) rd.getKey(), (String) rd.getValue());
        }
        conn.connect();
        StringBuilder sb1 = new StringBuilder();
        BufferedReader rd1 = null;
        HttpResponse httpResponse;
        try {
            rd1 = new BufferedReader(new InputStreamReader(conn.getInputStream(), Charset.defaultCharset()));
            String ignored;
            while ((ignored = rd1.readLine()) != null) {
                sb1.append(ignored);
            }
            httpResponse = new HttpResponse(sb1.toString(), conn.getResponseCode());
            httpResponse.setResponseMessage(conn.getResponseMessage());
        } catch (IOException e) {
            rd1 = new BufferedReader(new InputStreamReader(conn.getErrorStream(), Charset.defaultCharset()));
            String line;
            while ((line = rd1.readLine()) != null) {
                sb1.append(line);
            }
            httpResponse = new HttpResponse(sb1.toString(), conn.getResponseCode());
            httpResponse.setResponseMessage(conn.getResponseMessage());
        } finally {
            if (rd1 != null) {
                rd1.close();
            }
        }
        httpResponse1 = httpResponse;
    } finally {
        if (conn != null) {
            conn.disconnect();
        }
    }
    return httpResponse1;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Iterator(java.util.Iterator) HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Map(java.util.Map) HashMap(java.util.HashMap) URL(java.net.URL)

Example 12 with HTTPResponse

use of org.wso2.mdm.qsg.dto.HTTPResponse in project product-iots by wso2.

the class LicenseManagement method testGetLicense.

@Test(description = "Test get license.")
public void testGetLicense() throws Exception {
    HttpResponse response = client.get(Constants.LicenseManagement.GET_LICENSE_ENDPOINT);
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.LicenseManagement.LICENSE_RESPONSE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_GET).toString(), response.getData().toString(), true);
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Example 13 with HTTPResponse

use of org.wso2.mdm.qsg.dto.HTTPResponse in project product-iots by wso2.

the class MobileDeviceManagement method testGetUserDevices.

@Test(description = "Test getting devices")
public void testGetUserDevices() throws Exception {
    int expectedCount = this.userMode == TestUserMode.TENANT_ADMIN ? 3 : 13;
    HttpResponse response = client.get(Constants.MobileDeviceManagement.GET_ALL_DEVICES_ENDPOINT + Constants.MobileDeviceManagement.USER_DEVICE_ENDPOINT);
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    JsonObject devices = new JsonParser().parse(response.getData()).getAsJsonObject();
    Assert.assertEquals("Expected device count is not received", expectedCount, devices.get("count").getAsInt());
}
Also used : 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 14 with HTTPResponse

use of org.wso2.mdm.qsg.dto.HTTPResponse in project product-iots by wso2.

the class MobileDeviceManagement method testViewDevices.

@Test(description = "Test getting devices")
public void testViewDevices() throws Exception {
    int expectedCount = this.userMode == TestUserMode.TENANT_ADMIN ? 3 : 23;
    HttpResponse response = client.get(Constants.MobileDeviceManagement.GET_ALL_DEVICES_ENDPOINT);
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    JsonObject devices = new JsonParser().parse(response.getData()).getAsJsonObject();
    Assert.assertEquals("Expected device count is not received", expectedCount, devices.get("count").getAsInt());
}
Also used : 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 15 with HTTPResponse

use of org.wso2.mdm.qsg.dto.HTTPResponse in project product-iots by wso2.

the class MobileDeviceManagement method testAdvancedSearch.

@Test(description = "Test Advance search")
public void testAdvancedSearch() throws Exception {
    JsonArray pendingOperationsData = PayloadGenerator.getJsonArray(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.AndroidEnrollment.GET_PENDING_OPERATIONS_METHOD);
    JsonArray newPayload = new JsonArray();
    HttpResponse response = client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + Constants.DEVICE_ID + "/pending-operations", pendingOperationsData.toString());
    JsonArray pendingOperations = new JsonParser().parse(response.getData()).getAsJsonArray();
    for (JsonElement pendingOperation : pendingOperations) {
        JsonObject jsonObject = pendingOperation.getAsJsonObject();
        if (jsonObject.get("code").getAsString().equals("DEVICE_INFO")) {
            jsonObject.addProperty("operationResponse", PayloadGenerator.getJsonPayload(Constants.MobileDeviceManagement.REQUEST_PAYLOAD_FILE_NAME, Constants.MobileDeviceManagement.UPDATE_PAYLOAD_OPERATION).toString());
            jsonObject.addProperty("status", "COMPLETED");
            newPayload.add(jsonObject);
            break;
        }
    }
    client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + Constants.DEVICE_ID + "/pending-operations", newPayload.toString());
    response = client.post(Constants.MobileDeviceManagement.GET_ALL_DEVICES_ENDPOINT + Constants.MobileDeviceManagement.ADVANCE_SEARCH_ENDPOINT, PayloadGenerator.getJsonPayload(Constants.MobileDeviceManagement.REQUEST_PAYLOAD_FILE_NAME, Constants.MobileDeviceManagement.ADVANCE_SEARCH_OPERATION).toString());
    JsonObject devices = new JsonParser().parse(response.getData()).getAsJsonObject();
    Assert.assertEquals("Expected device count is not received", 1, devices.get("devices").getAsJsonArray().size());
}
Also used : JsonArray(com.google.gson.JsonArray) 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)

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