Add new UT Codes
authorGuangrongFu <fu.guangrong@zte.com.cn>
Sat, 18 Feb 2017 08:32:01 +0000 (16:32 +0800)
committerGuangrongFu <fu.guangrong@zte.com.cn>
Sat, 18 Feb 2017 08:32:01 +0000 (16:32 +0800)
Change-Id: I3b9ffb29274a1b28ae31055a5052a90af643682a
Issue-ID: HOLMES-43
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
rulemgt/src/main/java/org/openo/holmes/rulemgt/wrapper/RuleMgtWrapper.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/RuleActiveAppTest.java
rulemgt/src/test/java/org/openo/holmes/rulemgt/RuleAppConfigTest.java [new file with mode: 0644]
rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java [new file with mode: 0644]
rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java [new file with mode: 0644]
rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/RuleQueryConditionTest.java [new file with mode: 0644]
rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java [new file with mode: 0644]
rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java [new file with mode: 0644]
rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java [new file with mode: 0644]
rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/response/RuleResult4APITest.java [new file with mode: 0644]

index 67183b7..b1ed44e 100644 (file)
@@ -141,7 +141,7 @@ public class RuleMgtWrapper {
                         .getJdbiDaoByOnDemand(CorrelationRuleDao.class)\r
                         .getRuleByRid(ruleDeleteRequest.getRuleId());\r
             } catch (Exception e) {\r
-                throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_DB_ERROR);\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
index 69910c6..b025e01 100644 (file)
 
 package org.openo.holmes.rulemgt;
 
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsEqual.equalTo;
+
+import org.junit.Test;
+
 public class RuleActiveAppTest {
 
+    @Test
+    public void getName() throws Exception {
+        RuleActiveApp app = new RuleActiveApp();
+        assertThat(app.getName(), equalTo("Holmes Rule Management ActiveApp APP "));
+    }
+
     public static void main(String[] args) throws Exception {
         String filePath = "E:\\code\\OES_Analytics_FM_Relation\\correlation-mgt\\rulemgt-standalone\\src\\assembly\\resource\\conf\\correlation-rule.yml";
         new RuleActiveApp().run(new String[]{"server", filePath});
diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/RuleAppConfigTest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/RuleAppConfigTest.java
new file mode 100644 (file)
index 0000000..5724da2
--- /dev/null
@@ -0,0 +1,60 @@
+/**\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;\r
+\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.hamcrest.core.IsNull.notNullValue;\r
+import static org.junit.Assert.*;\r
+\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
+        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
+}
\ No newline at end of file
diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java
new file mode 100644 (file)
index 0000000..59e020c
--- /dev/null
@@ -0,0 +1,32 @@
+/**\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 static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.*;\r
+\r
+import org.junit.Test;\r
+\r
+public class CorrelationCheckRule4EngineTest {\r
+    @Test\r
+    public void getterAndSetter4Content(){\r
+        final String value = "content";\r
+        CorrelationCheckRule4Engine correlationCheckRule4Engine = new CorrelationCheckRule4Engine();\r
+        correlationCheckRule4Engine.setContent(value);\r
+        assertThat(correlationCheckRule4Engine.getContent(), equalTo(value));\r
+    }\r
+}
\ No newline at end of file
diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java
new file mode 100644 (file)
index 0000000..8a9b8ec
--- /dev/null
@@ -0,0 +1,40 @@
+/**\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 static org.junit.Assert.*;\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+\r
+import org.junit.Test;\r
+\r
+public class CorrelationDeployRule4EngineTest {\r
+    @Test\r
+    public void getterAndSetter4Content(){\r
+        final String value = "content";\r
+        CorrelationDeployRule4Engine correlationDeployRule4Engine = new CorrelationDeployRule4Engine();\r
+        correlationDeployRule4Engine.setContent(value);\r
+        assertThat(correlationDeployRule4Engine.getContent(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4EngineId(){\r
+        final String value = "engineId";\r
+        CorrelationDeployRule4Engine correlationDeployRule4Engine = new CorrelationDeployRule4Engine();\r
+        correlationDeployRule4Engine.setEngineId(value);\r
+        assertThat(correlationDeployRule4Engine.getEngineId(), equalTo(value));\r
+    }\r
+}
\ No newline at end of file
diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/RuleQueryConditionTest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/RuleQueryConditionTest.java
new file mode 100644 (file)
index 0000000..8bb5b8b
--- /dev/null
@@ -0,0 +1,65 @@
+/**\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 static org.hamcrest.core.Is.is;\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.*;\r
+\r
+import org.junit.Test;\r
+\r
+public class RuleQueryConditionTest {\r
+    @Test\r
+    public void getterAndSetter4RuleId(){\r
+        final String value = "ruleId";\r
+        RuleQueryCondition ruleQueryCondition = new RuleQueryCondition();\r
+        ruleQueryCondition.setRid(value);\r
+        assertThat(ruleQueryCondition.getRid(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4RuleName(){\r
+        final String value = "ruleName";\r
+        RuleQueryCondition ruleQueryCondition = new RuleQueryCondition();\r
+        ruleQueryCondition.setName(value);\r
+        assertThat(ruleQueryCondition.getName(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4Creator(){\r
+        final String value = "admin";\r
+        RuleQueryCondition ruleQueryCondition = new RuleQueryCondition();\r
+        ruleQueryCondition.setCreator(value);\r
+        assertThat(ruleQueryCondition.getCreator(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4Modifier(){\r
+        final String value = "admin";\r
+        RuleQueryCondition ruleQueryCondition = new RuleQueryCondition();\r
+        ruleQueryCondition.setModifier(value);\r
+        assertThat(ruleQueryCondition.getModifier(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4Enabled(){\r
+        final int value = 0;\r
+        RuleQueryCondition ruleQueryCondition = new RuleQueryCondition();\r
+        ruleQueryCondition.setEnabled(value);\r
+        assertThat(ruleQueryCondition.getEnabled(), is(value));\r
+    }\r
+}
\ No newline at end of file
diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java
new file mode 100644 (file)
index 0000000..4cd4744
--- /dev/null
@@ -0,0 +1,58 @@
+/**\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 static org.hamcrest.core.Is.is;\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.*;\r
+\r
+import org.junit.Test;\r
+\r
+\r
+public class RuleUpdateRequestTest {\r
+    @Test\r
+    public void getterAndSetter4RuleId(){\r
+        final String value = "ruleId";\r
+        RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();\r
+        ruleUpdateRequest.setRuleId(value);\r
+        assertThat(ruleUpdateRequest.getRuleId(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4Description(){\r
+        final String value = "desc";\r
+        RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();\r
+        ruleUpdateRequest.setDescription(value);\r
+        assertThat(ruleUpdateRequest.getDescription(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4Content(){\r
+        final String value = "content";\r
+        RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();\r
+        ruleUpdateRequest.setContent(value);\r
+        assertThat(ruleUpdateRequest.getContent(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4Enabled(){\r
+        final int value = 0;\r
+        RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();\r
+        ruleUpdateRequest.setEnabled(value);\r
+        assertThat(ruleUpdateRequest.getEnabled(), is(value));\r
+    }\r
+}
\ No newline at end of file
diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java
new file mode 100644 (file)
index 0000000..82731d6
--- /dev/null
@@ -0,0 +1,32 @@
+/**\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.response;\r
+\r
+import static org.junit.Assert.*;\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+\r
+import org.junit.Test;\r
+\r
+public class RuleAddAndUpdateResponseTest {\r
+    @Test\r
+    public void getterAndSetter4RuleId(){\r
+        final String value = "ruleId";\r
+        RuleAddAndUpdateResponse ruleAddAndUpdateResponse = new RuleAddAndUpdateResponse();\r
+        ruleAddAndUpdateResponse.setRuleId(value);\r
+        assertThat(ruleAddAndUpdateResponse.getRuleId(), equalTo(value));\r
+    }\r
+}
\ No newline at end of file
diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java
new file mode 100644 (file)
index 0000000..c6e0a7e
--- /dev/null
@@ -0,0 +1,45 @@
+/**\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.response;\r
+\r
+import static org.hamcrest.core.Is.is;\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.assertThat;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import org.junit.Test;\r
+\r
+public class RuleQueryListResponseTest {\r
+\r
+    @Test\r
+    public void getterAndSetter4CorrelationRules(){\r
+        final List<RuleResult4API> value = new ArrayList<>();\r
+        RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();\r
+        ruleQueryListResponse.setCorrelationRules(value);\r
+        assertThat(ruleQueryListResponse.getCorrelationRules(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4TotalCount(){\r
+        final int value = 0;\r
+        RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();\r
+        ruleQueryListResponse.setTotalCount(value);\r
+        assertThat(ruleQueryListResponse.getTotalCount(), is(value));\r
+    }\r
+\r
+}
\ No newline at end of file
diff --git a/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/response/RuleResult4APITest.java b/rulemgt/src/test/java/org/openo/holmes/rulemgt/bean/response/RuleResult4APITest.java
new file mode 100644 (file)
index 0000000..3af245e
--- /dev/null
@@ -0,0 +1,99 @@
+/**\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.response;\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 java.util.Date;\r
+import org.junit.Test;\r
+\r
+public class RuleResult4APITest {\r
+\r
+    @Test\r
+    public void getterAndSetter4RuleId(){\r
+        final String value = "ruleId";\r
+        RuleResult4API ruleResult4API = new RuleResult4API();\r
+        ruleResult4API.setRuleId(value);\r
+        assertThat(ruleResult4API.getRuleId(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4RuleName(){\r
+        final String value = "ruleName";\r
+        RuleResult4API ruleResult4API = new RuleResult4API();\r
+        ruleResult4API.setRuleName(value);\r
+        assertThat(ruleResult4API.getRuleName(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4Description(){\r
+        final String value = "desc";\r
+        RuleResult4API ruleResult4API = new RuleResult4API();\r
+        ruleResult4API.setDescription(value);\r
+        assertThat(ruleResult4API.getDescription(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4Content(){\r
+        final String value = "content";\r
+        RuleResult4API ruleResult4API = new RuleResult4API();\r
+        ruleResult4API.setContent(value);\r
+        assertThat(ruleResult4API.getContent(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4CreateTime(){\r
+        final Date value = new Date();\r
+        RuleResult4API ruleResult4API = new RuleResult4API();\r
+        ruleResult4API.setCreateTime(value);\r
+        assertThat(ruleResult4API.getCreateTime(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4Creator(){\r
+        final String value = "admin";\r
+        RuleResult4API ruleResult4API = new RuleResult4API();\r
+        ruleResult4API.setCreator(value);\r
+        assertThat(ruleResult4API.getCreator(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4UpdateTime(){\r
+        final Date value = new Date();\r
+        RuleResult4API ruleResult4API = new RuleResult4API();\r
+        ruleResult4API.setUpdateTime(value);\r
+        assertThat(ruleResult4API.getUpdateTime(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4Modifier(){\r
+        final String value = "admin";\r
+        RuleResult4API ruleResult4API = new RuleResult4API();\r
+        ruleResult4API.setModifier(value);\r
+        assertThat(ruleResult4API.getModifier(), equalTo(value));\r
+    }\r
+\r
+    @Test\r
+    public void getterAndSetter4Enabled(){\r
+        final int value = 0;\r
+        RuleResult4API ruleResult4API = new RuleResult4API();\r
+        ruleResult4API.setEnabled(value);\r
+        assertThat(ruleResult4API.getEnabled(), is(value));\r
+    }\r
+}
\ No newline at end of file