Example #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());
  }
Example #2
0
  @Test
  public void testTimestampQueryingAndOrder() throws IOException {
    ServiceLocator locator = container;
    SearchByTimestampAndOrderByTimestampRepository analysisGridRepository =
        locator.resolve(SearchByTimestampAndOrderByTimestampRepository.class);

    String marker = UUID.randomUUID().toString();
    OffsetDateTime dt1 = OffsetDateTime.now();
    OffsetDateTime dt2 = dt1.plusDays(1);
    OffsetDateTime dt3 = dt1.plusDays(2);
    OffsetDateTime dt4 = dt1.plusDays(3);

    SearchByTimestampAndOrderByTimestamp[] arr =
        new SearchByTimestampAndOrderByTimestamp[] {
          new SearchByTimestampAndOrderByTimestamp().setOndate(dt1).setMarker(marker),
          new SearchByTimestampAndOrderByTimestamp().setOndate(dt2).setMarker(marker),
          new SearchByTimestampAndOrderByTimestamp().setOndate(dt3).setMarker(marker),
          new SearchByTimestampAndOrderByTimestamp().setOndate(dt4).setMarker(marker)
        };
    analysisGridRepository.insert(arr);

    List<SearchByTimestampAndOrderByTimestamp> queryResults =
        analysisGridRepository
            .query(it -> it.getMarker().equals(marker) && it.getOndate().isAfter(dt2))
            .sortedDescendingBy(SearchByTimestampAndOrderByTimestamp::getOndate)
            .list();
    Assert.assertEquals(queryResults.size(), arr.length - 2);
    Assert.assertTrue(queryResults.get(0).getOndate().isEqual(dt4));
  }
Example #3
0
  @Test
  public void stringOrderingViaLambda() throws IOException {
    ServiceLocator locator = container;
    InfoRepository infoRepository = locator.resolve(InfoRepository.class);

    String id = UUID.randomUUID().toString();

    List<Info> infos = new ArrayList<Info>();
    for (char letter = 'A'; letter < 'Z'; letter++) {
      infos.add(
          new Info()
              .setCode(String.format("code %s %c", id, letter))
              .setName(String.format("name %s %c", id, letter)));
    }

    infoRepository.insert(infos);

    Specification<Info> filter = it -> it.getCode().startsWith("code " + id);

    List<Info> found =
        infoRepository
            .search(filter)
            .stream()
            .sorted((a, b) -> a.getName().compareTo(b.getName()))
            .collect(Collectors.toList());

    List<Info> infosAscByName =
        infoRepository.query().filter(filter).sortedBy(Info::getName).list();
    Assert.assertEquals(found, infosAscByName);

    List<Info> infosDescByName =
        infoRepository.query().filter(filter).sortedDescendingBy(Info::getName).list();
    Collections.reverse(infosDescByName);
    Assert.assertEquals(found, infosDescByName);
  }
Example #4
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());
  }
Example #5
0
 @Test
 public void uuidFunctions() throws IOException {
   ServiceLocator locator = container;
   CompositeRepository repository = locator.resolve(CompositeRepository.class);
   UUID id = UUID.randomUUID();
   String uri = repository.insert(new Composite().setId(id));
   Composite found =
       repository.query().filter(it -> it.getId().toString().equals(uri)).findAny().get();
   Assert.assertEquals(id, found.getId());
   found =
       repository.query().filter(it -> UUID.fromString(it.getURI()).equals(id)).findAny().get();
   Assert.assertEquals(id, found.getId());
 }
Example #6
0
 @Test
 public void substringMethods() throws IOException {
   ServiceLocator locator = container;
   CompositeRepository repository = locator.resolve(CompositeRepository.class);
   UUID id = UUID.randomUUID();
   repository.insert(
       new Composite().setId(id).setSimple(new Simple().setText("xxx" + id + "yyy")));
   List<Composite> found =
       repository
           .query()
           .filter(it -> it.getId().equals(id))
           .filter(it -> it.getSimple().getText().substring(3).equals(id.toString() + "yyy"))
           .filter(it -> it.getSimple().getText().substring(0, 3).equals("xxx"))
           .list();
   Assert.assertEquals(1, found.size());
   Assert.assertEquals(id, found.get(0).getId());
 }
Example #7
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());
 }
Example #8
0
  @Test
  public void testSQLMapping() throws IOException {
    ServiceLocator locator = container;
    CoverageUpdateRepository covUpdateRepo = locator.resolve(CoverageUpdateRepository.class);
    CoverageVersions1Repository covVersionsRepo =
        locator.resolve(CoverageVersions1Repository.class);

    String suppID = UUID.randomUUID().toString();
    covUpdateRepo.submit(new CoverageUpdate().setSupplierID(suppID));
    try {
      Thread.sleep(100);
    } catch (InterruptedException ignore) {
    }
    covUpdateRepo.submit(new CoverageUpdate().setSupplierID(suppID));

    List<CoverageVersions1> items =
        covVersionsRepo.query(it -> it.getSupplierID().equals(suppID)).list();
    Assert.assertEquals(items.size(), 2);
    Assert.assertNotEquals(
        items.get(0).getProcessedAt().isEqual(items.get(1).getProcessedAt()), true);
  }
Example #9
0
  @Test
  public void stringOrderingViaPropertyName() throws IOException, NoSuchMethodException {
    ServiceLocator locator = container;
    InfoRepository infoRepository = locator.resolve(InfoRepository.class);

    String id = UUID.randomUUID().toString();

    List<Info> infos = new ArrayList<Info>();
    for (char letter = 'A'; letter < 'Z'; letter++) {
      infos.add(
          new Info()
              .setCode(String.format("code %s %c", id, letter))
              .setName(String.format("name %s %c", id, letter)));
    }

    JinqMetaModel jinqMetaModel = locator.resolve(JinqMetaModel.class);
    Method method = Info.class.getMethod("getName");
    Query.Compare<Info, ?> nameOrder = jinqMetaModel.findGetter(method);

    Specification<Info> filter = it -> it.getCode().startsWith("code " + id);

    infoRepository.insert(infos);
    List<Info> found =
        infoRepository
            .search(filter)
            .stream()
            .sorted((a, b) -> a.getName().compareTo(b.getName()))
            .collect(Collectors.toList());

    List<Info> infosAscByName = infoRepository.query(filter).sortedBy(nameOrder).list();
    Assert.assertEquals(found, infosAscByName);

    List<Info> infosDescByName = infoRepository.query(filter).sortedDescendingBy(nameOrder).list();
    Collections.reverse(infosDescByName);
    Assert.assertEquals(found, infosDescByName);
  }