Modify the UT Due to the Code Modification
authorGuangrongFu <fu.guangrong@zte.com.cn>
Sat, 18 Feb 2017 06:33:57 +0000 (14:33 +0800)
committerGuangrongFu <fu.guangrong@zte.com.cn>
Sat, 18 Feb 2017 07:52:31 +0000 (15:52 +0800)
Change-Id: I5b787bb2f64d05050921ded375438d507efbfd61
Issue-ID:HOLMES-12
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java
rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
rulemgt/src/main/java/org/openo/holmes/rulemgt/constant/RuleMgtConstant.java
rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleDao.java
rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java
rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java
rulemgt/src/main/java/org/openo/holmes/rulemgt/wrapper/RuleMgtWrapper.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/resources/RuleMgtResourcesTest.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java

index 5c5a30c..3433678 100644 (file)
@@ -22,7 +22,6 @@ import javax.validation.constraints.NotNull;
 import org.hibernate.validator.constraints.NotEmpty;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import io.dropwizard.Configuration;
-import lombok.Getter;
 
 public class RuleAppConfig extends Configuration {
 
index e2f4fdd..329b9c9 100644 (file)
@@ -17,7 +17,7 @@ package org.openo.holmes.rulemgt.bolt.enginebolt;
 \r
 import lombok.extern.slf4j.Slf4j;\r
 import org.jvnet.hk2.annotations.Service;\r
-import org.openo.holmes.common.exception.CallException;\r
+import org.openo.holmes.common.exception.CorrelationException;\r
 import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
 import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
 \r
@@ -26,16 +26,16 @@ import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
 public class EngineWrapper {\r
 \r
 \r
-    public String deployEngine(CorrelationDeployRule4Engine correlationRule) throws CallException {\r
+    public String deployEngine(CorrelationDeployRule4Engine correlationRule) throws CorrelationException {\r
         return "";\r
     }\r
 \r
-    public boolean deleteRuleFromEngine(String packageName) throws CallException {\r
+    public boolean deleteRuleFromEngine(String packageName) throws CorrelationException {\r
         return true;\r
     }\r
 \r
     public boolean checkRuleFromEngine(CorrelationCheckRule4Engine correlationCheckRule4Engine)\r
-        throws CallException {\r
+            throws CorrelationException {\r
         return true;\r
     }\r
 }\r
index 55c3cd8..e086829 100644 (file)
 package org.openo.holmes.rulemgt.constant;\r
 \r
 public class RuleMgtConstant {\r
+\r
     public static final int STATUS_RULE_OPEN = 1;\r
     public static final int STATUS_RULE_CLOSE = 0;\r
     public static final int STATUS_RULE_ALL = 2;\r
     public static final String PACKAGE_NAME = "packagename";\r
+\r
+    private RuleMgtConstant() {\r
+\r
+    }\r
 }\r
index 7a7a0eb..a136d12 100644 (file)
@@ -53,9 +53,9 @@ public abstract class CorrelationRuleDao {
     private void deleteRule2DbInner(CorrelationRule correlationRule) {\r
         String name = correlationRule.getName() != null ? correlationRule.getName().trim() : "";\r
         String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : "";\r
-        if (!name.equals("") && !rid.equals("")) {\r
+        if (!"".equals(name) && !"".equals(rid)) {\r
             deleteRuleByRidAndName(rid, name);\r
-        } else if (!rid.equals("")) {\r
+        } else if (!"".equals(rid)) {\r
             deleteRuleByRid(rid);\r
         }\r
     }\r
index 9b66ae5..62f8bad 100644 (file)
  */\r
 package org.openo.holmes.rulemgt.db;\r
 \r
-import org.openo.holmes.common.api.entity.CorrelationRule;\r
-import org.openo.holmes.common.exception.DataFormatException;\r
-import org.openo.holmes.common.exception.DbException;\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.openo.holmes.rulemgt.constant.RuleMgtConstant;\r
-import lombok.extern.slf4j.Slf4j;\r
-import org.jvnet.hk2.annotations.Service;\r
-import org.skife.jdbi.v2.Handle;\r
-import org.skife.jdbi.v2.Query;\r
-\r
-import javax.inject.Inject;\r
 import java.beans.PropertyDescriptor;\r
 import java.lang.reflect.Field;\r
 import java.lang.reflect.Method;\r
@@ -36,14 +23,27 @@ import java.util.Date;
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Properties;\r
+import javax.inject.Inject;\r
+import lombok.extern.slf4j.Slf4j;\r
+import org.jvnet.hk2.annotations.Service;\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.openo.holmes.rulemgt.constant.RuleMgtConstant;\r
+import org.skife.jdbi.v2.Handle;\r
+import org.skife.jdbi.v2.Query;\r
 \r
 @Service\r
 @Slf4j\r
 public class CorrelationRuleQueryDao {\r
+\r
     @Inject\r
     private DbDaoUtil dbDaoUtil;\r
 \r
-    public List<CorrelationRule> getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition) throws DataFormatException, DbException {\r
+    public List<CorrelationRule> getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition)\r
+            throws CorrelationException {\r
         List<CorrelationRule> correlationRules = new ArrayList<CorrelationRule>();\r
         Handle handle = null;\r
         String whereStr = getWhereStrByRequestEntity(ruleQueryCondition);\r
@@ -58,7 +58,7 @@ public class CorrelationRuleQueryDao {
             return correlationRules;\r
         } catch (Exception e) {\r
             log.warn("Query rule: rule id =" + ruleQueryCondition.getRid() + " failed");\r
-            throw new DbException(I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED, e);\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED, e);\r
         } finally {\r
             dbDaoUtil.close(handle);\r
         }\r
@@ -86,7 +86,7 @@ public class CorrelationRuleQueryDao {
         return correlationRule;\r
     }\r
 \r
-    private String getWhereStrByRequestEntity(RuleQueryCondition ruleQueryCondition) throws DataFormatException {\r
+    private String getWhereStrByRequestEntity(RuleQueryCondition ruleQueryCondition) throws CorrelationException {\r
         try {\r
             Class clazz = ruleQueryCondition.getClass();\r
             Field[] fields = clazz.getDeclaredFields();\r
@@ -95,23 +95,17 @@ public class CorrelationRuleQueryDao {
             for (Field field : fields) {\r
                 PropertyDescriptor pd = new PropertyDescriptor(field.getName(),\r
                         clazz);\r
-                Method getMethod = pd.getReadMethod();//获得get方法\r
-                Object o = getMethod.invoke(ruleQueryCondition);//执行get方法返回一个Object\r
+                Method getMethod = pd.getReadMethod();\r
+                Object o = getMethod.invoke(ruleQueryCondition);\r
                 if (o != null) {\r
-                    if (field.getName().equals("enabled")) {\r
-                        int enabled = (int) o;\r
-                        if (enabled != RuleMgtConstant.STATUS_RULE_ALL) {\r
-                            whereSql = whereSql + "enable =" + enabled;\r
-                            whereSql += " AND ";\r
-                        }\r
-                    } else if (field.getName().equals("name")) {\r
-                        if (!"".equals(o.toString().trim())) {\r
-                            whereSql = whereSql + field.getName() + "  like '%" + o + "%'  AND ";\r
-                        }\r
-                    } else {\r
-                        if (!"".equals(o.toString().trim())) {\r
-                            whereSql = whereSql + field.getName() + "='" + o + "'  AND ";\r
-                        }\r
+                    String tempName = field.getName();\r
+                    if ("enabled".equals(tempName) && (int) o != RuleMgtConstant.STATUS_RULE_ALL) {\r
+                        whereSql = whereSql + "enable =" + (int) o;\r
+                        whereSql += " AND ";\r
+                    } else if ("name".equals(tempName) && !"".equals(o.toString().trim())) {\r
+                        whereSql = whereSql + field.getName() + "  like '%" + o + "%'  AND ";\r
+                    } else if (!"".equals(o.toString().trim())) {\r
+                        whereSql = whereSql + field.getName() + "='" + o + "'  AND ";\r
                     }\r
                 }\r
             }\r
@@ -121,7 +115,7 @@ public class CorrelationRuleQueryDao {
             }\r
             return "";\r
         } catch (Exception e) {\r
-            throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED, e);\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED, e);\r
         }\r
     }\r
 }\r
index 8395df7..c2d95f9 100644 (file)
@@ -35,9 +35,7 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;\r
 import lombok.extern.slf4j.Slf4j;\r
 import org.jvnet.hk2.annotations.Service;\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.ExceptionUtil;\r
 import org.openo.holmes.common.utils.I18nProxy;\r
 import org.openo.holmes.common.utils.JacksonUtil;\r
@@ -67,30 +65,18 @@ public class RuleMgtResources {
     @ApiOperation(value = "Save the alarm+ rule to the database, and deployed to the engine when the enable to open.", response = RuleAddAndUpdateResponse.class)\r
     @Timed\r
     public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request,\r
-        @ApiParam(value = "alarm+ rule create request.<br>[rulename]:<font color=\"red\">required</font><br>[content]:<font color=\"red\">required</font><br>[enabled]:<font color=\"red\">required</font>", required = true) RuleCreateRequest ruleCreateRequest) {\r
+            @ApiParam(value = "alarm+ rule create request.<br>[rulename]:<font color=\"red\">required</font><br>[content]:<font color=\"red\">required</font><br>[enabled]:<font color=\"red\">required</font>", required = true) RuleCreateRequest ruleCreateRequest) {\r
         Locale locale = LanguageUtil.getLocale(request);\r
         RuleAddAndUpdateResponse ruleChangeResponse;\r
         try {\r
             ruleChangeResponse = ruleMgtWrapper\r
-                .addCorrelationRule(UserUtil.getUserName(request), ruleCreateRequest);\r
+                    .addCorrelationRule(UserUtil.getUserName(request), ruleCreateRequest);\r
             log.info("create rule:" + ruleCreateRequest.getRuleName() + " success.");\r
             return ruleChangeResponse;\r
-        } catch (CallException e) {\r
+        } catch (CorrelationException e) {\r
             log.error("create rule:" + ruleCreateRequest.getRuleName() + " failed", e);\r
             throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                e.getMessage()));\r
-        } catch (DbException e) {\r
-            log.error("create rule:" + ruleCreateRequest.getRuleName() + " failed", e);\r
-            throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                e.getMessage()));\r
-        } catch (DataFormatException e) {\r
-            log.error("create rule:" + ruleCreateRequest.getRuleName() + " failed", e);\r
-            throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                e.getMessage()));\r
-        } catch (Exception e) {\r
-            log.error("create rule:" + ruleCreateRequest.getRuleName() + " failed", e);\r
-            throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                I18nProxy.RULE_MANAGEMENT_UNKNOWN_EXCEPTION));\r
+                    e.getMessage()));\r
         }\r
     }\r
 \r
@@ -99,29 +85,17 @@ public class RuleMgtResources {
     @ApiOperation(value = "Update the alarm+ rule and deployed to the engine when the enable to open.", response = RuleAddAndUpdateResponse.class)\r
     @Timed\r
     public RuleAddAndUpdateResponse updateCorrelationRule(@Context HttpServletRequest request,\r
-        @ApiParam(value = "alarm+ rule update request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleUpdateRequest ruleUpdateRequest) {\r
+            @ApiParam(value = "alarm+ rule update request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleUpdateRequest ruleUpdateRequest) {\r
         Locale locale = LanguageUtil.getLocale(request);\r
         RuleAddAndUpdateResponse ruleChangeResponse;\r
         try {\r
             ruleChangeResponse = ruleMgtWrapper\r
-                .updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);\r
+                    .updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);\r
             return ruleChangeResponse;\r
-        } catch (CallException e) {\r
+        } catch (CorrelationException e) {\r
             log.error("create rule:" + ruleUpdateRequest.getContent() + " failed", e);\r
             throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                e.getMessage()));\r
-        } catch (DataFormatException e) {\r
-            log.error("update alarm plus rule:" + ruleUpdateRequest.getContent() + " failed", e);\r
-            throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                e.getMessage()));\r
-        } catch (DbException e) {\r
-            log.error("update rule:" + ruleUpdateRequest.getContent() + " failed", e);\r
-            throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                e.getMessage()));\r
-        } catch (Exception e) {\r
-            log.error("update rule:" + ruleUpdateRequest.getRuleId() + " failed", e);\r
-            throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                I18nProxy.RULE_MANAGEMENT_UNKNOWN_EXCEPTION));\r
+                    e.getMessage()));\r
         }\r
     }\r
 \r
@@ -130,28 +104,16 @@ public class RuleMgtResources {
     @ApiOperation(value = "Delete the alarm+ rule,and when the enable is open also removed from the engine.")\r
     @Timed\r
     public boolean deleteCorrelationRule(@Context HttpServletRequest request,\r
-        @ApiParam(value = "alarm+ rule delete request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleDeleteRequest ruleDeleteRequest) {\r
+            @ApiParam(value = "alarm+ rule delete request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleDeleteRequest ruleDeleteRequest) {\r
         Locale locale = LanguageUtil.getLocale(request);\r
         try {\r
             ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
             log.info("delete rule:" + ruleDeleteRequest.getRuleId() + " successful");\r
             return true;\r
-        } catch (DataFormatException e) {\r
+        } catch (CorrelationException e) {\r
             log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);\r
             throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                e.getMessage()));\r
-        } catch (DbException e) {\r
-            log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);\r
-            throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                e.getMessage()));\r
-        } catch (CallException e) {\r
-            log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);\r
-            throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                e.getMessage()));\r
-        } catch (Exception e) {\r
-            log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);\r
-            throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                I18nProxy.RULE_MANAGEMENT_UNKNOWN_EXCEPTION));\r
+                    e.getMessage()));\r
         }\r
     }\r
 \r
@@ -160,38 +122,30 @@ public class RuleMgtResources {
     @ApiOperation(value = "According to the conditions query the alarm + rules", response = RuleQueryListResponse.class)\r
     @Timed\r
     public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request,\r
-        @ApiParam(value = "query condition:<br>" + " <b>[ruleid]</b>:Rule ID;<br>"\r
-            + "<b>[rulename]</b>:Rule name;<br>" + "<b>[creator]</b>:creator of the rule;<br>"\r
-            + "<b>[modifier]</b>:modifier of the rule;<br>"\r
-            + "<b>[enabled]</b>: 0 is Enabled,1 is disabled;<br><font color=\"red\">for example:</font><br>{\"ruleid\":\"rule_1484727187317\"}", required = false) @QueryParam("queryrequest") String ruleQueryRequest) {\r
+            @ApiParam(value = "query condition:<br>" + " <b>[ruleid]</b>:Rule ID;<br>"\r
+                    + "<b>[rulename]</b>:Rule name;<br>" + "<b>[creator]</b>:creator of the rule;<br>"\r
+                    + "<b>[modifier]</b>:modifier of the rule;<br>"\r
+                    + "<b>[enabled]</b>: 0 is Enabled,1 is disabled;<br><font color=\"red\">for example:</font><br>{\"ruleid\":\"rule_1484727187317\"}", required = false) @QueryParam("queryrequest") String ruleQueryRequest) {\r
         Locale locale = LanguageUtil.getLocale(request);\r
         RuleQueryListResponse ruleQueryListResponse;\r
         RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest, request);\r
         try {\r
             ruleQueryListResponse = ruleMgtWrapper\r
-                .getCorrelationRuleByCondition(ruleQueryCondition);\r
+                    .getCorrelationRuleByCondition(ruleQueryCondition);\r
             return ruleQueryListResponse;\r
-        } catch (DataFormatException e) {\r
+        } catch (CorrelationException e) {\r
             log.error("query rule failed,cause query condition conversion failure", e);\r
             throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                e.getMessage()));\r
-        } catch (DbException e) {\r
-            log.error("query rule failed", e);\r
-            throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                e.getMessage()));\r
-        } catch (Exception e) {\r
-            log.error("query rule failed", e);\r
-            throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                I18nProxy.RULE_MANAGEMENT_UNKNOWN_EXCEPTION));\r
+                    e.getMessage()));\r
         }\r
     }\r
 \r
     private RuleQueryCondition getRuleQueryCondition(String queryRequest,\r
-        HttpServletRequest request) {\r
+            HttpServletRequest request) {\r
         Locale locale = LanguageUtil.getLocale(request);\r
         try {\r
             RuleQueryCondition ruleQueryCondition = JacksonUtil\r
-                .jsonToBean(queryRequest, RuleQueryCondition.class);\r
+                    .jsonToBean(queryRequest, RuleQueryCondition.class);\r
             if (queryRequest == null) {\r
                 ruleQueryCondition.setEnabled(2);\r
             } else if (queryRequest.indexOf("enabled") == -1) {\r
@@ -201,7 +155,7 @@ public class RuleMgtResources {
         } catch (IOException e) {\r
             log.warn("queryRequest convert to json failed", e);\r
             throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
-                I18nProxy.RULE_MANAGEMENT_DATA_FORMAT_ERROR));\r
+                    I18nProxy.RULE_MANAGEMENT_DATA_FORMAT_ERROR));\r
         }\r
     }\r
 \r
index 60bce08..67183b7 100644 (file)
@@ -23,9 +23,7 @@ import javax.inject.Singleton;
 import lombok.extern.slf4j.Slf4j;\r
 import org.jvnet.hk2.annotations.Service;\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
@@ -56,24 +54,29 @@ public class RuleMgtWrapper {
     private DbDaoUtil daoUtil;\r
 \r
     public RuleAddAndUpdateResponse addCorrelationRule(String creator,\r
-        RuleCreateRequest ruleCreateRequest)\r
-        throws DataFormatException, CallException, DbException {\r
+            RuleCreateRequest ruleCreateRequest)\r
+            throws CorrelationException {\r
         CorrelationRule correlationRule = convertRuleCreateRequest2CorrelationRule(creator,\r
-            ruleCreateRequest);\r
+                ruleCreateRequest);\r
         if (correlationRule.getName() == null || "".equals(correlationRule.getName().trim())) {\r
-            throw new DbException(I18nProxy.RULE_MANAGEMENT_RULE_NAME_IS_EMPTY);\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NAME_IS_EMPTY);\r
+        }\r
+        CorrelationRule ruleTemp;\r
+        try {\r
+            ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
+                    .queryRuleByRuleName(correlationRule.getName());\r
+        } catch (Exception e) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR, e);\r
         }\r
-        CorrelationRule ruleTemp = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
-            .queryRuleByRuleName(correlationRule.getName());\r
         if (ruleTemp != null) {\r
-            throw new DbException(I18nProxy.RULE_MANAGEMENT_REPEAT_RULE_NAME);\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REPEAT_RULE_NAME);\r
         }\r
         correlationRule.setPackageName(deployRule2Engine(correlationRule));\r
         try {\r
             correlationRule = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
-                .saveRule(correlationRule);\r
-        } catch (RuntimeException e) {\r
-            throw new DbException(I18nProxy.RULE_MANAGEMENT_CREATE_RULE_FAILED, e);\r
+                    .saveRule(correlationRule);\r
+        } catch (Exception e) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CREATE_RULE_FAILED, e);\r
         }\r
         RuleAddAndUpdateResponse ruleAddAndUpdateResponse = new RuleAddAndUpdateResponse();\r
         ruleAddAndUpdateResponse.setRuleId(correlationRule.getRid());\r
@@ -81,17 +84,22 @@ public class RuleMgtWrapper {
     }\r
 \r
     public RuleAddAndUpdateResponse updateCorrelationRule(String modifier,\r
-        RuleUpdateRequest ruleUpdateRequest)\r
-        throws DataFormatException, DbException, CallException {\r
+            RuleUpdateRequest ruleUpdateRequest)\r
+            throws CorrelationException {\r
         if (ruleUpdateRequest != null) {\r
-            CorrelationRule oldCorrelationRule = daoUtil\r
-                .getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
-                .getRuleByRid(ruleUpdateRequest.getRuleId());\r
+            CorrelationRule oldCorrelationRule;\r
+            try {\r
+                oldCorrelationRule = daoUtil\r
+                        .getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
+                        .getRuleByRid(ruleUpdateRequest.getRuleId());\r
+            } catch (Exception e) {\r
+                throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR, e);\r
+            }\r
             if (oldCorrelationRule == null) {\r
-                throw new DbException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
+                throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
             }\r
             CorrelationRule newCorrelationRule = convertRuleUpdateRequest2CorrelationRule(modifier,\r
-                ruleUpdateRequest);\r
+                    ruleUpdateRequest);\r
             checkCorrelation(newCorrelationRule, oldCorrelationRule);\r
             RuleAddAndUpdateResponse ruleChangeResponse = new RuleAddAndUpdateResponse();\r
             try {\r
@@ -99,65 +107,68 @@ public class RuleMgtWrapper {
                     engineWarpper.deleteRuleFromEngine(oldCorrelationRule.getPackageName());\r
                 }\r
                 daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
-                    .updateRule(newCorrelationRule);\r
-            } catch (RuntimeException e) {\r
-                throw new DbException(I18nProxy.RULE_MANAGEMENT_UPDATE_RULE_FAILED, e);\r
+                        .updateRule(newCorrelationRule);\r
+            } catch (Exception e) {\r
+                throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_UPDATE_RULE_FAILED, e);\r
             }\r
             ruleChangeResponse.setRuleId(newCorrelationRule.getRid());\r
             deployRule2Engine(newCorrelationRule);\r
             return ruleChangeResponse;\r
         } else {\r
-            throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
         }\r
 \r
     }\r
 \r
     public void checkCorrelation(CorrelationRule newCorrelationRule,\r
-        CorrelationRule oldCorrelationRule) throws DataFormatException {\r
+            CorrelationRule oldCorrelationRule) throws CorrelationException {\r
         int newEnabled = newCorrelationRule.getEnabled();\r
         if (newCorrelationRule.getContent() == null) {\r
             newCorrelationRule.setContent(oldCorrelationRule.getContent());\r
         }\r
         if (newEnabled != RuleMgtConstant.STATUS_RULE_CLOSE\r
-            && newEnabled != RuleMgtConstant.STATUS_RULE_OPEN) {\r
-            throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
+                && newEnabled != RuleMgtConstant.STATUS_RULE_OPEN) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
         }\r
     }\r
 \r
     public void deleteCorrelationRule(RuleDeleteRequest ruleDeleteRequest)\r
-        throws DbException, DataFormatException, CallException {\r
+            throws CorrelationException {\r
         if (ruleDeleteRequest != null) {\r
-            CorrelationRule correlationRule = daoUtil\r
-                .getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
-                .getRuleByRid(ruleDeleteRequest.getRuleId());\r
+            CorrelationRule correlationRule;\r
+            try {\r
+                correlationRule = daoUtil\r
+                        .getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
+                        .getRuleByRid(ruleDeleteRequest.getRuleId());\r
+            } catch (Exception e) {\r
+                throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\r
+            }\r
             if (correlationRule == null) {\r
                 log.warn("the rule:rule id=" + ruleDeleteRequest.getRuleId()\r
-                    + " does not exist the database.");\r
-                throw new DbException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
+                        + " does not exist the database.");\r
+                throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
             }\r
             try {\r
                 if (correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {\r
                     engineWarpper.deleteRuleFromEngine(correlationRule.getPackageName());\r
                 }\r
                 daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
-                    .deleteRule(correlationRule);\r
-            } catch (RuntimeException e) {\r
-                throw new DbException(I18nProxy.RULE_MANAGEMENT_DELETE_RULE_FAILED, e);\r
+                        .deleteRule(correlationRule);\r
+            } catch (Exception e) {\r
+                throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DELETE_RULE_FAILED, e);\r
             }\r
-        } else\r
-\r
-        {\r
-            throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
+        } else {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
         }\r
 \r
     }\r
 \r
     public CorrelationRule convertRuleCreateRequest2CorrelationRule(String userName,\r
-        RuleCreateRequest ruleCreateRequest) throws DataFormatException {\r
+            RuleCreateRequest ruleCreateRequest) throws CorrelationException {\r
         if (ruleCreateRequest != null) {\r
             if (ruleCreateRequest.getEnabled() != RuleMgtConstant.STATUS_RULE_OPEN\r
-                && ruleCreateRequest.getEnabled() != RuleMgtConstant.STATUS_RULE_CLOSE) {\r
-                throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
+                    && ruleCreateRequest.getEnabled() != RuleMgtConstant.STATUS_RULE_CLOSE) {\r
+                throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
             }\r
             CorrelationRule correlationRule = new CorrelationRule();\r
             String ruleId = "rule_" + System.currentTimeMillis();\r
@@ -177,13 +188,13 @@ public class RuleMgtWrapper {
             correlationRule.setEnabled(ruleCreateRequest.getEnabled());\r
             return correlationRule;\r
         } else {\r
-            throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
         }\r
 \r
     }\r
 \r
     private CorrelationRule convertRuleUpdateRequest2CorrelationRule(String modifier,\r
-        RuleUpdateRequest ruleUpdateRequest) throws DataFormatException {\r
+            RuleUpdateRequest ruleUpdateRequest) throws CorrelationException {\r
         if (ruleUpdateRequest != null) {\r
             CorrelationRule correlationRule = new CorrelationRule();\r
             correlationRule.setRid(ruleUpdateRequest.getRuleId());\r
@@ -194,12 +205,12 @@ public class RuleMgtWrapper {
             correlationRule.setModifier(modifier);\r
             return correlationRule;\r
         } else {\r
-            throw new DataFormatException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
         }\r
 \r
     }\r
 \r
-    private String deployRule2Engine(CorrelationRule correlationRule) throws CallException {\r
+    private String deployRule2Engine(CorrelationRule correlationRule) throws CorrelationException {\r
         if (engineWarpper.checkRuleFromEngine(correlationRules2CheckRule(correlationRule))) {\r
             if (correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {\r
                 return engineWarpper.deployEngine(correlationRules2DeployRule(correlationRule));\r
@@ -209,18 +220,18 @@ public class RuleMgtWrapper {
     }\r
 \r
     public RuleQueryListResponse getCorrelationRuleByCondition(\r
-        RuleQueryCondition ruleQueryCondition) throws DataFormatException, DbException {\r
+            RuleQueryCondition ruleQueryCondition) throws CorrelationException {\r
         List<CorrelationRule> correlationRule = correlationRuleQueryDao\r
-            .getCorrelationRulesByCondition(ruleQueryCondition);\r
+                .getCorrelationRulesByCondition(ruleQueryCondition);\r
         RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();\r
         ruleQueryListResponse.setTotalCount(correlationRule.size());\r
         ruleQueryListResponse\r
-            .setCorrelationRules(correlationRules2RuleResult4APIs(correlationRule));\r
+                .setCorrelationRules(correlationRules2RuleResult4APIs(correlationRule));\r
         return ruleQueryListResponse;\r
     }\r
 \r
     private List<RuleResult4API> correlationRules2RuleResult4APIs(\r
-        List<CorrelationRule> correlationRules) {\r
+            List<CorrelationRule> correlationRules) {\r
         List<RuleResult4API> ruleResult4APIs = new ArrayList<RuleResult4API>();\r
         for (CorrelationRule correlationRule : correlationRules) {\r
             RuleResult4API ruleResult4API = new RuleResult4API();\r
@@ -239,7 +250,7 @@ public class RuleMgtWrapper {
     }\r
 \r
     private CorrelationDeployRule4Engine correlationRules2DeployRule(\r
-        CorrelationRule correlationRule) {\r
+            CorrelationRule correlationRule) {\r
         CorrelationDeployRule4Engine correlationDeployRule4Engine = new CorrelationDeployRule4Engine();\r
         correlationDeployRule4Engine.setContent(correlationRule.getContent());\r
         correlationDeployRule4Engine.setEngineId(correlationRule.getEngineId());\r
@@ -247,7 +258,7 @@ public class RuleMgtWrapper {
     }\r
 \r
     private CorrelationCheckRule4Engine correlationRules2CheckRule(\r
-        CorrelationRule correlationRule) {\r
+            CorrelationRule correlationRule) {\r
         CorrelationCheckRule4Engine correlationCheckRule4Engine = new CorrelationCheckRule4Engine();\r
         correlationCheckRule4Engine.setContent(correlationRule.getContent());\r
         return correlationCheckRule4Engine;\r
index 29e7f2b..2e7cc1c 100644 (file)
@@ -32,7 +32,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.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.RuleQueryCondition;\r
@@ -78,7 +78,7 @@ public class CorrelationRuleQueryDaoTest {
     @Test\r
     public void getCorrelationRulesByCondition_db_exception() throws Exception {\r
 \r
-        thrown.expect(DbException.class);\r
+        thrown.expect(CorrelationException.class);\r
         thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_QUERY_RULE_FAILED);\r
 \r
         EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);\r
index 1f6f331..e25c5b3 100644 (file)
@@ -23,9 +23,7 @@ import org.junit.Before;
 import org.junit.Rule;\r
 import org.junit.Test;\r
 import org.junit.rules.ExpectedException;\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.rulemgt.bean.request.RuleCreateRequest;\r
 import org.openo.holmes.rulemgt.bean.request.RuleDeleteRequest;\r
 import org.openo.holmes.rulemgt.bean.request.RuleQueryCondition;\r
@@ -54,53 +52,12 @@ public class RuleMgtResourcesTest {
     }\r
 \r
     @Test\r
-    public void addCorrelationRule_call_exception() throws Exception {\r
+    public void addCorrelationRule_correlation_exception() throws Exception {\r
         thrown.expect(WebApplicationException.class);\r
 \r
         final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();\r
         EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest))\r
-                .andThrow(new CallException(""));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
-        EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
-        PowerMock.replayAll();\r
-        ruleMgtResources.addCorrelationRule(request, ruleCreateRequest);\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void addCorrelationRule_db_exception() throws Exception {\r
-        thrown.expect(WebApplicationException.class);\r
-\r
-        final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();\r
-        EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest)).andThrow(new DbException(""));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
-        EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
-        PowerMock.replayAll();\r
-        ruleMgtResources.addCorrelationRule(request, ruleCreateRequest);\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void addCorrelationRule_data_format_exception() throws Exception {\r
-        thrown.expect(WebApplicationException.class);\r
-\r
-        final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();\r
-        EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest))\r
-                .andThrow(new DataFormatException(""));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
-        EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
-        PowerMock.replayAll();\r
-        ruleMgtResources.addCorrelationRule(request, ruleCreateRequest);\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void addCorrelationRule_exception() throws Exception {\r
-        thrown.expect(WebApplicationException.class);\r
-\r
-        final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();\r
-        EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest))\r
-                .andThrow(new RuntimeException(""));\r
+                .andThrow(new CorrelationException(EasyMock.anyObject(String.class)));\r
         EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
         EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
         PowerMock.replayAll();\r
@@ -121,54 +78,12 @@ public class RuleMgtResourcesTest {
     }\r
 \r
     @Test\r
-    public void updateCorrelationRule_call_exception() throws Exception {\r
-        thrown.expect(WebApplicationException.class);\r
-\r
-        final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();\r
-        EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin", ruleUpdateRequest))\r
-                .andThrow(new CallException(""));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
-        EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
-        PowerMock.replayAll();\r
-        ruleMgtResources.updateCorrelationRule(request, ruleUpdateRequest);\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void updateCorrelationRule_data_format_exception() throws Exception {\r
-        thrown.expect(WebApplicationException.class);\r
-\r
-        final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();\r
-        EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin", ruleUpdateRequest))\r
-                .andThrow(new DataFormatException(""));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
-        EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
-        PowerMock.replayAll();\r
-        ruleMgtResources.updateCorrelationRule(request, ruleUpdateRequest);\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void updateCorrelationRule_db_exception() throws Exception {\r
+    public void updateCorrelationRule_correlation_exception() throws Exception {\r
         thrown.expect(WebApplicationException.class);\r
 \r
         final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();\r
         EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin", ruleUpdateRequest))\r
-                .andThrow(new DbException(""));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
-        EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
-        PowerMock.replayAll();\r
-        ruleMgtResources.updateCorrelationRule(request, ruleUpdateRequest);\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void updateCorrelationRule_exception() throws Exception {\r
-        thrown.expect(WebApplicationException.class);\r
-\r
-        final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();\r
-        EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin", ruleUpdateRequest))\r
-                .andThrow(new RuntimeException(""));\r
+                .andThrow(new CorrelationException(EasyMock.anyObject(String.class)));\r
         EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
         EasyMock.expect(request.getHeader("username")).andReturn("admin");\r
         PowerMock.replayAll();\r
@@ -189,51 +104,12 @@ public class RuleMgtResourcesTest {
     }\r
 \r
     @Test\r
-    public void deleteCorrelationRule_call_exception() throws Exception {\r
-        thrown.expect(WebApplicationException.class);\r
-\r
-        final RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();\r
-        ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
-        EasyMock.expectLastCall().andThrow(new CallException(""));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
-        PowerMock.replayAll();\r
-        ruleMgtResources.deleteCorrelationRule(request, ruleDeleteRequest);\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void deleteCorrelationRule_data_format_exception() throws Exception {\r
-        thrown.expect(WebApplicationException.class);\r
-\r
-        final RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();\r
-        ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
-        EasyMock.expectLastCall().andThrow(new DataFormatException(""));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
-        PowerMock.replayAll();\r
-        ruleMgtResources.deleteCorrelationRule(request, ruleDeleteRequest);\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void deleteCorrelationRule_db_exception() throws Exception {\r
-        thrown.expect(WebApplicationException.class);\r
-\r
-        final RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();\r
-        ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
-        EasyMock.expectLastCall().andThrow(new DbException(""));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
-        PowerMock.replayAll();\r
-        ruleMgtResources.deleteCorrelationRule(request, ruleDeleteRequest);\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void deleteCorrelationRule_exception() throws Exception {\r
+    public void deleteCorrelationRule_correlation_exception() throws Exception {\r
         thrown.expect(WebApplicationException.class);\r
 \r
         final RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();\r
         ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
-        EasyMock.expectLastCall().andThrow(new RuntimeException(""));\r
+        EasyMock.expectLastCall().andThrow(new CorrelationException(EasyMock.anyObject(String.class)));\r
         EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
         PowerMock.replayAll();\r
         ruleMgtResources.deleteCorrelationRule(request, ruleDeleteRequest);\r
@@ -258,42 +134,13 @@ public class RuleMgtResourcesTest {
         final String requestStr = "{\"ruleid\":\"rule_001\",\"rulename\":\"Rule-001\","\r
                 + "\"enabled\":0,\"creator\":\"admin\"}";\r
         EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))\r
-                .andThrow(new DataFormatException(""));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);\r
-        PowerMock.replayAll();\r
-        ruleMgtResources.getCorrelationRules(request, requestStr);\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void getCorrelationRules_db_exception() throws Exception {\r
-        thrown.expect(WebApplicationException.class);\r
-\r
-        final String requestStr = "{\"ruleid\":\"rule_001\",\"rulename\":\"Rule-001\","\r
-                + "\"enabled\":0,\"creator\":\"admin\"}";\r
-        EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))\r
-                .andThrow(new DbException(""));\r
-        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);\r
-        PowerMock.replayAll();\r
-        ruleMgtResources.getCorrelationRules(request, requestStr);\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void getCorrelationRules_exception() throws Exception {\r
-        thrown.expect(WebApplicationException.class);\r
-\r
-        final String requestStr = "{\"ruleid\":\"rule_001\",\"rulename\":\"Rule-001\","\r
-                + "\"enabled\":0,\"creator\":\"admin\"}";\r
-        EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))\r
-                .andThrow(new RuntimeException(""));\r
+                .andThrow(new CorrelationException(EasyMock.anyObject(String.class)));\r
         EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);\r
         PowerMock.replayAll();\r
         ruleMgtResources.getCorrelationRules(request, requestStr);\r
         PowerMock.verifyAll();\r
     }\r
 \r
-\r
     @Test\r
     public void getCorrelationRules_normal_request_string_null() throws Exception {\r
         EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))\r
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