use of org.jpox.samples.widget.SetWidget in project tests by datanucleus.
the class ViewTest method testViewOfSetWidgets.
public void testViewOfSetWidgets() throws Exception {
/*
* We can't run this test on Cloudscape because the view used by
* SetWidgetCounts doesn't execute properly; some counts that should
* be 0 come up 1. This is presumably due to a bug in Cloudscape
* (last tried on both 3.6 and 4.0).
*/
if ("cloudscape".equals(vendorID)) {
return;
}
try {
LOG.info("Testing view derived from of " + StorageTester.TEST_OBJECT_COUNT + " " + SetWidget.class.getName() + " objects");
tester.insertObjects(SetWidget.class);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Extent ext = pm.getExtent(SetWidgetCounts.class, true);
Iterator exti = ext.iterator();
int count = 0;
while (exti.hasNext()) {
SetWidgetCounts actual = (SetWidgetCounts) exti.next();
SetWidgetCounts expected = new SetWidgetCounts(actual.getSetWidget());
StorageTester.assertFieldsEqual(expected, actual);
++count;
}
tx.commit();
assertEquals("Iteration over view extent returned wrong number of rows", StorageTester.TEST_OBJECT_COUNT, count);
tx.begin();
Query query = pm.newQuery(pm.getExtent(SetWidgetCounts.class, true));
query.setFilter("normalSetSize != 0");
query.setOrdering("sw.numElementWidgets descending");
Collection results = (Collection) query.execute();
TestObject[] objs = tester.getObjects();
try {
HashSet expected = new HashSet();
for (int i = 0; i < objs.length; ++i) {
SetWidget sw = (SetWidget) objs[i];
if (sw.getNormalSet().size() != 0) {
expected.add(new SetWidgetCounts(sw));
}
}
assertTrue("Query has no expected results (test is broken)", !expected.isEmpty());
assertTrue("Query returned no rows", !results.isEmpty());
HashSet actual = new HashSet(results);
assertEquals("Query returned duplicate rows", results.size(), actual.size());
assertTrue("Query did not return expected results: expected " + expected + ", but was " + actual, TestObject.compareSet(expected, actual));
} finally {
query.closeAll();
}
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} catch (JDOException e) {
LOG.error(">> Exception during test", e);
fail("Exception occurred during test : " + e.getMessage());
} finally {
tester.removeObjects();
clean(Widget.class);
}
}
Aggregations