Add rule management module unit tests
[holmes/rule-management.git] / rulemgt / src / test / java / org / openo / holmes / rulemgt / db / CorrelationRuleQueryDaoTest.java
index 0b1d151..8df2074 100644 (file)
@@ -30,26 +30,29 @@ import org.junit.Before;
 import org.junit.Rule;\r
 import org.junit.Test;\r
 import org.junit.rules.ExpectedException;\r
+import org.junit.runner.RunWith;\r
 import org.openo.holmes.common.api.entity.CorrelationRule;\r
 import org.openo.holmes.common.exception.CorrelationException;\r
 import org.openo.holmes.common.utils.DbDaoUtil;\r
 import org.openo.holmes.common.utils.I18nProxy;\r
 import org.openo.holmes.rulemgt.bean.request.RuleQueryCondition;\r
 import org.powermock.api.easymock.PowerMock;\r
+import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
 import org.powermock.modules.junit4.rule.PowerMockRule;\r
 import org.powermock.reflect.Whitebox;\r
 import org.skife.jdbi.v2.Handle;\r
 import org.skife.jdbi.v2.Query;\r
 \r
 \r
+\r
 public class CorrelationRuleQueryDaoTest {\r
 \r
     @Rule\r
     public ExpectedException thrown = ExpectedException.none();\r
 \r
-    @Rule\r
+           @Rule\r
     public PowerMockRule powerMockRule = new PowerMockRule();\r
-\r
     private DbDaoUtil dbDaoUtil;\r
 \r
     private Handle handle;\r
@@ -73,7 +76,6 @@ public class CorrelationRuleQueryDaoTest {
     }\r
 \r
 \r
-\r
     @Test\r
     public void getCorrelationRulesByCondition_db_exception() throws Exception {\r
 \r
@@ -109,6 +111,24 @@ public class CorrelationRuleQueryDaoTest {
         PowerMock.verifyAll();\r
     }\r
 \r
+    @Test\r
+    public void getCorrelationRulesByCondition_get_where_sql_exception() throws Exception {\r
+        thrown.expect(CorrelationException.class);\r
+        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED);\r
+\r
+        EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);\r
+        EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);\r
+        EasyMock.expect(query.list()).andReturn(createQueryResult()).anyTimes();\r
+        dbDaoUtil.close(handle);\r
+        EasyMock.expectLastCall();\r
+\r
+        PowerMock.replayAll();\r
+\r
+        correlationRuleQueryDao.getCorrelationRulesByCondition(null);\r
+\r
+        PowerMock.verifyAll();\r
+    }\r
+\r
     private List<Map<String, Object>> createQueryResult() {\r
         List<Map<String, Object>> list = new ArrayList<>();\r
         Map<String, Object> value = new HashMap<>();\r