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"));
}
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));
}
Aggregations