QuotaQueryConverter { QueryBuilder from(QuotaQuery query) { List<QuotaClause> clauses = query.getClause().getClauses(); if (clauses.isEmpty()) { return matchAllQuery(); } if (clauses.size() == 1) { return singleClauseAsESQuery(clauses.get(0)); } return clausesAsAndESQuery(clauses); } QuotaQueryConverter();   }
@Test void fromShouldReturnMatchAllWhenEmptyClauses() { QuotaQuery query = QuotaQuery.builder().build(); QueryBuilder expected = matchAllQuery(); QueryBuilder actual = testee.from(query); assertThat(actual).isEqualToComparingFieldByField(expected); }
@Test void fromShouldReturnDomainMatchWhenOnlyDomain() { QuotaQuery query = QuotaQuery.builder().hasDomain(Domain.of("my.tld")).build(); QueryBuilder expected = termQuery(JsonMessageConstants.DOMAIN, "my.tld"); QueryBuilder actual = testee.from(query); assertThat(actual).isEqualToComparingFieldByField(expected); }
@Test void fromShouldReturnQuotaRatioMatchWhenLessThan() { QuotaQuery query = QuotaQuery.builder().lessThan(new QuotaBoundary(0.1)).build(); QueryBuilder expected = rangeQuery(QUOTA_RATIO).lte(0.1); QueryBuilder actual = testee.from(query); assertThat(actual).isEqualToComparingFieldByField(expected); }
@Test void fromShouldReturnQuotaRatioMatchWhenMoreThan() { QuotaQuery query = QuotaQuery.builder().moreThan(new QuotaBoundary(0.1)).build(); QueryBuilder expected = rangeQuery(QUOTA_RATIO).gte(0.1); QueryBuilder actual = testee.from(query); assertThat(actual).isEqualToComparingFieldByField(expected); }