OperationAllowedSpecs { public static Specification<OperationAllowed> hasGroupId(final int groupId) { return new Specification<OperationAllowed>() { @Override public Predicate toPredicate(Root<OperationAllowed> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Path<Integer> mdIdAttributePath = root.get(OperationAllowed_.id).get(OperationAllowedId_.groupId); return cb.equal(mdIdAttributePath, cb.literal(groupId)); } }; } private  OperationAllowedSpecs(); static Specification<OperationAllowed> hasMetadataId(final String metadataId); static Specification<OperationAllowed> hasMetadataId(final int metadataId); static Specification<OperationAllowed> hasGroupId(final int groupId); static Specification<OperationAllowed> hasOperation(final ReservedOperation operation); static Specification<OperationAllowed> hasOperationId(final int operationId); static Specification<OperationAllowed> isPublic(final ReservedOperation operation); static Specification<OperationAllowed> hasMetadataIdIn(final Collection<Integer> metadataIds); static Specification<OperationAllowed> hasGroupIdIn(final Collection<Integer> groupIds); static Specification<OperationAllowed> hasOperationIdIn(final Collection<Integer> operationIds);  }
@Test public void testHasGroupId() { Specification<OperationAllowed> hasGroupId = OperationAllowedSpecs.hasGroupId(_intranetGroup.getId()); List<OperationAllowed> found = _opAllowRepo.findAll(hasGroupId, new Sort(groupIdPath(), metadataIdPath())); assertEquals(found.size(), 3); assertEquals(_intranetGroup.getId(), found.get(0).getId().getGroupId()); assertEquals(_intranetGroup.getId(), found.get(1).getId().getGroupId()); assertEquals(_intranetGroup.getId(), found.get(2).getId().getGroupId()); assertEquals(_viewOp.getId(), found.get(0).getId().getOperationId()); assertEquals(_downloadOp.getId(), found.get(1).getId().getOperationId()); assertEquals(_downloadOp.getId(), found.get(2).getId().getOperationId()); assertEquals(_md1.getId(), found.get(0).getId().getMetadataId()); assertEquals(_md1.getId(), found.get(1).getId().getMetadataId()); assertEquals(_md2.getId(), found.get(2).getId().getMetadataId()); }
@Test public void testHasOwnerIdAndSpec() { List<OperationAllowed> found = _opAllowRepo.findAllWithOwner(1, Optional.<Specification<OperationAllowed>>of (OperationAllowedSpecs.hasGroupId(_intranetGroup.getId()))); assertEquals(found.size(), 2); }