@Test
public void testStageSorting() throws Exception {

  List<SortRequestProperty> sortProperties = new ArrayList<SortRequestProperty>();
  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<String>(Arrays.<String>asList()),
      null, null, null, sortRequest);
  // get back all 5
  List<StageEntity> entities = stageDao.findAll(request, predicate);
  assertEquals(5, entities.size());
  // assert sorting ASC
  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;
  }
  // clear and do DESC
  sortProperties.clear();
  sortProperties.add(new SortRequestProperty(
      StageResourceProvider.STAGE_LOG_INFO, SortRequest.Order.DESC));
  // get back all 5
  entities = stageDao.findAll(request, predicate);
  assertEquals(5, entities.size());
  // assert sorting DESC
  lastInfo = null;
  for (StageEntity entity : entities) {
    if (null == lastInfo) {
      lastInfo = entity.getLogInfo();
      continue;
    }
    String currentInfo = entity.getLogInfo();
    assertTrue(lastInfo.compareTo(currentInfo) >= 0);
    lastInfo = currentInfo;
  }
}