| /* |
| * Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0, |
| * or the Eclipse Distribution License v. 1.0 which is available at |
| * http://www.eclipse.org/org/documents/edl-v10.php. |
| * |
| * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause |
| */ |
| |
| // Contributors: |
| // Oracle - initial API and implementation from Oracle TopLink |
| package org.eclipse.persistence.testing.sdo.model.dataobject.xpathpositional; |
| |
| import java.util.ArrayList; |
| import java.util.Calendar; |
| import java.util.Date; |
| import java.util.List; |
| |
| import junit.framework.TestCase; |
| import org.eclipse.persistence.sdo.SDOConstants; |
| import org.eclipse.persistence.sdo.SDOProperty; |
| |
| public class SDODataObjectGetDateByPositionalPathTest extends SDODataObjectGetByPositionalPathTestCases { |
| public SDODataObjectGetDateByPositionalPathTest(String name) { |
| super(name); |
| } |
| |
| //1. purpose: getDate with Boolean property |
| public void testGetDateFromBooleane() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_BOOLEAN); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| try { |
| dataObject_a.getDate(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //2. purpose: getDate with Byte property |
| public void testGetDateFromByte() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_BYTE); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| try { |
| dataObject_a.getDate(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //3. purpose: getDate with character property |
| public void testGetDateFromCharacter() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_CHARACTER); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| try { |
| dataObject_a.getDate(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //4. purpose: getDate with Double Property |
| public void testGetDateFromDouble() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_DOUBLE); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| try { |
| dataObject_a.getDate(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //5. purpose: getDate with float Property |
| public void testGetDateFromFloat() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_FLOAT); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| try { |
| dataObject_a.getDate(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //7. purpose: getDate with int Property |
| public void testGetDateFromInt() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_INT); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| try { |
| dataObject_a.getDate(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //8. purpose: getDate with Defined long Property |
| public void testGetDateConversionFromDefinedLongProperty() { |
| // dataObject's type add boolean property |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_LONG); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| long l = 12; |
| Date d = new Date(l); |
| |
| dataObject_c.setLong(property_c, l);// add it to instance list |
| |
| assertEquals(d, dataObject_a.getDate(propertyPath_a_b_c)); |
| } |
| |
| //9. purpose: getDate with Undefined Boolean Property |
| public void testGetDateConversionFromUnDefinedLongProperty() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_LONG); |
| //type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| try { |
| dataObject_a.getDate(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //10. purpose: getDate with short Property |
| public void testGetDateFromShort() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_SHORT); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| try { |
| dataObject_a.getDate(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //11. purpose: getDate with Defined String Property |
| public void testGetDateConversionFromDefinedStringProperty() { |
| // dataObject's type add int property |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_STRING); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| Calendar controlCalendar = Calendar.getInstance(); |
| controlCalendar.clear(); |
| controlCalendar.set(Calendar.YEAR, 2001); |
| controlCalendar.set(Calendar.MONTH, 0); |
| controlCalendar.set(Calendar.DATE, 1); |
| Date d = controlCalendar.getTime(); |
| |
| dataObject_c.setString(property_c, "2001-01-01");// add it to instance list |
| |
| assertEquals(d, dataObject_a.getDate(propertyPath_a_b_c)); |
| } |
| |
| //11. purpose: getDate with Defined String Property |
| public void testGetDateConversionFromDefinedStringPropertyList() { |
| // dataObject's type add int property |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setMany(true); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_STRING); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| Calendar controlCalendar = Calendar.getInstance(); |
| controlCalendar.clear(); |
| controlCalendar.set(Calendar.YEAR, 2001); |
| controlCalendar.set(Calendar.MONTH, 0); |
| controlCalendar.set(Calendar.DATE, 1); |
| Date d = controlCalendar.getTime(); |
| |
| List objects = new ArrayList(); |
| objects.add("2001-01-01"); |
| dataObject_c.set(property_c, objects);// add it to instance list |
| |
| assertEquals(d, dataObject_a.getDate(propertyPath_a_b_c + ".0")); |
| } |
| |
| //12. purpose: getDate with Undefined string Property |
| public void testGetDateConversionFromUnDefinedStringProperty() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_STRING); |
| //type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| try { |
| dataObject_a.getDate(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //13. purpose: getDate with bytes property |
| public void testGetDateFromBytes() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_BYTES); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| try { |
| dataObject_a.getDate(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //14. purpose: getBoolean with decimal property |
| public void testGetBooleanFromDecimal() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_DECIMAL); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| try { |
| dataObject_a.getBoolean(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //15. purpose: getDate with integer property |
| public void testGetDateFromInteger() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_INTEGER); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| try { |
| dataObject_a.getDate(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //16. purpose: getDate with Defined Date Property |
| public void testGetDateConversionFromDefinedDateProperty() { |
| // dataObject's type add int property |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_DATE); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| long l = 12000; |
| Date d = new Date(l); |
| dataObject_a.setDate(propertyPath_a_b_c, d);// add it to instance list |
| |
| assertEquals(d, dataObject_a.getDate(propertyPath_a_b_c)); |
| } |
| |
| //1. purpose: getBoolean with Defined Boolean Property |
| public void testGetDateConversionWithPathFromDefinedBooleanPropertyBracketPositionalSet() { |
| // dataObject's type add boolean property |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_DATE); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| long l = 12000; |
| Date d = new Date(l); |
| List b = new ArrayList(); |
| |
| //b.add(bb); |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setDate(property3, d); |
| |
| assertEquals(d, dataObject_a.getDate(property3)); |
| |
| } |
| |
| //1. purpose: getBoolean with Defined Boolean Property |
| public void testGetDateConversionWithPathFromDefinedBooleanPropertyDotPositionalSet() { |
| // dataObject's type add boolean property |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_DATE); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| long l = 12000; |
| Date d = new Date(l); |
| List b = new ArrayList(); |
| |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setDate(property + ".0", d); |
| |
| assertEquals(d, dataObject_a.getDate(property + ".0")); |
| |
| } |
| |
| //1. purpose: getBoolean with Defined Boolean Property |
| public void testGetBooleanConversionWithPathFromDefinedBooleanPropertyBracketInPathMiddle() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_DATE); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| long l = 12000; |
| Date d = new Date(l); |
| |
| dataObject_a.setDate(property1, d);// c dataobject's a property has value boolean 'true' |
| |
| assertEquals(d, dataObject_a.getDate(property1)); |
| } |
| |
| /*public void testGetBooleanConversionWithPathFromDefinedBooleanPropertyEqualSignBracketInPathDotSet() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_DATE); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c.setType(type_c); |
| |
| long l = 12000; |
| Date d = new Date(l); |
| List b = new ArrayList(); |
| |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setDate(property2+"[number=1]", d); |
| |
| this.assertEquals(d, dataObject_a.getDate(property2+"[number=1]")); |
| |
| }*/ |
| |
| //12. purpose: getDate with Undefined string Property |
| public void testGetDateConversionFromUnDefinedDateProperty() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_DATE); |
| //type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| try { |
| dataObject_a.getDate(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //purpose: getDate with nul value |
| public void testGetDateWithNullArgument() { |
| try { |
| String p = null; |
| dataObject_a.getDate(p); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| } |