Search in sources :

Example 81 with HttpResponse

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

the class AndroidEnrollment method testGetPendingOperations.

@Test(description = "Test get pending operations", dependsOnMethods = { "testModifyEnrollment" })
public void testGetPendingOperations() throws Exception {
    JsonArray pendingOperationsData = PayloadGenerator.getJsonArray(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.AndroidEnrollment.GET_PENDING_OPERATIONS_METHOD);
    HttpResponse response = client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId + "/pending-operations", pendingOperationsData.toString());
    JsonArray pendingOperations = new JsonParser().parse(response.getData()).getAsJsonArray();
    Assert.assertEquals("Error while getting pending operations for android device with the id " + deviceId, HttpStatus.SC_CREATED, response.getResponseCode());
    Assert.assertTrue("Pending operation count is 0. Periodic monitoring tasks are not running.", 0 < pendingOperations.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)

Example 82 with HttpResponse

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

the class AndroidEnrollment method testModifyEnrollment.

@Test(description = "Test modify enrollment.", dependsOnMethods = { "testIsEnrolled" })
public void testModifyEnrollment() throws Exception {
    JsonObject enrollmentData = PayloadGenerator.getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_PUT);
    HttpResponse response = client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId, enrollmentData.toString());
    AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_PUT).toString(), response.getData(), true);
}
Also used : JsonObject(com.google.gson.JsonObject) HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Example 83 with HttpResponse

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

the class WindowsEnrollment method testServerAvailability.

/**
 * Test the Windows Discovery Get endpoint to see if the server is available.
 *
 * @throws Exception
 */
@Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows Discovery get.")
public void testServerAvailability() throws Exception {
    client.setHttpHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_SOAP_XML);
    HttpResponse response = client.get(Constants.WindowsEnrollment.DISCOVERY_GET_URL);
    Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_OK);
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Example 84 with HttpResponse

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

the class AndroidPolicy method testGetEffectivePolicy.

@Test(groups = Constants.AndroidPolicy.POLICY_GROUP, description = "Test Android getEffectivePolicy.")
public void testGetEffectivePolicy() throws Exception {
    HttpResponse response = client.get(Constants.AndroidPolicy.POLICY_ENDPOINT + Constants.DEVICE_ID);
    AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.AndroidPolicy.POLICY_RESPONSE_PAYLOAD_FILE_NAME, Constants.AndroidPolicy.GET_EFFECTIVE_POLICY).toString(), response.getData().toString(), true);
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 85 with HttpResponse

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

the class AppOperations method uploadApplication.

public static MobileApplication uploadApplication(String platform, String appName, String appContentType) {
    String appUploadEndpoint = EMMQSGConfig.getInstance().getEmmHost() + appmPublisherMobileBinariesUrl;
    String filePath = "apps" + File.separator + platform + File.separator + appName;
    HTTPResponse httpResponse = HTTPInvoker.uploadFile(appUploadEndpoint, filePath, appContentType);
    if (Constants.HTTPStatus.OK == httpResponse.getResponseCode()) {
        JSONObject appMeta = null;
        MobileApplication application = new MobileApplication();
        try {
            appMeta = (JSONObject) new JSONParser().parse(httpResponse.getResponse());
            application.setPackageId((String) appMeta.get("package"));
            application.setAppId(QSGUtils.getResourceId((String) appMeta.get("path")));
            application.setVersion((String) appMeta.get("version"));
            application.setPlatform(platform);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return application;
    }
    return null;
}
Also used : JSONObject(org.json.simple.JSONObject) MobileApplication(org.wso2.mdm.qsg.dto.MobileApplication) HTTPResponse(org.wso2.mdm.qsg.dto.HTTPResponse) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

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