Beispiel #1
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));
  }
Beispiel #2
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());
  }
Beispiel #3
0
 @Test
 public void searchWithFilter() throws IOException {
   ServiceLocator locator = container;
   NextRepository repository = locator.resolve(NextRepository.class);
   String uri = repository.insert(new Next());
   int id = Integer.parseInt(uri);
   List<Next> found = repository.search(next -> next.getID() == id);
   Assert.assertEquals(1, found.size());
   Assert.assertEquals(id, found.get(0).getID());
 }
Beispiel #4
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);
  }
Beispiel #5
0
 @Test
 public void toStringAndValueOf() throws IOException {
   ServiceLocator locator = container;
   NextRepository repository = locator.resolve(NextRepository.class);
   String uri = repository.insert(new Next());
   int id = Integer.parseInt(uri);
   List<Next> found =
       repository.search(
           it -> String.valueOf(it.getID()).equals(uri) && id == Integer.valueOf(it.getURI()));
   Assert.assertEquals(1, found.size());
   Assert.assertEquals(id, found.get(0).getID());
 }
Beispiel #6
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());
 }
Beispiel #7
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());
 }
Beispiel #8
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());
  }