Details
-
Feature Request
-
Resolution: Unresolved
-
Major
-
None
-
persistence_1.0.0.Alpha4
-
None
Description
It would be handy to automagically be able to test JPA queries with a method like
@Test @UsingDataSet("all.xls") @ShouldMatchDataSet("hits.xls") public List<Customer> getAllowedCustomers() { return em.createNamedQuery("customers", Customer.class).getResultList(); }
for methods with signatures returning List<?>. Currently I have functionality like
@Test @UsingDataSet("all.xls") public void testCustomers() throws Exception { IDataSet expected = new XlsDataSet(getClass().getResourceAsStream("/hits.xls")); ITableMetaData metadata = expected.getTableMetaData(expected.getTableNames()[0]); IDataSet real = new PojoDataSet(em.createNamedQuery("customers", Customer.class).getResultList(), metadata); Assertion.assertEquals(expected, real); }
and
public class PojoDataSet extends DefaultDataSet { public PojoDataSet(List<?> entities, ITableMetaData metaData) { try { DefaultTable table = new DefaultTable(metaData); for (Object entity : entities) { List<Object> values = new ArrayList<Object>(); for (Column column : metaData.getColumns()) { values.add(BeanUtils.getNestedProperty(entity, column.getColumnName())); } table.addRow(values.toArray()); } addTable(table); } catch (Exception e) { throw new IllegalArgumentException(e); } } }
With the column names in the metadata (from the xls) mapped to Apache BeanUtils nested properties. This approach only verifies the identities of the top-level objects (OK, it can descend @OneToOne relations) and doesn't cover the whole POJO structure.
It would be nice if this process could somehow be automated with Arquillian-persistence.
Attachments
Issue Links
- is related to
-
ARQ-1336 Should be able to leverage JPA entities to seed and compare database set
- Open