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 TransportException, MalformedURLException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
final byte[] body = { 1, 2, 3 };
final URL mockUrl = new URL("https://www.microsoft.com");
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, body, "");
request.send();
new Verifications() {
{
new HttpsConnection(mockUrl, (HttpsMethod) any, null, true).writeOutput(body);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method setConnectTimeoutSetsConnectTimeout.
@Test
public void setConnectTimeoutSetsConnectTimeout(@Mocked final HttpsConnection mockConn) throws TransportException, MalformedURLException {
final HttpsMethod httpsMethod = HttpsMethod.POST;
final byte[] body = new byte[0];
final int readTimeout = 1;
final URL mockUrl = new URL("https://www.microsoft.com");
new NonStrictExpectations() {
{
new HttpsConnection(mockUrl, httpsMethod, null, true);
result = mockConn;
}
};
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, body, "");
request.setConnectTimeout(readTimeout);
request.send();
new Verifications() {
{
mockConn.setConnectTimeout(readTimeout);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method setReadTimeoutSetsReadTimeout.
// Tests_SRS_HTTPSREQUEST_11_014: [The function shall set the read timeout for the request to the given value.]
@Test
public void setReadTimeoutSetsReadTimeout(@Mocked final HttpsConnection mockConn) throws TransportException, MalformedURLException {
final HttpsMethod httpsMethod = HttpsMethod.POST;
final byte[] body = new byte[0];
final int readTimeout = 1;
final URL mockUrl = new URL("https://www.microsoft.com");
new NonStrictExpectations() {
{
new HttpsConnection(mockUrl, httpsMethod, null, true);
result = mockConn;
}
};
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, body, "");
request.setReadTimeout(readTimeout);
request.send();
new Verifications() {
{
mockConn.setReadTimeout(readTimeout);
}
};
}
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, TransportException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
final byte[] body = { 1, 2 };
new Expectations() {
{
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 readInputCompletelyReadsInputStream.
// Tests_SRS_HTTPSCONNECTION_11_011: [The function shall read from the input stream (response stream) and return the response.]
@Test
public void readInputCompletelyReadsInputStream(@Mocked final InputStream mockIs) throws IOException, TransportException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
mockUrlConn.getInputStream();
result = mockIs;
mockIs.read();
returns(1, 2, 3, -1);
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.connect();
byte[] testResponse = conn.readInput();
byte[] expectedResponse = { 1, 2, 3 };
assertThat(testResponse, is(expectedResponse));
}
Aggregations