summaryrefslogtreecommitdiffstats
path: root/rulemgt/src/test/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'rulemgt/src/test/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java')
-rw-r--r--rulemgt/src/test/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java26
1 files changed, 23 insertions, 3 deletions
diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java
index 0b1d151..8df2074 100644
--- a/rulemgt/src/test/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java
+++ b/rulemgt/src/test/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java
@@ -30,26 +30,29 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
import org.openo.holmes.common.api.entity.CorrelationRule;
import org.openo.holmes.common.exception.CorrelationException;
import org.openo.holmes.common.utils.DbDaoUtil;
import org.openo.holmes.common.utils.I18nProxy;
import org.openo.holmes.rulemgt.bean.request.RuleQueryCondition;
import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
+import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.rule.PowerMockRule;
import org.powermock.reflect.Whitebox;
import org.skife.jdbi.v2.Handle;
import org.skife.jdbi.v2.Query;
+
public class CorrelationRuleQueryDaoTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- @Rule
+ @Rule
public PowerMockRule powerMockRule = new PowerMockRule();
-
private DbDaoUtil dbDaoUtil;
private Handle handle;
@@ -73,7 +76,6 @@ public class CorrelationRuleQueryDaoTest {
}
-
@Test
public void getCorrelationRulesByCondition_db_exception() throws Exception {
@@ -109,6 +111,24 @@ public class CorrelationRuleQueryDaoTest {
PowerMock.verifyAll();
}
+ @Test
+ public void getCorrelationRulesByCondition_get_where_sql_exception() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED);
+
+ EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);
+ EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);
+ EasyMock.expect(query.list()).andReturn(createQueryResult()).anyTimes();
+ dbDaoUtil.close(handle);
+ EasyMock.expectLastCall();
+
+ PowerMock.replayAll();
+
+ correlationRuleQueryDao.getCorrelationRulesByCondition(null);
+
+ PowerMock.verifyAll();
+ }
+
private List<Map<String, Object>> createQueryResult() {
List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> value = new HashMap<>();