| /* |
| * 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.math.BigInteger; |
| import java.util.ArrayList; |
| import java.util.Calendar; |
| import java.util.List; |
| |
| import junit.framework.TestCase; |
| import junit.textui.TestRunner; |
| import org.eclipse.persistence.sdo.SDOConstants; |
| import org.eclipse.persistence.sdo.SDOProperty; |
| |
| public class SDODataObjectGetBooleanByPositionalPathTest extends SDODataObjectGetByPositionalPathTestCases { |
| public SDODataObjectGetBooleanByPositionalPathTest(String name) { |
| super(name); |
| } |
| |
| public static void main(String[] args) { |
| String[] arguments = { "-c", "org.eclipse.persistence.testing.sdo.model.dataobject.xpathpositional.SDODataObjectGetBooleanByPositionalPathTest" }; |
| TestRunner.main(arguments); |
| } |
| |
| //1. purpose: getBoolean with Defined Boolean Property |
| public void testGetBooleanConversionWithPathFromDefinedBooleanPropertyBracketPositionalSet() { |
| // dataObject's type add boolean property |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_BOOLEAN); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| Boolean bb = Boolean.valueOf(true); |
| List b = new ArrayList(); |
| |
| //b.add(bb); |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setBoolean(property3, true); |
| |
| assertEquals(bb.booleanValue(), dataObject_a.getBoolean(property3)); |
| |
| } |
| |
| //1. purpose: getBoolean with Defined Boolean Property |
| public void testGetBooleanConversionWithPathFromDefinedBooleanPropertyDotPositionalSet() { |
| // dataObject's type add boolean property |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_BOOLEAN); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| Boolean bb = Boolean.valueOf(true); |
| List b = new ArrayList(); |
| |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setBoolean(property + ".0", true); |
| |
| assertEquals(true, dataObject_a.getBoolean(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_BOOLEAN); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| Boolean b = Boolean.valueOf(true); |
| |
| dataObject_a.setBoolean(property1, true);// c dataobject's a property has value boolean 'true' |
| |
| assertEquals(true, dataObject_a.getBoolean(property1)); |
| } |
| |
| /*public void testGetBooleanConversionWithPathFromDefinedBooleanPropertyEqualSignBracketInPathDotSet() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_BOOLEAN); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c.setType(type_c); |
| |
| Boolean bb = Boolean.valueOf(true); |
| List b = new ArrayList(); |
| |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setBoolean(property2+"[number=1]", true); |
| |
| this.assertEquals(true, dataObject_a.getBoolean(property2+"[number=1]")); |
| |
| }*/ |
| |
| //2. purpose: getBoolean with Undefined Boolean Property |
| public void testGetBooleanConversionFromUnDefinedBooleanProperty() { |
| 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.getBoolean(property); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //3. purpose: getBoolean with Byte property |
| public void testGetBooleanFromByte() { |
| 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); |
| byte theByte = 1; |
| dataObject_c.set(property_c, theByte); |
| try { |
| boolean value = dataObject_a.getBoolean(property); |
| boolean controlValue = true; |
| assertEquals(controlValue, value); |
| //TODO: conversion not supported by sdo spec but is supported by TopLink |
| } catch (ClassCastException e) { |
| } |
| } |
| |
| //4. purpose: getBoolean with character property |
| public void testGetBooleanFromCharacter() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_CHARACTER); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| Character bb = Character.valueOf('1'); |
| List b = new ArrayList(); |
| |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setChar(property + ".0", bb.charValue()); |
| |
| assertEquals(true, dataObject_a.getBoolean(property + ".0")); |
| |
| /*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.getBoolean(property); |
| fail("ClassCastException should be thrown."); |
| } catch (ClassCastException e) { |
| }*/ |
| } |
| |
| //5. purpose: getBoolean with Double Property |
| public void testGetBooleanFromDouble() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_DOUBLE); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| Double bb = Double.valueOf(1); |
| List b = new ArrayList(); |
| |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setDouble(property + ".0", bb.doubleValue()); |
| |
| assertEquals(true, dataObject_a.getBoolean(property + ".0")); |
| |
| /*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.getBoolean(property); |
| fail("ClassCastException should be thrown."); |
| } catch (ClassCastException e) { |
| }*/ |
| } |
| |
| //6. purpose: getBoolean with float Property |
| public void testGetBooleanFromFloat() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_FLOAT); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| Float bb = Float.valueOf(1); |
| List b = new ArrayList(); |
| |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setFloat(property + ".0", bb.floatValue()); |
| |
| assertEquals(true, dataObject_a.getBoolean(property + ".0")); |
| |
| /*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.getBoolean(property); |
| fail("ClassCastException should be thrown."); |
| } catch (ClassCastException e) { |
| }*/ |
| } |
| |
| //7. purpose: getBooleab with int Property |
| public void testGetBooleanFromInt() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_INT); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| //short s = 1; |
| Integer bb = Integer.valueOf(1); |
| List b = new ArrayList(); |
| |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setInt(property + ".0", bb.intValue()); |
| |
| assertEquals(true, dataObject_a.getBoolean(property + ".0")); |
| |
| /*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.getBoolean(property); |
| fail("ClassCastException should be thrown."); |
| } catch (ClassCastException e) { |
| }*/ |
| } |
| |
| //8. purpose: getBoolea with long Property |
| public void testGetBooleanFromLong() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_LONG); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| long s = 1; |
| Long bb = Long.valueOf(s); |
| List b = new ArrayList(); |
| |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setLong(property + ".0", bb.longValue()); |
| |
| assertEquals(true, dataObject_a.getBoolean(property + ".0")); |
| |
| /*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.getBoolean(property); |
| fail("ClassCastException should be thrown."); |
| } catch (ClassCastException e) { |
| }*/ |
| } |
| |
| //9. purpose: getBytes with short Property |
| public void testGetBooleanFromShort() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_SHORT); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| short s = 1; |
| Short bb = Short.valueOf(s); |
| List b = new ArrayList(); |
| |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setShort(property + ".0", bb.shortValue()); |
| |
| assertEquals(true, dataObject_a.getBoolean(property + ".0")); |
| |
| /*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.getBoolean(property); |
| fail("ClassCastException should be thrown."); |
| } catch (ClassCastException e) { |
| }*/ |
| } |
| |
| //10. purpose: getBoolean with Defined String Property |
| public void testGetBooleanConversionFromDefinedStringProperty() { |
| 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); |
| |
| String str = "true"; |
| Boolean B_STR = Boolean.valueOf(str); |
| dataObject_c.setString(property_c, str);// add it to instance list |
| |
| assertEquals(B_STR.booleanValue(), dataObject_a.getBoolean(property)); |
| } |
| |
| //1. purpose: getBoolean with Defined Boolean Property |
| public void testGetBooleanConversionWithPathFromDefinedBooleanStringBracketPositionalSet() { |
| // dataObject's type add boolean property |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_BOOLEAN); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| String str = "true"; |
| Boolean bb = Boolean.valueOf(str); |
| List b = new ArrayList(); |
| |
| //b.add(bb); |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.set(property3, bb); |
| |
| assertEquals(bb.booleanValue(), dataObject_a.getBoolean(property3)); |
| |
| } |
| |
| //1. purpose: getBoolean with Defined Boolean Property |
| public void testGetBooleanConversionWithPathFromDefinedStringPropertyDotPositionalSet() { |
| // dataObject's type add boolean property |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_BOOLEAN); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| String str = "true"; |
| Boolean bb = Boolean.valueOf(str); |
| List b = new ArrayList(); |
| |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.set(property + ".0", bb); |
| |
| assertEquals(true, dataObject_a.getBoolean(property + ".0")); |
| |
| } |
| |
| //1. purpose: getBoolean with Defined Boolean Property |
| public void testGetBooleanConversionWithPathFromDefinedStringPropertyBracketInPathMiddle() { |
| 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); |
| |
| String str = "true"; |
| Boolean b = Boolean.valueOf(str); |
| |
| dataObject_a.set(property1, b);// c dataobject's a property has value boolean 'true' |
| |
| assertEquals(true, dataObject_a.getBoolean(property1)); |
| } |
| |
| /* public void testGetBooleanConversionWithPathFromDefinedStringPropertyEqualSignBracketInPathDotSet() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_BOOLEAN); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c.setType(type_c); |
| |
| String str = "true"; |
| Boolean bb = Boolean.valueOf(str); |
| List b = new ArrayList(); |
| |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.set(property2+"[number=1]", bb); |
| |
| this.assertEquals(true, dataObject_a.getBoolean(property2+"[number=1]")); |
| |
| }*/ |
| |
| //11. purpose: getDouble with Undefined string Property |
| public void testGetBooleanConversionFromUnDefinedStringProperty() { |
| 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.getBoolean(property); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //12. purpose: getBoolean with bytes property |
| public void testGetBooleanFromBytes() { |
| 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); |
| byte[] bytes = new byte[] { 10, 100 }; |
| dataObject_c.set(property_c, bytes); |
| try { |
| dataObject_a.getBoolean(property); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //13. 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 { |
| boolean value = dataObject_a.getBoolean(property); |
| boolean controlValue = false; |
| assertEquals(controlValue, value); |
| //TODO: conversion not supported by sdo spec but is supported by TopLink |
| } catch (ClassCastException e) { |
| } |
| } |
| |
| //14. purpose: getBoolean with integer property |
| public void testGetBooleanFromInteger() { |
| 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); |
| dataObject_c.set(property_c, new BigInteger("1")); |
| try { |
| boolean value = dataObject_a.getBoolean(property); |
| boolean controlValue = true; |
| assertEquals(controlValue, value); |
| //TODO: conversion not supported by sdo spec but is supported by TopLink |
| } catch (ClassCastException e) { |
| } |
| } |
| |
| //22. purpose: getBoolean with date property |
| public void testGetBooleanFromDate() { |
| 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); |
| dataObject_c.set(property_c, Calendar.getInstance().getTime()); |
| try { |
| dataObject_a.getBoolean(property); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //purpose: getDouble with nul value |
| public void testGetBooleanWithNullArgument() { |
| try { |
| String path = null; |
| dataObject_a.getBoolean(path); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| } |