Search in sources :

Example 11 with Root

use of org.apache.servicecomb.foundation.protobuf.internal.model.Root in project incubator-servicecomb-java-chassis by apache.

the class TestAnySchema method anys_json.

@Test
public void anys_json() throws IOException {
    Root root = new Root();
    root.setAnys(Arrays.asList("abc", "123"));
    scbRootBytes = rootSerializer.serialize(root);
    root = rootDeserializer.deserialize(scbRootBytes);
    Assert.assertThat(root.getAnys(), Matchers.contains("abc", "123"));
}
Also used : Root(org.apache.servicecomb.foundation.protobuf.internal.model.Root) ProtobufRoot(org.apache.servicecomb.foundation.protobuf.internal.model.ProtobufRoot) Test(org.junit.Test)

Example 12 with Root

use of org.apache.servicecomb.foundation.protobuf.internal.model.Root in project incubator-servicecomb-java-chassis by apache.

the class TestCompatibilityOfImplementations method testEmptyCollection.

@Test
@SuppressWarnings("unchecked")
public void testEmptyCollection() throws Exception {
    ProtobufRoot.Root.Builder builder = ProtobufRoot.Root.newBuilder();
    byte[] values = protobuf.serialize(builder);
    Assert.assertEquals(values.length, 0);
    ProtobufRoot.Root.Builder o = (ProtobufRoot.Root.Builder) protobuf.deserialize(values);
    Assert.assertTrue(o.getFixed32SNotPackedList().isEmpty());
    builder = ProtobufRoot.Root.newBuilder().addFixed32SNotPacked(30);
    values = protobuf.serialize(builder);
    Assert.assertArrayEquals(new byte[] { (byte) -123, (byte) 6, (byte) 30, (byte) 0, (byte) 0, (byte) 0 }, values);
    o = (ProtobufRoot.Root.Builder) protobuf.deserialize(values);
    Assert.assertEquals(30, (int) o.getFixed32SNotPackedList().get(0));
    Root root = new Root();
    root.setFixed32sNotPacked(new ArrayList<>());
    values = scbWeak.serialize(root);
    Assert.assertEquals(values.length, 0);
    Map<String, Object> newRootMap = (Map<String, Object>) scbWeak.deserialize(values);
    Assert.assertEquals(null, // This is different , because depends on default model initializer
    newRootMap.get("fixed32sNotPacked"));
    List<Integer> iValues = new ArrayList<>();
    iValues.add(30);
    root.setFixed32sNotPacked(iValues);
    values = scbWeak.serialize(root);
    Assert.assertArrayEquals(new byte[] { (byte) -123, (byte) 6, (byte) 30, (byte) 0, (byte) 0, (byte) 0 }, values);
    newRootMap = (Map<String, Object>) scbWeak.deserialize(values);
    Assert.assertEquals(30, (int) ((List<Integer>) newRootMap.get("fixed32sNotPacked")).get(0));
}
Also used : ProtobufRoot(org.apache.servicecomb.foundation.protobuf.internal.model.ProtobufRoot) Root(org.apache.servicecomb.foundation.protobuf.internal.model.Root) ArrayList(java.util.ArrayList) ProtobufRoot(org.apache.servicecomb.foundation.protobuf.internal.model.ProtobufRoot) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Root (org.apache.servicecomb.foundation.protobuf.internal.model.Root)12 ProtobufRoot (org.apache.servicecomb.foundation.protobuf.internal.model.ProtobufRoot)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ByteArrayInput (io.protostuff.ByteArrayInput)2 Input (io.protostuff.Input)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2