use of javax.jdo.JDOFatalUserException in project tests by datanucleus.
the class SchemaTest method testColumnWidth.
/**
* Test of the column width specification.
* Test the PMF property "datanucleus.rdbms.stringLengthExceededAction".
*/
public void testColumnWidth() {
try {
// 1). Persist an object with a "serialNo" too long for the column, and expect an Exception
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Employee e = new Employee(245, "Fred", "Flintstone", "fred.flintstone@warnerbros.com", (float) 178.90, "123456789012345");
pm.makePersistent(e);
tx.commit();
fail("Persisted an object with a field value that was too long for the column storing it!");
} catch (JDOFatalUserException e) {
// Expected this to be thrown
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
// 2). Persist an object with a "serialNo" too long for the column, and use PMF option to truncate
Properties userProps = new Properties();
userProps.setProperty(RDBMSPropertyNames.PROPERTY_RDBMS_STRING_LENGTH_EXCEEDED_ACTION, "TRUNCATE");
PersistenceManagerFactory pmf2 = getPMF(1, userProps);
pm = pmf2.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Employee e = new Employee(245, "Fred", "Flintstone", "fred.flintstone@warnerbros.com", (float) 178.90, "123456789012345");
pm.makePersistent(e);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
fail("Exception thrown when persisting object with too-long String field but truncate selected");
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pmf2.close();
} finally {
clean(Employee.class);
}
}
use of javax.jdo.JDOFatalUserException in project tests by datanucleus.
the class PersistenceManagerFactoryTest method testObjectForStringProperty.
/**
* Test setting an object for a property value but string was expected
*/
public void testObjectForStringProperty() {
Properties props = TestHelper.getPropertiesForDatastore(1);
Map<Object, Object> map = new HashMap<>();
map.putAll(props);
map.put("javax.jdo.option.Mapping", new Object());
try {
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(map);
try {
fail("Expected JDOFatalInternalException");
} finally {
pmf.close();
}
} catch (JDOFatalUserException ex) {
assertEquals(IllegalArgumentException.class, ex.getNestedExceptions()[0].getCause().getClass());
} catch (Exception e) {
fail("Incorrect exception thrown : expected JDOFatalUserException but got " + e.getClass().getName());
}
}
use of javax.jdo.JDOFatalUserException in project tests by datanucleus.
the class PersistenceManagerFactoryTest method testServerTimeZoneID.
/**
* Test for serverTimeZoneID setting.
*/
public void testServerTimeZoneID() {
PersistenceManagerFactory pmf = null;
// Try setting the serverTimeZoneID to an invalid value
try {
Properties userProps = new Properties();
userProps.setProperty("javax.jdo.option.ServerTimeZoneID", "JPOX_CENTRAL_TIMEZONE");
pmf = getPMF(1, userProps);
fail("Expected a JDOUserException when setting the ServerTimeZoneID to an invalid value but worked!");
} catch (JDOFatalUserException jdoe) {
// Expected
} finally {
if (pmf != null && !pmf.isClosed()) {
pmf.close();
}
}
// Try setting it to a valid value and make sure it is retained
try {
Properties userProps = new Properties();
userProps.setProperty("javax.jdo.option.ServerTimeZoneID", "UTC");
pmf = getPMF(1, userProps);
assertEquals("ServerTimeZoneID was not set correctly", ((JDOPersistenceManagerFactory) pmf).getServerTimeZoneID(), "UTC");
} catch (Exception e) {
fail("Exception thrown when setting the ServerTimeZoneID to UTC");
} finally {
if (pmf != null && !pmf.isClosed()) {
pmf.close();
}
}
// Try leaving it unset and check the value
try {
pmf = getPMF(1, null);
assertEquals("ServerTimeZoneID was not set correctly", ((JDOPersistenceManagerFactory) pmf).getServerTimeZoneID(), null);
} catch (Exception e) {
fail("Exception thrown when setting the ServerTimeZoneID to UTC");
} finally {
if (pmf != null && !pmf.isClosed()) {
pmf.close();
}
}
}
use of javax.jdo.JDOFatalUserException in project tests by datanucleus.
the class SchemaTest method testColumnWidth.
/**
* Test of the column width specification.
* Test the PMF property "org.jpox.rdbms.stringLengthExceededAction".
*/
public void testColumnWidth() {
try {
// 1). Persist an object with a "serialNo" too long for the column, and expect an Exception
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Employee e = new Employee(245, "Fred", "Flintstone", "fred.flintstone@warnerbros.com", (float) 178.90, "123456789012345");
pm.makePersistent(e);
tx.commit();
fail("Persisted an object with a field value that was too long for the column storing it!");
} catch (JDOFatalUserException e) {
// Expected this to be thrown
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
// 2). Persist an object with a "serialNo" too long for the column, and use PMF option to truncate
Properties userProps = new Properties();
userProps.setProperty(RDBMSPropertyNames.PROPERTY_RDBMS_STRING_LENGTH_EXCEEDED_ACTION, "TRUNCATE");
PersistenceManagerFactory pmf2 = getPMF(1, userProps);
pm = pmf2.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Employee e = new Employee(245, "Fred", "Flintstone", "fred.flintstone@warnerbros.com", (float) 178.90, "123456789012345");
pm.makePersistent(e);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
fail("Exception thrown when persisting object with too-long String field but truncate selected");
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pmf2.close();
} finally {
clean(Employee.class);
}
}
Aggregations