IncludeTransform implements Transform { @Override public List<Metric> transform(QueryContext context, List<Metric> metrics) { throw new UnsupportedOperationException("Include Transform cannot be performed without an regular expression."); }  @Override List<Metric> transform(QueryContext context, List<Metric> metrics); @Override List<Metric> transform(QueryContext queryContext, List<Metric> metrics, List<String> constants); @Override String getResultScopeName(); @Override List<Metric> transform(QueryContext queryContext, List<Metric>... listOfList);  }
@Test(expected = UnsupportedOperationException.class) public void testIncludeTransformWithoutMetrics() { Transform includeTransform = new IncludeTransform(); List<Metric> metrics = new ArrayList<Metric>(); includeTransform.transform(null, metrics); }
@Test(expected = UnsupportedOperationException.class) public void testIncludeTransformWithoutConstants() { Transform includeTransform = new IncludeTransform(); List<Metric> metrics = new ArrayList<Metric>(); includeTransform.transform(null, metrics); }
@Test(expected = IllegalArgumentException.class) public void testIncludeTransformWithMoreThanOneConstant() { Transform includeTransform = new IncludeTransform(); List<Metric> metrics = new ArrayList<Metric>(); List<String> constants = new ArrayList<String>(); constants.add(TEST_INCLUDE_LITERAL); constants.add(TEST_BAD_STRING); includeTransform.transform(null, metrics, constants); }
@Test(expected = IllegalArgumentException.class) public void testIncludeTransformWithEmptyRegex() { Transform includeTransform = new IncludeTransform(); List<Metric> metrics = new ArrayList<Metric>(); List<String> constants = new ArrayList<String>(); constants.add(TEST_INCLUDE_LITERAL); constants.add(TEST_BAD_STRING); includeTransform.transform(null, metrics, constants); }
@Test public void testIncludeTransformRegex() { Transform includeTransform = new IncludeTransform(); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC + "1"); metric_1.setNamespace(TEST_NAMESPACE); metric_1.setTags(TEST_TAGS); Metric metric_2 = new Metric(TEST_SCOPE, TEST_METRIC + "2"); metric_2.setNamespace(TEST_NAMESPACE); metric_2.setTags(TEST_TAGS); Metric metric_3 = new Metric(TEST_SCOPE, TEST_METRIC + "3"); metric_3.setNamespace(TEST_NAMESPACE); metric_3.setTags(TEST_TAGS); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric_1); metrics.add(metric_2); metrics.add(metric_3); List<String> constants = new ArrayList<String>(); constants.add(TEST_INCLUDE_REGEX); List<Metric> result = includeTransform.transform(null, metrics, constants); assertEquals(result.size(), 2); assertEquals("test-metric1", result.get(0).getMetric()); assertEquals("test-metric2", result.get(1).getMetric()); }
@Test public void testIncludeTransformLiteral() { Transform includeTransform = new IncludeTransform(); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC); metric_1.setNamespace(TEST_NAMESPACE); metric_1.setTags(TEST_TAGS); Metric metric_2 = new Metric(TEST_SCOPE, TEST_METRIC); metric_2.setNamespace(TEST_NAMESPACE); metric_2.setTags(TEST_TAGS); Metric metric_3 = new Metric(TEST_SCOPE, TEST_METRIC); metric_3.setNamespace(TEST_NAMESPACE); metric_3.setTags(TEST_TAGS); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric_1); metrics.add(metric_2); metrics.add(metric_3); List<String> constants = new ArrayList<String>(); constants.add(TEST_METRIC); List<Metric> result = includeTransform.transform(null, metrics, constants); assertEquals(result.size(), 0); }