1
2
3
4
5
6
7
8 package gov.noaa.eds.xapi.generic;
9
10 import junit.framework.*;
11
12 import org.w3c.dom.Node;
13 import org.xmldb.api.base.ErrorCodes;
14 import org.xmldb.api.base.Resource;
15 import org.xmldb.api.base.ResourceIterator;
16 import org.xmldb.api.base.XMLDBException;
17
18 /***
19 *
20 * @author tns
21 */
22 public class GenericResourceSetTest extends TestCase {
23
24 GenericResourceSet resourceSet = null;
25 GenericXmlNodeResource resource = null;
26
27 public GenericResourceSetTest(String testName) {
28 super(testName);
29 }
30
31 protected void setUp() throws java.lang.Exception {
32 Node node = GenericResourceTest.loadTestResource();
33 resourceSet = new GenericResourceSet();
34 resource = new GenericXmlNodeResource(node);
35 resource.setId("1");
36 resourceSet.addResource(resource);
37 resource = new GenericXmlNodeResource(node.getFirstChild());
38 resource.setId("2");
39 resourceSet.addResource(resource);
40
41 }
42
43 protected void tearDown() throws java.lang.Exception {
44 }
45
46 public static junit.framework.Test suite() {
47 junit.framework.TestSuite suite = new junit.framework.TestSuite(GenericResourceSetTest.class);
48
49 return suite;
50 }
51
52 /***
53 * Test of addResource method, of class gov.noaa.eds.xapi.generic.GenericResourceSet.
54 */
55 public void testAddResource() throws Exception {
56 System.out.println("testAddResource");
57
58 resourceSet.addResource(resource);
59 }
60
61 /***
62 * Test of removeResource method, of class gov.noaa.eds.xapi.generic.GenericResourceSet.
63 */
64 public void testRemoveResource() throws Exception {
65 System.out.println("testRemoveResource");
66
67
68 resourceSet.removeResource(0);
69
70 assertEquals("Different amount of resources than expected",1,resourceSet.getSize());
71
72 Resource r = resourceSet.getResource(0);
73 assertEquals("Unexpected resource at index 0","2",r.getId());
74
75 }
76
77 /***
78 * Test of getSize method, of class gov.noaa.eds.xapi.generic.GenericResourceSet.
79 */
80 public void testGetSize() throws Exception {
81 System.out.println("testGetSize");
82
83
84 assertEquals("Unexpected size",2,resourceSet.getSize());
85 }
86
87 /***
88 * Test of getResource method, of class gov.noaa.eds.xapi.generic.GenericResourceSet.
89 */
90 public void testGetResource() throws Exception {
91 System.out.println("testGetResource");
92
93
94 Resource r = resourceSet.getResource(0);
95 assertNotNull(r);
96 assertEquals("Unexpected ID","1",r.getId());
97
98 r = resourceSet.getResource(1);
99 assertNotNull(r);
100 assertEquals("Unexpected ID","2",r.getId());
101 }
102
103 public void testGetNullResource() throws Exception {
104 try {
105 Resource r = resourceSet.getResource(7);
106 fail("expected an excpetion");
107 } catch (XMLDBException expected){
108 assertEquals("Expected a NO_SUCH_RESOURCE exception",
109 ErrorCodes.NO_SUCH_RESOURCE,expected.errorCode);
110 }
111 }
112
113 /***
114 * Test of getMembersAsResource method, of class gov.noaa.eds.xapi.generic.GenericResourceSet.
115 */
116 public void testGetMembersAsResource() {
117 System.out.println("testGetMembersAsResource");
118
119
120 try {
121 resourceSet.getMembersAsResource();
122 fail("Exception expected");
123 } catch (XMLDBException e){
124 assertEquals("Expected not implemented exception",ErrorCodes.NOT_IMPLEMENTED,e.errorCode);
125 }
126 }
127
128 /***
129 * Test of getIterator method, of class gov.noaa.eds.xapi.generic.GenericResourceSet.
130 */
131 public void testGetIterator() throws Exception {
132 System.out.println("testGetIterator");
133
134
135 ResourceIterator it = resourceSet.getIterator();
136 assertNotNull("iterator should not be null",it);
137 }
138
139
140
141
142 }