コード例 #1
0
 @org.junit.Test
 public void testStringArrayToStringArrayDependingOnIn() throws Exception {
   CopyBookSerializer serializer =
       new CopyBookSerializer(StringArrayToStringArrayDependingInOn.class);
   StringArrayToStringArrayDependingInOn test = new StringArrayToStringArrayDependingInOn();
   test.fields = new String[] {"test", "test2"};
   test.subfield = new CounterDependingInOn();
   test.subfield.count = test.fields.length;
   byte[] testBytes = serializer.serialize(test);
   assertEquals(2 + 8 * test.fields.length, testBytes.length);
   StringArrayToStringArrayDependingInOn test2 =
       serializer.deserialize(testBytes, StringArrayToStringArrayDependingInOn.class);
   assertArrayEquals(test.fields, test2.fields);
 }
コード例 #2
0
  @Test
  public void testSerializeDeserializeNullValues() throws Exception {
    // Build test object
    RequestTest requestTest = new RequestTest();
    requestTest.hellos = new RequestMessage[] {null};
    requestTest.hellos_count = requestTest.hellos.length;

    // Serializer and Deserializer object to and from bytes
    CopyBookSerializer requestTestSerializer = new CopyBookSerializer(RequestTest.class);
    byte[] bytes = requestTestSerializer.serialize(requestTest);
    RequestTest requestTest1 = requestTestSerializer.deserialize(bytes, RequestTest.class);

    assertEquals(0, requestTest1.args.length);
  }
コード例 #3
0
  @Test
  public void testSerializeDeserializeEmptyList() throws Exception {
    // Build test object
    RequestTest requestTest = new RequestTest();
    requestTest.args = new String[] {};
    requestTest.messages = new RequestMessage[] {};

    // Serializer and Deserializer object to and from bytes
    CopyBookSerializer requestTestSerializer = new CopyBookSerializer(RequestTest.class);
    byte[] bytes = requestTestSerializer.serialize(requestTest);
    RequestTest requestTest1 = requestTestSerializer.deserialize(bytes, RequestTest.class);

    assertEquals(0, requestTest1.args.length);
    assertEquals(0, requestTest1.messages.length);
  }
コード例 #4
0
 @org.junit.Test
 public void twoStringArrayToStringArrayDependingOnTest() throws Exception {
   CopyBookSerializer serializer =
       new CopyBookSerializer(TwoStringArrayToStringArrayDependingOn.class);
   TwoStringArrayToStringArrayDependingOn test = new TwoStringArrayToStringArrayDependingOn();
   test.fields1 = new String[] {"test", "test2"};
   test.fields2 = new String[] {"tset", "2tset"};
   test.xfields1 = test.fields1.length;
   test.xfields2 = test.fields2.length;
   byte[] testBytes = serializer.serialize(test);
   assertEquals(2 + 2 + 8 * test.fields1.length + 8 * test.fields2.length, testBytes.length);
   TwoStringArrayToStringArrayDependingOn test2 =
       serializer.deserialize(testBytes, TwoStringArrayToStringArrayDependingOn.class);
   assertArrayEquals(test.fields1, test2.fields1);
   assertArrayEquals(test.fields2, test2.fields2);
 }
コード例 #5
0
  @Test
  public void testSerializeDeserialize() throws Exception {
    // Build test object
    RequestTest requestTest = new RequestTest();
    requestTest.id = 1;
    requestTest.command = "cmd1234()";
    requestTest.hello = new RequestMessage("Hello", "Body1234");
    requestTest.hellos = new RequestMessage[] {new RequestMessage("abc", "1234ydob")};
    requestTest.hellos_count = requestTest.hellos.length;
    requestTest.messages =
        new RequestMessage[] {
          new RequestMessage("msg1", "stuff123"), new RequestMessage("msg2", "stuff12345")
        };
    requestTest.messages_count = requestTest.messages.length;
    requestTest.args = new String[] {"do", "stuff"};
    requestTest.args_count = requestTest.args.length;

    // Serializer and Deserializer object to and from bytes
    CopyBookSerializer requestTestSerializer = new CopyBookSerializer(RequestTest.class);
    byte[] bytes = requestTestSerializer.serialize(requestTest);
    RequestTest requestTest1 = requestTestSerializer.deserialize(bytes, RequestTest.class);

    assertEquals(requestTest.id, requestTest1.id);
    assertEquals(requestTest.command, requestTest1.command);
    assertEquals(requestTest.hello.title, requestTest1.hello.title);
    assertEquals(requestTest.hello.body, requestTest1.hello.body);
    assertEquals(requestTest.messages_count, requestTest1.messages_count);
    assertEquals(requestTest.messages.length, requestTest1.messages.length);
    assertEquals(requestTest.messages[0].title, requestTest1.messages[0].title);
    assertEquals(requestTest.messages[0].body, requestTest1.messages[0].body);
    assertEquals(requestTest.messages[1].title, requestTest1.messages[1].title);
    assertEquals(requestTest.messages[1].body, requestTest1.messages[1].body);
    assertEquals(requestTest.args_count, requestTest1.args_count);
    assertEquals(requestTest.args.length, requestTest1.args.length);
    assertEquals(requestTest.args[0], requestTest1.args[0]);
    assertEquals(requestTest.args[1], requestTest1.args[1]);
  }