Beispiel #1
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);
  }
Beispiel #2
0
  @Test
  public void queryWithComplexSpecificationFromCube() throws IOException, NoSuchMethodException {
    ServiceLocator locator = container;

    CompositeCube cube = new CompositeCube(locator);
    CompositeCube.ForSimple filter = new CompositeCube.ForSimple();
    List<Map<String, Object>> results =
        cube.analyze(Collections.singletonList(CompositeCube.number), null, filter::test);

    Assert.assertNotNull(results);
  }
Beispiel #3
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);
  }