use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method connectStreamsRequestBody.
// Tests_SRS_SERVICE_SDK_JAVA_HTTPSCONNECTION_12_006: [The function shall stream the request body, if present, through the connection.]
@Test
public void connectStreamsRequestBody() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.PUT;
byte[] body = { 1, 2, 3 };
final byte[] expectedBody = { 1, 2, 3 };
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
// Act
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
conn.writeOutput(body);
body[0] = 5;
conn.connect();
// Assert
new Verifications() {
{
mockUrl.openConnection().getOutputStream().write(expectedBody);
}
};
}
use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method constructorSetsRequestMethod.
// Tests_SRS_SERVICE_SDK_JAVA_HTTPSCONNECTION_12_003: [The constructor shall set the HTTPS method to the given method.]
@Test
public void constructorSetsRequestMethod() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.PUT;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
// Act
new HttpConnection(mockUrl, httpsMethod);
// Assert
new Verifications() {
{
mockUrl.openConnection();
}
};
}
use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method setRequestHeaderSetsRequestHeader.
// Tests_SRS_SERVICE_SDK_JAVA_HTTPSCONNECTION_12_010: [The function shall set the given request header field.]
@Test
public void setRequestHeaderSetsRequestHeader() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.POST;
final String field = "test-field";
final String value = "test-value";
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
// Act
conn.setRequestHeader(field, value);
// Assert
new Verifications() {
{
mockUrl.openConnection().setRequestProperty(field, value);
}
};
}
use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method readInputClosesInputStream.
// Tests_SRS_SERVICE_SDK_JAVA_HTTPSCONNECTION_12_016: [The function shall close the input stream after it has been completely read.]
@Test
public void readInputClosesInputStream(@Mocked final InputStream mockIs) throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.GET;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
mockUrlConn.getInputStream();
result = mockIs;
mockIs.read();
result = -1;
}
};
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
conn.connect();
// Act
conn.readInput();
// Assert
new Verifications() {
{
mockIs.close();
}
};
}
use of mockit.Verifications in project docker-maven-plugin by fabric8io.
the class LogRequestorTest method testAllStreams.
@Test
public void testAllStreams() throws Exception {
final Random rand = new Random();
final int upperBound = 1024;
RandomStringGenerator randomGenerator = new RandomStringGenerator.Builder().build();
final Streams type0 = Streams.STDIN;
final String msg0 = randomGenerator.generate(rand.nextInt(upperBound));
final ByteBuffer buf0 = messageToBuffer(type0, msg0);
final Streams type1 = Streams.STDOUT;
final String msg1 = randomGenerator.generate(rand.nextInt(upperBound));
final ByteBuffer buf1 = messageToBuffer(type1, msg1);
final Streams type2 = Streams.STDERR;
final String msg2 = randomGenerator.generate(rand.nextInt(upperBound));
final ByteBuffer buf2 = messageToBuffer(type2, msg2);
final ByteBuffer body = combineBuffers(buf0, buf1, buf2);
final InputStream inputStream = new ByteArrayInputStream(body.array());
setupMocks(inputStream);
new LogRequestor(client, urlBuilder, containerId, callback).fetchLogs();
new Verifications() {
{
callback.log(type0.type, (Timestamp) any, msg0);
callback.log(type1.type, (Timestamp) any, msg1);
callback.log(type2.type, (Timestamp) any, msg2);
}
};
}
Aggregations