示例#1
0
 @Test
 public void queryWithFilterAndCount() throws IOException {
   ServiceLocator locator = container;
   NextRepository repository = locator.resolve(NextRepository.class);
   String uri = repository.insert(new Next());
   int id = Integer.parseInt(uri);
   long found = repository.query().filter(next -> next.getID() == id).count();
   Assert.assertEquals(1, found);
   found = repository.query().filter(next -> false).count();
   Assert.assertEquals(0, found);
   found = repository.query().filter(next -> true).count();
   Assert.assertNotEquals(0, found);
 }
示例#2
0
 @Test
 public void queryWithFilterAndFindAny() throws IOException {
   ServiceLocator locator = container;
   NextRepository repository = locator.resolve(NextRepository.class);
   String uri = repository.insert(new Next());
   int id = Integer.parseInt(uri);
   repository.insert(new Next());
   boolean found = repository.query().anyMatch(next -> next.getID() == id);
   Assert.assertTrue(found);
   found = repository.query().allMatch(next -> next.getID() == id);
   Assert.assertFalse(found);
   found = repository.query().noneMatch(next -> next.getID() == id);
   Assert.assertFalse(found);
   found = repository.query().noneMatch(next -> next.getID() == id + 2);
   Assert.assertTrue(found);
 }
示例#3
0
 @Test
 public void queryWithRegisteredSpecification() throws IOException {
   ServiceLocator locator = container;
   NextRepository repository = locator.resolve(NextRepository.class);
   String uri = repository.insert(new Next());
   int id = Integer.parseInt(uri);
   long size = repository.query(new Next.BetweenIds(id, id)).count();
   Assert.assertEquals(1, size);
 }
示例#4
0
 @Test
 public void queryWithFilter() throws IOException {
   ServiceLocator locator = container;
   NextRepository repository = locator.resolve(NextRepository.class);
   String uri = repository.insert(new Next());
   int id = Integer.parseInt(uri);
   Optional<Next> found = repository.query().filter(next -> next.getID() == id).findAny();
   Assert.assertTrue(found.isPresent());
   Assert.assertEquals(id, found.get().getID());
 }
示例#5
0
 @Test
 public void simpleQuery() throws IOException {
   ServiceLocator locator = container;
   NextRepository repository = locator.resolve(NextRepository.class);
   repository.insert(new Next());
   List<Next> search = repository.search();
   Query<Next> stream = repository.query();
   List<Next> list = stream.list();
   Assert.assertEquals(search.size(), list.size());
 }
示例#6
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());
 }
示例#7
0
 @Test
 public void queryWithNotFilter() throws IOException {
   ServiceLocator locator = container;
   NextRepository repository = locator.resolve(NextRepository.class);
   String uri = repository.insert(new Next());
   int id = Integer.parseInt(uri);
   Specification<Next> filter = next -> next.getID() == id + 1;
   Optional<Next> found = repository.query().filter(filter).findAny();
   Assert.assertFalse(found.isPresent());
   // found = repository.query().filter(filter.negate()).findAny();
   // Assert.assertTrue(found.isPresent());
 }
示例#8
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());
 }
示例#9
0
 @Test
 public void modOperator() throws IOException {
   ServiceLocator locator = container;
   NextRepository repository = locator.resolve(NextRepository.class);
   long total = repository.query().count();
   long totalEven = repository.query(it -> it.getID() % 2 == 0).count();
   long totalOdd = repository.query(it -> it.getID() % 2 != 0).count();
   Assert.assertEquals(total, totalEven, totalOdd);
   String uri = repository.insert(new Next());
   int id = Integer.parseInt(uri);
   long newTotal = repository.query().count();
   long newTotalEven = repository.query(it -> it.getID() % 2 == 0).count();
   long newTotalOdd = repository.query(it -> it.getID() % 2 != 0).count();
   Assert.assertEquals(newTotal, newTotalEven, newTotalOdd);
   Assert.assertEquals(total + 1, newTotal);
   if (id % 2 == 0) {
     Assert.assertEquals(totalEven + 1, newTotalEven);
   } else {
     Assert.assertEquals(totalOdd + 1, newTotalOdd);
   }
 }