示例#1
0
  @Test
  public void queryWithOrderingAndSearchFilter() throws IOException, NoSuchMethodException {
    ServiceLocator locator = container;
    ArticleRepository repository = locator.resolve(ArticleRepository.class);

    Random random = new Random();
    int projectID = random.nextInt();
    Article article1 =
        new Article()
            .setProjectID(projectID)
            .setSku(UUID.randomUUID().toString().substring(0, 10))
            .setTitle("Article A");
    Article article2 =
        new Article()
            .setProjectID(projectID)
            .setSku(UUID.randomUUID().toString().substring(0, 10))
            .setTitle("Article Z");
    repository.insert(Arrays.asList(article1, article2));

    ArticleGridRepository gridRepository = locator.resolve(ArticleGridRepository.class);
    Specification<ArticleGrid> spec =
        new ArticleGrid.filterSearch().setProjectID(projectID).setFilter("article");

    JinqMetaModel jmm = locator.resolve(JinqMetaModel.class);
    Method method = ArticleGrid.class.getMethod("getTitle");
    Query.Compare<ArticleGrid, ?> order = jmm.findGetter(method);

    List<ArticleGrid> list = gridRepository.query(spec).sortedDescendingBy(order).list();

    Assert.assertEquals(2, list.size());
    Assert.assertEquals(article2.getID(), list.get(0).getID());
    Assert.assertEquals(article1.getID(), list.get(1).getID());
  }
示例#2
0
 @Test
 public void queryWithLimit() throws IOException {
   ServiceLocator locator = container;
   NextRepository repository = locator.resolve(NextRepository.class);
   String[] uris = repository.insert(Arrays.asList(new Next(), new Next()));
   Assert.assertEquals(2, uris.length);
   int id1 = Integer.parseInt(uris[0]);
   int id2 = Integer.parseInt(uris[1]);
   List<Next> found =
       repository.query(next -> next.getID() == id1 || next.getID() == id2).limit(1).list();
   Assert.assertEquals(1, found.size());
 }
示例#3
0
 @Test
 public void collectionContainsQuery() throws IOException {
   ServiceLocator locator = container;
   NextRepository repository = locator.resolve(NextRepository.class);
   String uri = repository.insert(new Next());
   int id = Integer.parseInt(uri);
   List<Integer> numbers = Arrays.asList(-1, 0, id);
   List<Next> found =
       repository.query().filter(it -> numbers.contains(it.getID())).limit(2).list();
   Assert.assertEquals(1, found.size());
   Assert.assertEquals(id, found.get(0).getID());
 }