Add rule management module unit tests
authoryoubowu <wu.youbo@zte.com.cn>
Mon, 27 Feb 2017 01:21:05 +0000 (09:21 +0800)
committer6092002067 <wu.youbo@zte.com.cn>
Mon, 27 Feb 2017 02:15:46 +0000 (10:15 +0800)
Issue-ID:HOLMES-50

Change-Id: Ie21a9046cb3d237aa0c52c9c8ccb77123da2de1d
Signed-off-by: youbowu <wu.youbo@zte.com.cn>
19 files changed:
pom.xml
rulemgt/pom.xml
rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java
rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationRestRequest.java [new file with mode: 0644]
rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineService.java [new file with mode: 0644]
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/CorrelationRuleQueryDao.java
rulemgt/src/main/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapper.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/RuleAppConfigTest.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java [new file with mode: 0644]
rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java [new file with mode: 0644]
rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/db/mapper/CorrelationRuleMapperTest.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/resources/RuleMgtResourcesTest.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java

diff --git a/pom.xml b/pom.xml
index 1a0b116..f2e9540 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                 <artifactId>holmes-actions</artifactId>\r
                 <version>${project.version}</version>\r
             </dependency>\r
-            <dependency>\r
-                <groupId>io.dropwizard</groupId>\r
-                <artifactId>dropwizard-core</artifactId>\r
-                <version>${dropwizard.version}</version>\r
-                <scope>provided</scope>\r
-            </dependency>\r
-\r
             <dependency>\r
                 <groupId>io.dropwizard</groupId>\r
                 <artifactId>dropwizard-db</artifactId>\r
index 7159332..c4f1ecf 100644 (file)
             <artifactId>holmes-actions</artifactId>
             <exclusions>
                 <exclusion>
-                    <groupId>org.glassfish.jersey.core</groupId>
-                    <artifactId>jersey-common</artifactId>
+                    <groupId>org.glassfish.jersey.containers</groupId>
+                    <artifactId>jersey-container-servlet-core</artifactId>
                 </exclusion>
             </exclusions>
         </dependency>
         <dependency>
-            <groupId>org.glassfish.jersey.core</groupId>
-            <artifactId>jersey-common</artifactId>
+            <groupId>org.glassfish.jersey.containers</groupId>
+            <artifactId>jersey-container-servlet-core</artifactId>
             <version>2.16</version>
         </dependency>
         <dependency>
             <groupId>org.openo.common-services.common-utilities</groupId>
             <artifactId>dropwizard-ioc-container</artifactId>
         </dependency>
-        <dependency>
-            <groupId>io.dropwizard</groupId>
-            <artifactId>dropwizard-core</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
             <version>3.15.0-GA</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.3.6</version>
+        </dependency>
+        <dependency>
+            <groupId>com.googlecode.json-simple</groupId>
+            <artifactId>json-simple</artifactId>
+            <version>1.1.1</version>
+        </dependency>
+        <dependency>
+            <groupId>net.sf.json-lib</groupId>
+            <artifactId>json-lib</artifactId>
+            <version>2.4</version>
+            <classifier>jdk15</classifier>
+        </dependency>
     </dependencies>
     <build>
         <plugins>
index 3433678..57ae0c5 100644 (file)
  */
 package org.openo.holmes.rulemgt;
 
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.dropwizard.Configuration;
 import io.dropwizard.db.DataSourceFactory;
 import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
-
 import org.hibernate.validator.constraints.NotEmpty;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import io.dropwizard.Configuration;
+import org.jvnet.hk2.annotations.Service;
 
+@Service
 public class RuleAppConfig extends Configuration {
 
     @NotEmpty
@@ -31,6 +32,8 @@ public class RuleAppConfig extends Configuration {
     @NotEmpty
     private String apidescription = "Holmes rule management rest API";
 
+    @NotEmpty
+    private String msbServerAddr;
 
     @Valid
     @NotNull
@@ -51,8 +54,17 @@ public class RuleAppConfig extends Configuration {
         return apidescription;
     }
 
-    public void setApidescription( String apidescription ) {
+    public void setApidescription(String apidescription) {
         this.apidescription = apidescription;
     }
 
+    @JsonProperty
+    public String getMsbServerAddr() {
+        return msbServerAddr;
+    }
+
+    @JsonProperty
+    public void setMsbServerAddr(String msbServerAddr) {
+        this.msbServerAddr = msbServerAddr;
+    }
 }
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationRestRequest.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bean/request/CorrelationRestRequest.java
new file mode 100644 (file)
index 0000000..463eb2a
--- /dev/null
@@ -0,0 +1,27 @@
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.openo.holmes.rulemgt.bean.request;\r
+\r
+import lombok.Getter;\r
+import lombok.Setter;\r
+\r
+@Getter\r
+@Setter\r
+public class CorrelationRestRequest {\r
+\r
+    private String rootURL;\r
+}
\ No newline at end of file
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineService.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineService.java
new file mode 100644 (file)
index 0000000..6267cff
--- /dev/null
@@ -0,0 +1,129 @@
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.openo.holmes.rulemgt.bolt.enginebolt;\r
+\r
+import com.fasterxml.jackson.databind.ObjectMapper;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.UnsupportedEncodingException;\r
+import javax.inject.Inject;\r
+import org.apache.commons.lang3.StringUtils;\r
+import org.apache.http.HttpEntity;\r
+import org.apache.http.HttpResponse;\r
+import org.apache.http.client.HttpClient;\r
+import org.apache.http.client.methods.HttpDelete;\r
+import org.apache.http.client.methods.HttpPost;\r
+import org.apache.http.client.methods.HttpPut;\r
+import org.apache.http.client.methods.HttpRequestBase;\r
+import org.apache.http.entity.BufferedHttpEntity;\r
+import org.apache.http.entity.ByteArrayEntity;\r
+import org.apache.http.impl.client.HttpClients;\r
+import org.jvnet.hk2.annotations.Service;\r
+import org.openo.holmes.common.exception.CorrelationException;\r
+import org.openo.holmes.common.utils.I18nProxy;\r
+import org.openo.holmes.rulemgt.RuleAppConfig;\r
+import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
+import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
+import org.openo.holmes.rulemgt.constant.RuleMgtConstant;\r
+\r
+@Service\r
+public class EngineService {\r
+\r
+    @Inject\r
+    private RuleAppConfig ruleAppConfig;\r
+\r
+    protected HttpResponse delete(String packageName) throws Exception {\r
+        return deleteRequest(ruleAppConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH + "/" + packageName);\r
+    }\r
+\r
+    protected HttpResponse check(CorrelationCheckRule4Engine correlationCheckRule4Engine) throws Exception {\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        String content = mapper.writeValueAsString(correlationCheckRule4Engine);\r
+        return postRequest(ruleAppConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH, content);\r
+    }\r
+\r
+    protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine) throws Exception {\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        String content = mapper.writeValueAsString(correlationDeployRule4Engine);\r
+        return putRequest(ruleAppConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH, content);\r
+    }\r
+\r
+    private HttpResponse postRequest(String url, String content) throws Exception {\r
+        HttpClient httpClient = HttpClients.createDefault();\r
+        HttpPost httpPost = new HttpPost(url);\r
+        setHeader(httpPost);\r
+        if (StringUtils.isNotEmpty(content)) {\r
+            httpPost.setEntity(new ByteArrayEntity(content.getBytes()));\r
+        }\r
+        return httpClient.execute(httpPost);\r
+    }\r
+\r
+    private HttpResponse putRequest(String url, String content)\r
+            throws Exception {\r
+        HttpClient httpClient = HttpClients.createDefault();\r
+        HttpPut httpPut = new HttpPut(url);\r
+        setHeader(httpPut);\r
+        if (StringUtils.isNotEmpty(content)) {\r
+            httpPut.setEntity(new ByteArrayEntity(content.getBytes()));\r
+        }\r
+        return httpClient.execute(httpPut);\r
+    }\r
+\r
+    private HttpResponse deleteRequest(String url) throws Exception {\r
+        HttpClient httpClient = HttpClients.createDefault();\r
+        HttpDelete httpDelete = new HttpDelete(url);\r
+        setHeader(httpDelete);\r
+        return httpClient.execute(httpDelete);\r
+    }\r
+\r
+    private void setHeader(HttpRequestBase httpRequestBase) {\r
+        httpRequestBase.setHeader("Content-Type", "text/html;charset=UTF-8");\r
+        httpRequestBase.setHeader("Accept", "application/json");\r
+        httpRequestBase.setHeader("Content-Type", "application/json");\r
+    }\r
+\r
+    public byte[] getData(HttpEntity httpEntity) throws Exception {\r
+        BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(httpEntity);\r
+        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();\r
+        bufferedHttpEntity.writeTo(byteArrayOutputStream);\r
+        byte[] responseBytes = byteArrayOutputStream.toByteArray();\r
+        return responseBytes;\r
+    }\r
+\r
+    public String getResponseContent(HttpResponse httpResponse) throws CorrelationException {\r
+        byte[] dataByte;\r
+        String result = null;\r
+        try {\r
+            HttpEntity httpEntity = httpResponse.getEntity();\r
+            if (httpEntity != null) {\r
+                byte[] responseBytes = getData(httpEntity);\r
+                dataByte = responseBytes;\r
+                result = bytesToString(dataByte);\r
+            }\r
+            return result;\r
+        } catch (Exception e) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR, e);\r
+        }\r
+    }\r
+\r
+    private String bytesToString(byte[] bytes) throws UnsupportedEncodingException {\r
+        if (bytes != null) {\r
+            String returnStr = new String(bytes, "utf-8");\r
+            returnStr = StringUtils.trim(returnStr);\r
+            return returnStr;\r
+        }\r
+        return null;\r
+    }\r
+}\r
index 329b9c9..b69e66b 100644 (file)
  */\r
 package org.openo.holmes.rulemgt.bolt.enginebolt;\r
 \r
+import javax.inject.Inject;\r
 import lombok.extern.slf4j.Slf4j;\r
+import net.sf.json.JSONObject;\r
+import org.apache.http.HttpResponse;\r
 import org.jvnet.hk2.annotations.Service;\r
 import org.openo.holmes.common.exception.CorrelationException;\r
+import org.openo.holmes.common.utils.I18nProxy;\r
 import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
 import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
+import org.openo.holmes.rulemgt.constant.RuleMgtConstant;\r
 \r
 @Service\r
 @Slf4j\r
 public class EngineWrapper {\r
 \r
+    @Inject\r
+    private EngineService engineService;\r
 \r
     public String deployEngine(CorrelationDeployRule4Engine correlationRule) throws CorrelationException {\r
-        return "";\r
+        HttpResponse httpResponse;\r
+        try {\r
+            httpResponse = engineService.deploy(correlationRule);\r
+        } catch (Exception e) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED,e);\r
+        }\r
+        if (httpResponse.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
+            log.info("Call deploy rule rest interface in engine successfully.");\r
+            String content = engineService.getResponseContent(httpResponse);\r
+            try {\r
+                JSONObject json = JSONObject.fromObject(content);\r
+                return json.get(RuleMgtConstant.PACKAGE).toString();\r
+            } catch (Exception e) {\r
+                throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR,e);\r
+            }\r
+        } else {\r
+            throw new CorrelationException(I18nProxy.ENGINE_DEPLOY_RULE_FAILED);\r
+        }\r
     }\r
 \r
     public boolean deleteRuleFromEngine(String packageName) throws CorrelationException {\r
-        return true;\r
+        HttpResponse httpResponse;\r
+        try {\r
+            httpResponse = engineService.delete(packageName);\r
+        } catch (Exception e) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_DELETE_RULE_REST_FAILED,e);\r
+        }\r
+        if (httpResponse.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
+            log.info("Call delete rule rest interface in engine successfully.");\r
+            return true;\r
+        } else {\r
+            throw new CorrelationException(I18nProxy.ENGINE_DELETE_RULE_FAILED);\r
+        }\r
     }\r
 \r
     public boolean checkRuleFromEngine(CorrelationCheckRule4Engine correlationCheckRule4Engine)\r
             throws CorrelationException {\r
-        return true;\r
+        HttpResponse httpResponse;\r
+        try {\r
+            httpResponse = engineService.check(correlationCheckRule4Engine);\r
+        } catch (Exception e) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED,e);\r
+        }\r
+        if (httpResponse.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
+            log.info("Call check rule rest interface in engine successfully.");\r
+            return true;\r
+        } else {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CHECK_NO_PASS);\r
+        }\r
     }\r
 }\r
index e086829..348056d 100644 (file)
@@ -17,12 +17,13 @@ package org.openo.holmes.rulemgt.constant;
 \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
+    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 = "package";\r
+    public static final String ENGINE_PATH = "/api/correlation-engine/v1/rule";\r
+    public static final int RESPONSE_STATUS_OK = 200;\r
 }\r
index 5096db3..224f861 100644 (file)
@@ -71,7 +71,7 @@ public class CorrelationRuleQueryDao {
         correlationRule.setDescription((String) value.get("description"));\r
         correlationRule.setEnabled((Integer) value.get("enable"));\r
         correlationRule.setTemplateID((Integer) value.get("templateID"));\r
-        correlationRule.setEngineId((String) value.get("engineID"));\r
+        correlationRule.setEngineID((String) value.get("engineID"));\r
         correlationRule.setEngineType((String) value.get("engineType"));\r
         correlationRule.setCreator((String) value.get("creator"));\r
         correlationRule.setCreateTime((Date) value.get("createTime"));\r
@@ -80,7 +80,6 @@ public class CorrelationRuleQueryDao {
         correlationRule.setParams((Properties) value.get("params"));\r
         correlationRule.setDomain((String) value.get("domain"));\r
         correlationRule.setContent((String) value.get("content"));\r
-        correlationRule.setIsManual((Integer) value.get("isManual"));\r
         correlationRule.setVendor((String) value.get("vendor"));\r
         correlationRule.setPackageName((String) value.get("package"));\r
         return correlationRule;\r
@@ -95,21 +94,25 @@ public class CorrelationRuleQueryDao {
             for (Field field : fields) {\r
                 // Jacoco will cause an exception when calculating the coverage of the UT\r
                 // Remove this if jacoco solves this problem in the future\r
-                if (field.getName().contains("jacoco")){\r
+                if (field.getName().contains("jacoco")) {\r
                     continue;\r
                 }\r
-\r
                 PropertyDescriptor pd = new PropertyDescriptor(field.getName(),\r
                         clazz);\r
                 Method getMethod = pd.getReadMethod();\r
                 Object o = getMethod.invoke(ruleQueryCondition);\r
                 if (o != null) {\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
+                    if ("enabled".equals(tempName)) {\r
+                        int enabled = (int) o;\r
+                        if (enabled != RuleMgtConstant.STATUS_RULE_ALL) {\r
+                            whereSql = whereSql + "enable =" + enabled;\r
+                            whereSql += " AND ";\r
+                        }\r
+                    } else if ("name".equals(tempName)) {\r
+                        if (!"".equals(o.toString().trim())) {\r
+                            whereSql = whereSql + field.getName() + "  like '%" + o + "%'  AND ";\r
+                        }\r
                     } else if (!"".equals(o.toString().trim())) {\r
                         whereSql = whereSql + field.getName() + "='" + o + "'  AND ";\r
                     }\r
@@ -124,17 +127,4 @@ public class CorrelationRuleQueryDao {
             throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED, e);\r
         }\r
     }\r
-\r
-    private String getMethodName(Field field){\r
-        String ret = field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);;\r
-        Class clazz = field.getDeclaringClass();\r
-\r
-        if (clazz.equals(Boolean.class)){\r
-            ret = "is" + ret;\r
-        }else{\r
-            ret = "get" + ret;\r
-        }\r
-\r
-        return ret;\r
-    }\r
 }\r
index d318de9..a8b114d 100644 (file)
@@ -32,7 +32,7 @@ public class CorrelationRuleMapper implements ResultSetMapper<CorrelationRule> {
         correlationRule.setDescription(resultSet.getString("description"));\r
         correlationRule.setEnabled(resultSet.getInt("enable"));\r
         correlationRule.setTemplateID(resultSet.getInt("templateID"));\r
-        correlationRule.setEngineId(resultSet.getString("engineID"));\r
+        correlationRule.setEngineID(resultSet.getString("engineID"));\r
         correlationRule.setEngineType(resultSet.getString("engineType"));\r
         correlationRule.setCreator(resultSet.getString("creator"));\r
         correlationRule.setCreateTime(resultSet.getDate("createTime"));\r
@@ -41,7 +41,6 @@ public class CorrelationRuleMapper implements ResultSetMapper<CorrelationRule> {
         correlationRule.setParams((Properties)resultSet.getObject("params"));\r
         correlationRule.setDomain(resultSet.getString("domain"));\r
         correlationRule.setContent(resultSet.getString("content"));\r
-        correlationRule.setIsManual(resultSet.getInt("isManual"));\r
         correlationRule.setVendor(resultSet.getString("vendor"));\r
         correlationRule.setPackageName(resultSet.getString("package"));\r
         return correlationRule;\r
index c2d95f9..682faf0 100644 (file)
@@ -34,6 +34,7 @@ import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;\r
 import javax.ws.rs.core.MediaType;\r
 import lombok.extern.slf4j.Slf4j;\r
+import net.sf.json.JSONObject;\r
 import org.jvnet.hk2.annotations.Service;\r
 import org.openo.holmes.common.exception.CorrelationException;\r
 import org.openo.holmes.common.utils.ExceptionUtil;\r
@@ -47,10 +48,11 @@ import org.openo.holmes.rulemgt.bean.request.RuleQueryCondition;
 import org.openo.holmes.rulemgt.bean.request.RuleUpdateRequest;\r
 import org.openo.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;\r
 import org.openo.holmes.rulemgt.bean.response.RuleQueryListResponse;\r
+import org.openo.holmes.rulemgt.constant.RuleMgtConstant;\r
 import org.openo.holmes.rulemgt.wrapper.RuleMgtWrapper;\r
 \r
-@SwaggerDefinition\r
 @Service\r
+@SwaggerDefinition\r
 @Path("/rule")\r
 @Api(tags = {"CorrelationRules"})\r
 @Produces(MediaType.APPLICATION_JSON)\r
@@ -89,11 +91,11 @@ public class RuleMgtResources {
         Locale locale = LanguageUtil.getLocale(request);\r
         RuleAddAndUpdateResponse ruleChangeResponse;\r
         try {\r
-            ruleChangeResponse = ruleMgtWrapper\r
-                    .updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);\r
+            ruleChangeResponse = ruleMgtWrapper.updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);\r
+            log.info("update rule:" + ruleUpdateRequest.getRuleId() + " successful");\r
             return ruleChangeResponse;\r
         } catch (CorrelationException e) {\r
-            log.error("create rule:" + ruleUpdateRequest.getContent() + " failed", e);\r
+            log.error("update rule:" + ruleUpdateRequest.getContent() + " failed", e);\r
             throw ExceptionUtil.buildExceptionResponse(I18nProxy.getInstance().getValue(locale,\r
                     e.getMessage()));\r
         }\r
@@ -132,6 +134,7 @@ public class RuleMgtResources {
         try {\r
             ruleQueryListResponse = ruleMgtWrapper\r
                     .getCorrelationRuleByCondition(ruleQueryCondition);\r
+            log.info("query rule successful by condition:" + JSONObject.fromObject(ruleQueryCondition));\r
             return ruleQueryListResponse;\r
         } catch (CorrelationException e) {\r
             log.error("query rule failed,cause query condition conversion failure", e);\r
@@ -147,9 +150,9 @@ public class RuleMgtResources {
             RuleQueryCondition ruleQueryCondition = JacksonUtil\r
                     .jsonToBean(queryRequest, RuleQueryCondition.class);\r
             if (queryRequest == null) {\r
-                ruleQueryCondition.setEnabled(2);\r
+                ruleQueryCondition.setEnabled(RuleMgtConstant.STATUS_RULE_ALL);\r
             } else if (queryRequest.indexOf("enabled") == -1) {\r
-                ruleQueryCondition.setEnabled(2);\r
+                ruleQueryCondition.setEnabled(RuleMgtConstant.STATUS_RULE_ALL);\r
             }\r
             return ruleQueryCondition;\r
         } catch (IOException e) {\r
@@ -158,5 +161,4 @@ public class RuleMgtResources {
                     I18nProxy.RULE_MANAGEMENT_DATA_FORMAT_ERROR));\r
         }\r
     }\r
-\r
 }\r
index b1ed44e..afd80b1 100644 (file)
@@ -18,6 +18,7 @@ package org.openo.holmes.rulemgt.wrapper;
 import java.util.ArrayList;\r
 import java.util.Date;\r
 import java.util.List;\r
+import javax.annotation.PostConstruct;\r
 import javax.inject.Inject;\r
 import javax.inject.Singleton;\r
 import lombok.extern.slf4j.Slf4j;\r
@@ -53,168 +54,143 @@ public class RuleMgtWrapper {
     @Inject\r
     private DbDaoUtil daoUtil;\r
 \r
-    public RuleAddAndUpdateResponse addCorrelationRule(String creator,\r
-            RuleCreateRequest ruleCreateRequest)\r
+    private CorrelationRuleDao correlationRuleDao;\r
+\r
+    @PostConstruct\r
+    public void initDaoUtil() {\r
+        correlationRuleDao = daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class);\r
+    }\r
+\r
+    public RuleAddAndUpdateResponse addCorrelationRule(String creator, RuleCreateRequest ruleCreateRequest)\r
             throws CorrelationException {\r
-        CorrelationRule correlationRule = convertRuleCreateRequest2CorrelationRule(creator,\r
-                ruleCreateRequest);\r
-        if (correlationRule.getName() == null || "".equals(correlationRule.getName().trim())) {\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
+        if (ruleCreateRequest == null) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
         }\r
+        CorrelationRule correlationRule = convertCreateRequest2Rule(creator,\r
+                ruleCreateRequest);\r
+        checkCorrelation(correlationRule);\r
+        CorrelationRule ruleTemp = correlationRuleDao.queryRuleByRuleName(correlationRule.getName());\r
         if (ruleTemp != null) {\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 (Exception e) {\r
-            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CREATE_RULE_FAILED, e);\r
-        }\r
+        CorrelationRule result = correlationRuleDao.saveRule(correlationRule);\r
         RuleAddAndUpdateResponse ruleAddAndUpdateResponse = new RuleAddAndUpdateResponse();\r
-        ruleAddAndUpdateResponse.setRuleId(correlationRule.getRid());\r
+        ruleAddAndUpdateResponse.setRuleId(result.getRid());\r
         return ruleAddAndUpdateResponse;\r
     }\r
 \r
-    public RuleAddAndUpdateResponse updateCorrelationRule(String modifier,\r
-            RuleUpdateRequest ruleUpdateRequest)\r
+    public RuleAddAndUpdateResponse updateCorrelationRule(String modifier, RuleUpdateRequest ruleUpdateRequest)\r
             throws CorrelationException {\r
-        if (ruleUpdateRequest != null) {\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 CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
-            }\r
-            CorrelationRule newCorrelationRule = convertRuleUpdateRequest2CorrelationRule(modifier,\r
-                    ruleUpdateRequest);\r
-            checkCorrelation(newCorrelationRule, oldCorrelationRule);\r
-            RuleAddAndUpdateResponse ruleChangeResponse = new RuleAddAndUpdateResponse();\r
-            try {\r
-                if (oldCorrelationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {\r
-                    engineWarpper.deleteRuleFromEngine(oldCorrelationRule.getPackageName());\r
-                }\r
-                daoUtil.getJdbiDaoByOnDemand(CorrelationRuleDao.class)\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
+        if (ruleUpdateRequest == null) {\r
             throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
         }\r
-\r
+        CorrelationRule oldCorrelationRule = correlationRuleDao.queryRuleByRid(ruleUpdateRequest.getRuleId());\r
+        if (oldCorrelationRule == null) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
+        }\r
+        CorrelationRule newCorrelationRule = convertRuleUpdateRequest2CorrelationRule(modifier,\r
+                ruleUpdateRequest, oldCorrelationRule.getName());\r
+        checkCorrelation(newCorrelationRule);\r
+        RuleAddAndUpdateResponse ruleChangeResponse = new RuleAddAndUpdateResponse();\r
+        ruleChangeResponse.setRuleId(newCorrelationRule.getRid());\r
+        if (!haveChange(newCorrelationRule, oldCorrelationRule)) {\r
+            return ruleChangeResponse;\r
+        }\r
+        if (oldCorrelationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {\r
+            engineWarpper.deleteRuleFromEngine(oldCorrelationRule.getPackageName());\r
+        }\r
+        correlationRuleDao.updateRule(newCorrelationRule);\r
+        deployRule2Engine(newCorrelationRule);\r
+        return ruleChangeResponse;\r
     }\r
 \r
-    public void checkCorrelation(CorrelationRule newCorrelationRule,\r
-            CorrelationRule oldCorrelationRule) throws CorrelationException {\r
-        int newEnabled = newCorrelationRule.getEnabled();\r
-        if (newCorrelationRule.getContent() == null) {\r
-            newCorrelationRule.setContent(oldCorrelationRule.getContent());\r
+    private void checkCorrelation(CorrelationRule correlationRule) throws CorrelationException {\r
+        int enabled = correlationRule.getEnabled();\r
+        String ruleName = correlationRule.getName() == null ? "" : correlationRule.getName().trim();\r
+        String content = correlationRule.getContent() == null ? "" : correlationRule.getContent().trim();\r
+        if ("".equals(content)) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CONTENT_CANNOT_BE_EMPTY);\r
         }\r
-        if (newEnabled != RuleMgtConstant.STATUS_RULE_CLOSE\r
-                && newEnabled != RuleMgtConstant.STATUS_RULE_OPEN) {\r
+        if (enabled != RuleMgtConstant.STATUS_RULE_CLOSE\r
+                && enabled != RuleMgtConstant.STATUS_RULE_OPEN) {\r
             throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
         }\r
+        if ("".equals(ruleName)) {\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NAME_CANNOT_BE_EMPTY);\r
+        }\r
+    }\r
+\r
+    private boolean haveChange(CorrelationRule newCorrelationRule, CorrelationRule oldCorrelationRule) {\r
+        String newContent = newCorrelationRule.getContent();\r
+        String oldContent = oldCorrelationRule.getContent();\r
+        int newEnabled = newCorrelationRule.getEnabled();\r
+        int oldEnabled = oldCorrelationRule.getEnabled();\r
+        String newDes = newCorrelationRule.getDescription();\r
+        String oldDes = oldCorrelationRule.getDescription();\r
+        if (newContent.equals(oldContent) && newEnabled == oldEnabled && newDes.equals(oldDes)) {\r
+            return false;\r
+        }\r
+        return true;\r
     }\r
 \r
     public void deleteCorrelationRule(RuleDeleteRequest ruleDeleteRequest)\r
             throws CorrelationException {\r
-        if (ruleDeleteRequest != null) {\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, e);\r
-            }\r
-            if (correlationRule == null) {\r
-                log.warn("the rule:rule id=" + ruleDeleteRequest.getRuleId()\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 (Exception e) {\r
-                throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DELETE_RULE_FAILED, e);\r
-            }\r
-        } else {\r
+        if (ruleDeleteRequest == null) {\r
             throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
         }\r
-\r
+        CorrelationRule correlationRule = correlationRuleDao.queryRuleByRid(ruleDeleteRequest.getRuleId());\r
+        if (correlationRule == null) {\r
+            log.warn("the rule:rule id=" + ruleDeleteRequest.getRuleId() + " does not exist the database.");\r
+            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
+        }\r
+        if (correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN) {\r
+            engineWarpper.deleteRuleFromEngine(correlationRule.getPackageName());\r
+        }\r
+        correlationRuleDao.deleteRule(correlationRule);\r
     }\r
 \r
-    public CorrelationRule convertRuleCreateRequest2CorrelationRule(String userName,\r
+    private CorrelationRule convertCreateRequest2Rule(String userName,\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 CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
-            }\r
-            CorrelationRule correlationRule = new CorrelationRule();\r
-            String ruleId = "rule_" + System.currentTimeMillis();\r
-            correlationRule.setRid(ruleId);\r
-            correlationRule.setContent(ruleCreateRequest.getContent());\r
-            correlationRule.setDescription(ruleCreateRequest.getDescription());\r
-            correlationRule.setCreateTime(new Date());\r
-            correlationRule.setUpdateTime(new Date());\r
-            correlationRule.setName(ruleCreateRequest.getRuleName());\r
-            correlationRule.setEngineId("correlation-d");\r
-            correlationRule.setEngineType("");\r
-            correlationRule.setIsManual(0);\r
-            correlationRule.setTemplateID(0);\r
-            correlationRule.setVendor("");\r
-            correlationRule.setCreator(userName);\r
-            correlationRule.setModifier(userName);\r
-            correlationRule.setEnabled(ruleCreateRequest.getEnabled());\r
-            return correlationRule;\r
-        } else {\r
-            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
+        String tempContent = ruleCreateRequest.getContent();\r
+        CorrelationRule correlationRule = new CorrelationRule();\r
+        String ruleId = "rule_" + System.currentTimeMillis();\r
+        correlationRule.setRid(ruleId);\r
+        if (tempContent != null) {\r
+            correlationRule.setContent(tempContent.trim());\r
         }\r
-\r
+        correlationRule.setDescription(ruleCreateRequest.getDescription());\r
+        correlationRule.setCreateTime(new Date());\r
+        correlationRule.setUpdateTime(new Date());\r
+        correlationRule.setName(ruleCreateRequest.getRuleName());\r
+        correlationRule.setEngineID("correlation-d");\r
+        correlationRule.setEngineType("");\r
+        correlationRule.setTemplateID(0);\r
+        correlationRule.setVendor("");\r
+        correlationRule.setCreator(userName);\r
+        correlationRule.setModifier(userName);\r
+        correlationRule.setEnabled(ruleCreateRequest.getEnabled());\r
+        return correlationRule;\r
     }\r
 \r
     private CorrelationRule convertRuleUpdateRequest2CorrelationRule(String modifier,\r
-            RuleUpdateRequest ruleUpdateRequest) throws CorrelationException {\r
-        if (ruleUpdateRequest != null) {\r
-            CorrelationRule correlationRule = new CorrelationRule();\r
-            correlationRule.setRid(ruleUpdateRequest.getRuleId());\r
-            correlationRule.setContent(ruleUpdateRequest.getContent());\r
-            correlationRule.setDescription(ruleUpdateRequest.getDescription());\r
-            correlationRule.setEnabled(ruleUpdateRequest.getEnabled());\r
-            correlationRule.setUpdateTime(new Date());\r
-            correlationRule.setModifier(modifier);\r
-            return correlationRule;\r
-        } else {\r
-            throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY);\r
-        }\r
-\r
+            RuleUpdateRequest ruleUpdateRequest, String ruleName) throws CorrelationException {\r
+        CorrelationRule correlationRule = new CorrelationRule();\r
+        correlationRule.setRid(ruleUpdateRequest.getRuleId());\r
+        correlationRule.setContent(ruleUpdateRequest.getContent());\r
+        correlationRule.setDescription(ruleUpdateRequest.getDescription());\r
+        correlationRule.setEnabled(ruleUpdateRequest.getEnabled());\r
+        correlationRule.setUpdateTime(new Date());\r
+        correlationRule.setModifier(modifier);\r
+        correlationRule.setName(ruleName);\r
+        return correlationRule;\r
     }\r
 \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
-            }\r
+    private String deployRule2Engine(CorrelationRule correlationRule)\r
+            throws CorrelationException {\r
+        if (engineWarpper.checkRuleFromEngine(correlationRules2CheckRule(correlationRule)) && (\r
+                correlationRule.getEnabled() == RuleMgtConstant.STATUS_RULE_OPEN)) {\r
+            return engineWarpper.deployEngine(correlationRules2DeployRule(correlationRule));\r
         }\r
         return "";\r
     }\r
@@ -253,7 +229,7 @@ public class RuleMgtWrapper {
             CorrelationRule correlationRule) {\r
         CorrelationDeployRule4Engine correlationDeployRule4Engine = new CorrelationDeployRule4Engine();\r
         correlationDeployRule4Engine.setContent(correlationRule.getContent());\r
-        correlationDeployRule4Engine.setEngineId(correlationRule.getEngineId());\r
+        correlationDeployRule4Engine.setEngineId(correlationRule.getEngineID());\r
         return correlationDeployRule4Engine;\r
     }\r
 \r
index 996f80e..e451410 100644 (file)
@@ -22,34 +22,45 @@ import static org.junit.Assert.assertThat;
 \r
 import io.dropwizard.db.DataSourceFactory;\r
 import org.junit.Before;\r
+import org.junit.Test;\r
 \r
 public class RuleAppConfigTest {\r
 \r
     private RuleAppConfig ruleAppConfig;\r
 \r
     @Before\r
-    public void setUp(){\r
+    public void setUp() {\r
         ruleAppConfig = new RuleAppConfig();\r
     }\r
 \r
+    @Test\r
     public void getDataSourceFactory() throws Exception {\r
         assertThat(ruleAppConfig.getDataSourceFactory(), notNullValue());\r
     }\r
 \r
+    @Test\r
     public void setDataSourceFactory() throws Exception {\r
         final DataSourceFactory factory = new DataSourceFactory();\r
         ruleAppConfig.setDataSourceFactory(factory);\r
         assertThat(ruleAppConfig.getDataSourceFactory(), equalTo(factory));\r
     }\r
 \r
+    @Test\r
     public void getApidescription() throws Exception {\r
         assertThat(ruleAppConfig.getApidescription(), equalTo("Holmes rule management rest API"));\r
     }\r
 \r
+    @Test\r
     public void setApidescription() throws Exception {\r
         final String value = "desc";\r
         ruleAppConfig.setApidescription(value);\r
         assertThat(ruleAppConfig.getApidescription(), equalTo(value));\r
     }\r
 \r
+    @Test\r
+    public void getterAndSetter4MsbServerAddr() throws Exception {\r
+        final String value = "msbServerAddr";\r
+        ruleAppConfig.setMsbServerAddr(value);\r
+        assertThat(ruleAppConfig.getMsbServerAddr(), equalTo(value));\r
+    }\r
 }
\ No newline at end of file
diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java
new file mode 100644 (file)
index 0000000..5f3c5c1
--- /dev/null
@@ -0,0 +1,34 @@
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+\r
+package org.openo.holmes.rulemgt.bean.request;\r
+\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.assertThat;\r
+\r
+import org.junit.Test;\r
+\r
+public class CorrelationRestRequestTest {\r
+\r
+    @Test\r
+    public void getterAndSetter4RootURL() {\r
+        final String rootURL = "rootURL";\r
+        CorrelationRestRequest correlationRestRequest = new CorrelationRestRequest();\r
+        correlationRestRequest.setRootURL(rootURL);\r
+        assertThat(correlationRestRequest.getRootURL(), equalTo(rootURL));\r
+    }\r
+}
\ No newline at end of file
diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java
new file mode 100644 (file)
index 0000000..d911f9c
--- /dev/null
@@ -0,0 +1,64 @@
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+\r
+package org.openo.holmes.rulemgt.bolt.enginebolt;\r
+\r
+\r
+import org.apache.http.HttpEntity;\r
+import org.apache.http.HttpResponse;\r
+import org.apache.http.client.HttpClient;\r
+import org.easymock.EasyMock;\r
+import org.junit.Before;\r
+import org.junit.Rule;\r
+import org.junit.Test;\r
+import org.junit.rules.ExpectedException;\r
+import org.openo.holmes.rulemgt.RuleAppConfig;\r
+import org.powermock.api.easymock.PowerMock;\r
+import org.powermock.modules.junit4.rule.PowerMockRule;\r
+import org.powermock.reflect.Whitebox;\r
+\r
+public class EngineServiceTest {\r
+\r
+    @Rule\r
+    public ExpectedException thrown = ExpectedException.none();\r
+    @Rule\r
+    public PowerMockRule powerMockRule = new PowerMockRule();\r
+    private EngineService engineService;\r
+    private HttpEntity httpEntityMock;\r
+    private HttpResponse httpResponseMock;\r
+    private HttpClient httpClient;\r
+    private RuleAppConfig ruleAppConfig = new RuleAppConfig();\r
+\r
+    @Before\r
+    public void setUp() {\r
+        engineService = new EngineService();\r
+        httpEntityMock = PowerMock.createMock(HttpEntity.class);\r
+        httpResponseMock = PowerMock.createMock(HttpResponse.class);\r
+        httpClient = PowerMock.createMock(HttpClient.class);\r
+        Whitebox.setInternalState(engineService, "ruleAppConfig", ruleAppConfig);\r
+    }\r
+\r
+    @Test\r
+    public void getResponseContent_http_entity_is_null() throws Exception {\r
+        EasyMock.expect(httpResponseMock.getEntity()).andReturn(null);\r
+        PowerMock.replayAll();\r
+\r
+        engineService.getResponseContent(httpResponseMock);\r
+\r
+        PowerMock.verifyAll();\r
+    }\r
+}
\ No newline at end of file
index b729def..24839e8 100644 (file)
 \r
 package org.openo.holmes.rulemgt.bolt.enginebolt;\r
 \r
-import static org.hamcrest.core.Is.is;\r
-import static org.hamcrest.core.IsEqual.equalTo;\r
-import static org.junit.Assert.*;\r
 \r
+import static org.hamcrest.MatcherAssert.assertThat;\r
+import static org.hamcrest.Matchers.equalTo;\r
+\r
+import org.apache.http.HttpResponse;\r
+import org.apache.http.StatusLine;\r
+import org.easymock.EasyMock;\r
 import org.junit.Before;\r
+import org.junit.Rule;\r
 import org.junit.Test;\r
+import org.junit.rules.ExpectedException;\r
+import org.openo.holmes.common.exception.CorrelationException;\r
+import org.openo.holmes.common.utils.I18nProxy;\r
 import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
 import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
+import org.powermock.api.easymock.PowerMock;\r
+import org.powermock.reflect.Whitebox;\r
 \r
 public class EngineWrapperTest {\r
 \r
+    @Rule\r
+    public ExpectedException thrown = ExpectedException.none();\r
     private EngineWrapper engineWrapper = new EngineWrapper();\r
+    private EngineService engineServiceMock;\r
+    private HttpResponse httpResponseMock;\r
+    private StatusLine statusLineMock;\r
 \r
     @Before\r
     public void setUp() throws Exception {\r
+        engineServiceMock = PowerMock.createMock(EngineService.class);\r
+        httpResponseMock = PowerMock.createMock(HttpResponse.class);\r
+        statusLineMock = PowerMock.createMock(StatusLine.class);\r
+        Whitebox.setInternalState(engineWrapper, "engineService", engineServiceMock);\r
+    }\r
+\r
+    @Test\r
+    public void deployEngine_invoke_rule_deploy_exception() throws Exception {\r
+        thrown.expect(CorrelationException.class);\r
+        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED);\r
+\r
+        EasyMock.expect(engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class))).andThrow(\r
+                new RuntimeException(""));\r
+        PowerMock.replayAll();\r
+\r
+        engineWrapper.deployEngine(new CorrelationDeployRule4Engine());\r
+\r
+        PowerMock.verifyAll();\r
+    }\r
+\r
+    @Test\r
+    public void deployEngine_http_status_not_ok() throws Exception {\r
+        thrown.expect(CorrelationException.class);\r
+        thrown.expectMessage(I18nProxy.ENGINE_DEPLOY_RULE_FAILED);\r
+\r
+        EasyMock.expect(engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
+                .andReturn(httpResponseMock);\r
+        EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);\r
+        EasyMock.expect(statusLineMock.getStatusCode()).andReturn(400);\r
+\r
+        PowerMock.replayAll();\r
+\r
+        engineWrapper.deployEngine(new CorrelationDeployRule4Engine());\r
+\r
+        PowerMock.verifyAll();\r
+    }\r
+\r
+    @Test\r
+    public void deployEngine_parse_content_exception() throws Exception {\r
+        String content = "";\r
+\r
+        thrown.expect(CorrelationException.class);\r
+        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR);\r
+        EasyMock.expect(engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
+                .andReturn(httpResponseMock);\r
+        EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);\r
+        EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);\r
+        EasyMock.expect(engineServiceMock.getResponseContent(EasyMock.anyObject(HttpResponse.class)))\r
+                .andReturn(content);\r
+\r
+        PowerMock.replayAll();\r
+\r
+        engineWrapper.deployEngine(new CorrelationDeployRule4Engine());\r
+\r
+        PowerMock.verifyAll();\r
+    }\r
+\r
+    @Test\r
+    public void deployEngine_success() throws Exception {\r
+        String content = "{\"package\":\"test\"}";\r
+        EasyMock.expect(engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
+                .andReturn(httpResponseMock);\r
+        EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);\r
+        EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);\r
+        EasyMock.expect(engineServiceMock.getResponseContent(EasyMock.anyObject(HttpResponse.class)))\r
+                .andReturn(content);\r
+        PowerMock.replayAll();\r
+\r
+        String result = engineWrapper.deployEngine(new CorrelationDeployRule4Engine());\r
+\r
+        assertThat(result, equalTo("test"));\r
+\r
+    }\r
+\r
+    @Test\r
+    public void deleteRuleFromEngine_invoke_rule_delete_exception() throws Exception {\r
+        thrown.expect(CorrelationException.class);\r
+        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CALL_DELETE_RULE_REST_FAILED);\r
+\r
+        EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class))).andThrow(\r
+                new RuntimeException(""));\r
+        PowerMock.replayAll();\r
 \r
+        engineWrapper.deleteRuleFromEngine("");\r
+\r
+        PowerMock.verifyAll();\r
     }\r
 \r
     @Test\r
-    public void deployEngine() throws Exception {\r
-        assertThat(engineWrapper.deployEngine(new CorrelationDeployRule4Engine()), equalTo(""));\r
+    public void deleteRuleFromEngine_http_status_not_ok() throws Exception {\r
+        thrown.expect(CorrelationException.class);\r
+        thrown.expectMessage(I18nProxy.ENGINE_DELETE_RULE_FAILED);\r
+\r
+        EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class)))\r
+                .andReturn(httpResponseMock);\r
+        EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);\r
+        EasyMock.expect(statusLineMock.getStatusCode()).andReturn(400);\r
+\r
+        PowerMock.replayAll();\r
+\r
+        engineWrapper.deleteRuleFromEngine("");\r
+\r
+        PowerMock.verifyAll();\r
     }\r
 \r
     @Test\r
-    public void deleteRuleFromEngine() throws Exception {\r
-        assertThat(engineWrapper.deleteRuleFromEngine(""), is(true));\r
+    public void deleteRuleFromEngine_success() throws Exception {\r
+        EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class)))\r
+                .andReturn(httpResponseMock);\r
+        EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);\r
+        EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);\r
+\r
+        PowerMock.replayAll();\r
+\r
+        boolean result = engineWrapper.deleteRuleFromEngine("");\r
+\r
+        assertThat(result, equalTo(true));\r
     }\r
 \r
     @Test\r
-    public void checkRuleFromEngine() throws Exception {\r
-        assertThat(engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine()), is(true));\r
+    public void checkRuleFromEngine_invoke_rule_delete_exception() throws Exception {\r
+        thrown.expect(CorrelationException.class);\r
+        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED);\r
+\r
+        EasyMock.expect(engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class))).andThrow(\r
+                new RuntimeException(""));\r
+        PowerMock.replayAll();\r
+\r
+        engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine());\r
+\r
+        PowerMock.verifyAll();\r
     }\r
 \r
+    @Test\r
+    public void checkRuleFromEngine_http_status_not_ok() throws Exception {\r
+        thrown.expect(CorrelationException.class);\r
+        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CHECK_NO_PASS);\r
+\r
+        EasyMock.expect(engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
+                .andReturn(httpResponseMock);\r
+        EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);\r
+        EasyMock.expect(statusLineMock.getStatusCode()).andReturn(400);\r
+\r
+        PowerMock.replayAll();\r
+\r
+        engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine());\r
+\r
+        PowerMock.verifyAll();\r
+    }\r
+\r
+    @Test\r
+    public void checkRuleFromEngine_success() throws Exception {\r
+        EasyMock.expect(engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
+                .andReturn(httpResponseMock);\r
+        EasyMock.expect(httpResponseMock.getStatusLine()).andReturn(statusLineMock);\r
+        EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);\r
+\r
+        PowerMock.replayAll();\r
+\r
+        boolean result = engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine());\r
+\r
+        assertThat(result, equalTo(true));\r
+    }\r
 }
\ No newline at end of file
index 0b1d151..8df2074 100644 (file)
@@ -30,26 +30,29 @@ import org.junit.Before;
 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
@@ -73,7 +76,6 @@ public class CorrelationRuleQueryDaoTest {
     }\r
 \r
 \r
-\r
     @Test\r
     public void getCorrelationRulesByCondition_db_exception() throws Exception {\r
 \r
@@ -109,6 +111,24 @@ public class CorrelationRuleQueryDaoTest {
         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
index b69a1f7..2a6b5f4 100644 (file)
@@ -44,7 +44,6 @@ public class CorrelationRuleMapperTest {
         expect(resultSet.getObject("params")).andReturn(new Properties());\r
         expect(resultSet.getString("domain")).andReturn("");\r
         expect(resultSet.getString("content")).andReturn("");\r
-        expect(resultSet.getInt("isManual")).andReturn(0);\r
         expect(resultSet.getString("vendor")).andReturn("");\r
         expect(resultSet.getString("package")).andReturn("");\r
         PowerMock.replay(resultSet);\r
index e25c5b3..16a547b 100644 (file)
@@ -19,6 +19,7 @@ package org.openo.holmes.rulemgt.resources;
 import javax.servlet.http.HttpServletRequest;\r
 import javax.ws.rs.WebApplicationException;\r
 import org.easymock.EasyMock;\r
+import org.eclipse.jetty.server.Request;\r
 import org.junit.Before;\r
 import org.junit.Rule;\r
 import org.junit.Test;\r
@@ -45,6 +46,8 @@ public class RuleMgtResourcesTest {
 \r
     private RuleMgtResources ruleMgtResources = new RuleMgtResources();\r
 \r
+    private Request requestMock = PowerMock.createMock(Request.class);\r
+\r
     @Before\r
     public void setUp() throws Exception {\r
         Whitebox.setInternalState(ruleMgtResources, "ruleMgtWrapper", ruleMgtWrapper);\r
@@ -67,6 +70,7 @@ public class RuleMgtResourcesTest {
 \r
     @Test\r
     public void addCorrelationRule_normal() throws Exception {\r
+        StringBuilder stringBuilder = new StringBuilder("http://localhost");\r
         final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();\r
         EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin",\r
                 ruleCreateRequest)).andReturn(new RuleAddAndUpdateResponse());\r
@@ -141,6 +145,19 @@ public class RuleMgtResourcesTest {
         PowerMock.verifyAll();\r
     }\r
 \r
+    @Test\r
+    public void getCorrelationRules_param_translate_exception() {\r
+        thrown.expect(WebApplicationException.class);\r
+\r
+        String queryRequest = "this is error param";\r
+        EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);\r
+\r
+        PowerMock.replayAll();\r
+        ruleMgtResources.getCorrelationRules(request, queryRequest);\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 db13d17..f6d0544 100644 (file)
@@ -45,8 +45,6 @@ import org.openo.holmes.rulemgt.bolt.enginebolt.EngineWrapper;
 import org.openo.holmes.rulemgt.db.CorrelationRuleDao;\r
 import org.openo.holmes.rulemgt.db.CorrelationRuleQueryDao;\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
 \r
@@ -54,7 +52,6 @@ public class RuleMgtWrapperTest {
 \r
     @Rule\r
     public ExpectedException thrown = ExpectedException.none();\r
-\r
     @Rule\r
     public PowerMockRule powerMockRule = new PowerMockRule();\r
 \r
@@ -83,144 +80,73 @@ public class RuleMgtWrapperTest {
         Whitebox.setInternalState(ruleMgtWrapper, "daoUtil", dbDaoUtilMock);\r
         Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleQueryDao", correlationRuleQueryDaoMock);\r
         Whitebox.setInternalState(ruleMgtWrapper, "engineWarpper", engineWrapperMock);\r
+        Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleDao", correlationRuleDaoMock);\r
 \r
         PowerMock.resetAll();\r
     }\r
 \r
     @Test\r
-    public void addCorrelationRule_name_is_null() throws Exception {\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
-                "Mocked contents.", 0));\r
+    public void initDaoUtil_normal() {\r
+        ruleMgtWrapper.initDaoUtil();\r
     }\r
 \r
     @Test\r
-    public void addCorrelationRule_name_is_empty() throws Exception {\r
+    public void addCorrelationRule_name_is_null() throws Exception {\r
         thrown.expect(CorrelationException.class);\r
-        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_RULE_NAME_IS_EMPTY);\r
+        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_RULE_NAME_CANNOT_BE_EMPTY);\r
 \r
-        ruleMgtWrapper.addCorrelationRule("admin", createRuleCreateRequest("", "This is a rule for testing.",\r
+        ruleMgtWrapper.addCorrelationRule(USER_NAME, createRuleCreateRequest(null, "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
+    public void addCorrelationRule_request_null() 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.queryRuleByRuleName(ruleName))\r
-                .andThrow(new RuntimeException(""));\r
-\r
-        PowerMock.replayAll();\r
-\r
-        ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest);\r
+        thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY));\r
 \r
-        PowerMock.verifyAll();\r
+        ruleMgtWrapper.addCorrelationRule(USER_NAME, null);\r
     }\r
 \r
     @Test\r
-    public void addCorrelationRule_duplicated_rule() 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
-        CorrelationRule correlationRule = convertCreateRequest2CorrelationRule(ruleCreateRequest);\r
-\r
+    public void addCorrelationRule_name_is_empty() throws Exception {\r
         thrown.expect(CorrelationException.class);\r
-        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_REPEAT_RULE_NAME);\r
-\r
-        EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
-                correlationRuleDaoMock);\r
-        EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(correlationRule);\r
-\r
-        PowerMock.replayAll();\r
-\r
-        ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest);\r
+        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_RULE_NAME_CANNOT_BE_EMPTY);\r
 \r
-        PowerMock.verifyAll();\r
+        ruleMgtWrapper.addCorrelationRule("admin", createRuleCreateRequest("", "This is a rule for testing.",\r
+                "Mocked contents.", 0));\r
     }\r
 \r
     @Test\r
-    public void addCorrelationRule_rule_deploy_verify_failure() 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
+    public void addCorrelationRule_content_is_empty() throws Exception {\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 CorrelationException(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED));\r
+        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CONTENT_CANNOT_BE_EMPTY);\r
 \r
-        PowerMock.replayAll();\r
-\r
-        ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest);\r
-\r
-        PowerMock.verifyAll();\r
+        ruleMgtWrapper.addCorrelationRule("admin", createRuleCreateRequest("test", "This is a rule for testing.",\r
+                "", 0));\r
     }\r
 \r
     @Test\r
-    public void addCorrelationRule_rule_deploy_rule_enabled_failure() throws Exception {\r
-\r
-        final String ruleName = "Rule-001";\r
-\r
-        RuleCreateRequest ruleCreateRequest = createRuleCreateRequest(ruleName, "This is a rule for testing.",\r
-                "Mocked contents.", 1);\r
-\r
+    public void addCorrelationRule_enabled_is_off_limit() throws Exception {\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
-                correlationRuleDaoMock);\r
-        EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(null);\r
-        EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
-                .andReturn(true);\r
-        EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
-                .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED));\r
-\r
-        PowerMock.replayAll();\r
-\r
-        ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest);\r
+        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
 \r
-        PowerMock.verifyAll();\r
+        ruleMgtWrapper.addCorrelationRule("admin", createRuleCreateRequest("test", "This is a rule for testing.",\r
+                "Mocked contents.", 3));\r
     }\r
 \r
     @Test\r
-    public void addCorrelationRule_rule_save_failure() throws Exception {\r
+    public void addCorrelationRule_duplicated_rule() throws Exception {\r
+\r
         final String ruleName = "Rule-001";\r
 \r
         RuleCreateRequest ruleCreateRequest = createRuleCreateRequest(ruleName, "This is a rule for testing.",\r
-                "Mocked contents.", 1);\r
+                "Mocked contents.", 0);\r
+        CorrelationRule correlationRule = convertCreateRequest2CorrelationRule(ruleCreateRequest);\r
 \r
         thrown.expect(CorrelationException.class);\r
-        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_CREATE_RULE_FAILED);\r
-\r
-        EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
-                correlationRuleDaoMock).times(2);\r
-        EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(null);\r
-        EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
-                .andReturn(true);\r
-        EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
-                .andReturn("package-001");\r
-        EasyMock.expect(correlationRuleDaoMock.saveRule(EasyMock.anyObject(CorrelationRule.class)))\r
-                .andThrow(new RuntimeException("any message"));\r
+        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_REPEAT_RULE_NAME);\r
 \r
+        EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(correlationRule);\r
         PowerMock.replayAll();\r
 \r
         ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest);\r
@@ -238,8 +164,6 @@ public class RuleMgtWrapperTest {
         CorrelationRule correlationRuleRet = new CorrelationRule();\r
         correlationRuleRet.setRid("rule_" + System.currentTimeMillis());\r
 \r
-        EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
-                correlationRuleDaoMock).times(2);\r
         EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(null);\r
         EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
                 .andReturn(true);\r
@@ -265,268 +189,69 @@ public class RuleMgtWrapperTest {
     }\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(CorrelationException.class);\r
-        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE);\r
-\r
-        EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
-                correlationRuleDaoMock);\r
-        EasyMock.expect(correlationRuleDaoMock.getRuleByRid(EasyMock.anyObject(String.class))).andReturn(null);\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_status_illegal_with_contents() throws Exception {\r
-        thrown.expect(CorrelationException.class);\r
-        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
-\r
-        RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
-                "desc", "contents", 3);\r
-        CorrelationRule correlationRule = convertUpdateRequest2CorrelationRule(ruleUpdateRequest);\r
-        correlationRule.setContent("previous contents");\r
-\r
-        EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
-                correlationRuleDaoMock);\r
-        EasyMock.expect(correlationRuleDaoMock.getRuleByRid(EasyMock.anyObject(String.class)))\r
-                .andReturn(correlationRule);\r
-\r
-        PowerMock.replayAll();\r
-\r
-        ruleMgtWrapper.updateCorrelationRule(USER_NAME, ruleUpdateRequest);\r
-\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void updateCorrelationRule_rule_status_illegal_with_null_contents() throws Exception {\r
-        thrown.expect(CorrelationException.class);\r
-        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
-\r
-        RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
-                "desc", null, 3);\r
-        CorrelationRule correlationRule = convertUpdateRequest2CorrelationRule(ruleUpdateRequest);\r
-        correlationRule.setContent("previous contents");\r
-\r
-        EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
-                correlationRuleDaoMock);\r
-        EasyMock.expect(correlationRuleDaoMock.getRuleByRid(EasyMock.anyObject(String.class)))\r
-                .andReturn(correlationRule);\r
-\r
-        PowerMock.replayAll();\r
-\r
-        ruleMgtWrapper.updateCorrelationRule(USER_NAME, ruleUpdateRequest);\r
-\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void updateCorrelationRule_rule_disabled_update_failure() throws Exception {\r
-        thrown.expect(CorrelationException.class);\r
-        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_UPDATE_RULE_FAILED);\r
-\r
-        RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
-                "desc", "contents", 0);\r
-        CorrelationRule correlationRuleOld = convertUpdateRequest2CorrelationRule(ruleUpdateRequest);\r
-        correlationRuleOld.setContent("previous contents");\r
-\r
-        EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
-                correlationRuleDaoMock).anyTimes();\r
-        EasyMock.expect(correlationRuleDaoMock.getRuleByRid(EasyMock.anyObject(String.class)))\r
-                .andReturn(correlationRuleOld);\r
-        correlationRuleDaoMock.updateRule(EasyMock.anyObject(CorrelationRule.class));\r
-        EasyMock.expectLastCall().andThrow(new RuntimeException("Failed to update the rule."));\r
-\r
-        PowerMock.replayAll();\r
-\r
-        ruleMgtWrapper.updateCorrelationRule(USER_NAME, ruleUpdateRequest);\r
-\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void updateCorrelationRule_rule_disabled_deploy_verify_exception() throws Exception {\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
-                "desc", null, 0);\r
-        CorrelationRule correlationRuleOld = convertUpdateRequest2CorrelationRule(ruleUpdateRequest);\r
-        correlationRuleOld.setContent("previous contents");\r
-\r
-        EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
-                correlationRuleDaoMock).anyTimes();\r
-        EasyMock.expect(correlationRuleDaoMock.getRuleByRid(EasyMock.anyObject(String.class)))\r
-                .andReturn(correlationRuleOld);\r
+    public void updateCorrelationRule_normal() throws Exception {\r
+        CorrelationRule oldCorrelationRule = new CorrelationRule();\r
+        oldCorrelationRule.setRid("rule_1");\r
+        oldCorrelationRule.setName("name");\r
+        oldCorrelationRule.setDescription("des1");\r
+        oldCorrelationRule.setContent("content");\r
+        oldCorrelationRule.setPackageName("testName");\r
+        oldCorrelationRule.setEnabled(1);\r
+        RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_1", "des2", "contetnt2", 1);\r
+\r
+        EasyMock.expect(correlationRuleDaoMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule);\r
+        EasyMock.expect(engineWrapperMock.deleteRuleFromEngine("testName")).andReturn(true);\r
         correlationRuleDaoMock.updateRule(EasyMock.anyObject(CorrelationRule.class));\r
         EasyMock.expectLastCall();\r
         EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
-                .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED));\r
-\r
+                .andReturn(true);\r
+        EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
+                .andReturn("packageName1");\r
         PowerMock.replayAll();\r
 \r
         ruleMgtWrapper.updateCorrelationRule(USER_NAME, ruleUpdateRequest);\r
 \r
         PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void updateCorrelationRule_rule_disabled_deploy_verify_false() throws Exception {\r
-\r
-        RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
-                "desc", null, 0);\r
-        CorrelationRule correlationRuleOld = convertUpdateRequest2CorrelationRule(ruleUpdateRequest);\r
-        correlationRuleOld.setContent("previous contents");\r
-\r
-        EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
-                correlationRuleDaoMock).anyTimes();\r
-        EasyMock.expect(correlationRuleDaoMock.getRuleByRid(EasyMock.anyObject(String.class)))\r
-                .andReturn(correlationRuleOld);\r
-        correlationRuleDaoMock.updateRule(EasyMock.anyObject(CorrelationRule.class));\r
-        EasyMock.expectLastCall();\r
-        EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
-                .andReturn(false);\r
-\r
-        PowerMock.replayAll();\r
-\r
-        RuleAddAndUpdateResponse response = ruleMgtWrapper.updateCorrelationRule(USER_NAME, ruleUpdateRequest);\r
 \r
-        assertThat(response.getRuleId(), equalTo(ruleUpdateRequest.getRuleId()));\r
-\r
-        PowerMock.verifyAll();\r
+        assertThat(oldCorrelationRule.getRid(), equalTo(ruleUpdateRequest.getRuleId()));\r
     }\r
 \r
     @Test\r
-    public void updateCorrelationRule_rule_enabled_engine_delete_failure() throws Exception {\r
-        thrown.expect(CorrelationException.class);\r
-        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_UPDATE_RULE_FAILED);\r
-\r
-        RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
-                "desc", null, 1);\r
-        CorrelationRule correlationRuleOld = convertUpdateRequest2CorrelationRule(ruleUpdateRequest);\r
-        correlationRuleOld.setContent("previous contents");\r
-\r
-        EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
-                correlationRuleDaoMock).anyTimes();\r
-        EasyMock.expect(correlationRuleDaoMock.getRuleByRid(EasyMock.anyObject(String.class)))\r
-                .andReturn(correlationRuleOld);\r
-        engineWrapperMock.deleteRuleFromEngine(correlationRuleOld.getPackageName());\r
-        EasyMock.expectLastCall().andThrow(new RuntimeException("Failed to delete the rule from the engine."));\r
+    public void updateCorrelationRule_param_no_change() throws Exception {\r
+        CorrelationRule oldCorrelationRule = new CorrelationRule();\r
+        oldCorrelationRule.setRid("rule_1");\r
+        oldCorrelationRule.setName("name");\r
+        oldCorrelationRule.setDescription("des1");\r
+        oldCorrelationRule.setContent("content");\r
+        oldCorrelationRule.setPackageName("testName");\r
+        oldCorrelationRule.setEnabled(1);\r
+        RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_1", "des1", "content", 1);\r
+\r
+        EasyMock.expect(correlationRuleDaoMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule);\r
 \r
         PowerMock.replayAll();\r
 \r
         ruleMgtWrapper.updateCorrelationRule(USER_NAME, ruleUpdateRequest);\r
 \r
         PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void updateCorrelationRule_rule_enabled_engine_deploy_failure() throws Exception {\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
-                "desc", null, 1);\r
-        CorrelationRule correlationRuleOld = convertUpdateRequest2CorrelationRule(ruleUpdateRequest);\r
-        correlationRuleOld.setContent("previous contents");\r
-\r
-        EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
-                correlationRuleDaoMock).anyTimes();\r
-        EasyMock.expect(correlationRuleDaoMock.getRuleByRid(EasyMock.anyObject(String.class)))\r
-                .andReturn(correlationRuleOld);\r
-        EasyMock.expect(engineWrapperMock.deleteRuleFromEngine(correlationRuleOld.getPackageName())).andReturn(true);\r
-        correlationRuleDaoMock.updateRule(EasyMock.anyObject(CorrelationRule.class));\r
-        EasyMock.expectLastCall();\r
-        EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
-                .andReturn(true);\r
-        EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
-                .andThrow(new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED));\r
-\r
-        PowerMock.replayAll();\r
 \r
-        ruleMgtWrapper.updateCorrelationRule(USER_NAME, ruleUpdateRequest);\r
-\r
-        PowerMock.verifyAll();\r
+        assertThat(oldCorrelationRule.getRid(), equalTo(ruleUpdateRequest.getRuleId()));\r
     }\r
 \r
     @Test\r
-    public void updateCorrelationRule_rule_enabled_deploy_rule_enabled() throws Exception {\r
-\r
-        RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
-                "desc", null, 1);\r
-        CorrelationRule correlationRuleOld = convertUpdateRequest2CorrelationRule(ruleUpdateRequest);\r
-        correlationRuleOld.setContent("previous contents");\r
+    public void updateCorrelationRule_rule_not_exist() throws Exception {\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
-                correlationRuleDaoMock).anyTimes();\r
-        EasyMock.expect(correlationRuleDaoMock.getRuleByRid(EasyMock.anyObject(String.class)))\r
-                .andReturn(correlationRuleOld);\r
-        EasyMock.expect(engineWrapperMock.deleteRuleFromEngine(correlationRuleOld.getPackageName())).andReturn(true);\r
-        correlationRuleDaoMock.updateRule(EasyMock.anyObject(CorrelationRule.class));\r
-        EasyMock.expectLastCall();\r
-        EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))\r
-                .andReturn(true);\r
-        EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))\r
-                .andReturn("package-name");\r
+        EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(EasyMock.anyObject(String.class))).andReturn(null);\r
 \r
         PowerMock.replayAll();\r
 \r
-        RuleAddAndUpdateResponse response = ruleMgtWrapper.updateCorrelationRule(USER_NAME, ruleUpdateRequest);\r
-\r
-        assertThat(response.getRuleId(), equalTo(ruleUpdateRequest.getRuleId()));\r
+        ruleMgtWrapper.updateCorrelationRule(USER_NAME, new RuleUpdateRequest());\r
 \r
         PowerMock.verifyAll();\r
     }\r
 \r
-    @Test\r
-    public void checkCorrelation_content_null() throws Exception {\r
-        RuleUpdateRequest ruleCreateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
-                "desc", null, 0);\r
-        CorrelationRule correlationRuleOld = convertUpdateRequest2CorrelationRule(ruleCreateRequest);\r
-        CorrelationRule correlationRuleNew = convertUpdateRequest2CorrelationRule(ruleCreateRequest);\r
-        correlationRuleOld.setContent("previous contents");\r
-\r
-        ruleMgtWrapper.checkCorrelation(correlationRuleNew, correlationRuleOld);\r
-\r
-        assertThat(correlationRuleNew.getContent(), equalTo(correlationRuleOld.getContent()));\r
-    }\r
-\r
-    @Test\r
-    public void checkCorrelation_illegal_status() throws Exception {\r
-        thrown.expect(CorrelationException.class);\r
-        thrown.expectMessage(I18nProxy.RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR);\r
-\r
-        RuleUpdateRequest ruleCreateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
-                "desc", null, 2);\r
-        CorrelationRule correlationRuleOld = convertUpdateRequest2CorrelationRule(ruleCreateRequest);\r
-        CorrelationRule correlationRuleNew = convertUpdateRequest2CorrelationRule(ruleCreateRequest);\r
-        correlationRuleOld.setContent("previous contents");\r
-\r
-        ruleMgtWrapper.checkCorrelation(correlationRuleNew, correlationRuleOld);\r
-    }\r
-\r
-\r
     @Test\r
     public void deleteCorrelationRule_request_null() throws Exception {\r
         thrown.expect(CorrelationException.class);\r
@@ -535,25 +260,6 @@ public class RuleMgtWrapperTest {
         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(CorrelationException.class);\r
@@ -563,7 +269,7 @@ public class RuleMgtWrapperTest {
 \r
         EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
                 correlationRuleDaoMock).anyTimes();\r
-        EasyMock.expect(correlationRuleDaoMock.getRuleByRid(ruleDeleteRequest.getRuleId()))\r
+        EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(ruleDeleteRequest.getRuleId()))\r
                 .andReturn(null);\r
 \r
         PowerMock.replayAll();\r
@@ -573,69 +279,16 @@ public class RuleMgtWrapperTest {
         PowerMock.verifyAll();\r
     }\r
 \r
-    @Test\r
-    public void deleteCorrelationRule_rule_enabled_engine_delete_exception() throws Exception {\r
-        thrown.expect(CorrelationException.class);\r
-        thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_DELETE_RULE_FAILED));\r
-\r
-        RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());\r
-        RuleUpdateRequest ruleCreateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
-                "desc", "contents", 1);\r
-        CorrelationRule correlationRule = convertUpdateRequest2CorrelationRule(ruleCreateRequest);\r
-\r
-        EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
-                correlationRuleDaoMock).anyTimes();\r
-        EasyMock.expect(correlationRuleDaoMock.getRuleByRid(ruleDeleteRequest.getRuleId()))\r
-                .andReturn(correlationRule);\r
-        EasyMock.expect(engineWrapperMock.deleteRuleFromEngine(correlationRule.getPackageName()))\r
-                .andThrow(new RuntimeException("Failed to delete the rule from the engine"));\r
-\r
-        PowerMock.replayAll();\r
-\r
-        ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
-\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void deleteCorrelationRule_rule_disabled_delete_exception() throws Exception {\r
-        thrown.expect(CorrelationException.class);\r
-        thrown.expectMessage((I18nProxy.RULE_MANAGEMENT_DELETE_RULE_FAILED));\r
-\r
-        RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());\r
-        RuleUpdateRequest ruleCreateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
-                "desc", "contents", 0);\r
-        CorrelationRule correlationRule = convertUpdateRequest2CorrelationRule(ruleCreateRequest);\r
-\r
-        EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
-                correlationRuleDaoMock).anyTimes();\r
-        EasyMock.expect(correlationRuleDaoMock.getRuleByRid(ruleDeleteRequest.getRuleId()))\r
-                .andReturn(correlationRule);\r
-        correlationRuleDaoMock.deleteRule(correlationRule);\r
-        EasyMock.expectLastCall().andThrow(new RuntimeException("Failed to delete the rule from the DB"));\r
-\r
-        PowerMock.replayAll();\r
-\r
-        ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
-\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
     @Test\r
     public void deleteCorrelationRule_normal() throws Exception {\r
         RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());\r
-        RuleUpdateRequest ruleCreateRequest = createRuleUpdateRequest("rule_" + System.currentTimeMillis(),\r
-                "desc", "contents", 1);\r
-        CorrelationRule correlationRule = convertUpdateRequest2CorrelationRule(ruleCreateRequest);\r
-\r
-        EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(\r
-                correlationRuleDaoMock).anyTimes();\r
-        EasyMock.expect(correlationRuleDaoMock.getRuleByRid(ruleDeleteRequest.getRuleId()))\r
+        CorrelationRule correlationRule = new CorrelationRule();\r
+        correlationRule.setEnabled(1);\r
+        EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(ruleDeleteRequest.getRuleId()))\r
                 .andReturn(correlationRule);\r
-        EasyMock.expect(engineWrapperMock.deleteRuleFromEngine(correlationRule.getPackageName())).andReturn(true);\r
-        correlationRuleDaoMock.deleteRule(correlationRule);\r
+        EasyMock.expect(engineWrapperMock.deleteRuleFromEngine(EasyMock.anyObject(String.class))).andReturn(true);\r
+        correlationRuleDaoMock.deleteRule(EasyMock.anyObject(CorrelationRule.class));\r
         EasyMock.expectLastCall();\r
-\r
         PowerMock.replayAll();\r
 \r
         ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
@@ -683,9 +336,8 @@ public class RuleMgtWrapperTest {
             correlationRule.setContent("content" + i);\r
             correlationRule.setName("name" + i);\r
             correlationRule.setRid("rule_" + i);\r
-            correlationRule.setIsManual(i % 2);\r
             correlationRule.setEngineType("engineType" + (i % 2 + 1));\r
-            correlationRule.setEngineId("engineId" + i);\r
+            correlationRule.setEngineID("engineId" + i);\r
             correlationRule.setCreateTime(new Date());\r
             correlationRule.setCreator(USER_NAME);\r
             correlationRule.setDescription("description" + i);\r