Ejemplo n.º 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());
  }
Ejemplo n.º 2
0
 @Test
 public void sendDomainObjectAsArgument() throws IOException {
   ServiceLocator locator = container;
   CompositeRepository repository = locator.resolve(CompositeRepository.class);
   UUID id = UUID.randomUUID();
   Random rnd = new Random();
   int next = rnd.nextInt(100000);
   repository.insert(
       new Composite().setId(id).setSimple(new Simple().setEn(En.A).setNumber(next)));
   Simple simple = new Simple().setEn(En.A).setNumber(next);
   Composite found =
       repository
           .query()
           .filter(it -> it.getSimple().getNumber() == simple.getNumber())
           .sortedBy(it -> it.getId())
           .findFirst()
           .get();
   Assert.assertEquals(id, found.getId());
 }
Ejemplo n.º 3
0
  @Test
  public void queryWithNullSearchFilter() throws IOException {
    ServiceLocator locator = container;
    ArticleRepository repository = locator.resolve(ArticleRepository.class);

    Random random = new Random();
    Article article =
        new Article()
            .setProjectID(random.nextInt())
            .setSku(UUID.randomUUID().toString().substring(0, 10))
            .setTitle(UUID.randomUUID().toString().substring(0, 25));
    repository.insert(article);

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

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

    Assert.assertEquals(1, list.size());
    Assert.assertEquals(article.getID(), list.get(0).getID());
  }