Search in sources :

Example 6 with Input

use of io.protostuff.Input in project java-chassis by ServiceComb.

the class TestArgsWrapSchema method testReadObject.

@Test
public void testReadObject() {
    boolean status = true;
    Input input = null;
    String[] stringArray = new String[1];
    stringArray[0] = "abc";
    MultiWrapper multiWrapper = Mockito.mock(MultiWrapper.class);
    Mockito.when(schema.newMessage()).thenReturn(multiWrapper);
    try {
        Object object = argsWrapSchema.readObject(input);
        Assert.assertNull(object);
    } catch (IOException e) {
        status = true;
    }
    Assert.assertTrue(status);
}
Also used : Input(io.protostuff.Input) MultiWrapper(io.servicecomb.common.javassist.MultiWrapper) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with Input

use of io.protostuff.Input in project incubator-servicecomb-java-chassis by apache.

the class TestHighwayCodec method testReadRequestHeader.

@Test
public void testReadRequestHeader() {
    boolean status = true;
    try {
        new MockUp<NotWrapSchema>() {

            @Mock
            public Object readObject(Input input) throws IOException {
                return new RequestHeader();
            }
        };
        bodyBuffer = Buffer.buffer("\"abc\"");
        RequestHeader requestHeader = HighwayCodec.readRequestHeader(bodyBuffer, null);
        Assert.assertNotNull(requestHeader);
        Assert.assertEquals(0, requestHeader.getFlags());
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : Input(io.protostuff.Input) RequestHeader(org.apache.servicecomb.transport.highway.message.RequestHeader) MockUp(mockit.MockUp) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with Input

use of io.protostuff.Input in project incubator-servicecomb-java-chassis by apache.

the class TestProtobufSchemaUtils method object.

@Test
public void object() throws Exception {
    WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(Object.class);
    LinkedBuffer linkedBuf = LinkedBuffer.allocate();
    ProtobufOutput output = new ProtobufOutput(linkedBuf);
    schema.writeObject(output, 1);
    Input input = new ByteArrayInput(output.toByteArray(), false);
    Object result = schema.readObject(input);
    Assert.assertEquals(1, result);
    Assert.assertThat(result, Matchers.instanceOf(Integer.class));
}
Also used : LinkedBuffer(io.protostuff.LinkedBuffer) ByteArrayInput(io.protostuff.ByteArrayInput) Input(io.protostuff.Input) ByteArrayInput(io.protostuff.ByteArrayInput) ProtobufOutput(io.protostuff.ProtobufOutput) Test(org.junit.Test)

Example 9 with Input

use of io.protostuff.Input in project incubator-servicecomb-java-chassis by apache.

the class TestArgsWrapSchema method testReadObject.

@Test
public void testReadObject() {
    boolean status = true;
    Input input = null;
    String[] stringArray = new String[1];
    stringArray[0] = "abc";
    MultiWrapper multiWrapper = Mockito.mock(MultiWrapper.class);
    Mockito.when(schema.newMessage()).thenReturn(multiWrapper);
    try {
        Object object = argsWrapSchema.readObject(input);
        Assert.assertNull(object);
    } catch (IOException e) {
        status = true;
    }
    Assert.assertTrue(status);
}
Also used : Input(io.protostuff.Input) MultiWrapper(org.apache.servicecomb.common.javassist.MultiWrapper) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with Input

use of io.protostuff.Input in project java-chassis by ServiceComb.

the class Protostuff method deserialize.

@Override
public Object deserialize(byte[] bytes) throws IOException {
    Input input = new ByteArrayInput(bytes, false);
    Root result = new Root();
    rootSchema.mergeFrom(input, result);
    return result;
}
Also used : ByteArrayInput(io.protostuff.ByteArrayInput) Input(io.protostuff.Input) ByteArrayInput(io.protostuff.ByteArrayInput) Root(org.apache.servicecomb.foundation.protobuf.internal.model.Root)

Aggregations

Input (io.protostuff.Input)10 Test (org.junit.Test)7 IOException (java.io.IOException)4 ByteArrayInput (io.protostuff.ByteArrayInput)2 ByteBufferInput (io.protostuff.ByteBufferInput)2 ByteBuffer (java.nio.ByteBuffer)2 MockUp (mockit.MockUp)2 LinkedBuffer (io.protostuff.LinkedBuffer)1 ProtobufOutput (io.protostuff.ProtobufOutput)1 MultiWrapper (io.servicecomb.common.javassist.MultiWrapper)1 RequestHeader (io.servicecomb.transport.highway.message.RequestHeader)1 MultiWrapper (org.apache.servicecomb.common.javassist.MultiWrapper)1 Root (org.apache.servicecomb.foundation.protobuf.internal.model.Root)1 RequestHeader (org.apache.servicecomb.transport.highway.message.RequestHeader)1