### Question:
StageDAO { @RequiresSession public List<StageEntity> findAll() { return daoUtils.selectAll(entityManagerProvider.get(), StageEntity.class); }  @RequiresSession StageEntity findByPK(StageEntityPK stageEntityPK); @RequiresSession List<StageEntity> findAll(); @RequiresSession long getLastRequestId(); @RequiresSession StageEntity findByActionId(String actionId); @RequiresSession List<StageEntity> findByRequestId(long requestId); @RequiresSession List<StageEntity> findByRequestIdAndCommandStatuses(Long requestId, Collection<HostRoleStatus> statuses); @RequiresSession List<StageEntity> findFirstStageByStatus(Collection<HostRoleStatus> statuses); @RequiresSession Map<Long, String> findRequestContext(List<Long> requestIds); @RequiresSession String findRequestContext(long requestId); @Transactional void create(StageEntity stageEntity); @Transactional StageEntity merge(StageEntity stageEntity); @Transactional void remove(StageEntity stageEntity); @Transactional void removeByPK(StageEntityPK stageEntityPK); @RequiresSession List<StageEntity> findAll(Request request, Predicate predicate); @Transactional void updateStageStatus(StageEntity stage, HostRoleStatus desiredStatus,
      ActionManager actionManager); @Transactional void updateStatus(StageEntityPK stageEntityPK, HostRoleStatus status, HostRoleStatus displayStatus);  }### Answer:
@Test public void testStagePredicate() throws Exception { Predicate predicate = new PredicateBuilder().property( StageResourceProvider.STAGE_CLUSTER_NAME).equals("c1").toPredicate(); List<StageEntity> entities = stageDao.findAll(PropertyHelper.getReadRequest(), predicate); assertEquals(5, entities.size()); predicate = new PredicateBuilder(). property(StageResourceProvider.STAGE_CONTEXT).equals("request context for 3").or(). property(StageResourceProvider.STAGE_CONTEXT).equals("request context for 4"). toPredicate(); entities = stageDao.findAll(PropertyHelper.getReadRequest(), predicate); assertEquals(2, entities.size()); }
@Test public void testStageSorting() throws Exception { List<SortRequestProperty> sortProperties = new ArrayList<>(); SortRequest sortRequest = new SortRequestImpl(sortProperties); Predicate predicate = new PredicateBuilder().property( StageResourceProvider.STAGE_CLUSTER_NAME).equals("c1").toPredicate(); sortProperties.add(new SortRequestProperty( StageResourceProvider.STAGE_LOG_INFO, SortRequest.Order.ASC)); Request request = PropertyHelper.getReadRequest(new HashSet<>(Arrays.asList()), null, null, null, sortRequest); List<StageEntity> entities = stageDao.findAll(request, predicate); assertEquals(5, entities.size()); String lastInfo = null; for (StageEntity entity : entities) { if (lastInfo == null) { lastInfo = entity.getLogInfo(); continue; } String currentInfo = entity.getLogInfo(); assertTrue(lastInfo.compareTo(currentInfo) <= 0); lastInfo = currentInfo; } sortProperties.clear(); sortProperties.add(new SortRequestProperty( StageResourceProvider.STAGE_LOG_INFO, SortRequest.Order.DESC)); entities = stageDao.findAll(request, predicate); assertEquals(5, entities.size()); lastInfo = null; for (StageEntity entity : entities) { if (null == lastInfo) { lastInfo = entity.getLogInfo(); continue; } String currentInfo = entity.getLogInfo(); assertTrue(lastInfo.compareTo(currentInfo) >= 0); lastInfo = currentInfo; } }