use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method sendThrowsIoExceptionIfCannotConnect.
// Tests_SRS_HTTPSREQUEST_11_011: [If the client cannot connect to the server, the function shall throw an IOException.]
@Test(expected = IOException.class)
public void sendThrowsIoExceptionIfCannotConnect(@Mocked final HttpsConnection mockConn) throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.POST;
final byte[] body = new byte[0];
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockConn.connect();
result = new IOException();
mockConn.getResponseHeaders();
result = new IOException();
mockConn.getResponseStatus();
result = new IOException();
mockConn.readInput();
result = new IOException();
mockConn.readError();
result = new IOException();
}
};
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, body);
request.send();
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method setHeaderFieldSetsHeaderField.
// Tests_SRS_HTTPSREQUEST_11_013: [The function shall set the header field with the given name to the given value.]
@Test
public void setHeaderFieldSetsHeaderField(@Mocked final HttpsConnection mockConn) throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.POST;
final byte[] body = new byte[0];
final String field = "test-field";
final String value = "test-value";
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
}
};
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, body);
request.setHeaderField(field, value);
new Verifications() {
{
mockConn.setRequestHeader(field, value);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method constructorOpensConnection.
// Tests_SRS_HTTPSREQUEST_11_001: [The function shall open a connection with the given URL as the endpoint.]
@Test
public void constructorOpensConnection(@Mocked final HttpsConnection mockConn) throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
final byte[] body = new byte[0];
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
}
};
new HttpsRequest(mockUrl, httpsMethod, body);
new Verifications() {
{
new HttpsConnection(mockUrl, (HttpsMethod) any);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method sendReturnsHeaderFieldsOnBadStatusException.
// Tests_SRS_HTTPSREQUEST_11_009: [The function shall return the HTTPS response received, including the status code, body, header fields, and error reason (if any).]
@Test
public void sendReturnsHeaderFieldsOnBadStatusException(@Mocked final HttpsConnection mockConn) throws IOException {
final Map<String, List<String>> headerFields = new HashMap<>();
final String field = "test-field";
final List<String> values = new LinkedList<>();
final String value = "test-value0";
values.add(value);
headerFields.put(field, values);
final HttpsMethod httpsMethod = HttpsMethod.POST;
final byte[] body = new byte[0];
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockConn.connect();
result = new IOException();
mockConn.getResponseHeaders();
result = headerFields;
}
};
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, body);
HttpsResponse response = request.send();
String testValues = response.getHeaderField(field);
final String expectedValues = value;
assertThat(testValues, is(expectedValues));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method setSSLContextThrowsOnNull.
//Tests_SRS_HTTPSREQUEST_25_015: [**The function shall throw IllegalArgumentException if parameter is null .**]**
@Test(expected = IllegalArgumentException.class)
public void setSSLContextThrowsOnNull(@Mocked final HttpsConnection mockConn, @Mocked final IotHubSSLContext mockedContext) throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.POST;
final byte[] body = new byte[0];
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
}
};
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, body);
request.setSSLContext(null);
}
Aggregations