Example #1
0
 @Test
 public void chars() {
   Definitions d = newDefinitions();
   new Sample(
           d,
           "xsdtypes.Chars",
           ProtoMessage.Chars.newBuilder().setValue("hello proto").build().toByteArray(),
           ".value",
           "hello proto")
       .check();
 }
Example #2
0
 @Test
 public void someComplexType() {
   com.bol.protojx.test.binding.ProtoMessage.SomeComplexType st =
       com.bol.protojx.test.binding.ProtoMessage.SomeComplexType.newBuilder()
           .setBooleanElement(false)
           .setStringElement("hello some")
           .setIntElement(42)
           .setFloatElement(3.14f)
           .setLongElement(1234567890L)
           .setInteger32Element(toInteger32(23))
           .setInteger64Element(toInteger64(68))
           .setBoolElement(toBool(false))
           .setCharsElement(ProtoMessage.Chars.newBuilder().setValue("hello proto"))
           .setTimeElement(newTime_8_38_42())
           .setDateElement(newDay_2016_3_18())
           .setDateTimeElement(newDayTime_2016_12_20_8_41_42())
           .setDefaultableElement("missing")
           .setOtherElement(newOther_one_two())
           .setNestedTypeElement(newNested())
           .setSTRING("HELLO")
           .setTokenElement("token")
           .addItems(com.bol.protojx.test.binding.ProtoMessage.ItemType.newBuilder().setId(42))
           .addChars(ProtoMessage.Chars.newBuilder().setValue("three"))
           .addLongId(42)
           .addLongId(84)
           .build();
   byte[] payload = st.toByteArray();
   String messageType = "test.binding.SomeComplexType";
   String[] fixtures =
       new String[] {
         ".booleanElement", "false",
         ".stringElement", "hello some",
         ".intElement", "42",
         ".floatElement", "3.14",
         ".longElement", "1234567890",
         ".integer32Element.value", "23",
         ".integer64Element.value", "68",
         ".boolElement.value", "false",
         ".charsElement.value", "hello proto",
         ".timeElement.value.hours", "8",
         ".dateElement.value.year", "2016",
         ".dateElement.value.year", "2016",
         ".dateElement.value.year", "2016",
         ".dateTimeElement.value.day.year", "2016",
         ".defaultableElement", "missing",
         ".otherElement.textItem.0", "one",
         ".otherElement.textItem.1", "two",
         ".nestedTypeElement.decimalElement.value.unscaledValue", "161",
         ".nestedTypeElement.decimalElement.value.scale", "2",
         ".items.0.id", "42",
         ".chars.0.value", "three",
         ".longId.1", "84"
       };
   for (int c = 0; c < fixtures.length; c += 2) {
     new Sample(newDefinitions(), messageType, payload, fixtures[c], fixtures[c + 1]).check();
   }
   String[] failures =
       new String[] {
         ".items.0", Inspector.InvalidPath,
         "..", Inspector.InvalidPath,
         ".x", Inspector.InvalidPath,
         "", Inspector.InvalidPath,
         ".stringElement.unexpected", Inspector.InvalidPath,
       };
   for (int c = 0; c < failures.length; c += 2) {
     new Sample(newDefinitions(), messageType, payload, failures[c], failures[c + 1]).check();
   }
 }