1
2
3
4
5
6
7
8 package gov.noaa.eds.xapi.generic;
9
10 import java.util.ArrayList;
11 import junit.framework.*;
12
13 import org.w3c.dom.Node;
14 import org.xmldb.api.base.ErrorCodes;
15
16 import org.xmldb.api.base.Resource;
17 import org.xmldb.api.base.XMLDBException;
18
19 /***
20 *
21 * @author tns
22 */
23 public class GenericResourceIteratorTest extends TestCase {
24
25 private GenericResourceIterator iterator = null;
26
27 public GenericResourceIteratorTest(String testName) {
28 super(testName);
29 }
30
31 protected void setUp() throws java.lang.Exception {
32 Node n = GenericResourceTest.loadTestResource();
33 GenericXmlNodeResource resource = new GenericXmlNodeResource(n);
34 resource.setId("1");
35 ArrayList resources = new ArrayList();
36 resources.add(resource);
37 resource = new GenericXmlNodeResource(n);
38 resource.setId("2");
39 resources.add(resource);
40 this.iterator = new GenericResourceIterator(resources.iterator());
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(GenericResourceIteratorTest.class);
48
49 return suite;
50 }
51
52 /***
53 * Test of nextResource method, of class gov.noaa.eds.xapi.generic.GenericResourceIterator.
54 */
55 public void testNextResource() throws Exception {
56 System.out.println("testNextResource");
57
58
59 Resource r = iterator.nextResource();
60 assertNotNull(r);
61 assertEquals("unexpected resource","1",r.getId());
62 Resource r2 = iterator.nextResource();
63 assertNotNull(r2);
64 assertEquals("unexpected resource","2",r2.getId());
65 }
66
67 public void testNextNullResource() throws Exception {
68 iterator.nextResource();
69 iterator.nextResource();
70 try {
71 iterator.nextResource();
72 fail("Exception expected");
73 } catch (XMLDBException expected){
74 assertEquals("no such resource error expected",ErrorCodes.NO_SUCH_RESOURCE, expected.errorCode);
75 }
76 }
77
78 /***
79 * Test of hasMoreResources method, of class gov.noaa.eds.xapi.generic.GenericResourceIterator.
80 */
81 public void testHasMoreResources() throws Exception {
82 System.out.println("testHasMoreResources");
83
84 boolean has = iterator.hasMoreResources();
85 assertTrue("more resources expected",has);
86 iterator.nextResource();
87 has = iterator.hasMoreResources();
88 assertTrue("more resources expected",has);
89 iterator.nextResource();
90 has = iterator.hasMoreResources();
91 assertFalse("no more resources expected",has);
92
93 }
94
95
96
97
98 }