コード例 #1
0
  public void testJavaBean() {
    try {
      MyBean lTest1 = new MyBean();
      lTest1.setId(100);
      lTest1.setName("SISE Rules!");
      lTest1.setInt1(new Integer(0));
      lTest1.setInt2(new Integer(0));

      System.out.println(marshall.marshall(lTest1).render(true));
      MarshallValue lResult = marshall.unmarshall(marshall.marshall(lTest1));
      Assert.assertTrue(MarshallValue.REFERENCE == lResult.getType());
      MyBean lTest2 = (MyBean) lResult.getReference();

      // Test if the contents are intact.
      Assert.assertNotNull(lTest2);
      Assert.assertEquals(lTest2.getName(), "SISE Rules!");
      Assert.assertEquals(lTest2.getId(), 100);

      // Different physical objects should remain different, even if they
      // are equal.
      Assert.assertTrue(!(lTest2.getInt1() == lTest2.getInt2()));
    } catch (Exception e) {
      e.printStackTrace(System.out);
      Assert.fail();
    }
  }
コード例 #2
0
  public void testJavaBeanArray() {
    try {
      MyBean lTest1 = new MyBean();
      lTest1.setId(100);
      lTest1.setName("SISE Rules!");

      MyBean lTest2 = new MyBean();
      lTest2.setId(200);
      lTest2.setName("S.D.I.-Consulting");

      MarshallValue lResult = marshall.unmarshall(marshall.marshall(new MyBean[] {lTest1, lTest2}));
      Assert.assertTrue(MarshallValue.REFERENCE == lResult.getType());
      MyBean[] lArr = (MyBean[]) lResult.getReference();

      Assert.assertNotNull(lArr);
      Assert.assertTrue(lArr.length == 2);

      Assert.assertEquals(lArr[0].getName(), "SISE Rules!");
      Assert.assertEquals(lArr[0].getId(), 100);

      Assert.assertEquals(lArr[1].getName(), "S.D.I.-Consulting");
      Assert.assertEquals(lArr[1].getId(), 200);
    } catch (Exception e) {
      e.printStackTrace(System.out);
      Assert.fail();
    }
  }
コード例 #3
0
 public void testNull() {
   try {
     MarshallValue lResult = marshall.unmarshall(marshall.marshall(null));
     Assert.assertTrue(MarshallValue.REFERENCE == lResult.getType());
     Assert.assertTrue(lResult.getReference() == null);
   } catch (Exception e) {
     Assert.fail();
   }
 }
コード例 #4
0
  public void testSelfReference() {
    try {
      MyBean lTest1 = new MyBean();
      lTest1.setId(113);
      lTest1.setName("SELF-POINTING");
      lTest1.setPtr(lTest1);

      MarshallValue lResult = marshall.unmarshall(marshall.marshall(lTest1));
      Assert.assertTrue(MarshallValue.REFERENCE == lResult.getType());
      MyBean lTest2 = (MyBean) lResult.getReference();
      Assert.assertNotNull(lTest2);
      Assert.assertEquals(lTest2.getName(), "SELF-POINTING");
      Assert.assertEquals(lTest2.getId(), 113);
      Assert.assertTrue(lTest2 == lTest2.getPtr());
    } catch (Exception e) {
      Assert.fail();
    }
  }
コード例 #5
0
  public void testCycle() {
    try {
      MyBean[] lTest1 = new MyBean[10];
      for (int i = 0; i < 10; i++) {
        lTest1[i] = new MyBean();
        lTest1[i].setName("CYCLE-" + i);
        lTest1[i].setId(i);
      }

      lTest1[0].setPtr(lTest1[9]);
      for (int i = 1; i < 10; i++) lTest1[i].setPtr(lTest1[i - 1]);

      MarshallValue lResult = marshall.unmarshall(marshall.marshall(lTest1));
      Assert.assertTrue(MarshallValue.REFERENCE == lResult.getType());
      MyBean[] lTest2 = (MyBean[]) lResult.getReference();

      Assert.assertTrue(lTest2[0].getPtr() == lTest2[9]);
      for (int i = 1; i < 10; i++) Assert.assertTrue(lTest2[i].getPtr() == lTest2[i - 1]);
    } catch (Exception e) {
      Assert.fail();
    }
  }