@Transactional
public void testFindByCriteria2() throws InstanceNotFoundException {
Criterion criterion1 = givenStoredCriterion();
Criterion criterion2 = givenStoredCriterion();
OrderLine orderLine1 = createValidOrderLine();
orderLine1.addCriterionRequirement(new DirectCriterionRequirement(
criterion1));
orderLine1.addCriterionRequirement(new DirectCriterionRequirement(
criterion2));
orderElementDAO.save(orderLine1);
OrderLine orderLine2 = createValidOrderLine();
orderElementDAO.save(orderLine2);
OrderLine orderLine3 = createValidOrderLine();
orderLine3.addCriterionRequirement(new DirectCriterionRequirement(
criterion2));
orderElementDAO.save(orderLine3);
List<OrderElement> orderELements = orderElementDAO
.findByLabelsAndCriteria(null, Collections.singleton(criterion1));
assertEquals(1, orderELements.size());
assertEquals(orderLine1.getId(), orderELements.get(0).getId());
orderELements = orderElementDAO.findByLabelsAndCriteria(null,
Collections.singleton(criterion2));
assertEquals(2, orderELements.size());
for (OrderElement each : orderELements) {
assertTrue(each.getId().equals(orderLine1.getId())
|| each.getId().equals(orderLine3.getId()));
}
orderELements = orderElementDAO.findByLabelsAndCriteria(null,
new HashSet<Criterion>(Arrays.asList(criterion1, criterion2)));
assertEquals(1, orderELements.size());