KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > xmldb > other > ResourceTest


1 /*
2  * The XML:DB Initiative Software License, Version 1.0
3  *
4  *
5  * Copyright (c) 2000-2001 The XML:DB Initiative. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * XML:DB Initiative (http://www.xmldb.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The name "XML:DB Initiative" must not be used to endorse or
28  * promote products derived from this software without prior written
29  * permission. For written permission, please contact info@xmldb.org.
30  *
31  * 5. Products derived from this software may not be called "XML:DB",
32  * nor may "XML:DB" appear in their name, without prior written
33  * permission of the XML:DB Initiative.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the XML:DB Initiative. For more information
51  * on the XML:DB Initiative, please see <http://www.xmldb.org/>.
52  */

53 package test.xmldb.other;
54
55
56 import junit.framework.*;
57
58 import org.xmldb.api.modules.*;
59 import org.w3c.dom.*;
60
61 import test.xmldb.*;
62
63 public class ResourceTest extends XMLDBTestCase {
64
65    public ResourceTest(String JavaDoc name) {
66       super(name);
67    }
68
69    public static Test suite() {
70       return new TestSuite(ResourceTest.class);
71    }
72
73    public void testBinaryResource() {
74       try {
75          byte[] content = new byte[3];
76          content[0] = 0x1;
77          content[1] = 0x2;
78          content[2] = 0x3;
79          BinaryResource res =
80             (BinaryResource) col.createResource("test", BinaryResource.RESOURCE_TYPE);
81          assertTrue(res.getId().equals("test"));
82          assertTrue(res.getParentCollection() == col);
83
84          res.setContent(content);
85          byte[] result = (byte[]) res.getContent();
86
87          assertTrue(result != null);
88          assertTrue(result[0] == 0x1);
89          assertTrue(result[1] == 0x2);
90          assertTrue(result[2] == 0x3);
91       } catch (Exception JavaDoc e) {
92          e.printStackTrace();
93          fail( e.getMessage( ) );
94       }
95    }
96
97    public void testXMLResource() {
98       try {
99          String JavaDoc content = "<?xml version=\"1.0\"?><tag1><tag2>value</tag2></tag1>";
100
101          XMLResource res =
102             (XMLResource) col.createResource("test", XMLResource.RESOURCE_TYPE);
103          assertTrue(res.getId().equals("test"));
104          assertTrue(res.getParentCollection() == col);
105
106          res.setContent(content);
107          String JavaDoc result = (String JavaDoc) res.getContent();
108
109          assertTrue(result != null);
110          assertTrue(content.equals(result));
111
112          Node node = res.getContentAsDOM();
113          assertTrue(node != null);
114
115          res.setContentAsDOM(node);
116          Node node2 = res.getContentAsDOM();
117          assertTrue(node2 != null);
118
119          // TODO: better validate DOM handling
120
// TODO: add SAX validation
121
} catch (Exception JavaDoc e) {
122          e.printStackTrace();
123          fail( e.getMessage( ) );
124       }
125    }
126
127    /*
128    public void testStub() {
129       try {
130
131       } catch (Exception e) {
132          fail( e.getUserName( ) );
133       }
134    }
135    */

136 }
137
Popular Tags