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;
}
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);
}
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());
}
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());
}
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());
}
Aggregations