Modify the UT Due to the Code Modification
[holmes/rule-management.git] / rulemgt / src / test / java / org / openo / holmes / rulemgt / wrapper / RuleMgtWrapperTest.java
index 41cb494..1cb63cd 100644 (file)
@@ -20,7 +20,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
 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
@@ -31,9 +30,7 @@ import org.junit.Test;
 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
@@ -90,7 +87,7 @@ public class RuleMgtWrapperTest {
 \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
@@ -99,13 +96,36 @@ public class RuleMgtWrapperTest {
 \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
@@ -115,7 +135,7 @@ public class RuleMgtWrapperTest {
                 "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
@@ -137,14 +157,14 @@ public class RuleMgtWrapperTest {
         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
@@ -161,7 +181,7 @@ public class RuleMgtWrapperTest {
         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
@@ -170,7 +190,7 @@ public class RuleMgtWrapperTest {
         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
@@ -186,7 +206,7 @@ public class RuleMgtWrapperTest {
         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
@@ -236,15 +256,32 @@ public class RuleMgtWrapperTest {
 \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
@@ -260,7 +297,7 @@ public class RuleMgtWrapperTest {
 \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
@@ -282,7 +319,7 @@ public class RuleMgtWrapperTest {
 \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
@@ -304,7 +341,7 @@ public class RuleMgtWrapperTest {
 \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
@@ -328,7 +365,7 @@ public class RuleMgtWrapperTest {
 \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
@@ -343,7 +380,7 @@ public class RuleMgtWrapperTest {
         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
@@ -380,7 +417,7 @@ public class RuleMgtWrapperTest {
 \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
@@ -404,7 +441,7 @@ public class RuleMgtWrapperTest {
 \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
@@ -422,7 +459,7 @@ public class RuleMgtWrapperTest {
         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
@@ -475,7 +512,7 @@ public class RuleMgtWrapperTest {
 \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
@@ -490,15 +527,34 @@ public class RuleMgtWrapperTest {
 \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
@@ -517,7 +573,7 @@ public class RuleMgtWrapperTest {
 \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
@@ -541,7 +597,7 @@ public class RuleMgtWrapperTest {
 \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
@@ -587,12 +643,12 @@ public class RuleMgtWrapperTest {
 \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
@@ -603,12 +659,12 @@ public class RuleMgtWrapperTest {
 \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