import static org.hamcrest.Matchers.equalTo;\r
import static org.hamcrest.Matchers.is;\r
\r
-\r
import java.util.ArrayList;\r
import java.util.Date;\r
import java.util.List;\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.CallException;\r
-import org.openo.holmes.common.exception.DataFormatException;\r
-import org.openo.holmes.common.exception.DbException;\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.CorrelationCheckRule4Engine;\r
\r
@Test\r
public void addCorrelationRule_name_is_null() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_RULE_NAME_IS_EMPTY);\r
\r
ruleMgtWrapper.addCorrelationRule(USER_NAME, createRuleCreateRequest(null, "This is a rule for testing.",\r
\r
@Test\r
public void addCorrelationRule_name_is_empty() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_RULE_NAME_IS_EMPTY);\r
\r
ruleMgtWrapper.addCorrelationRule("admin", createRuleCreateRequest("", "This is a rule for testing.",\r
"Mocked contents.", 0));\r
}\r
\r
+ @Test\r
+ public void addCorrelationRule_rule_query_exception() throws Exception {\r
+\r
+ final String ruleName = "Rule-001";\r
+\r
+ RuleCreateRequest ruleCreateRequest = createRuleCreateRequest(ruleName, "This is a rule for testing.",\r
+ "Mocked contents.", 0);\r
+\r
+ thrown.expect(CorrelationException.class);\r
+ thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+\r
+ EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
+ correlationRuleDaoMock);\r
+ EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName))\r
+ .andThrow(new RuntimeException(""));\r
+\r
+ PowerMock.replayAll();\r
+\r
+ ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest);\r
+\r
+ PowerMock.verifyAll();\r
+ }\r
+\r
@Test\r
public void addCorrelationRule_duplicated_rule() throws Exception {\r
\r
"Mocked contents.", 0);\r
CorrelationRule correlationRule = convertCreateRequest2CorrelationRule(ruleCreateRequest);\r
\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_REPEAT_RULE_NAME);\r
\r
EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
RuleCreateRequest ruleCreateRequest = createRuleCreateRequest(ruleName, "This is a rule for testing.",\r
"Mocked contents.", 0);\r
\r
- thrown.expect(CallException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED);\r
\r
EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
correlationRuleDaoMock);\r
EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(null);\r
EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
- .andThrow(new CallException(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED));\r
+ .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED));\r
\r
PowerMock.replayAll();\r
\r
RuleCreateRequest ruleCreateRequest = createRuleCreateRequest(ruleName, "This is a rule for testing.",\r
"Mocked contents.", 1);\r
\r
- thrown.expect(CallException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED);\r
\r
EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
.andReturn(true);\r
EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
- .andThrow(new CallException(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED));\r
+ .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED));\r
\r
PowerMock.replayAll();\r
\r
RuleCreateRequest ruleCreateRequest = createRuleCreateRequest(ruleName, "This is a rule for testing.",\r
"Mocked contents.", 1);\r
\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CREATE_RULE_FAILED);\r
\r
EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
\r
@Test\r
public void updateCorrelationRule_param_null() throws Exception {\r
- thrown.expect(DataFormatException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
\r
ruleMgtWrapper.updateCorrelationRule(USER_NAME, null);\r
}\r
\r
+ @Test\r
+ public void updateCorrelationRule_rule_query_exception() throws Exception {\r
+ thrown.expect(CorrelationException.class);\r
+ thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+\r
+ EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
+ correlationRuleDaoMock);\r
+ EasyMock.expect(correlationRuleDaoMock.getRuleByRid(EasyMock.anyObject(String.class)))\r
+ .andThrow(new RuntimeException(""));\r
+\r
+ PowerMock.replayAll();\r
+\r
+ ruleMgtWrapper.updateCorrelationRule(USER_NAME, new RuleUpdateRequest());\r
+\r
+ PowerMock.verifyAll();\r
+ }\r
+\r
@Test\r
public void updateCorrelationRule_rule_not_exist() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
\r
EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
\r
@Test\r
public void updateCorrelationRule_rule_status_illegal_with_contents() throws Exception {\r
- thrown.expect(DataFormatException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
\r
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
\r
@Test\r
public void updateCorrelationRule_rule_status_illegal_with_null_contents() throws Exception {\r
- thrown.expect(DataFormatException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
\r
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
\r
@Test\r
public void updateCorrelationRule_rule_disabled_update_failure() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_UPDATE_RULE_FAILED);\r
\r
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
\r
@Test\r
public void updateCorrelationRule_rule_disabled_deploy_verify_exception() throws Exception {\r
- thrown.expect(CallException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED);\r
\r
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
correlationRuleDaoMock.updateRule(EasyMock.anyObject(CorrelationRule.class));\r
EasyMock.expectLastCall();\r
EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
- .andThrow(new CallException(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED));\r
+ .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED));\r
\r
PowerMock.replayAll();\r
\r
\r
@Test\r
public void updateCorrelationRule_rule_enabled_engine_delete_failure() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_UPDATE_RULE_FAILED);\r
\r
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
\r
@Test\r
public void updateCorrelationRule_rule_enabled_engine_deploy_failure() throws Exception {\r
- thrown.expect(CallException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED);\r
\r
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
.andReturn(true);\r
EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
- .andThrow(new CallException(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED));\r
+ .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED));\r
\r
PowerMock.replayAll();\r
\r
\r
@Test\r
public void checkCorrelation_illegal_status() throws Exception {\r
- thrown.expect(DataFormatException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
\r
RuleUpdateRequest ruleCreateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
\r
@Test\r
public void deleteCorrelationRule_request_null() throws Exception {\r
- thrown.expect(DataFormatException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY));\r
\r
ruleMgtWrapper.deleteCorrelationRule(null);\r
}\r
\r
+ @Test\r
+ public void deleteCorrelationRule_rule_query_exception() throws Exception {\r
+ thrown.expect(CorrelationException.class);\r
+ thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_DB_ERROR));\r
+\r
+ RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());\r
+\r
+ EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
+ correlationRuleDaoMock).anyTimes();\r
+ EasyMock.expect(correlationRuleDaoMock.getRuleByRid(ruleDeleteRequest.getRuleId()))\r
+ .andThrow(new RuntimeException(""));\r
+\r
+ PowerMock.replayAll();\r
+\r
+ ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
+\r
+ PowerMock.verifyAll();\r
+ }\r
+\r
@Test\r
public void deleteCorrelationRule_rule_not_exit() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE));\r
\r
RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());\r
\r
@Test\r
public void deleteCorrelationRule_rule_enabled_engine_delete_exception() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_DELETE_RULE_FAILED));\r
\r
RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());\r
\r
@Test\r
public void deleteCorrelationRule_rule_disabled_delete_exception() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_DELETE_RULE_FAILED));\r
\r
RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());\r
\r
@Test\r
public void getCorrelationRuleByCondition_data_format_exception() throws Exception {\r
- thrown.expect(DataFormatException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED));\r
\r
EasyMock.expect(correlationRuleQueryDaoMock.getCorrelationRulesByCondition(EasyMock.anyObject(\r
RuleQueryCondition.class)))\r
- .andThrow(new DataFormatException(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED));\r
+ .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED));\r
\r
PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);\r
\r
\r
@Test\r
public void getCorrelationRuleByCondition_db_exception() throws Exception {\r
- thrown.expect(DbException.class);\r
+ thrown.expect(CorrelationException.class);\r
thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED));\r
\r
EasyMock.expect(correlationRuleQueryDaoMock.getCorrelationRulesByCondition(EasyMock.anyObject(\r
RuleQueryCondition.class)))\r
- .andThrow(new DbException(I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED));\r
+ .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED));\r
\r
PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);\r
\r