summaryrefslogtreecommitdiffstats
path: root/rulemgt/src
diff options
context:
space:
mode:
authorGuangrongFu <fu.guangrong@zte.com.cn>2017-02-23 18:24:50 +0800
committerGuangrongFu <fu.guangrong@zte.com.cn>2017-02-23 18:24:50 +0800
commit27e71c9c0f9ec16e377a5f21ec4f72bbd5c1efc0 (patch)
tree173d77985875dbe48751d18393b909a4eab72298 /rulemgt/src
parent2a7cf2d3d4a5a3551346cf52a19c27ef21ae4946 (diff)
Do some Optimizations on the UT Class
Get the getter name using PropertyDescriptor Change-Id: Ib51ac622c316f20fb8fd365b66529eda265f65d1 Issue-ID: HOLMES-47 Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'rulemgt/src')
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java15
1 files changed, 8 insertions, 7 deletions
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java
index b3e6b38..5096db3 100644
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java
+++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/db/CorrelationRuleQueryDao.java
@@ -15,6 +15,7 @@
*/
package org.openo.holmes.rulemgt.db;
+import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -92,16 +93,16 @@ public class CorrelationRuleQueryDao {
String whereSql = " WHERE ";
for (Field field : fields) {
- String methodName = getMethodName(field);
-
- // If these lines are removed, Jacoco will cause an exception when calculation the coverage of UT
- // Remove it if someday Jacoco solve this problem
- if (methodName.contains("jacoco")){
+ // Jacoco will cause an exception when calculating the coverage of the UT
+ // Remove this if jacoco solves this problem in the future
+ if (field.getName().contains("jacoco")){
continue;
}
- Method method = clazz.getMethod(methodName);
- Object o = method.invoke(ruleQueryCondition);
+ PropertyDescriptor pd = new PropertyDescriptor(field.getName(),
+ clazz);
+ Method getMethod = pd.getReadMethod();
+ Object o = getMethod.invoke(ruleQueryCondition);
if (o != null) {
String tempName = field.getName();
if ("enabled".equals(tempName) && (int) o != RuleMgtConstant.STATUS_RULE_ALL) {