OperationAllowedSpecs { public static Specification<OperationAllowed> hasOperationId(final int operationId) { return new Specification<OperationAllowed>() { @Override public Predicate toPredicate(Root<OperationAllowed> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Path<Integer> opIdAttributePath = root.get(OperationAllowed_.id).get(OperationAllowedId_.operationId); Predicate opIdEqualPredicate = cb.equal(opIdAttributePath, cb.literal(operationId)); return opIdEqualPredicate; } }; } 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 testHasOperationId() { Specification<OperationAllowed> hasMetadataId = OperationAllowedSpecs.hasOperationId(_viewOp.getId()); List<OperationAllowed> found = _opAllowRepo.findAll(hasMetadataId, new Sort(groupIdPath(), metadataIdPath())); assertEquals(found.size(), 2); assertEquals(_allGroup.getId(), found.get(0).getId().getGroupId()); assertEquals(_viewOp.getId(), found.get(0).getId().getOperationId()); assertEquals(_viewOp.getId(), found.get(1).getId().getOperationId()); assertEquals(_md1.getId(), found.get(0).getId().getMetadataId()); assertEquals(_md1.getId(), found.get(1).getId().getMetadataId()); }