}
@Test
public void theHierarchyOfCriterionsIsConsidered() {
final Criterion[] parentCriteron = { null };
Resource worker = transactionService
.runOnTransaction(new IOnTransaction<Resource>() {
@Override
public Resource execute() {
Worker result = givenValidWorker();
CriterionType type = createCriterionType("testType");
Criterion parent = createCriterion("parent", type);
parentCriteron[0] = parent;
Criterion child = createCriterion("child", type);
child.setParent(parent);
addSatisfactionsOn(result,
Interval.from(new LocalDate(1970, 1, 1)), child);
return result;
}
});
final Criterion parent = transactionService
.runOnReadOnlyTransaction(new IOnTransaction<Criterion>() {
@Override
public Criterion execute() {
return criterionDAO
.findExistingEntity(parentCriteron[0].getId());
}
});
List<Resource> resources = transactionService
.runOnReadOnlyTransaction(new IOnTransaction<List<Resource>>() {
@Override
public List<Resource> execute() {
return resourcesSearcher.searchBoth()
.byCriteria(Collections.singleton(parent))
.execute();
}
});
assertThat(resources.size(), equalTo(1));
Resource resource = resources.get(0);
assertThat(resource.getId(), equalTo(worker.getId()));
}