KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > junit > RecursionTest


1 package org.apache.ws.jaxme.junit;
2
3 import org.apache.ws.jaxme.test.recursion.Attribute;
4 import org.apache.ws.jaxme.test.recursion.DirectEmployee;
5 import org.apache.ws.jaxme.test.recursion.IndirectEmployee;
6 import org.apache.ws.jaxme.test.recursion.PotEmployee;
7
8
9 /**
10  * Tests for unmarshalling from a string, them marshalling to another
11  * string and unmarshalling back to another object for comparison.
12  * Three different recursive schemas are used:
13  * <ol>
14  * <li>Direct recursion: A node is recurring directly under itself.</li>
15  * <li>Indirect recursion: A node is recurring as a child of another
16  * node within itself.</li>
17  * <li>Potential direct/indirect recursion: A node is directly
18  * recurring/indirectly recurring under as one of the choices under
19  * itself.</li>
20  * </ol>
21  */

22 public class RecursionTest extends BaseTestCase {
23     /** Creates a new instance with the given name.
24      */

25     public RecursionTest(String JavaDoc pName) { super(pName); }
26
27     /** Tests indirect recursion: The recursing element is a child
28      * elements child.
29      */

30     public void testIndirectRecursion() throws Exception JavaDoc {
31         final String JavaDoc xml =
32             "<rec:IndirectEmployee name=\"Bill\" id=\"1\" xmlns:rec=\"http://ws.apache.org/jaxme/test/recursion\">\n" +
33             " <rec:Manager>\n" +
34             " <rec:Employees name=\"Bud\" id=\"2\">\n" +
35             " <rec:Manager>\n" +
36             " <rec:Employees name=\"Buck\" id=\"3\">\n" +
37             " <rec:Manager/>\n" +
38             " </rec:Employees>\n" +
39             " </rec:Manager>\n" +
40             " </rec:Employees>\n" +
41             " </rec:Manager>\n" +
42             "</rec:IndirectEmployee>";
43
44         unmarshalMarshalUnmarshal(IndirectEmployee.class, xml);
45     }
46
47     /** Tests direct recursion: The recursing element is an
48      * immediate child.
49      */

50     public void testDirectRecursion() throws Exception JavaDoc {
51         final String JavaDoc xml =
52             "<rec:DirectEmployee name=\"John\" id=\"4\" xmlns:rec=\"http://ws.apache.org/jaxme/test/recursion\">\n" +
53             " <rec:Employees name=\"Jack\" id=\"5\">\n" +
54             " <rec:Employees name=\"Jim\" id=\"6\">\n" +
55             " <rec:Employees name=\"James\" id=\"7\"/>\n" +
56             " </rec:Employees>\n" +
57             " </rec:Employees>\n" +
58             "</rec:DirectEmployee>";
59         unmarshalMarshalUnmarshal(DirectEmployee.class, xml);
60     }
61
62     /** Tests potential recursion: The recursing element may
63      * be a direct or an indirect child.
64      */

65     public void testPotentialRecursion() throws Exception JavaDoc {
66         final String JavaDoc xml1 =
67             "<rec:PotEmployee name=\"John\" id=\"1\" xmlns:rec=\"http://ws.apache.org/jaxme/test/recursion\">\n" +
68             " <rec:Employees name=\"Francis\" id=\"3\"/>\n" +
69             "</rec:PotEmployee>";
70         unmarshalMarshalUnmarshal(PotEmployee.class, xml1);
71         final String JavaDoc xml2 =
72             "<rec:PotEmployee name=\"John\" id=\"1\" xmlns:rec=\"http://ws.apache.org/jaxme/test/recursion\">\n" +
73             " <rec:Manager>\n" +
74             " <rec:Employees name=\"Francis\" id=\"3\"/>\n" +
75             " </rec:Manager>\n" +
76             "</rec:PotEmployee>";
77         unmarshalMarshalUnmarshal(PotEmployee.class, xml2);
78     }
79
80     /** Tests recursion using element references.
81      */

82     public void testElementRecursion() throws Exception JavaDoc {
83         final String JavaDoc xml =
84             "<rec:Attribute name=\"Sam\" id=\"1\" xmlns:rec=\"http://ws.apache.org/jaxme/test/recursion\">\n" +
85             " <rec:AttributeList>\n" +
86             " <rec:Attribute name=\"Sonny\" id=\"2\">\n" +
87             " <rec:AttributeList/>\n" +
88             " </rec:Attribute>\n" +
89             " <rec:Attribute name=\"Severine\" id=\"3\">\n" +
90             " <rec:AttributeList/>\n" +
91             " </rec:Attribute>\n" +
92             " </rec:AttributeList>\n" +
93             "</rec:Attribute>";
94         unmarshalMarshalUnmarshal(Attribute.class, xml);
95     }
96 }
97
Popular Tags