001: /*
002: * $Id: TestAxionException.java,v 1.3 2005/04/08 14:12:04 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2002-2004 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: package org.axiondb;
041:
042: import junit.framework.Test;
043: import junit.framework.TestCase;
044: import junit.framework.TestSuite;
045:
046: import java.io.InputStream;
047: import java.sql.SQLException;
048: import java.util.PropertyResourceBundle;
049:
050: /**
051: * @author Alexander
052: */
053: public class TestAxionException extends TestCase {
054:
055: public static Test suite() {
056: TestSuite suite = new TestSuite(TestAxionException.class);
057: return suite;
058: }
059:
060: public void setUp() throws Exception {
061: // This will make this test run my eclipse env
062: // don't want to copy conf/AxionStateCodes.properties to org/axiondb
063: ClassLoader cl = AxionException.class.getClassLoader();
064: InputStream in = cl
065: .getResourceAsStream("org/axiondb/AxionStateCodes.properties");
066: if (in == null) {
067: class MyAxionException extends AxionException {
068: MyAxionException(PropertyResourceBundle bundle) {
069: _bundle = bundle;
070: }
071: }
072: in = cl.getResourceAsStream("AxionStateCodes.properties");
073: new MyAxionException(new PropertyResourceBundle(in));
074: }
075: }
076:
077: public void testGetVendorCode() {
078: AxionException e = new AxionException();
079: assertEquals(99999, e.getVendorCode());
080: }
081:
082: public void testGetMessage() {
083: AxionException e = new AxionException(24000);
084: assertEquals("invalid cursor state", e.getMessage());
085: e = new AxionException("My custom message", 99000);
086: assertEquals("My custom message", e.getMessage());
087:
088: e = new AxionException(898967598);
089: assertEquals("-- Unknown Exception (898967598) --", e
090: .getMessage());
091: }
092:
093: public void testGetSQLState() {
094: AxionException e = new AxionException(2010206);
095: assertEquals("0102F", e.getSQLState());
096: e = new AxionException(1022000);
097: assertEquals("0V000", e.getSQLState());
098: e = new AxionException(499000);
099: assertEquals("HZ000", e.getSQLState());
100: e = new AxionException(0);
101: assertEquals("00000", e.getSQLState());
102:
103: e = new AxionException(499001);
104: assertEquals("99099", e.getSQLState());
105:
106: e = new AxionException(8000);
107: assertEquals("08000", e.getSQLState());
108:
109: e = new AxionException(222222222);
110: assertEquals("2222V", e.getSQLState());
111: }
112:
113: public void testGetNestedThrowable() {
114: AxionException e = new AxionException(null, new SQLException(
115: "SQL Error", "1000", 1000), 99999);
116: assertNotNull(e.getNestedThrowable());
117: assertTrue(e.getNestedThrowable() instanceof SQLException);
118: }
119:
120: }
|