use of org.jpox.samples.interfaces.ShapeHolder2 in project tests by datanucleus.
the class ReachabilityTest method testIncorrectAssignment.
/**
* Tests whether a ClassCastException is thrown upon incorrect (that is undeclared) assignment
* to a interface field. See JDO spec 1.0 �6.4.3 Object Class type: "If an implementation
* restricts instances to be assigned to the field, a ClassCastException must be thrown at the
* time of any incorrect assignment."
*/
public void testIncorrectAssignment() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Square square1 = new Square(101, 250.5, 650.0);
ShapeHolder2 holder = new ShapeHolder2(301);
holder.setShape1(square1);
holder.setShape2(null);
try {
// Try to set "shape2" field to this Square - should be prohibited.
LOG.info(">> Persisting ShapeHolder.shape2 as Square");
pm.makePersistent(holder);
LOG.info(">> makePersistent called");
tx.commit();
LOG.info(">> committed");
assertTrue("incorrect assignment of Square instance was accepted", false);
} catch (ClassCastException e) {
// this exception is expected
}
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(ShapeHolder2.class);
clean(Square.class);
}
}
use of org.jpox.samples.interfaces.ShapeHolder2 in project tests by datanucleus.
the class InterfacesTest method testMultipleImplementations.
/**
* Test the specification of multiple implementations. One field has duplicate impls, and another
* has full specification including columns (ORM only).
*/
public void testMultipleImplementations() throws Exception {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
// Create container and some shapes
tx.begin();
ShapeHolder2 holder = new ShapeHolder2(r.nextInt());
Circle circle = new Circle(1, 102.0);
holder.setShape1(circle);
Rectangle rect = new Rectangle(2, 250, 200);
holder.setShape2(rect);
pm.makePersistent(holder);
tx.commit();
} catch (Exception e) {
fail(e.getLocalizedMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out our data
clean(ShapeHolder2.class);
clean(Rectangle.class);
clean(Circle.class);
}
}
Aggregations