示例#1
0
 // @Test
 public void numberFunctions() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   LocalDate ld = LocalDate.now();
   Clicked cl = new Clicked().setDate(ld);
   db.submit(cl);
   Query<Clicked> query = db.query(Clicked.class);
   String uri = cl.getURI();
   // TODO: produces incorrect queries
   boolean found1 =
       query.anyMatch(
           it ->
               Long.valueOf(3).equals(it.getBigint()) && it.getEn() == En.A
                   || it.getURI().toUpperCase().equals(uri));
   boolean found2 =
       query.anyMatch(
           it ->
               3L >= it.getBigint() && it.getDate() == LocalDate.now()
                   || Integer.valueOf(it.getURI()).equals(Integer.valueOf(uri)));
   boolean found3 =
       query.anyMatch(
           it ->
               Long.valueOf(3).equals(it.getBigint()) && it.getEn() == En.B
                   || it.getURI().toUpperCase().equals(uri));
   En b = En.B;
   boolean found4 = query.anyMatch(it -> it.getEn() == b || it.getURI().toUpperCase().equals(uri));
   Assert.assertTrue(found1);
   Assert.assertTrue(found2);
   Assert.assertTrue(found3);
   Assert.assertTrue(found4);
 }
示例#2
0
 @Test
 public void staticMemberAccess() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   Query<Document> query = db.query(Document.class);
   boolean found = query.anyMatch(it -> it.equals(Document.MEANING_OF_LIFE()));
   Assert.assertFalse(found);
 }
示例#3
0
 @Test
 public void floatType() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   boolean notFound =
       db.query(Composite.class).anyMatch(it -> (float) it.getSimple().getNumber() == 4.2f);
   Assert.assertFalse(notFound);
 }
示例#4
0
 @Test
 public void willUseRewrittenSpecificationInSearch() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   LocalDate ld = LocalDate.now().plusDays(15);
   Clicked cl = new Clicked().setDate(ld);
   db.submit(cl);
   List<ClickedList> found = db.search(ClickedList.class, new ClickedList.FindAt(ld));
   Assert.assertTrue(found.size() > 0);
 }
示例#5
0
 @Test
 public void willRecognizeSpecificationOnSql() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   LocalDate ld = LocalDate.now();
   Clicked cl = new Clicked().setDate(ld);
   db.submit(cl);
   long count = db.query(ClickedList.class).filter(new ClickedList.FindAt(ld)).count();
   Assert.assertTrue(count > 0);
 }
示例#6
0
 @Test
 public void canUseQueryDirectly() throws IOException, ReflectiveOperationException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   LocalDate ld = LocalDate.now().plusDays(15);
   Clicked cl = new Clicked().setDate(ld);
   db.submit(cl);
   List<ClickedList> found =
       locator.resolve(Query.class, ClickedList.class).filter(new ClickedList.FindAt(ld)).list();
   Assert.assertTrue(found.size() > 0);
 }
示例#7
0
 @Test
 public void willUseRewrittenSpecificationInBulk() throws Exception {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   RepositoryBulkReader reader = locator.resolve(RepositoryBulkReader.class);
   LocalDate ld = LocalDate.now().plusDays(44);
   Clicked cl = new Clicked().setDate(ld).setNumber(BigDecimal.valueOf(111));
   db.submit(cl);
   Callable<List<ClickedSeq>> found =
       reader.search(ClickedSeq.class, new ClickedSeq.OnDateOrNumber(ld, 111));
   reader.execute();
   Assert.assertTrue(found.call().size() > 0);
 }
示例#8
0
 // @Test
 public void nestedSubqueryWithStream() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   // TODO: does not work yet
   boolean notFound =
       db.query(Composite.class)
           .anyMatch(
               it ->
                   it.getEntities()
                       .stream()
                       .anyMatch(e -> e.getDetail1().stream().anyMatch(d -> d.getFf() == 4.2f)));
   Assert.assertFalse(notFound);
 }
示例#9
0
 @Test
 public void offsetDateTimeFunctions() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   Clicked cl = new Clicked();
   db.submit(cl);
   Query<Clicked> query = db.query(Clicked.class);
   OffsetDateTime dt = cl.getQueuedAt();
   boolean found =
       query.anyMatch(
           it -> it.getURI().equals(cl.getURI()) && it.getProcessedAt().compareTo(dt) == 0);
   boolean notFound =
       query.anyMatch(
           it -> it.getURI().equals(cl.getURI()) && it.getProcessedAt().compareTo(dt) != 0);
   Assert.assertTrue(found);
   Assert.assertFalse(notFound);
 }
示例#10
0
 @Test
 public void localDateFunctions() throws IOException {
   ServiceLocator locator = container;
   DataContext db = locator.resolve(DataContext.class);
   LocalDate ld = LocalDate.now();
   Clicked cl = new Clicked().setDate(ld);
   db.submit(cl);
   Query<Clicked> query = db.query(Clicked.class);
   String uri = cl.getURI();
   boolean found1 =
       query.anyMatch(it -> it.getURI().equals(uri) && ld.compareTo(it.getDate()) == 0);
   boolean found2 =
       query.anyMatch(
           it -> it.getURI().equals(uri) && ld.equals(it.getDate()) && ld.isEqual(it.getDate()));
   boolean notFound =
       query.anyMatch(it -> it.getURI().equals(uri) && ld.compareTo(it.getDate()) != 0);
   Assert.assertTrue(found1);
   Assert.assertTrue(found2);
   Assert.assertFalse(notFound);
 }