| /* |
| * 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.BigDecimal; |
| import java.math.BigInteger; |
| import java.util.ArrayList; |
| import java.util.Arrays; |
| 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 SDODataObjectGetBytesByPositionalPathTest extends SDODataObjectGetByPositionalPathTestCases { |
| public SDODataObjectGetBytesByPositionalPathTest(String name) { |
| super(name); |
| } |
| |
| public static void main(String[] args) { |
| String[] arguments = { "-c", "org.eclipse.persistence.testing.sdo.model.dataobject.xpathpositional.SDODataObjectGetBytesByPositionalPathTest" }; |
| TestRunner.main(arguments); |
| } |
| |
| //1. purpose: getBytes with Boolean property |
| public void testGetBytesFromBoolean() { |
| 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); |
| dataObject_c.set(property_c, true); |
| |
| try { |
| dataObject_a.getBytes(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //2. purpose: getBytes with Byte property |
| public void testGetBytesFromByte() { |
| 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 = 10; |
| dataObject_c.set(property_c, theByte); |
| try { |
| dataObject_a.getBytes(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //3. purpose: getBytes with character property |
| public void testGetBytesFromCharacter() { |
| 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); |
| dataObject_c.set(property_c, 'c'); |
| |
| try { |
| dataObject_a.getBytes(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //4. purpose: getBytes with Double Property |
| public void testGetBytesFromDouble() { |
| 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); |
| double value = 2; |
| dataObject_c.set(property_c, value); |
| |
| try { |
| dataObject_a.getBytes(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //5. purpose: getBytes with float Property |
| public void testGetBytesFromFloat() { |
| 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); |
| float value = 2; |
| dataObject_c.set(property_c, value); |
| ; |
| |
| try { |
| dataObject_a.getBytes(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //6. purpose: getBytes with int Property |
| public void testGetBytesFromInt() { |
| 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); |
| int value = 2; |
| dataObject_c.set(property_c, value); |
| |
| try { |
| dataObject_a.getBytes(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //7. purpose: getBytes with long Property |
| public void testGetBytesFromLong() { |
| 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 value = 2; |
| dataObject_c.set(property_c, value); |
| |
| try { |
| dataObject_a.getBytes(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //8. purpose: getBytes with short Property |
| public void testGetBytesFromShort() { |
| 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); |
| short value = 2; |
| dataObject_c.set(property_c, value); |
| |
| try { |
| dataObject_a.getBytes(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //9. purpose: getBytes with string Property |
| public void testGetBytesFromString() { |
| 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); |
| |
| dataObject_c.set(property_c, "0A64"); |
| |
| try { |
| byte[] bytes = dataObject_a.getBytes(propertyPath_a_b_c); |
| byte[] controlBytes = new byte[] { 10, 100 }; |
| assertEqualsBytes(controlBytes, bytes); |
| } catch (ClassCastException e) { |
| } |
| } |
| |
| //10. purpose: getBytes with Defined Bytes Property |
| public void testGetBytesConversionFromDefinedBytesProperty() { |
| // dataObject's type add boolean property |
| 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[] b = { 12, 13 }; |
| |
| dataObject_a.setBytes(propertyPath_a_b_c, b);// add it to instance list |
| |
| assertTrue(Arrays.equals(b, dataObject_a.getBytes(propertyPath_a_b_c))); |
| } |
| |
| //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_BYTES); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| byte[] bb = { 12, 13 }; |
| List b = new ArrayList(); |
| |
| //b.add(bb); |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setBytes(property3, bb); |
| |
| assertTrue(Arrays.equals(bb, dataObject_a.getBytes(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_BYTES); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| byte[] bb = { 12, 13 }; |
| List b = new ArrayList(); |
| |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setBytes(property + ".0", bb); |
| |
| assertTrue(Arrays.equals(bb, dataObject_a.getBytes(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_BYTES); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c._setType(type_c); |
| |
| byte[] bb = { 12, 13 }; |
| |
| dataObject_a.setBytes(property1, bb);// c dataobject's a property has value boolean 'true' |
| |
| assertTrue(Arrays.equals(bb, dataObject_a.getBytes(property1))); |
| } |
| |
| /* public void testGetBooleanConversionWithPathFromDefinedBooleanPropertyEqualSignBracketInPathDotSet() { |
| property_c = new SDOProperty(aHelperContext); |
| property_c.setName(PROPERTY_NAME_C); |
| property_c.setType(SDOConstants.SDO_BYTES); |
| property_c.setMany(true); |
| type_c.addDeclaredProperty(property_c); |
| dataObject_c.setType(type_c); |
| |
| byte[] bb = { 12, 13 }; |
| List b = new ArrayList(); |
| |
| dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true' |
| dataObject_a.setBytes(property2+"[number=1]", bb); |
| |
| this.assertTrue(Arrays.equals(bb, dataObject_a.getBytes(property2+"[number=1]"))); |
| |
| }*/ |
| |
| //11. purpose: getBytes with Undefined Bytes Property |
| public void testGetBytesConversionFromUnDefinedBytesProperty() { |
| 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.getBytes(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //12. purpose: getBytes with decimal property |
| public void testGetBytesFromDecimal() { |
| 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); |
| BigDecimal value = new BigDecimal(2); |
| dataObject_c.set(property_c, value); |
| try { |
| dataObject_a.getBytes(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| /* //13. purpose: getBytes with Defined BigInteger Property !! OX PRO !! |
| public void testGetBytesConversionFromDefinedIntegerProperty() { |
| // dataObject's type add boolean property |
| 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); |
| |
| BigInteger bin = new BigInteger("12"); |
| byte[] b = bin.toByteArray(); |
| |
| dataObject_a.setBigInteger(propertyPath_a_b_c, bin);// add it to instance list |
| byte[] b1 = dataObject_a.getBytes(propertyPath_a_b_c); |
| this.assertTrue(Arrays.equals(b, b1)); |
| } |
| */ |
| |
| //11. purpose: getBytes with Undefined Integer Property |
| public void testGetBytesConversionFromUnDefinedIntegerProperty() { |
| 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.getBytes(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //22. purpose: getBytes with date property |
| public void testGetBytesFromDate() { |
| 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.getBytes(propertyPath_a_b_c); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| |
| //purpose: getBytes with nul value |
| public void testGetBytesWithNullArgument() { |
| try { |
| String p = null; |
| dataObject_a.getBytes(p); |
| } catch (Exception e) { |
| fail("No Exception expected, but caught " + e.getClass()); |
| } |
| } |
| } |