use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.
the class WindowsEnrollment method testBST.
@Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows BST.")
public void testBST() throws Exception {
JSONObject bsdObject = new JSONObject(Constants.WindowsEnrollment.BSD_PAYLOAD);
JSONObject childObject = bsdObject.getJSONObject("credentials");
JSONObject modifiedObject = new JSONObject();
modifiedObject.put("token", OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL));
childObject.put("token", modifiedObject);
HttpResponse response = client.post(Constants.WindowsEnrollment.BSD_URL, Constants.WindowsEnrollment.BSD_PAYLOAD);
bsd = response.getData();
Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_OK);
}
use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.
the class WindowsEnrollment method testMSXCEP.
@Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows MS XCEP post.", dependsOnMethods = "testBST")
public void testMSXCEP() throws Exception {
String xml = readXML(Constants.WindowsEnrollment.MS_XCEP_FILE, Constants.UTF8);
String payload = xml.replace(BSD_PLACEHOLDER, bsd);
client.setHttpHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_SOAP_XML);
HttpResponse response = client.post(Constants.WindowsEnrollment.MS_EXCEP, payload);
Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_ACCEPTED);
}
use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.
the class WindowsEnrollment method testDiscoveryPost.
@Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows Discovery post.")
public void testDiscoveryPost() throws Exception {
String xml = readXML(Constants.WindowsEnrollment.DISCOVERY_POST_FILE, Constants.UTF8);
client.setHttpHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_SOAP_XML);
HttpResponse response = client.post(Constants.WindowsEnrollment.DISCOVERY_POST_URL, xml);
Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_OK);
}
use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.
the class HTTPInvoker method sendHTTPPostWithOAuthSecurity.
public static HTTPResponse sendHTTPPostWithOAuthSecurity(String url, HttpEntity entity, HashMap<String, String> headers) {
HttpPost post = null;
HttpResponse response = null;
HTTPResponse httpResponse = new HTTPResponse();
CloseableHttpClient httpclient = null;
try {
httpclient = (CloseableHttpClient) createHttpClient();
post = new HttpPost(url);
post.setEntity(entity);
for (String key : headers.keySet()) {
post.setHeader(key, headers.get(key));
}
post.setHeader(Constants.Header.AUTH, OAUTH_BEARER + oAuthToken);
response = httpclient.execute(post);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyStoreException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
BufferedReader rd = null;
try {
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
} catch (IOException e) {
e.printStackTrace();
}
StringBuffer result = new StringBuffer();
String line = "";
try {
while ((line = rd.readLine()) != null) {
result.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
httpResponse.setResponseCode(response.getStatusLine().getStatusCode());
httpResponse.setResponse(result.toString());
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
return httpResponse;
}
use of org.wso2.carbon.automation.test.utils.http.client.HttpResponse in project product-iots by wso2.
the class HTTPInvoker method sendHTTPPostWithOAuthSecurity.
public static HTTPResponse sendHTTPPostWithOAuthSecurity(String url, String payload, HashMap<String, String> headers) {
HttpPost post = null;
HttpResponse response = null;
HTTPResponse httpResponse = new HTTPResponse();
CloseableHttpClient httpclient = null;
try {
httpclient = (CloseableHttpClient) createHttpClient();
StringEntity requestEntity = new StringEntity(payload, Constants.UTF_8);
post = new HttpPost(url);
post.setEntity(requestEntity);
for (String key : headers.keySet()) {
post.setHeader(key, headers.get(key));
}
post.setHeader(Constants.Header.AUTH, OAUTH_BEARER + oAuthToken);
response = httpclient.execute(post);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyStoreException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
BufferedReader rd = null;
try {
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
} catch (IOException e) {
e.printStackTrace();
}
StringBuffer result = new StringBuffer();
String line = "";
try {
while ((line = rd.readLine()) != null) {
result.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
httpResponse.setResponseCode(response.getStatusLine().getStatusCode());
httpResponse.setResponse(result.toString());
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
return httpResponse;
}
Aggregations