AggregationVerificationStrategy extends AbstractMinMaxVerificationStrategy implements VerificationStrategy<AggregationVerification> { @Override public <T extends ExecutableRule> Result.Status verify(T executable, AggregationVerification verification, List<String> columnNames, List<Map<String, Object>> rows) throws RuleException { LOGGER.debug("Verifying result of " + executable); if (rows.isEmpty()) { return getStatus(executable, 0, verification.getMin(), verification.getMax()); } if (columnNames.isEmpty()) { throw new RuleException("Result contains no columns, at least one with a numeric value is expected."); } String column = verification.getColumn(); if (column == null) { column = columnNames.get(0); LOGGER.debug("No aggregation column specified, using " + column); } for (Map<String, Object> row : rows) { Object value = row.get(column); if (value == null) { throw new RuleException("The result does not contain a column '" + column); } else if (!Number.class.isAssignableFrom(value.getClass())) { throw new RuleException("The value in column '" + column + "' must be a numeric value but was '" + value + "'"); } int aggregationValue = ((Number) value).intValue(); Result.Status status = getStatus(executable, aggregationValue, verification.getMin(), verification.getMax()); if (Result.Status.FAILURE.equals(status)) { return Result.Status.FAILURE; } } return Result.Status.SUCCESS; }  @Override Class<AggregationVerification> getVerificationType(); @Override Result.Status verify(T executable, AggregationVerification verification, List<String> columnNames,
            List<Map<String, Object>> rows);  }
@Test public void defaultConcept() throws RuleException { AggregationVerification aggregationVerification = AggregationVerification.builder().build(); result = asList(createRow(0), createRow(0)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(SUCCESS)); result = asList(createRow(0), createRow(1)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); result = asList(createRow(1), createRow(1)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(SUCCESS)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); }
@Test public void min() throws RuleException { AggregationVerification aggregationVerification = AggregationVerification.builder().min(1).build(); result = asList(createRow(0), createRow(0)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); result = asList(createRow(0), createRow(1)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); result = asList(createRow(1), createRow(1)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(SUCCESS)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(SUCCESS)); }
@Test public void max() throws RuleException { AggregationVerification aggregationVerification = AggregationVerification.builder().max(0).build(); result = asList(createRow(0), createRow(0)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(SUCCESS)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(SUCCESS)); result = asList(createRow(0), createRow(1)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); result = asList(createRow(1), createRow(1)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); }
@Test public void minMax() throws RuleException { AggregationVerification aggregationVerification = AggregationVerification.builder().min(1).max(1).build(); result = asList(createRow(0), createRow(0)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); result = asList(createRow(0), createRow(1)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); result = asList(createRow(1), createRow(1)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(SUCCESS)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(SUCCESS)); result = asList(createRow(1), createRow(2)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); result = asList(createRow(2), createRow(2)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); }
@Test public void colum() throws RuleException { AggregationVerification aggregationVerification = AggregationVerification.builder().column("c1").build(); result = asList(createRow(0, 1), createRow(0, 1)); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(SUCCESS)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); }
@Test public void emptyResult() throws RuleException { AggregationVerification aggregationVerification = AggregationVerification.builder().build(); result = Collections.emptyList(); assertThat(strategy.verify(concept, aggregationVerification, COLUMN_NAMES, result), equalTo(FAILURE)); assertThat(strategy.verify(constraint, aggregationVerification, COLUMN_NAMES, result), equalTo(SUCCESS)); }