Search in sources :

Example 1 with SDOException

use of org.eclipse.persistence.exceptions.SDOException in project eclipselink by eclipse-ee4j.

the class DateConvertBug5672591TestCases method testExceptionSet.

public void testExceptionSet() {
    DataObject testDataObject = dataFactory.create(rootType);
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(Calendar.YEAR, 1975);
    cal.set(Calendar.MONTH, Calendar.FEBRUARY);
    cal.set(Calendar.DATE, 21);
    Date dateValue = cal.getTime();
    try {
        // value should be converted to a string with dataHelper but unsupported conversion
        testDataObject.setDate(rootType.getProperty("theBooleanProp"), dateValue);
    } catch (IllegalArgumentException e) {
        assertTrue(e.getCause() instanceof SDOException);
        // assertEquals(SDOException.WRONG_VALUE_FOR_PROPERTY ,((SDOException)e.getCause()).getErrorCode());
        // changed from WRONG_VALUE_FOR_PROPERTY to conversion error...this is because of removal of datahelper.isconversionsupported
        assertEquals(SDOException.CONVERSION_ERROR, ((SDOException) e.getCause()).getErrorCode());
        return;
    }
    fail("An IllegalArgumentException should have occurred");
}
Also used : SDOException(org.eclipse.persistence.exceptions.SDOException) DataObject(commonj.sdo.DataObject) Calendar(java.util.Calendar) Date(java.util.Date)

Example 2 with SDOException

use of org.eclipse.persistence.exceptions.SDOException in project eclipselink by eclipse-ee4j.

the class SDOTypeHelperDefineInvalidTestCases method testDefineInvalidPropertyTypeName.

public void testDefineInvalidPropertyTypeName() {
    SDOHelperContext ctx = new SDOHelperContext();
    DataObject typeDataObject = ctx.getDataFactory().create(SDOConstants.SDO_URL, SDOConstants.TYPE);
    typeDataObject.set("name", "ValidPropertyName");
    DataObject propertyTypeDataObject = ctx.getDataFactory().create(SDOConstants.SDO_URL, SDOConstants.TYPE);
    // invalid code point 0x36F at index 0
    propertyTypeDataObject.set("name", "\u036FInvalidPropertyTypeName");
    DataObject propertyDataObject = typeDataObject.createDataObject("property");
    propertyDataObject.set("name", "ValidPropertyName");
    propertyDataObject.set("type", propertyTypeDataObject);
    try {
        ctx.getTypeHelper().define(typeDataObject);
        fail("IllegalArgumentException exception expected but did not occur.");
    } catch (IllegalArgumentException e) {
        assertNotNull("Not null cause expected.", e.getCause());
        assertTrue("SDOException expected as cause.", e.getCause() instanceof SDOException);
        assertEquals(SDOException.ERROR_DEFINING_TYPE_INVALID_NAME, ((SDOException) e.getCause()).getErrorCode());
    }
}
Also used : SDOException(org.eclipse.persistence.exceptions.SDOException) DataObject(commonj.sdo.DataObject) SDOHelperContext(org.eclipse.persistence.sdo.helper.SDOHelperContext)

Example 3 with SDOException

use of org.eclipse.persistence.exceptions.SDOException in project eclipselink by eclipse-ee4j.

the class SDOTypeHelperDefineInvalidTestCases method testDefineInvalidPropertyName.

public void testDefineInvalidPropertyName() {
    SDOHelperContext ctx = new SDOHelperContext();
    DataObject typeDataObject = ctx.getDataFactory().create(SDOConstants.SDO_URL, SDOConstants.TYPE);
    typeDataObject.set("name", "ValidTypeName");
    DataObject propertyDataObject = typeDataObject.createDataObject("property");
    // invalid code point \u00BA
    propertyDataObject.set("name", "N\u00BANF");
    propertyDataObject.set("type", ctx.getTypeHelper().getType(SDOConstants.SDO_URL, SDOConstants.STRING));
    try {
        ctx.getTypeHelper().define(typeDataObject);
        fail("IllegalArgumentException exception expected but did not occur.");
    } catch (IllegalArgumentException e) {
        assertNotNull("Not null cause expected.", e.getCause());
        assertTrue("SDOException expected as cause.", e.getCause() instanceof SDOException);
        assertEquals(SDOException.ERROR_DEFINING_PROPERTY_INVALID_NAME, ((SDOException) e.getCause()).getErrorCode());
    }
}
Also used : SDOException(org.eclipse.persistence.exceptions.SDOException) DataObject(commonj.sdo.DataObject) SDOHelperContext(org.eclipse.persistence.sdo.helper.SDOHelperContext)

Example 4 with SDOException

use of org.eclipse.persistence.exceptions.SDOException in project eclipselink by eclipse-ee4j.

the class SDOTypeHelperDefineNullTestCases method testPropertyWithNullType.

public void testPropertyWithNullType() {
    DataObject purchaseOrderTypeType = dataFactory.create("commonj.sdo", "Type");
    SDOProperty prop = (SDOProperty) purchaseOrderTypeType.getType().getProperty("uri");
    purchaseOrderTypeType.set(prop, "http://example.com/");
    prop = (SDOProperty) purchaseOrderTypeType.getType().getProperty("name");
    purchaseOrderTypeType.set(prop, "PurchaseOrderType");
    // create a orderDateProperty
    addProperty(purchaseOrderTypeType, "orderDate", null);
    try {
        typeHelper.define(purchaseOrderTypeType);
    } catch (SDOException e) {
        assertEquals(e.getErrorCode(), SDOException.NO_TYPE_SPECIFIED_FOR_PROPERTY);
        return;
    } catch (Exception e) {
    }
    fail("An exception should have been thrown but wasn't");
}
Also used : SDOException(org.eclipse.persistence.exceptions.SDOException) DataObject(commonj.sdo.DataObject) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) SDOException(org.eclipse.persistence.exceptions.SDOException)

Example 5 with SDOException

use of org.eclipse.persistence.exceptions.SDOException in project eclipselink by eclipse-ee4j.

the class DefineFailsDontRegisterTypesTestCases method testDefine.

@Override
public void testDefine() {
    InputStream is = getSchemaInputStream(getSchemaToDefine());
    int sizeBefore = ((SDOTypeHelper) typeHelper).getTypesHashMap().size();
    boolean exceptionCase = false;
    List types = null;
    try {
        types = xsdHelper.define(is, getSchemaLocation());
    } catch (SDOException e) {
        exceptionCase = true;
    // do nothing
    }
    assertTrue(exceptionCase);
    assertEquals(sizeBefore, ((SDOTypeHelper) typeHelper).getTypesHashMap().size());
    assertNull(types);
    assertNull(typeHelper.getType("http://www.example.org", "address-type"));
    assertNull(typeHelper.getType("http://www.example.org", "customer-type"));
    assertNull(typeHelper.getType("http://www.example.org", "bad-type"));
    assertNull(xsdHelper.getGlobalProperty("http://www.example.org", "customer", true));
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) SDOException(org.eclipse.persistence.exceptions.SDOException) InputStream(java.io.InputStream) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

SDOException (org.eclipse.persistence.exceptions.SDOException)71 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)43 SDOSequence (org.eclipse.persistence.sdo.SDOSequence)37 DataObject (commonj.sdo.DataObject)33 Property (commonj.sdo.Property)33 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)25 List (java.util.List)9 InputStream (java.io.InputStream)7 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)5 FileInputStream (java.io.FileInputStream)4 ArrayList (java.util.ArrayList)4 SDOHelperContext (org.eclipse.persistence.sdo.helper.SDOHelperContext)4 Type (commonj.sdo.Type)3 JAXBContext (jakarta.xml.bind.JAXBContext)3 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)3 SDOType (org.eclipse.persistence.sdo.SDOType)3 SDODataFactory (org.eclipse.persistence.sdo.helper.SDODataFactory)3 ChangeSummary (commonj.sdo.ChangeSummary)1 Sequence (commonj.sdo.Sequence)1 Calendar (java.util.Calendar)1