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.Document;
13 import org.w3c.dom.Node;
14 import org.xmldb.api.base.ErrorCodes;
15 import org.xmldb.api.base.XMLDBException;
16
17 /***
18 *
19 * @author tns
20 */
21 public class GenericXmlNodeResourceTest extends TestCase {
22
23 private Document testDoc = null;
24 private GenericXmlNodeResource resource = null;
25
26 public GenericXmlNodeResourceTest(String testName) {
27 super(testName);
28 }
29
30 protected void setUp() throws java.lang.Exception {
31 testDoc = GenericResourceTest.loadTestResource();
32 resource = new GenericXmlNodeResource(testDoc);
33 resource.setId("1");
34 }
35
36 protected void tearDown() throws java.lang.Exception {
37 }
38
39 public static junit.framework.Test suite() {
40 junit.framework.TestSuite suite = new junit.framework.TestSuite(GenericXmlNodeResourceTest.class);
41
42 return suite;
43 }
44
45 /***
46 * Test of getSAXFeature method, of class gov.noaa.eds.xapi.generic.GenericNodeXmlResource.
47 */
48 public void testGetSAXFeature() throws Exception {
49 System.out.println("testGetSAXFeature");
50
51 try {
52 resource.getSAXFeature("");
53 fail("Exception expected");
54 } catch (UnsupportedOperationException expected){
55
56 }
57 }
58
59 /***
60 * Test of getResourceType method, of class gov.noaa.eds.xapi.generic.GenericNodeXmlResource.
61 */
62 public void testGetResourceType() {
63 System.out.println("testGetResourceType");
64
65 String type = resource.getResourceType();
66 assertEquals("Unexpected type","XMLResource",type);
67 }
68
69 /***
70 * Test of setContentAsDOM method, of class gov.noaa.eds.xapi.generic.GenericNodeXmlResource.
71 */
72 public void testSetContentAsDOM() throws Exception {
73 System.out.println("testSetContentAsDOM");
74
75 resource.setContentAsDOM(testDoc);
76 }
77
78 /***
79 * Test of getContentAsSAX method, of class gov.noaa.eds.xapi.generic.GenericNodeXmlResource.
80 */
81 public void testGetContentAsSAX() {
82 System.out.println("testGetContentAsSAX");
83
84 try {
85 resource.setContentAsSAX();
86 fail("Exception expected");
87 } catch (XMLDBException expected){
88 assertEquals("Not implemented exception expected",expected.errorCode,ErrorCodes.NOT_IMPLEMENTED);
89 }
90 }
91
92 /***
93 * Test of setSAXFeature method, of class gov.noaa.eds.xapi.generic.GenericNodeXmlResource.
94 */
95 public void testSetSAXFeature() throws Exception {
96 System.out.println("testSetSAXFeature");
97
98 try {
99 resource.setSAXFeature("",true);
100 fail("Exception expected");
101 } catch (UnsupportedOperationException expected){
102
103 }
104
105 }
106
107 /***
108 * Test of setContentAsSAX method, of class gov.noaa.eds.xapi.generic.GenericNodeXmlResource.
109 */
110 public void testSetContentAsSAX() {
111 System.out.println("testSetContentAsSAX");
112
113
114 try {
115 resource.setContentAsSAX();
116 fail("Exception expected");
117 } catch (XMLDBException expected){
118 assertEquals("Not implemented exception expected",expected.errorCode,ErrorCodes.NOT_IMPLEMENTED);
119 }
120 }
121
122 /***
123 * Test of getDocumentId method, of class gov.noaa.eds.xapi.generic.GenericNodeXmlResource.
124 */
125 public void testGetDocumentId() throws Exception {
126 System.out.println("testGetDocumentId");
127
128 String id = resource.getId();
129 assertEquals("unexpected id","1",id);
130 }
131
132 /***
133 * Test of getContentAsDOM method, of class gov.noaa.eds.xapi.generic.GenericNodeXmlResource.
134 */
135 public void testGetContentAsDOM() {
136 System.out.println("testGetContentAsDOM");
137
138 Node node = resource.getContentAsDOM();
139
140 assertEquals("Unexpected document node name","#document",node.getNodeName());
141 Node comment = node.getFirstChild();
142 assertEquals("Unexpected comment node name","#comment",comment.getNodeName());
143 Node root = comment.getNextSibling();
144 assertEquals("Unexpected root node name","root",root.getNodeName());
145 }
146
147
148
149
150 }