@Test public void extraValueTagsOk() { PrototypeMeasurementFilter.ValueFilterPattern pattern = new PrototypeMeasurementFilter.ValueFilterPattern(valueSpecAxBy); List<Tag> tagsAxBy = Arrays.asList(new BasicTag("tagX", "X"), new BasicTag("tagA", "X"), new BasicTag("tagC", "C"), new BasicTag("tagB", "Y")); List<Tag> tagsByAx = Arrays.asList(tagsAxBy.get(3), tagsAxBy.get(2), tagsAxBy.get(1), tagsAxBy.get(0)); Assertions.assertTrue(pattern.test(tagsAxBy)); Assertions.assertTrue(pattern.test(tagsByAx)); }
@Test public void valueTagsOk() { PrototypeMeasurementFilter.ValueFilterPattern pattern = new PrototypeMeasurementFilter.ValueFilterPattern(valueSpecAxBy); List<Tag> tagsAxBy = Arrays.asList(new BasicTag("tagA", "X"), new BasicTag("tagB", "Y")); List<Tag> tagsByAx = Arrays.asList(tagsAxBy.get(1), tagsAxBy.get(0)); Assertions.assertTrue(pattern.test(tagsAxBy)); Assertions.assertTrue(pattern.test(tagsByAx)); }
/** * Implements the MeasurementFilter interface. */ @SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation") public boolean test(Measurement measurement) { boolean ok = include.isEmpty(); for (ValueFilterPattern pattern : include) { if (pattern.test(measurement.id().tags())) { ok = true; break; } } if (ok) { for (ValueFilterPattern pattern : exclude) { if (pattern.test(measurement.id().tags())) { return false; } } } return ok; } }
/** * Implements the MeasurementFilter interface. */ @SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation") public boolean test(Measurement measurement) { boolean ok = include.isEmpty(); for (ValueFilterPattern pattern : include) { if (pattern.test(measurement.id().tags())) { ok = true; break; } } if (ok) { for (ValueFilterPattern pattern : exclude) { if (pattern.test(measurement.id().tags())) { return false; } } } return ok; } }
@Test public void valueTagsMissing() { PrototypeMeasurementFilter.ValueFilterPattern pattern = new PrototypeMeasurementFilter.ValueFilterPattern(valueSpecAxBy); List<Tag> tagsAx = Collections.singletonList(new BasicTag("tagA", "X")); List<Tag> tagsAxZy = Arrays.asList(new BasicTag("tagA", "X"), new BasicTag("tagZ","Y")); List<Tag> tagsAyBy = Arrays.asList(new BasicTag("tagA", "Y"), new BasicTag("tagB", "Y")); Assertions.assertFalse(pattern.test(tagsAx)); Assertions.assertFalse(pattern.test(tagsAxZy)); Assertions.assertFalse(pattern.test(tagsAyBy)); }