package com.linkedin.thirdeye.datalayer.bao;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.linkedin.thirdeye.constant.AnomalyFeedbackType;
import com.linkedin.thirdeye.constant.FeedbackStatus;
import com.linkedin.thirdeye.datalayer.dto.AnomalyFeedbackDTO;
import com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO;
import com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO;
public class TestAnomalyResultManager extends AbstractManagerTestBase {
RawAnomalyResultDTO anomalyResult;
AnomalyFunctionDTO spec = getTestFunctionSpec("metric", "dataset");
@BeforeClass
void beforeClass() {
super.init();
}
@AfterClass(alwaysRun = true)
void afterClass() {
super.cleanup();
}
@Test
public void testAnomalyResultCRUD() {
anomalyFunctionDAO.save(spec);
Assert.assertNotNull(spec);
// create anomaly result
anomalyResult = getAnomalyResult();
anomalyResult.setFunction(spec);
rawAnomalyResultDAO.save(anomalyResult);
RawAnomalyResultDTO resultRet = rawAnomalyResultDAO.findById(anomalyResult.getId());
Assert.assertEquals(resultRet.getFunction(), spec);
}
@Test(dependsOnMethods = {"testAnomalyResultCRUD"})
public void testResultFeedback() {
RawAnomalyResultDTO result = rawAnomalyResultDAO.findById(anomalyResult.getId());
Assert.assertNotNull(result);
Assert.assertNull(result.getFeedback());
AnomalyFeedbackDTO feedback = new AnomalyFeedbackDTO();
feedback.setComment("this is a good find");
feedback.setFeedbackType(AnomalyFeedbackType.ANOMALY);
feedback.setStatus(FeedbackStatus.NEW);
result.setFeedback(feedback);
rawAnomalyResultDAO.save(result);
RawAnomalyResultDTO resultRet = rawAnomalyResultDAO.findById(anomalyResult.getId());
Assert.assertEquals(resultRet.getId(), result.getId());
Assert.assertNotNull(resultRet.getFeedback());
AnomalyFunctionDTO functionSpec = result.getFunction();
rawAnomalyResultDAO.deleteById(anomalyResult.getId());
anomalyFunctionDAO.deleteById(functionSpec.getId());
}
}