Search in sources :

Example 6 with BufferInputStream

use of org.apache.servicecomb.foundation.vertx.stream.BufferInputStream in project incubator-servicecomb-java-chassis by apache.

the class TestVertxUtils method testgetBytesFastBufferInputStream.

@Test
public void testgetBytesFastBufferInputStream() throws IOException {
    byte[] bytes = new byte[] { 1 };
    ByteBuf byteBuf = Unpooled.wrappedBuffer(bytes);
    try (BufferInputStream inputStream = new BufferInputStream(byteBuf)) {
        byte[] result = VertxUtils.getBytesFast(inputStream);
        Assert.assertSame(bytes, result);
    }
}
Also used : BufferInputStream(org.apache.servicecomb.foundation.vertx.stream.BufferInputStream) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 7 with BufferInputStream

use of org.apache.servicecomb.foundation.vertx.stream.BufferInputStream in project incubator-servicecomb-java-chassis by apache.

the class TestStream method testBufferInputStream.

@Test
public void testBufferInputStream() {
    ByteBuf obuf = Buffer.buffer(DIRECT_BUFFER_SIZE).getByteBuf();
    obuf.writeBytes(("testss").getBytes());
    @SuppressWarnings("resource") BufferInputStream oBufferInputStream = new BufferInputStream(obuf);
    Assert.assertNotEquals(1234, oBufferInputStream.skip(0));
    Assert.assertNotEquals(obuf.readByte(), oBufferInputStream.readByte());
    Assert.assertEquals(obuf.readByte() + 1, oBufferInputStream.read());
    Assert.assertEquals(obuf.readBoolean(), oBufferInputStream.readBoolean());
    Assert.assertEquals(obuf.readerIndex(), oBufferInputStream.getIndex());
    Assert.assertEquals(obuf.readableBytes(), oBufferInputStream.available());
    Assert.assertNotEquals(null, oBufferInputStream.read(("test").getBytes()));
}
Also used : BufferInputStream(org.apache.servicecomb.foundation.vertx.stream.BufferInputStream) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 8 with BufferInputStream

use of org.apache.servicecomb.foundation.vertx.stream.BufferInputStream in project incubator-servicecomb-java-chassis by apache.

the class TestStandardHttpServletRequestEx method parameterMap_merge.

@Test
public void parameterMap_merge() throws IOException {
    Map<String, String[]> inherited = new HashMap<>();
    String[] v1 = new String[] { "v1-1", "v1-2" };
    inherited.put("p1", v1);
    Buffer buffer = Buffer.buffer("p1=v1-3;p2=v2");
    BufferInputStream inputStream = new BufferInputStream(buffer.getByteBuf());
    new Expectations() {

        {
            request.getParameterMap();
            result = inherited;
            request.getMethod();
            result = HttpMethod.PUT;
            request.getContentType();
            result = MediaType.APPLICATION_FORM_URLENCODED.toUpperCase(Locale.US) + ";abc";
            request.getInputStream();
            result = inputStream;
        }
    };
    Assert.assertThat(Collections.list(requestEx.getParameterNames()), Matchers.contains("p1", "p2"));
    Assert.assertThat(requestEx.getParameterValues("p1"), Matchers.arrayContaining("v1-1", "v1-2", "v1-3"));
    Assert.assertEquals("v1-1", requestEx.getParameter("p1"));
}
Also used : Buffer(io.vertx.core.buffer.Buffer) BufferInputStream(org.apache.servicecomb.foundation.vertx.stream.BufferInputStream) Expectations(mockit.Expectations) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

BufferInputStream (org.apache.servicecomb.foundation.vertx.stream.BufferInputStream)8 ByteBuf (io.netty.buffer.ByteBuf)6 Test (org.junit.Test)6 Buffer (io.vertx.core.buffer.Buffer)2 HashMap (java.util.HashMap)2 Expectations (mockit.Expectations)2