package com.linkedin.thirdeye.datalayer.bao; import java.util.List; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.linkedin.thirdeye.constant.MetricAggFunction; import com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO; public class TestAnomalyFunctionManager extends AbstractManagerTestBase { private Long anomalyFunctionId; private static String collection = "my dataset"; private static String metricName = "__counts"; @BeforeClass void beforeClass() { super.init(); } @AfterClass(alwaysRun = true) void afterClass() { super.cleanup(); } @Test public void testCreate() { anomalyFunctionId = anomalyFunctionDAO.save(getTestFunctionSpec(metricName, collection)); Assert.assertNotNull(anomalyFunctionId); // test fetch all List<AnomalyFunctionDTO> functions = anomalyFunctionDAO.findAll(); Assert.assertEquals(functions.size(), 1); functions = anomalyFunctionDAO.findAllActiveFunctions(); Assert.assertEquals(functions.size(), 1); } @Test(dependsOnMethods = {"testCreate"}) public void testFindAllByCollection() { List<AnomalyFunctionDTO> functions = anomalyFunctionDAO.findAllByCollection(collection); Assert.assertEquals(functions.size(), 1); } @Test(dependsOnMethods = {"testFindAllByCollection"}) public void testDistinctMetricsByCollection() { List<String> metrics = anomalyFunctionDAO.findDistinctTopicMetricsByCollection(collection); Assert.assertEquals(metrics.get(0), metricName); } @Test(dependsOnMethods = { "testDistinctMetricsByCollection" }) public void testUpdate() { AnomalyFunctionDTO spec = anomalyFunctionDAO.findById(anomalyFunctionId); Assert.assertNotNull(spec); Assert.assertEquals(spec.getMetricFunction(), MetricAggFunction.SUM); spec.setMetricFunction(MetricAggFunction.COUNT); anomalyFunctionDAO.save(spec); AnomalyFunctionDTO specReturned = anomalyFunctionDAO.findById(anomalyFunctionId); Assert.assertEquals(specReturned.getMetricFunction(), MetricAggFunction.COUNT); } @Test(dependsOnMethods = { "testUpdate" }) public void testDelete() { anomalyFunctionDAO.deleteById(anomalyFunctionId); AnomalyFunctionDTO spec = anomalyFunctionDAO.findById(anomalyFunctionId); Assert.assertNull(spec); } }