//public void SetName(String name) {
    //   this.name = name;
    //}
 public void TestDefaultWithParameters() {
    Persister persister = new Persister();
    DefaultTestClass type = new DefaultTestClass();
    type.foo = 100;
    persister.write(type, System.out);
    validate(type, persister);
 }
 public void TestPersistence() {
    String[] list = new String[] { "one", "two", "three", "four"};
    Persister persister = new Persister();
    StringArrayExample example = new StringArrayExample(list);
    StringWriter out = new StringWriter();
    AssertEquals(example.attribute[0], "one");
    AssertEquals(example.attribute[1], "two");
    AssertEquals(example.attribute[2], "three");
    AssertEquals(example.attribute[3], "four");
    AssertEquals(example.element[0], "one");
    AssertEquals(example.element[1], "two");
    AssertEquals(example.element[2], "three");
    AssertEquals(example.element[3], "four");
    AssertEquals(example.list.get(0)[0], "one");
    AssertEquals(example.list.get(0)[1], "two");
    AssertEquals(example.list.get(0)[2], "three");
    AssertEquals(example.list.get(0)[3], "four");
    AssertEquals(example.array[0][0], "one");
    AssertEquals(example.array[0][1], "two");
    AssertEquals(example.array[0][2], "three");
    AssertEquals(example.array[0][3], "four");
    persister.write(example, out);
    String text = out.toString();
    System.err.println(text);
    example = persister.read(StringArrayExample.class, text);
    //public List<Entry> GetEntries() {
    //   return list;
    //}
 public void TestCycle() {
    CycleStrategy inner = new CycleStrategy();
    AnnotationStrategy strategy = new AnnotationStrategy(inner);
    Persister persister = new Persister(strategy);
    EntryListExample list = new EntryListExample();
    StringWriter writer = new StringWriter();
    Entry a = new Entry("A", "a");
    Entry b = new Entry("B", "b");
    Entry c = new Entry("C", "c");
    Entry primary = new Entry("PRIMARY", "primary");
    list.Primary = primary;
    list.AddEntry(a);
    list.AddEntry(b);
    list.AddEntry(c);
    list.AddEntry(b);
    list.AddEntry(c);
    persister.write(list, writer);
    persister.write(list, System.out);
    String text = writer.toString();
    EntryListExample copy = persister.read(EntryListExample.class, text);
Beispiel #4
0
 public void TestEnumSet() {
    Persister persister = new Persister();
    EnumSetExample example = new EnumSetExample();
    example.Add(Qualification.BEGINNER);
    example.Add(Qualification.EXPERT);
    assertTrue(example.Contains(Qualification.BEGINNER));
    assertTrue(example.Contains(Qualification.EXPERT));
    assertFalse(example.Contains(Qualification.GURU));
    persister.write(example, System.out);
    validate(persister, example);
 }
 /// <summary>
 /// </summary>
 /// <param name="args">
 /// the command line arguments
 /// </param>
 public void TestEmptyMapEntry() {
     Strategy resolver = new CycleStrategy("id", "ref");
     Serializer s = new Persister(resolver);
     StringWriter w = new StringWriter();
     SimpleBug1 bug1 = new SimpleBug1();
     AssertEquals(bug1.test1.data.get("key1"), "value1");
     AssertEquals(bug1.test1.data.get("key2"), "value1");
     AssertEquals(bug1.test1.data.get("key3"), "");
     AssertEquals(bug1.test1.data.get(""), "");
     s.write(bug1, w);
     System.err.println(w.toString());
     SimpleBug1 bug2 = s.read(SimpleBug1.class, w.toString());
 public void TestDefaultWithTransientErrors() {
    Persister persister = new Persister();
    DefaultTestClassWithInvalidTransient type = new DefaultTestClassWithInvalidTransient();
    type.foo = 100;
    bool failure = false;
    try {
       persister.write(type, System.out);
    }catch(Exception e) {
       e.printStackTrace();
       failure=true;
    }
    assertTrue("Annotation on a method which is not a property succeeded", failure);
 }
 public void TestStrategy() {
    Visitor visitor = new ClassToNamespaceVisitor();
    Strategy strategy = new VisitorStrategy(visitor);
    Persister persister = new Persister(strategy);
    VisitorExample item = new VisitorExample();
    StringWriter writer = new StringWriter();
    item.Put("1", "ONE");
    item.Put("2", "TWO");
    item.Add("A");
    item.Add("B");
    persister.write(item, writer);
    String text = writer.toString();
    System.out.println(text);
    VisitorExample recover = persister.read(VisitorExample.class, text);
 public void TestReplaceParent() {
     Persister persister = new Persister();
     Set<String> children = new HashSet<String>();
     RealParent parent = new RealParent(children);
     children.add("Tom");
     children.add("Dick");
     children.add("Harry");
     StringWriter writer = new StringWriter();
     persister.write(parent, writer);
     String text = writer.toString();
     System.out.println(text);
     AssertEquals(text.indexOf("Tom"), -1);
     AssertEquals(text.indexOf("Dick"), -1);
     AssertEquals(text.indexOf("Harry"), -1);
     validate(persister, parent);
 }
 public void TestMissingGenerics() {
     MissingGenerics example = new MissingGenerics();
     Persister persister = new Persister();
     Dictionary map = example.Map;
     map.put("a", "A");
     map.put("b", "B");
     map.put("c", "C");
     map.put("d", "D");
     map.put("e", "E");
     List list = example.List;
     list.add("1");
     list.add("2");
     list.add("3");
     list.add("4");
     list.add("5");
     StringWriter out = new StringWriter();
     persister.write(example, out);
     String text = out.toString();
     MissingGenerics recovered = persister.read(MissingGenerics.class, text);
 public void TestNamespacePrefix() {
    AaaWithPrefix parent = new AaaWithPrefix();
    BbbWithPrefix child = new BbbWithPrefix();
    parent.bbb = child;
    AaaWithPrefix grandchild = new AaaWithPrefix();
    child.aaa = grandchild;
    grandchild.bbb = new BbbWithPrefix();
    ByteArrayOutputStream tmp = new ByteArrayOutputStream();
    Serializer serializer = new Persister();
    serializer.write(parent, tmp);
    String result = new String(tmp.toByteArray());
    System.out.println(result);
    assertElementHasAttribute(result, "/aaaWithPrefix", "xmlns:aaa", "namespace1");
    assertElementHasAttribute(result, "/aaaWithPrefix/bbb", "xmlns:bbb", "namespace2");
    assertElementDoesNotHaveAttribute(result, "/aaaWithPrefix/bbb/aaa", "xmlns:aaa", "namespace1");
    assertElementDoesNotHaveAttribute(result, "/aaaWithPrefix/bbb/aaa/bbb", "xmlns:bbb", "namespace2");
    assertElementHasNamespace(result, "/aaaWithPrefix", "namespace1");
    assertElementHasNamespace(result, "/aaaWithPrefix/bbb", "namespace2");
    assertElementHasNamespace(result, "/aaaWithPrefix/bbb/aaa", "namespace1");
    assertElementHasNamespace(result, "/aaaWithPrefix/bbb/aaa/bbb", "namespace2");
 }
Beispiel #11
0
    //public String GetContent() {
    //   return text;
    //}
    //public void SetContent(String text) {
    //   this.text = text;
    //}
 public void TestStatic() {
    Persister persister = new Persister();
    Document document = new Document("Secret Document");
    Section section = new Section("Introduction");
    Paragraph first = new Paragraph();
    Paragraph second = new Paragraph();
    Paragraph third = new Paragraph();
    first.setContent("First paragraph of document");
    second.setContent("Second paragraph in the document");
    third.setContent("Third and readonly paragraph");
    section.Add(first);
    section.Add(second);
    section.Add(third);
    document.Add(section);
    persister.write(document, System.out);
    validate(persister, document);
 }