001: /*
002: * $Id: TestCLOBType.java,v 1.6 2005/11/24 20:47:31 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2002 Axion Development Team. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040:
041: package org.axiondb.types;
042:
043: import java.io.File;
044: import java.io.Reader;
045: import java.io.Writer;
046: import java.sql.Clob;
047:
048: import junit.framework.Test;
049: import junit.framework.TestCase;
050: import junit.framework.TestSuite;
051:
052: import org.axiondb.jdbc.AxionClob;
053:
054: /**
055: * @version $Revision: 1.6 $ $Date: 2005/11/24 20:47:31 $
056: * @author James Burke
057: * @author Rodney Waldhoff
058: */
059: public class TestCLOBType extends TestCase {
060:
061: public TestCLOBType(String name) {
062: super (name);
063: }
064:
065: public static void main(String args[]) {
066: String[] testCaseName = { TestCLOBType.class.getName() };
067: junit.textui.TestRunner.main(testCaseName);
068: }
069:
070: public static Test suite() {
071: return new TestSuite(TestCLOBType.class);
072: }
073:
074: private LOBType _clobtype = null;
075: private String _origLobDirProp = null;
076:
077: public void setUp() throws Exception {
078: super .setUp();
079: _origLobDirProp = System.getProperty("axoindb.lobdir");
080: System.setProperty("axiondb.lobdir", "testlobdir");
081: File file = new File("testlobdir");
082: file.deleteOnExit();
083: file.mkdirs();
084: _clobtype = new CLOBType();
085: _clobtype.setLobDir(file);
086: }
087:
088: public void tearDown() throws Exception {
089: deleteFile((new File("testlobdir")));
090: if (null == _origLobDirProp) {
091: System.getProperties().remove("axiondb.lobdir");
092: } else {
093: System.setProperty("axiondb.lobdir", _origLobDirProp);
094: }
095: super .tearDown();
096: }
097:
098: private boolean deleteFile(File file) throws Exception {
099: if (file.exists()) {
100: if (file.isDirectory()) {
101: File[] files = file.listFiles();
102: for (int i = 0; i < files.length; i++) {
103: deleteFile(files[i]);
104: }
105: }
106: return file.delete();
107: }
108: return true;
109: }
110:
111: public void testSupportsSuccessor() throws Exception {
112: assertTrue(!_clobtype.supportsSuccessor());
113: }
114:
115: public void testAcceptsNewClob() throws Exception {
116: assertTrue(_clobtype.accepts("newlob()"));
117: }
118:
119: public void testCreateNewClob() throws Exception {
120: Clob clob = _clobtype.toClob("newlob()");
121: assertNotNull(clob);
122: AxionClob aclob = (AxionClob) (clob);
123:
124: Writer out = aclob.setCharacterStream(0L);
125: out.write("Four score and seven years ago.");
126: out.close();
127:
128: Reader in = aclob.getCharacterStream();
129: StringBuffer buf = new StringBuffer();
130: for (int c = in.read(); c != -1; c = in.read()) {
131: buf.append((char) c);
132: }
133: assertEquals("Four score and seven years ago.", buf.toString());
134: in.close();
135: }
136: }
|