Search in sources :

Example 1 with Expectations

use of mockit.Expectations in project jersey by jersey.

the class FormDataMultiPartReaderWriterTest method mimeTempFileRemovedAfterAbortedUpload.

/**
     * Mocked JERSEY-2794 reproducer. Real test is under integration tests.
     */
@Test
public void mimeTempFileRemovedAfterAbortedUpload(@Mocked final MIMEMessage message) throws Exception {
    new Expectations() {

        {
            message.getAttachments();
            result = new MIMEParsingException();
        }
    };
    final URL url = new URL(getBaseUri().toString() + "MediaTypeWithBoundaryResource");
    final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("PUT");
    connection.setRequestProperty("Accept", "text/plain");
    connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=XXXX_YYYY");
    connection.setDoOutput(true);
    connection.connect();
    final OutputStream outputStream = connection.getOutputStream();
    outputStream.write("--XXXX_YYYY".getBytes());
    outputStream.write('\n');
    outputStream.write("Content-Type: text/plain".getBytes());
    outputStream.write('\n');
    outputStream.write("Content-Disposition: form-data; name=\"big-part\"".getBytes());
    outputStream.write('\n');
    outputStream.write('\n');
    // Send big chunk of data.
    for (int i = 0; i < 16 * 4096; i++) {
        outputStream.write('E');
        if (i % 1024 == 0) {
            outputStream.flush();
        }
    }
    // Do NOT send end of the MultiPart message to simulate the issue.
    // Get Response ...
    final int response = connection.getResponseCode();
    // ... Disconnect.
    connection.disconnect();
    assertThat("Bad Request expected", response, is(400));
    // Make sure that the Mimepull message and it's parts have been closed and temporary files deleted.
    new Verifications() {

        {
            message.close();
            times = 1;
        }
    };
}
Also used : Expectations(mockit.Expectations) HttpURLConnection(java.net.HttpURLConnection) MIMEParsingException(org.jvnet.mimepull.MIMEParsingException) OutputStream(java.io.OutputStream) Verifications(mockit.Verifications) URL(java.net.URL) Test(org.junit.Test)

Example 2 with Expectations

use of mockit.Expectations in project pulsar by yahoo.

the class AbstractStatelessLongHashTest method testCalculateReadOnlyByteBuffer.

@Test
public void testCalculateReadOnlyByteBuffer() {
    final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
    input.position(5);
    input.limit(15);
    new Expectations(hash) {

        {
            hash.calculateUnchecked(withInstanceOf(byte[].class), 0, 10);
        }
    };
    hash.calculate(input);
    assertEquals(input.limit(), input.position());
}
Also used : Expectations(mockit.Expectations) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 3 with Expectations

use of mockit.Expectations in project pulsar by yahoo.

the class AbstractIncrementalIntHashTest method testCalculateByteBuffer.

@Test
public void testCalculateByteBuffer() {
    final ByteBuffer input = ByteBuffer.allocate(10);
    new Expectations(hash) {

        {
            hash.initial();
            result = 42;
            hash.resume(42, input);
        }
    };
    hash.calculate(input);
}
Also used : Expectations(mockit.Expectations) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 4 with Expectations

use of mockit.Expectations in project pulsar by yahoo.

the class AbstractIncrementalIntHashTest method testResumeIntReadOnlyByteBuffer.

@Test
public void testResumeIntReadOnlyByteBuffer() {
    final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
    input.position(5);
    input.limit(15);
    new Expectations(hash) {

        {
            hash.resumeUnchecked(42, withInstanceOf(byte[].class), 0, 10);
        }
    };
    hash.resume(42, input);
    assertEquals(input.limit(), input.position());
}
Also used : Expectations(mockit.Expectations) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 5 with Expectations

use of mockit.Expectations in project pulsar by yahoo.

the class AbstractIncrementalIntHashTest method testResumeIntByteBuffer.

@Test
public void testResumeIntByteBuffer() {
    final ByteBuffer input = ByteBuffer.allocate(20);
    input.position(5);
    input.limit(15);
    new Expectations(hash) {

        {
            hash.resumeUnchecked(42, input.array(), input.arrayOffset() + 5, 10);
        }
    };
    hash.resume(42, input);
    assertEquals(input.limit(), input.position());
}
Also used : Expectations(mockit.Expectations) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Aggregations

Expectations (mockit.Expectations)113 Test (org.junit.Test)98 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)60 FeedbackReceiver (com.microsoft.azure.sdk.iot.service.FeedbackReceiver)19 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)19 Test (org.testng.annotations.Test)14 AmqpSendHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler)12 ByteBuffer (java.nio.ByteBuffer)12 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)10 AmqpFeedbackReceivedHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler)6 AmqpReceive (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpReceive)5 URIEndpointObject (io.servicecomb.foundation.common.net.URIEndpointObject)5 FeedbackBatch (com.microsoft.azure.sdk.iot.service.FeedbackBatch)4 Message (com.microsoft.azure.sdk.iot.service.Message)4 AmqpSend (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend)4 HeartbeatResponse (io.servicecomb.serviceregistry.api.response.HeartbeatResponse)4 WebSocketImpl (com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl)3 Tools (com.microsoft.azure.sdk.iot.service.Tools)3 AmqpFileUploadNotificationReceive (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFileUploadNotificationReceive)3 Endpoint (io.servicecomb.core.Endpoint)3