use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method constructorSetsHttpsMethodCorrectly.
// Tests_SRS_HTTPSREQUEST_11_004: [The function shall use the given HTTPS method (i.e. GET) as the request method.]
@Test
public void constructorSetsHttpsMethodCorrectly(@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((URL) any, httpsMethod);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection 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.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 {
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));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method setRequestMethodRejectsNonPostOrPutIfHasBody.
// Tests_SRS_HTTPSCONNECTION_11_007: [The function shall throw an IllegalArgumentException if the request currently has a non-empty body and the new method is not a POST or a PUT.]
@Test(expected = IllegalArgumentException.class)
public void setRequestMethodRejectsNonPostOrPutIfHasBody() throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.POST;
final HttpsMethod illegalHttpsMethod = HttpsMethod.DELETE;
final byte[] body = { 1, 2, 3 };
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
returns(httpsMethod.name(), illegalHttpsMethod.name());
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.writeOutput(body);
conn.setRequestMethod(illegalHttpsMethod);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method setRequestMethodSetsRequestMethod.
// Tests_SRS_HTTPSCONNECTION_11_006: [The function shall set the request method.]
@Test
public void setRequestMethodSetsRequestMethod() throws IOException {
final HttpsMethod httpsMethod = HttpsMethod.PUT;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.setRequestMethod(httpsMethod);
new Verifications() {
{
((HttpsURLConnection) mockUrl.openConnection()).setRequestMethod(httpsMethod.name());
}
};
}
Aggregations