001: /*
002: * The XML:DB Initiative Software License, Version 1.0
003: *
004: *
005: * Copyright (c) 2000-2001 The XML:DB Initiative. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * XML:DB Initiative (http://www.xmldb.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The name "XML:DB Initiative" must not be used to endorse or
028: * promote products derived from this software without prior written
029: * permission. For written permission, please contact info@xmldb.org.
030: *
031: * 5. Products derived from this software may not be called "XML:DB",
032: * nor may "XML:DB" appear in their name, without prior written
033: * permission of the XML:DB Initiative.
034: *
035: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: *
049: * This software consists of voluntary contributions made by many
050: * individuals on behalf of the XML:DB Initiative. For more information
051: * on the XML:DB Initiative, please see <http://www.xmldb.org/>.
052: */
053: package test.xmldb.other;
054:
055: import java.io.*;
056:
057: import junit.framework.*;
058:
059: import org.xmldb.api.*;
060: import org.xmldb.api.base.*;
061: import org.xmldb.api.modules.*;
062: import org.w3c.dom.*;
063:
064: import test.xmldb.*;
065:
066: public class ResourceTest extends XMLDBTestCase {
067:
068: public ResourceTest(String name) {
069: super (name);
070: }
071:
072: public static Test suite() {
073: return new TestSuite(ResourceTest.class);
074: }
075:
076: public void testBinaryResource() {
077: try {
078: byte[] content = new byte[3];
079: content[0] = 0x1;
080: content[1] = 0x2;
081: content[2] = 0x3;
082: BinaryResource res = (BinaryResource) col.createResource(
083: "test", BinaryResource.RESOURCE_TYPE);
084: assert (res.getId().equals("test"));
085: assert (res.getParentCollection() == col);
086:
087: res.setContent(content);
088: byte[] result = (byte[]) res.getContent();
089:
090: assert (result != null);
091: assert (result[0] == 0x1);
092: assert (result[1] == 0x2);
093: assert (result[2] == 0x3);
094: } catch (Exception e) {
095: e.printStackTrace();
096: fail(e.getMessage());
097: }
098: }
099:
100: public void testXMLResource() {
101: try {
102: String content = "<?xml version=\"1.0\"?><tag1><tag2>value</tag2></tag1>";
103:
104: XMLResource res = (XMLResource) col.createResource("test",
105: XMLResource.RESOURCE_TYPE);
106: assert (res.getId().equals("test"));
107: assert (res.getParentCollection() == col);
108:
109: res.setContent(content);
110: String result = (String) res.getContent();
111:
112: assert (result != null);
113: assert (content.equals(result));
114:
115: Node node = res.getContentAsDOM();
116: assert (node != null);
117:
118: res.setContentAsDOM(node);
119: Node node2 = res.getContentAsDOM();
120: assert (node2 != null);
121:
122: // TODO: better validate DOM handling
123: // TODO: add SAX validation
124: } catch (Exception e) {
125: e.printStackTrace();
126: fail(e.getMessage());
127: }
128: }
129:
130: /*
131: public void testStub() {
132: try {
133:
134: } catch (Exception e) {
135: fail( e.getMessage( ) );
136: }
137: }
138: */
139: }
|