use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method writeOutputFailsWhenMethodIsNotPostOrPut.
// Tests_SRS_HTTPSCONNECTION_11_010: [The function shall throw an IllegalArgumentException if the request does not currently use method POST or PUT and the body is non-empty.]
@Test(expected = IllegalArgumentException.class)
public void writeOutputFailsWhenMethodIsNotPostOrPut() throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
final byte[] body = { 1, 2 };
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.writeOutput(body);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method setSSLContextThrowsOnNullContext.
//Tests_SRS_HTTPSCONNECTION_25_025: [The function shall throw IllegalArgumentException if the context is null value.**]**
@Test(expected = IllegalArgumentException.class)
public void setSSLContextThrowsOnNullContext(@Mocked final SSLContext mockedContext) throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.POST;
final String field = "test-field";
final String value = "test-value";
final int timeout = 1;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
final HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
Deencapsulation.invoke(conn, "setSSLContext", SSLContext.class);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method getResponseStatusReturnsResponseStatus.
// Tests_SRS_HTTPSCONNECTION_11_015: [The function shall return the response status code.]
@Test
public void getResponseStatusReturnsResponseStatus(@Mocked final InputStream mockIs) throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
final int status = 204;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
mockUrlConn.getResponseCode();
result = status;
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.connect();
int testStatus = conn.getResponseStatus();
int expectedStatus = status;
assertThat(testStatus, is(expectedStatus));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method constructorThrowsIoExceptionIfCannotSetupConnection.
// Tests_SRS_HTTPSREQUEST_11_005: [If an IOException occurs in setting up the HTTPS connection, the function shall throw an IOException.]
@Test(expected = IOException.class)
public void constructorThrowsIoExceptionIfCannotSetupConnection(@Mocked final HttpsConnection mockConn) throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
final byte[] body = new byte[0];
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
new HttpsConnection(mockUrl, httpsMethod);
result = new IOException();
}
};
new HttpsRequest(mockUrl, httpsMethod, body);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method constructorWritesBodyToConnection.
// Tests_SRS_HTTPSREQUEST_11_002: [The function shall write the body to the connection.]
@Test
public void constructorWritesBodyToConnection(@Mocked final HttpsConnection mockConn) throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
final byte[] body = { 1, 2, 3 };
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
}
};
new HttpsRequest(mockUrl, httpsMethod, body);
final byte[] expectedBody = body;
new Verifications() {
{
new HttpsConnection(mockUrl, (HttpsMethod) any).writeOutput(expectedBody);
}
};
}
Aggregations