diff options
Diffstat (limited to 'java/sdo-cts/sdo2.1/src/main/java/test/sdo21/tests/conversion/TypeConversionTest2.java')
-rw-r--r-- | java/sdo-cts/sdo2.1/src/main/java/test/sdo21/tests/conversion/TypeConversionTest2.java | 1301 |
1 files changed, 0 insertions, 1301 deletions
diff --git a/java/sdo-cts/sdo2.1/src/main/java/test/sdo21/tests/conversion/TypeConversionTest2.java b/java/sdo-cts/sdo2.1/src/main/java/test/sdo21/tests/conversion/TypeConversionTest2.java deleted file mode 100644 index 01479cc351..0000000000 --- a/java/sdo-cts/sdo2.1/src/main/java/test/sdo21/tests/conversion/TypeConversionTest2.java +++ /dev/null @@ -1,1301 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * $Rev$ $Date$ - */ -package test.sdo21.tests.conversion; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.lang.reflect.Method; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.text.SimpleDateFormat; -import java.util.Comparator; -import java.util.Date; -import java.util.List; -import java.util.TimeZone; - -import org.junit.After; -import org.junit.Before; - -import test.sdo21.framework.CTSTestCase; -import test.sdo21.tests.TestData.StandardDynamicFactory; -import test.sdo21.tests.TestData.StandardFactory; -import test.sdo21.tests.TestData.TestDataFactory; - -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Type; - -/** - * FIXME there appears to be overlap between this class and {@link TypeConversionTest} - * - */ -public class TypeConversionTest2 extends CTSTestCase { - private DataObject testDO; - TestDataFactory factory; - - public TypeConversionTest2() { - factory = createFactory(); - } - - protected TestDataFactory createFactory() { - return new StandardDynamicFactory(); - } - - @Before - public void setUp () throws Exception { - super.setUp(); - factory.defineMetaData(getScope()); - testDO = factory.createTestData(getScope(), StandardFactory.API_TYPE); - - COMPARE_ANY = new GeneralComparator(); - API_TEST_TYPE = testDO.getType(); - - List properties = API_TEST_TYPE.getProperties(); - Property property; - String name; - - for (int i = 0; i < properties.size(); i++) { - property = (Property)properties.get(i); - name = property.getName(); - - if (name.equals("booleanVal")) { - BOOLEAN_VAL_INDEX = i; - BOOLEAN_VAL_PROP = property; - } else if (name.equals("stringVal")) { - STRING_VAL_INDEX = i; - STRING_VAL_PROP = property; - } else if (name.equals("byteVal")) { - BYTE_VAL_INDEX = i; - BYTE_VAL_PROP = property; - } else if (name.equals("decimalVal")) { - DECIMAL_VAL_INDEX = i; - DECIMAL_VAL_PROP = property; - } else if (name.equals("intVal")) { - INT_VAL_INDEX = i; - INT_VAL_PROP = property; - } else if (name.equals("floatVal")) { - FLOAT_VAL_INDEX = i; - FLOAT_VAL_PROP = property; - } else if (name.equals("doubleVal")) { - DOUBLE_VAL_INDEX = i; - DOUBLE_VAL_PROP = property; - } else if (name.equals("dateVal")) { - DATE_VAL_INDEX = i; - DATE_VAL_PROP = property; - } else if (name.equals("shortVal")) { - SHORT_VAL_INDEX = i; - SHORT_VAL_PROP = property; - } else if (name.equals("longVal")) { - LONG_VAL_INDEX = i; - LONG_VAL_PROP = property; - } else if (name.equals("bytesVal")) { - BYTES_VAL_INDEX = i; - BYTES_VAL_PROP = property; - } else if (name.equals("integerVal")) { - INTEGER_VAL_INDEX = i; - INTEGER_VAL_PROP = property; - } else if (name.equals("charVal")) { - CHAR_VAL_INDEX = i; - CHAR_VAL_PROP = property; - } - } - } - - - @After - public void tearDown() throws Exception { - super.tearDown(); - } - - // The following constants describe the index for the fields in - // api_test.xsd. - - private static int STRING_VAL_INDEX; - - private static int BOOLEAN_VAL_INDEX; - - private static int BYTE_VAL_INDEX; - - private static int DECIMAL_VAL_INDEX; - - private static int INT_VAL_INDEX; - - private static int FLOAT_VAL_INDEX; - - private static int DOUBLE_VAL_INDEX; - - private static int DATE_VAL_INDEX; - - private static int SHORT_VAL_INDEX; - - private static int LONG_VAL_INDEX; - - private static int BYTES_VAL_INDEX; - - private static int INTEGER_VAL_INDEX; - - private static int CHAR_VAL_INDEX; - - // TODO: these properties are not used . . . should they be ? - private static Property STRING_VAL_PROP; - - private static Property BOOLEAN_VAL_PROP; - - private static Property BYTE_VAL_PROP; - - private static Property DECIMAL_VAL_PROP; - - private static Property INT_VAL_PROP; - - private static Property FLOAT_VAL_PROP; - - private static Property DOUBLE_VAL_PROP; - - private static Property DATE_VAL_PROP; - - private static Property SHORT_VAL_PROP; - - private static Property LONG_VAL_PROP; - - private static Property BYTES_VAL_PROP; - - private static Property INTEGER_VAL_PROP; - - private static Property CHAR_VAL_PROP; - - // The following variables are Method arrays. Each array refers to a - // specific get<Type>, but within - // the array exist the get<Type>(index), get<Type>(property), and - // get<Type>(path). Rather than - // referring to each of the three in every circumstance, the more compact - // array appears. - - private static ConversionType TO_BOOLEAN = new ConversionType("getBoolean"); - - private static ConversionType TO_BYTE = new ConversionType("getByte"); - - private static ConversionType TO_CHAR = new ConversionType("getChar"); - - private static ConversionType TO_DOUBLE = new ConversionType("getDouble"); - - private static ConversionType TO_FLOAT = new ConversionType("getFloat"); - - private static ConversionType TO_INT = new ConversionType("getInt"); - - private static ConversionType TO_LONG = new ConversionType("getLong"); - - private static ConversionType TO_SHORT = new ConversionType("getShort"); - - private static ConversionType TO_BYTES = new ConversionType("getBytes"); - - private static ConversionType TO_BIGDECIMAL = new ConversionType("getBigDecimal"); - - private static ConversionType TO_BIGINTEGER = new ConversionType("getBigInteger"); - - private static ConversionType TO_DATAOBJECT = new ConversionType("getDataObject"); - - private static ConversionType TO_DATE = new ConversionType("getDate"); - - private static ConversionType TO_STRING = new ConversionType("getString"); - - private static ConversionType TO_LIST = new ConversionType("getList"); - - private static ConversionType TO_SEQUENCE = new ConversionType("getSequence"); - - private static GeneralComparator COMPARE_ANY; - - // There will be several instances where a Property must be passed as a - // parameter. Have available the Type - // to call getProperty() as needed. - - private static Type API_TEST_TYPE; - - - private static class ConversionType { - // The following constants are used because the getMethod function - // requires an Class - // array describing the parameters to the functions. - - private static final Class[] INT_CLASS_ARRAY = {int.class}; - - private static final Class[] PROPERTY_CLASS_ARRAY = {Property.class}; - - private static final Class[] STRING_CLASS_ARRAY = {String.class}; - - Method index_method; - - Method property_method; - - Method path_method; - - public ConversionType(String method_name) { - try { - this.index_method = DataObject.class.getMethod(method_name, INT_CLASS_ARRAY); - this.property_method = DataObject.class.getMethod(method_name, PROPERTY_CLASS_ARRAY); - this.path_method = DataObject.class.getMethod(method_name, STRING_CLASS_ARRAY); - } catch (NoSuchMethodException e) { - this.index_method = null; - this.property_method = null; - this.path_method = null; - } - } - - public Method getIndexMethod() { - return this.index_method; - } - - public Method getPropertyMethod() { - return this.property_method; - } - - public Method getPathMethod() { - return this.path_method; - } - } - - // Each instance of Test describes a convert-from type. The index, property - // and path parms - // will refer to the same field, which is a field of the convert-from type. - - private static class Test { - Object[] index_parm; - - Object[] property_parm; - - Object[] path_parm; - - Object expected_value; - - String from_type; - - // The constructor prepares a test DataObject and determines how to - // access the field - // in three different ways - index, property, and path. - - Test(String path, int index) { - this.index_parm = new Object[] {new Integer(index)}; - this.property_parm = new Object[] {API_TEST_TYPE.getProperty(path)}; - this.path_parm = new Object[] {path}; - this.expected_value = null; - } - - /** - * initialize() is a private method that establishes the initial value - * of the test field. - * - * @return - */ - - private void initialize(Class type, String type_name, Object initial_value, DataObject testDO) { - try { - Class[] classArray = {int.class, type}; - Object[] initValueArray = new Object[] {this.index_parm[0], initial_value}; - - Method setter = DataObject.class.getMethod("set" + type_name, classArray); - setter.invoke(testDO, initValueArray); - - this.expected_value = initial_value; - this.from_type = type_name; - } catch (Exception e) { - e.printStackTrace(); - fail("Exception using reflection to establish initial value for test : " + e.toString()); - } - } - - /** - * checkConversionException verifies that for a particular to and from - * Type pairing, the expected Exceptoin is thrown. - * - * @param to_type - * @param expected_exception - * @param testDO - */ - - private void checkConversionException(ConversionType to_type, Class expected_exception, DataObject testDO) { - try { - boolean index_err, path_err, property_err; - - index_err = executeExceptionCase(to_type.getIndexMethod(), this.index_parm, expected_exception, testDO); - path_err = executeExceptionCase(to_type.getPathMethod(), this.path_parm, expected_exception, testDO); - property_err = - executeExceptionCase(to_type.getPropertyMethod(), this.property_parm, expected_exception, testDO); - - assertEquals("Testing that expected exception for index paramater is equal to path paramater exception ", - index_err, - path_err); - assertEquals("Testing that expected exception for path paramater is equal to property paramater exception ", - property_err, - path_err); - - // TODO: test case needs reworking - /* - * else if (index_err == false) attemptConversion(to_type, - * testDO); - */ - if (!index_err) { - attemptConversion(to_type, testDO); - } - - // TODO: test for unexpected consistency - /* - * if (consistency_err) throw new ExpectedConditionError("An - * exception inconsistency exists for " + - * to_type.getPathMethod().getName() + " when called " + "for a " + - * this.from_type + " property."); - */ - } catch (Exception e) { - e.printStackTrace(); - fail("exception caught : " + e.toString()); - } - } - - /** - * attemptConversion is a private method that attempts the conversion to - * the specified type, using DataObject.get____(). The get___() function - * can be called with an index, path, and property. attemptConversion() - * calls each of those three. - * - * @param to_type - * @param testDO - */ - - private void attemptConversion(ConversionType to_type, DataObject testDO) { - - try { - performConversion(to_type.getIndexMethod(), this.index_parm, testDO); - performConversion(to_type.getPathMethod(), this.path_parm, testDO); - performConversion(to_type.getPropertyMethod(), this.property_parm, testDO); - } catch (Exception e) { - e.printStackTrace(); - fail("Exception caught invoking attemptConversion for " + to_type + " : " + e.toString()); - } - } - - /** - * performConversion is a private method that is called by - * attemptConversion for each of the Property identification mechanisms. - * (Property, index, or name.) - * - * @param convert - * @param parm - * @param testDO - */ - - private void performConversion(Method convert, Object[] parm, DataObject testDO) throws Exception { - - assertEquals("Conversion did not yield expected value for " + convert.getName() - + " on a " - + this.from_type - + " property.", COMPARE_ANY.compare(convert.invoke(testDO, parm), this.expected_value), 0); - } - - /** - * executeExceptionCase is a private method that insures a particular to - * and from Type pairing will throw the expected Exception when an a - * conversion is attempted using get____(<x>). executeExceptionCase is - * called by checkConversionException for each mechanism of identifying - * the Property. (Property, name, or index.) - * - * @param convert - * @param parm - * @param expected_exception - * @param testDO - * @return whether or not the expected exception was thrown and caught - */ - private boolean executeExceptionCase(Method convert, Object[] parm, Class expected_exception, DataObject testDO) { - boolean exception_thrown = false; - try { - convert.invoke(testDO, parm); - } catch (Exception e) { - - exception_thrown = true; - Throwable cause = e.getCause(); - if (cause == null) { - assertEquals("An unexpected exception occurred while performing " + convert.getName() - + " on a " - + this.from_type - + " property.", expected_exception, e.getClass()); - } else { - assertEquals("An unexpected exception occurred while performing " + convert.getName() - + " on a " - + this.from_type - + " property.", expected_exception, cause.getClass()); - } - } - - return exception_thrown; - } - } - - private static class GeneralComparator implements Comparator { - /** - * The compare method fo the GeneralComparator class is used to compare - * two of any Types between which a covnersion is permitted in SDO. - */ - - public int compare(Object obj1, Object obj2) { - if (obj1.getClass() == obj2.getClass()) { - if (obj1.equals(obj2)) - return 0; - else - return 1; - } - - else if (obj1.getClass() == Date.class) { - if (obj2.getClass() == String.class) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy'-'MM'-'dd'T'H':'mm':'ss.S"); - - sdf.setTimeZone(TimeZone.getTimeZone("UTC")); - obj2 = sdf.parse((String)obj2); - - if (obj1.equals(obj2)) - return 0; - } catch (Exception e) { - System.out.println(e.getMessage()); - } - - return 1; - } - - else { - Date temp = (Date)obj1; - - return compare(new Long(temp.getTime()), obj2); - } - - } - - else if (obj2.getClass() == Date.class) { - return compare(obj2, obj1); - } - - else if (obj1.getClass() == Boolean.class) { - Boolean temp = (Boolean)obj1; - - if (temp.booleanValue()) { - if (obj2.toString().equalsIgnoreCase("true")) - return 0; - else - return 1; - } - - else { - if (obj2.toString().equalsIgnoreCase("true")) - return 1; - else - return 0; - } - } - - else if (obj2.getClass() == Boolean.class) - return compare(obj2, obj1); - - else if (obj1.getClass() == Byte.class || obj2.getClass() == Byte.class) { - byte b1 = (Double.valueOf(obj1.toString())).byteValue(); - byte b2 = (Double.valueOf(obj2.toString())).byteValue(); - - if (b1 == b2) - return 0; - else if (b1 < b2) - return -1; - else - return 1; - } - - else if (obj1.getClass().toString().charAt(6) == '[') { - long result = 0; - long multiplier = 1; - - byte[] array = (byte[])obj1; - for (int i = 0; i < array.length; i++) { - result += array[array.length - i - 1] * multiplier; - multiplier *= 256; - } - - return compare(obj2, new Long(result)); - } - - else if (obj2.getClass().toString().charAt(6) == '[') { - return compare(obj2, obj1); - } - - else if (obj1.getClass() == Short.class || obj2.getClass() == Short.class) { - short s1 = (Double.valueOf(obj1.toString())).shortValue(); - short s2 = (Double.valueOf(obj2.toString())).shortValue(); - - if (s1 == s2) - return 0; - else if (s1 < s2) - return -1; - else - return 1; - } - - else if (obj1.getClass() == Integer.class || obj2.getClass() == Integer.class) { - int i1 = (Double.valueOf(obj1.toString())).intValue(); - int i2 = (Double.valueOf(obj2.toString())).intValue(); - - if (i1 == i2) - return 0; - else if (i1 < i2) - return -1; - else - return 1; - } - - else if (obj1.getClass() == Long.class || obj2.getClass() == Long.class - || obj1.getClass() == BigInteger.class - || obj2.getClass() == BigInteger.class) { - long l1 = (Double.valueOf(obj1.toString())).longValue(); - long l2 = (Double.valueOf(obj2.toString())).longValue(); - - if (l1 == l2) - return 0; - else if (l1 < l2) - return -1; - else - return 1; - } - - else if (obj1.getClass() == Float.class || obj2.getClass() == Float.class) { - float f1 = (Double.valueOf(obj1.toString())).floatValue(); - float f2 = (Double.valueOf(obj2.toString())).floatValue(); - - if (f1 == f2) - return 0; - else if (f1 < f2) - return -1; - else - return 1; - } - - else if (obj1.getClass() == Double.class || obj2.getClass() == Double.class) { - Double b1 = Double.valueOf(obj1.toString()); - Double b2 = Double.valueOf(obj2.toString()); - - return b1.compareTo(b2); - } - - else if (obj1.getClass() == BigDecimal.class || obj2.getClass() == BigDecimal.class) { - BigDecimal b1 = new BigDecimal(obj1.toString()); - BigDecimal b2 = new BigDecimal(obj2.toString()); - - return b1.compareTo(b2); - } - - else { - if (obj1.toString().equals(obj2.toString())) - return 0; - else - return 1; - } - } - - } - - /** - * TODO: Uncomment below as appropriate when TUSCANY-581 is resolved. In the - * following test cases, several instances are commented out. For these - * cases, the test case currently fails. A JIRA issue (TUSCANY-581) has been - * opened to either correct the behavior (then uncomment the lines) or to - * alter the specification against which the test cases were designed (and - * then remove the lines - assuming the alteration is to remove stating the - * nature of the exception). - */ - - /** - * testBooleanConversion verifies the conversion from boolean to each of the - * allowed types. - */ - @org.junit.Test - public void testBooleanConversion() { - Test FromBoolean = new Test("booleanVal", BOOLEAN_VAL_INDEX); - - FromBoolean.initialize(boolean.class, "Boolean", Boolean.valueOf(true), testDO); - - try { - FromBoolean.attemptConversion(TO_BOOLEAN, testDO); - FromBoolean.attemptConversion(TO_STRING, testDO); - } catch (Exception e) { - e.printStackTrace(); - fail("Unexpected exception " + e.toString()); - - } - } - - /** - * testBooleanExceptions verifies that the appropriate Exceptions are thrown - * when an unpermitted conversion from boolean is attempted. - */ - @org.junit.Test - public void testBooleanExceptions() { - try { - Test FromBoolean = new Test("booleanVal", BOOLEAN_VAL_INDEX); - - FromBoolean.initialize(boolean.class, "Boolean", Boolean.valueOf(true), testDO); - - // FromBoolean.checkConversionException(TO_BYTE, - // ClassCastException.class, testDO); - // FromBoolean.checkConversionException(TO_CHAR, - // ClassCastException.class, testDO); - // FromBoolean.checkConversionException(TO_DOUBLE, - // ClassCastException.class, testDO); - // FromBoolean.checkConversionException(TO_FLOAT, - // ClassCastException.class, testDO); - // FromBoolean.checkConversionException(TO_INT, - // ClassCastException.class, testDO); - // FromBoolean.checkConversionException(TO_LONG, - // ClassCastException.class, testDO); - // FromBoolean.checkConversionException(TO_SHORT, - // ClassCastException.class, testDO); - // FromBoolean.checkConversionException(TO_BYTES, - // ClassCastException.class, testDO); - // FromBoolean.checkConversionException(TO_BIGDECIMAL, - // ClassCastException.class, testDO); - // FromBoolean.checkConversionException(TO_BIGINTEGER, - // ClassCastException.class, testDO); - FromBoolean.checkConversionException(TO_DATAOBJECT, ClassCastException.class, testDO); - // FromBoolean.checkConversionException(TO_DATE, - // ClassCastException.class, testDO); - FromBoolean.checkConversionException(TO_LIST, ClassCastException.class, testDO); - FromBoolean.checkConversionException(TO_SEQUENCE, ClassCastException.class, testDO); - - } catch (Exception e) { - e.printStackTrace(); - fail("Unexpected exception " + e.toString()); - - } - } - - /** - * testByteConversion verifies the conversion from byte to each of the - * allowed types. - */ - @org.junit.Test - public void testByteConversion() { - try { - Test FromByte = new Test("byteVal", BYTE_VAL_INDEX); - - FromByte.initialize(byte.class, "Byte", Byte.valueOf("-127"), testDO); - - FromByte.attemptConversion(TO_BYTE, testDO); - FromByte.attemptConversion(TO_DOUBLE, testDO); - FromByte.attemptConversion(TO_FLOAT, testDO); - FromByte.attemptConversion(TO_INT, testDO); - FromByte.attemptConversion(TO_LONG, testDO); - FromByte.attemptConversion(TO_SHORT, testDO); - FromByte.attemptConversion(TO_STRING, testDO); - } catch (Exception e) { - e.printStackTrace(); - fail("Unexpected exception " + e.toString()); - - } - } - - /** - * testByteExceptions verifies that the appropriate Exceptions are thrown - * when an unpermitted conversion from byte is attempted. - */ - @org.junit.Test - public void testByteExceptions() { - try { - Test FromByte = new Test("byteVal", BYTE_VAL_INDEX); - - FromByte.initialize(byte.class, "Byte", Byte.valueOf("-127"), testDO); - - // FromByte.checkConversionException(TO_BOOLEAN, - // ClassCastException.class, testDO); - // FromByte.checkConversionException(TO_CHAR, - // ClassCastException.class, - // testDO); - // FromByte.checkConversionException(TO_BYTES, - // ClassCastException.class, - // testDO); - FromByte.checkConversionException(TO_BIGDECIMAL, ClassCastException.class, testDO); - FromByte.checkConversionException(TO_BIGINTEGER, ClassCastException.class, testDO); - FromByte.checkConversionException(TO_DATAOBJECT, ClassCastException.class, testDO); - // FromByte.checkConversionException(TO_DATE, - // ClassCastException.class, - // testDO); - FromByte.checkConversionException(TO_LIST, ClassCastException.class, testDO); - FromByte.checkConversionException(TO_SEQUENCE, ClassCastException.class, testDO); - } catch (Exception e) { - e.printStackTrace(); - fail("Unexpected exception " + e.toString()); - - } - } - - /** - * testCharConversion verifies the conversion from char to each of the - * allowed types. - */ - @org.junit.Test - public void testCharConversion() { - try { - Test FromChar = new Test("charVal", CHAR_VAL_INDEX); - - FromChar.initialize(char.class, "Char", new Character('?'), testDO); - - FromChar.attemptConversion(TO_CHAR, testDO); - FromChar.attemptConversion(TO_STRING, testDO); - } catch (Exception e) { - e.printStackTrace(); - fail("Unexpected exception " + e.toString()); - - } - } - - /** - * testCharExceptions verifies that the appropriate Exceptions are thrown - * when an unpermitted conversion from char is attempted. - */ - @org.junit.Test - public void testCharExceptions() { - try { - Test FromChar = new Test("charVal", CHAR_VAL_INDEX); - - FromChar.initialize(char.class, "Char", new Character('?'), testDO); - - // FromChar.checkConversionException(TO_BOOLEAN, - // ClassCastException.class, testDO); - // FromChar.checkConversionException(TO_BYTE, - // ClassCastException.class, - // testDO); - // FromChar.checkConversionException(TO_DOUBLE, - // ClassCastException.class, testDO); - // FromChar.checkConversionException(TO_FLOAT, - // ClassCastException.class, - // testDO); - // FromChar.checkConversionException(TO_INT, - // ClassCastException.class, - // testDO); - // FromChar.checkConversionException(TO_LONG, - // ClassCastException.class, - // testDO); - // FromChar.checkConversionException(TO_SHORT, - // ClassCastException.class, - // testDO); - // FromChar.checkConversionException(TO_BYTES, - // ClassCastException.class, - // testDO); - // FromChar.checkConversionException(TO_BIGDECIMAL, - // ClassCastException.class, testDO); - // FromChar.checkConversionException(TO_BIGINTEGER, - // ClassCastException.class, testDO); - FromChar.checkConversionException(TO_DATAOBJECT, ClassCastException.class, testDO); - // FromChar.checkConversionException(TO_DATE, - // ClassCastException.class, - // testDO); - FromChar.checkConversionException(TO_LIST, ClassCastException.class, testDO); - FromChar.checkConversionException(TO_SEQUENCE, ClassCastException.class, testDO); - } catch (Exception e) { - e.printStackTrace(); - fail("Unexpected exception " + e.toString()); - - } - } - - /** - * testDoubleConversion verifies the conversion from double to each of the - * allowed types. - */ - @org.junit.Test - public void testDoubleConversion() { - try { - Test FromDouble = new Test("doubleVal", DOUBLE_VAL_INDEX); - - FromDouble.initialize(double.class, "Double", new Double(Double.MAX_VALUE), testDO); - - FromDouble.attemptConversion(TO_BYTE, testDO); - FromDouble.attemptConversion(TO_DOUBLE, testDO); - FromDouble.attemptConversion(TO_FLOAT, testDO); - FromDouble.attemptConversion(TO_INT, testDO); - FromDouble.attemptConversion(TO_LONG, testDO); - FromDouble.attemptConversion(TO_SHORT, testDO); - FromDouble.attemptConversion(TO_BIGDECIMAL, testDO); - FromDouble.attemptConversion(TO_BIGINTEGER, testDO); - FromDouble.attemptConversion(TO_STRING, testDO); - } catch (Exception e) { - e.printStackTrace(); - fail("Unexpected exception " + e.toString()); - - } - } - - /** - * testDoubleExceptions verifies that the appropriate Exceptions are thrown - * when an unpermitted conversion from double is attempted. - */ - @org.junit.Test - public void testDoubleExceptions() { - try { - Test FromDouble = new Test("doubleVal", DOUBLE_VAL_INDEX); - - FromDouble.initialize(double.class, "Double", new Double(Double.MAX_VALUE), testDO); - - // FromDouble.checkConversionException(TO_BOOLEAN, - // ClassCastException.class, testDO); - // FromDouble.checkConversionException(TO_CHAR, - // ClassCastException.class, testDO); - // FromDouble.checkConversionException(TO_BYTES, - // ClassCastException.class, testDO); - FromDouble.checkConversionException(TO_DATAOBJECT, ClassCastException.class, testDO); - // FromDouble.checkConversionException(TO_DATE, - // ClassCastException.class, testDO); - FromDouble.checkConversionException(TO_LIST, ClassCastException.class, testDO); - FromDouble.checkConversionException(TO_SEQUENCE, ClassCastException.class, testDO); - } catch (Exception e) { - e.printStackTrace(); - fail("Unexpected exception " + e.toString()); - - } - } - - /** - * testFloatConversion verifies the conversion from float to each of the - * allowed types. - */ - @org.junit.Test - public void testFloatConversion() { - try { - Test FromFloat = new Test("floatVal", FLOAT_VAL_INDEX); - - FromFloat.initialize(float.class, "Float", new Float(Float.MIN_VALUE), testDO); - - FromFloat.attemptConversion(TO_BYTE, testDO); - FromFloat.attemptConversion(TO_DOUBLE, testDO); - FromFloat.attemptConversion(TO_FLOAT, testDO); - FromFloat.attemptConversion(TO_INT, testDO); - FromFloat.attemptConversion(TO_LONG, testDO); - FromFloat.attemptConversion(TO_SHORT, testDO); - FromFloat.attemptConversion(TO_BIGDECIMAL, testDO); - FromFloat.attemptConversion(TO_BIGINTEGER, testDO); - FromFloat.attemptConversion(TO_STRING, testDO); - } catch (Exception e) { - e.printStackTrace(); - fail("Unexpected exception " + e.toString()); - - } - } - - /** - * testFloatExceptions verifies that the appropriate Exceptions are thrown - * when an unpermitted conversion from float is attempted. - */ - @org.junit.Test - public void testFloatExceptions() { - try { - Test FromFloat = new Test("floatVal", FLOAT_VAL_INDEX); - - FromFloat.initialize(float.class, "Float", new Float(Float.MIN_VALUE), testDO); - - // FromFloat.checkConversionException(TO_BOOLEAN, - // ClassCastException.class, testDO); - // FromFloat.checkConversionException(TO_CHAR, - // ClassCastException.class, - // testDO); - // FromFloat.checkConversionException(TO_BYTES, - // ClassCastException.class, testDO); - FromFloat.checkConversionException(TO_DATAOBJECT, ClassCastException.class, testDO); - // FromFloat.checkConversionException(TO_DATE, - // ClassCastException.class, - // testDO); - FromFloat.checkConversionException(TO_LIST, ClassCastException.class, testDO); - FromFloat.checkConversionException(TO_SEQUENCE, ClassCastException.class, testDO); - } catch (Exception e) { - e.printStackTrace(); - fail("Unexpected exception " + e.toString()); - - } - } - - /** - * testIntConversion verifies the conversion from int to each of the allowed - * types. - */ - @org.junit.Test - public void testIntConversion() { - Test FromInt = new Test("intVal", INT_VAL_INDEX); - - FromInt.initialize(int.class, "Int", new Integer(5), testDO); - - FromInt.attemptConversion(TO_BYTE, testDO); - FromInt.attemptConversion(TO_DOUBLE, testDO); - FromInt.attemptConversion(TO_FLOAT, testDO); - FromInt.attemptConversion(TO_INT, testDO); - FromInt.attemptConversion(TO_LONG, testDO); - FromInt.attemptConversion(TO_SHORT, testDO); - FromInt.attemptConversion(TO_BIGDECIMAL, testDO); - FromInt.attemptConversion(TO_BIGINTEGER, testDO); - FromInt.attemptConversion(TO_STRING, testDO); - } - - /** - * testIntExceptions verifies that the appropriate Exceptions are thrown - * when an unpermitted conversion from int is attempted. - */ - @org.junit.Test - public void testIntExceptions() { - - Test FromInt = new Test("intVal", INT_VAL_INDEX); - - FromInt.initialize(int.class, "Int", new Integer(5), testDO); - - // FromInt.checkConversionException(TO_BOOLEAN, - // ClassCastException.class, testDO); - // FromInt.checkConversionException(TO_CHAR, ClassCastException.class, - // testDO); - // FromInt.checkConversionException(TO_BYTES, ClassCastException.class, - // testDO); - FromInt.checkConversionException(TO_DATAOBJECT, ClassCastException.class, testDO); - // FromInt.checkConversionException(TO_DATE, ClassCastException.class, - // testDO); - FromInt.checkConversionException(TO_LIST, ClassCastException.class, testDO); - FromInt.checkConversionException(TO_SEQUENCE, ClassCastException.class, testDO); - } - - /** - * testLongConversion verifies the conversion from long to each of the - * allowed types. - */ - @org.junit.Test - public void testLongConversion() { - Test FromLong = new Test("longVal", LONG_VAL_INDEX); - - FromLong.initialize(long.class, "Long", new Long(7000L), testDO); - - FromLong.attemptConversion(TO_BYTE, testDO); - FromLong.attemptConversion(TO_DOUBLE, testDO); - FromLong.attemptConversion(TO_FLOAT, testDO); - FromLong.attemptConversion(TO_INT, testDO); - FromLong.attemptConversion(TO_LONG, testDO); - FromLong.attemptConversion(TO_SHORT, testDO); - FromLong.attemptConversion(TO_BIGDECIMAL, testDO); - FromLong.attemptConversion(TO_BIGINTEGER, testDO); - FromLong.attemptConversion(TO_DATE, testDO); - FromLong.attemptConversion(TO_STRING, testDO); - } - - /** - * testLongExceptions verifies that the appropriate Exceptions are thrown - * when an unpermitted conversion from long is attempted. - */ - @org.junit.Test - public void testLongExceptions() { - Test FromLong = new Test("longVal", LONG_VAL_INDEX); - - FromLong.initialize(long.class, "Long", new Long(7000L), testDO); - - // FromLong.checkConversionException(TO_BOOLEAN, - // ClassCastException.class, testDO); - // FromLong.checkConversionException(TO_CHAR, ClassCastException.class, - // testDO); - // FromLong.checkConversionException(TO_BYTES, ClassCastException.class, - // testDO); - FromLong.checkConversionException(TO_DATAOBJECT, ClassCastException.class, testDO); - FromLong.checkConversionException(TO_LIST, ClassCastException.class, testDO); - FromLong.checkConversionException(TO_SEQUENCE, ClassCastException.class, testDO); - } - - /** - * testShortConversion verifies the conversion from short to each of the - * allowed types. - */ - @org.junit.Test - public void testShortConversion() { - Test FromShort = new Test("shortVal", SHORT_VAL_INDEX); - - FromShort.initialize(short.class, "Short", new Short("-8000"), testDO); - - FromShort.attemptConversion(TO_BYTE, testDO); - FromShort.attemptConversion(TO_DOUBLE, testDO); - FromShort.attemptConversion(TO_FLOAT, testDO); - FromShort.attemptConversion(TO_INT, testDO); - FromShort.attemptConversion(TO_LONG, testDO); - FromShort.attemptConversion(TO_SHORT, testDO); - FromShort.attemptConversion(TO_STRING, testDO); - } - - /** - * testShortExceptions verifies that the appropriate Exceptions are thrown - * when an unpermitted conversion from short is attempted. - */ - @org.junit.Test - public void testShortExceptions() { - Test FromShort = new Test("shortVal", SHORT_VAL_INDEX); - - FromShort.initialize(short.class, "Short", new Short("-8000"), testDO); - - // FromShort.checkConversionException(TO_BOOLEAN, - // ClassCastException.class, testDO); - // FromShort.checkConversionException(TO_CHAR, ClassCastException.class, - // testDO); - // FromShort.checkConversionException(TO_BYTES, - // ClassCastException.class, testDO); - FromShort.checkConversionException(TO_BIGDECIMAL, ClassCastException.class, testDO); - FromShort.checkConversionException(TO_BIGINTEGER, ClassCastException.class, testDO); - FromShort.checkConversionException(TO_DATAOBJECT, ClassCastException.class, testDO); - // FromShort.checkConversionException(TO_DATE, ClassCastException.class, - // testDO); - FromShort.checkConversionException(TO_LIST, ClassCastException.class, testDO); - FromShort.checkConversionException(TO_SEQUENCE, ClassCastException.class, testDO); - } - - /** - * testStringConversion verifies the conversion from String to each of the - * allowed types. - */ - @org.junit.Test - public void testStringConversion() { - Test FromString = new Test("stringVal", STRING_VAL_INDEX); - - FromString.initialize(String.class, "String", "5", testDO); - - FromString.attemptConversion(TO_BOOLEAN, testDO); - FromString.attemptConversion(TO_BYTE, testDO); - FromString.attemptConversion(TO_CHAR, testDO); - FromString.attemptConversion(TO_DOUBLE, testDO); - FromString.attemptConversion(TO_FLOAT, testDO); - FromString.attemptConversion(TO_INT, testDO); - FromString.attemptConversion(TO_LONG, testDO); - FromString.attemptConversion(TO_SHORT, testDO); - FromString.attemptConversion(TO_BIGDECIMAL, testDO); - FromString.attemptConversion(TO_BIGINTEGER, testDO); - FromString.attemptConversion(TO_STRING, testDO); - - FromString.initialize(String.class, "String", "1999-07-25T8:50:14.33Z", testDO); - FromString.attemptConversion(TO_DATE, testDO); - } - - /** - * testStringExceptions verifies that the appropriate Exceptions are thrown - * when an unpermitted conversion from String is attempted. - */ - @org.junit.Test - public void testStringExceptions() { - Test FromString = new Test("stringVal", STRING_VAL_INDEX); - - FromString.initialize(String.class, "String", "5", testDO); - - // FromString.checkConversionException(TO_BYTES, - // ClassCastException.class, testDO); - FromString.checkConversionException(TO_DATAOBJECT, ClassCastException.class, testDO); - FromString.checkConversionException(TO_LIST, ClassCastException.class, testDO); - FromString.checkConversionException(TO_SEQUENCE, ClassCastException.class, testDO); - } - - /** - * testBytesConversion verifies the conversion from Bytes to each of the - * allowed types. - */ - @org.junit.Test - public void testBytesConversion() { - Test FromBytes = new Test("bytesVal", BYTES_VAL_INDEX); - - FromBytes.initialize(byte[].class, "Bytes", new byte[] {10, 100}, testDO); - - FromBytes.attemptConversion(TO_BYTES, testDO); - FromBytes.attemptConversion(TO_BIGINTEGER, testDO); - } - - /** - * testBytesExceptions verifies that the appropriate Exceptions are thrown - * when an unpermitted conversion from Bytes is attempted. - */ - @org.junit.Test - public void testBytesExceptions() { - Test FromBytes = new Test("bytesVal", BYTES_VAL_INDEX); - - FromBytes.initialize(byte[].class, "Bytes", new byte[] {10, 100}, testDO); - - // FromBytes.checkConversionException(TO_BOOLEAN, - // ClassCastException.class, testDO); - // FromBytes.checkConversionException(TO_BYTE, ClassCastException.class, - // testDO); - // FromBytes.checkConversionException(TO_CHAR, ClassCastException.class, - // testDO); - // FromBytes.checkConversionException(TO_DOUBLE, - // ClassCastException.class, testDO); - // FromBytes.checkConversionException(TO_FLOAT, - // ClassCastException.class, testDO); - // FromBytes.checkConversionException(TO_INT, ClassCastException.class, - // testDO); - // FromBytes.checkConversionException(TO_LONG, ClassCastException.class, - // testDO); - // FromBytes.checkConversionException(TO_SHORT, - // ClassCastException.class, testDO); - // FromBytes.checkConversionException(TO_BIGDECIMAL, - // ClassCastException.class, testDO); - FromBytes.checkConversionException(TO_DATAOBJECT, ClassCastException.class, testDO); - // FromBytes.checkConversionException(TO_DATE, ClassCastException.class, - // testDO); - // FromBytes.checkConversionException(TO_STRING, - // ClassCastException.class, testDO); - FromBytes.checkConversionException(TO_LIST, ClassCastException.class, testDO); - FromBytes.checkConversionException(TO_SEQUENCE, ClassCastException.class, testDO); - } - - /** - * testBigDecimalConversion verifies the conversion from BigDecimal to each - * of the allowed types. - */ - @org.junit.Test - public void testBigDecimalConversion() { - Test FromBigDecimal = new Test("decimalVal", DECIMAL_VAL_INDEX); - - FromBigDecimal.initialize(BigDecimal.class, "BigDecimal", new BigDecimal("-3"), testDO); - - FromBigDecimal.attemptConversion(TO_DOUBLE, testDO); - FromBigDecimal.attemptConversion(TO_FLOAT, testDO); - FromBigDecimal.attemptConversion(TO_INT, testDO); - FromBigDecimal.attemptConversion(TO_LONG, testDO); - FromBigDecimal.attemptConversion(TO_BIGDECIMAL, testDO); - FromBigDecimal.attemptConversion(TO_BIGINTEGER, testDO); - FromBigDecimal.attemptConversion(TO_STRING, testDO); - } - - /** - * testBigDecimalExceptions verifies that the appropriate Exceptions are - * thrown when an unpermitted conversion from BigDecimal is attempted. - */ - @org.junit.Test - public void testBigDecimalExceptions() { - Test FromBigDecimal = new Test("decimalVal", DECIMAL_VAL_INDEX); - - FromBigDecimal.initialize(BigDecimal.class, "BigDecimal", new BigDecimal("-3"), testDO); - - // FromBigDecimal.checkConversionException(TO_BOOLEAN, - // ClassCastException.class, testDO); - // FromBigDecimal.checkConversionException(TO_BYTE, - // ClassCastException.class, testDO); - // FromBigDecimal.checkConversionException(TO_CHAR, - // ClassCastException.class, testDO); - // FromBigDecimal.checkConversionException(TO_SHORT, - // ClassCastException.class, testDO); - // FromBigDecimal.checkConversionException(TO_BYTES, - // ClassCastException.class, testDO); - FromBigDecimal.checkConversionException(TO_DATAOBJECT, ClassCastException.class, testDO); - // FromBigDecimal.checkConversionException(TO_DATE, - // ClassCastException.class, testDO); - FromBigDecimal.checkConversionException(TO_LIST, ClassCastException.class, testDO); - FromBigDecimal.checkConversionException(TO_SEQUENCE, ClassCastException.class, testDO); - } - - /** - * testBigIntegerConversion verifies the conversion from BigInteger to each - * of the allowed types. - */ - @org.junit.Test - public void testBigIntegerConversion() { - Test FromBigInteger = new Test("integerVal", INTEGER_VAL_INDEX); - - FromBigInteger.initialize(BigInteger.class, "BigInteger", new BigInteger("31500"), testDO); - - FromBigInteger.attemptConversion(TO_DOUBLE, testDO); - FromBigInteger.attemptConversion(TO_FLOAT, testDO); - FromBigInteger.attemptConversion(TO_INT, testDO); - FromBigInteger.attemptConversion(TO_LONG, testDO); - FromBigInteger.attemptConversion(TO_SHORT, testDO); - FromBigInteger.attemptConversion(TO_BYTES, testDO); - FromBigInteger.attemptConversion(TO_BIGDECIMAL, testDO); - FromBigInteger.attemptConversion(TO_BIGINTEGER, testDO); - FromBigInteger.attemptConversion(TO_STRING, testDO); - } - - /** - * testBigIntegerExceptions verifies that the appropriate Exceptions are - * thrown when an unpermitted conversion from BigInteger is attempted. - * - * @throws Exception - */ - @org.junit.Test - public void testBigIntegerExceptions() { - Test FromBigInteger = new Test("integerVal", INTEGER_VAL_INDEX); - - FromBigInteger.initialize(BigInteger.class, "BigInteger", new BigInteger("31500"), testDO); - - // FromBigInteger.checkConversionException(TO_BOOLEAN, - // ClassCastException.class, testDO); - // FromBigInteger.checkConversionException(TO_BYTE, - // ClassCastException.class, testDO); - // FromBigInteger.checkConversionException(TO_CHAR, - // ClassCastException.class, testDO); - FromBigInteger.checkConversionException(TO_DATAOBJECT, ClassCastException.class, testDO); - // FromBigInteger.checkConversionException(TO_DATE, - // ClassCastException.class, testDO); - FromBigInteger.checkConversionException(TO_LIST, ClassCastException.class, testDO); - FromBigInteger.checkConversionException(TO_SEQUENCE, ClassCastException.class, testDO); - } - - /** - * testDateConversion verifies the conversion from Date to each of the - * allowed types. - */ - @org.junit.Test - public void testDateConversion() { - Test FromDate = new Test("dateVal", DATE_VAL_INDEX); - - FromDate.initialize(Date.class, "Date", new Date(System.currentTimeMillis()), testDO); - - FromDate.attemptConversion(TO_LONG, testDO); - FromDate.attemptConversion(TO_DATE, testDO); - FromDate.attemptConversion(TO_STRING, testDO); - } - - /** - * testDateExceptions verifies that the appropriate Exceptions are thrown - * when an unpermitted conversion from Date is attempted. - */ - @org.junit.Test - public void testDateExceptions() { - - Test FromDate = new Test("dateVal", DATE_VAL_INDEX); - - FromDate.initialize(Date.class, "Date", new Date(System.currentTimeMillis()), testDO); - - // FromDate.checkConversionException(TO_BOOLEAN, - // ClassCastException.class, testDO); - // FromDate.checkConversionException(TO_BYTE, ClassCastException.class, - // testDO); - // FromDate.checkConversionException(TO_CHAR, ClassCastException.class, - // testDO); - // FromDate.checkConversionException(TO_DOUBLE, - // ClassCastException.class, testDO); - // FromDate.checkConversionException(TO_FLOAT, ClassCastException.class, - // testDO); - // FromDate.checkConversionException(TO_INT, ClassCastException.class, - // testDO); - // FromDate.checkConversionException(TO_SHORT, ClassCastException.class, - // testDO); - // FromDate.checkConversionException(TO_BYTES, ClassCastException.class, - // testDO); - // FromDate.checkConversionException(TO_BIGDECIMAL, - // ClassCastException.class, testDO); - // FromDate.checkConversionException(TO_BIGINTEGER, - // ClassCastException.class, testDO); - FromDate.checkConversionException(TO_DATAOBJECT, ClassCastException.class, testDO); - FromDate.checkConversionException(TO_LIST, ClassCastException.class, testDO); - FromDate.checkConversionException(TO_SEQUENCE, ClassCastException.class, testDO); - } -} |