AliasTransform implements Transform { @Override public List<Metric> transform(QueryContext context, List<Metric> metrics) { throw new UnsupportedOperationException("Alias Transform cannot be performed without an alias expression and an alias type"); }  @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, @SuppressWarnings("unchecked") List<Metric>... listOfList);  }
@Test(expected = UnsupportedOperationException.class) public void testAliasTransformWithoutMetrics() { Transform aliasTransform = new AliasTransform(); List<Metric> metrics = new ArrayList<Metric>(); aliasTransform.transform(null, metrics); }
@Test(expected = UnsupportedOperationException.class) public void testAliasTransformWithoutConstants() { Transform aliasTransform = new AliasTransform(); List<Metric> metrics = new ArrayList<Metric>(); aliasTransform.transform(null, metrics); }
@Test(expected = IllegalArgumentException.class) public void testAliasTransformWithOnlyOneConstant() { Transform aliasTransform = new AliasTransform(); List<Metric> metrics = null; List<String> constants = new ArrayList<String>(); constants.add(TEST_ALIAS_LITERAL); aliasTransform.transform(null, metrics, constants); }
@Test(expected = IllegalArgumentException.class) public void testAliasTransformWithInvalidType() { Transform aliasTransform = new AliasTransform(); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(new Metric(TEST_SCOPE, TEST_METRIC)); List<String> constants = new ArrayList<String>(); constants.add(TEST_ALIAS_LITERAL); constants.add(TEST_BAD_STRING); aliasTransform.transform(null, metrics, constants); }
@Test(expected = IllegalArgumentException.class) public void testAliasTransformWithInvalidRegex() { Transform aliasTransform = new AliasTransform(); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(new Metric(TEST_SCOPE, TEST_METRIC)); List<String> constants = new ArrayList<String>(); constants.add(TEST_BAD_STRING); constants.add(TEST_ALIAS_REGEX); aliasTransform.transform(null, metrics, constants); }
@Test public void testAliasTransformRegex() { Transform aliasTransform = new AliasTransform(); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC_NAME_1); Metric metric_2 = new Metric(TEST_SCOPE, TEST_METRIC_NAME_2); Metric metric_3 = new Metric(TEST_SCOPE, TEST_METRIC_NAME_3); 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_ALIAS_REGEX); constants.add(TEST_TYPE_REGEX); List<Metric> result = aliasTransform.transform(null, metrics, constants); assertEquals(result.size(), 3); assertEquals(TEST_METRIC_NAME_1, result.get(0).getMetric()); assertEquals(TEST_ALIAS_LITERAL, result.get(1).getMetric()); assertEquals(TEST_ALIAS_LITERAL, result.get(2).getMetric()); }
@Test public void testAliasTransformLiteral() { Transform aliasTransform = new AliasTransform(); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC_NAME_1); Metric metric_2 = new Metric(TEST_SCOPE, TEST_METRIC_NAME_2); Metric metric_3 = new Metric(TEST_SCOPE, TEST_METRIC_NAME_3); 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_ALIAS_LITERAL); constants.add(TEST_TYPE_LITERAL); List<Metric> result = aliasTransform.transform(null, metrics, constants); assertEquals(result.size(), 3); assertEquals(TEST_ALIAS_LITERAL, result.get(0).getMetric()); assertEquals(TEST_ALIAS_LITERAL, result.get(1).getMetric()); assertEquals(TEST_ALIAS_LITERAL, result.get(2).getMetric()); }
@Test public void testAliasTransformLiteralScope() { Transform aliasTransform = new AliasTransform(); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC_NAME_1); Metric metric_2 = new Metric(TEST_SCOPE, TEST_METRIC_NAME_2); Metric metric_3 = new Metric(TEST_SCOPE, TEST_METRIC_NAME_3); 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("m"); constants.add(TEST_TYPE_LITERAL); constants.add("s"); constants.add(TEST_TYPE_LITERAL); List<Metric> result = aliasTransform.transform(null, metrics, constants); assertEquals(result.size(), 3); assertEquals("m", result.get(0).getMetric()); assertEquals("m", result.get(1).getMetric()); assertEquals("m", result.get(2).getMetric()); assertEquals("s", result.get(0).getScope()); assertEquals("s", result.get(1).getScope()); assertEquals("s", result.get(2).getScope()); }