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
}\r
\r
\r
-\r
@Test\r
public void getCorrelationRulesByCondition_db_exception() throws Exception {\r
\r
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