diff options
author | Guangrong Fu <fu.guangrong@zte.com.cn> | 2017-08-07 12:30:35 +0800 |
---|---|---|
committer | Guangrong Fu <fu.guangrong@zte.com.cn> | 2017-08-07 12:41:11 +0800 |
commit | 20a1514bf93035472d4f940f00a357106d4bec1f (patch) | |
tree | 53c8e874f204f4b5ac7e64cbfdf783dbd2e9e019 /rulemgt/src/test/java/org/onap | |
parent | 40f54b8acefce59ecbd9e9fde60e062373243982 (diff) |
Change the groupid from openo to onap
Change the groupid and package paths to onap.
Change-Id: I8432e9ac2c979bbc36e10e6a702c6f04fc41446a
Issue-ID: HOLMES-7
Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'rulemgt/src/test/java/org/onap')
18 files changed, 1636 insertions, 0 deletions
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleActiveAppTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleActiveAppTest.java new file mode 100644 index 0000000..cd79ae8 --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleActiveAppTest.java @@ -0,0 +1,36 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.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 = "C:\\correlation-rule.yml"; + new RuleActiveApp().run(new String[]{"server", filePath}); + } +}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAppConfigTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAppConfigTest.java new file mode 100644 index 0000000..d411603 --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAppConfigTest.java @@ -0,0 +1,59 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+
+import io.dropwizard.db.DataSourceFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+public class RuleAppConfigTest {
+
+ private RuleAppConfig ruleAppConfig;
+
+ @Before
+ public void setUp() {
+ ruleAppConfig = new RuleAppConfig();
+ }
+
+ @Test
+ public void getDataSourceFactory() throws Exception {
+ assertThat(ruleAppConfig.getDataSourceFactory(), notNullValue());
+ }
+
+ @Test
+ public void setDataSourceFactory() throws Exception {
+ final DataSourceFactory factory = new DataSourceFactory();
+ ruleAppConfig.setDataSourceFactory(factory);
+ assertThat(ruleAppConfig.getDataSourceFactory(), equalTo(factory));
+ }
+
+ @Test
+ public void getApidescription() throws Exception {
+ assertThat(ruleAppConfig.getApidescription(), equalTo("Holmes rule management rest API"));
+ }
+
+ @Test
+ public void setApidescription() throws Exception {
+ final String value = "desc";
+ ruleAppConfig.setApidescription(value);
+ assertThat(ruleAppConfig.getApidescription(), equalTo(value));
+ }
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java new file mode 100644 index 0000000..e292e16 --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4EngineTest.java @@ -0,0 +1,32 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.bean.request;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class CorrelationCheckRule4EngineTest {
+ @Test
+ public void getterAndSetter4Content(){
+ final String value = "content";
+ CorrelationCheckRule4Engine correlationCheckRule4Engine = new CorrelationCheckRule4Engine();
+ correlationCheckRule4Engine.setContent(value);
+ assertThat(correlationCheckRule4Engine.getContent(), equalTo(value));
+ }
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java new file mode 100644 index 0000000..418ff41 --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4EngineTest.java @@ -0,0 +1,40 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.bean.request;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.core.IsEqual.equalTo;
+
+import org.junit.Test;
+
+public class CorrelationDeployRule4EngineTest {
+ @Test
+ public void getterAndSetter4Content(){
+ final String value = "content";
+ CorrelationDeployRule4Engine correlationDeployRule4Engine = new CorrelationDeployRule4Engine();
+ correlationDeployRule4Engine.setContent(value);
+ assertThat(correlationDeployRule4Engine.getContent(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4EngineId(){
+ final String value = "engineId";
+ CorrelationDeployRule4Engine correlationDeployRule4Engine = new CorrelationDeployRule4Engine();
+ correlationDeployRule4Engine.setEngineId(value);
+ assertThat(correlationDeployRule4Engine.getEngineId(), equalTo(value));
+ }
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java new file mode 100644 index 0000000..e616a71 --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/CorrelationRestRequestTest.java @@ -0,0 +1,34 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.onap.holmes.rulemgt.bean.request;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class CorrelationRestRequestTest {
+
+ @Test
+ public void getterAndSetter4RootURL() {
+ final String rootURL = "rootURL";
+ CorrelationRestRequest correlationRestRequest = new CorrelationRestRequest();
+ correlationRestRequest.setRootURL(rootURL);
+ assertThat(correlationRestRequest.getRootURL(), equalTo(rootURL));
+ }
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequestTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequestTest.java new file mode 100644 index 0000000..54fa132 --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequestTest.java @@ -0,0 +1,58 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.bean.request;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class RuleCreateRequestTest {
+
+ @Test
+ public void getterAndSetter4RuleName(){
+ final String rulename = "rulename";
+ RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();
+ ruleCreateRequest.setRuleName(rulename);
+ assertThat(ruleCreateRequest.getRuleName(), equalTo(rulename));
+ }
+
+ @Test
+ public void getterAndSetter4Description(){
+ final String description = "desc";
+ RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();
+ ruleCreateRequest.setDescription(description);
+ assertThat(ruleCreateRequest.getDescription(), equalTo(description));
+ }
+
+ @Test
+ public void getterAndSetter4Content(){
+ final String contents = "contents";
+ RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();
+ ruleCreateRequest.setContent(contents);
+ assertThat(ruleCreateRequest.getContent(), equalTo(contents));
+ }
+
+ @Test
+ public void getterAndSetter4Enabled(){
+ final int enabled = 0;
+ RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();
+ ruleCreateRequest.setEnabled(enabled);
+ assertThat(ruleCreateRequest.getEnabled(), is(enabled));
+ }
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequestTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequestTest.java new file mode 100644 index 0000000..3d49b2f --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequestTest.java @@ -0,0 +1,33 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.bean.request;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+
+public class RuleDeleteRequestTest {
+ @Test
+ public void getterAndSetter4RuleId(){
+ final String ruleId = "ruleId";
+ RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();
+ ruleDeleteRequest.setRuleId(ruleId);
+ assertThat(ruleDeleteRequest.getRuleId(), equalTo(ruleId));
+ }
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleQueryConditionTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleQueryConditionTest.java new file mode 100644 index 0000000..36d5024 --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleQueryConditionTest.java @@ -0,0 +1,65 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.bean.request;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class RuleQueryConditionTest {
+ @Test
+ public void getterAndSetter4RuleId(){
+ final String value = "ruleId";
+ RuleQueryCondition ruleQueryCondition = new RuleQueryCondition();
+ ruleQueryCondition.setRid(value);
+ assertThat(ruleQueryCondition.getRid(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4RuleName(){
+ final String value = "ruleName";
+ RuleQueryCondition ruleQueryCondition = new RuleQueryCondition();
+ ruleQueryCondition.setName(value);
+ assertThat(ruleQueryCondition.getName(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4Creator(){
+ final String value = "admin";
+ RuleQueryCondition ruleQueryCondition = new RuleQueryCondition();
+ ruleQueryCondition.setCreator(value);
+ assertThat(ruleQueryCondition.getCreator(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4Modifier(){
+ final String value = "admin";
+ RuleQueryCondition ruleQueryCondition = new RuleQueryCondition();
+ ruleQueryCondition.setModifier(value);
+ assertThat(ruleQueryCondition.getModifier(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4Enabled(){
+ final int value = 0;
+ RuleQueryCondition ruleQueryCondition = new RuleQueryCondition();
+ ruleQueryCondition.setEnabled(value);
+ assertThat(ruleQueryCondition.getEnabled(), is(value));
+ }
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java new file mode 100644 index 0000000..9f24c0c --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequestTest.java @@ -0,0 +1,58 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.bean.request;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+
+public class RuleUpdateRequestTest {
+ @Test
+ public void getterAndSetter4RuleId(){
+ final String value = "ruleId";
+ RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();
+ ruleUpdateRequest.setRuleId(value);
+ assertThat(ruleUpdateRequest.getRuleId(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4Description(){
+ final String value = "desc";
+ RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();
+ ruleUpdateRequest.setDescription(value);
+ assertThat(ruleUpdateRequest.getDescription(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4Content(){
+ final String value = "content";
+ RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();
+ ruleUpdateRequest.setContent(value);
+ assertThat(ruleUpdateRequest.getContent(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4Enabled(){
+ final int value = 0;
+ RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();
+ ruleUpdateRequest.setEnabled(value);
+ assertThat(ruleUpdateRequest.getEnabled(), is(value));
+ }
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java new file mode 100644 index 0000000..a7db0fe --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponseTest.java @@ -0,0 +1,32 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.bean.response;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.core.IsEqual.equalTo;
+
+import org.junit.Test;
+
+public class RuleAddAndUpdateResponseTest {
+ @Test
+ public void getterAndSetter4RuleId(){
+ final String value = "ruleId";
+ RuleAddAndUpdateResponse ruleAddAndUpdateResponse = new RuleAddAndUpdateResponse();
+ ruleAddAndUpdateResponse.setRuleId(value);
+ assertThat(ruleAddAndUpdateResponse.getRuleId(), equalTo(value));
+ }
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java new file mode 100644 index 0000000..fa423db --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponseTest.java @@ -0,0 +1,45 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.bean.response;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+
+public class RuleQueryListResponseTest {
+
+ @Test
+ public void getterAndSetter4CorrelationRules(){
+ final List<RuleResult4API> value = new ArrayList<>();
+ RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();
+ ruleQueryListResponse.setCorrelationRules(value);
+ assertThat(ruleQueryListResponse.getCorrelationRules(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4TotalCount(){
+ final int value = 0;
+ RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse();
+ ruleQueryListResponse.setTotalCount(value);
+ assertThat(ruleQueryListResponse.getTotalCount(), is(value));
+ }
+
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleResult4APITest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleResult4APITest.java new file mode 100644 index 0000000..2c006ab --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bean/response/RuleResult4APITest.java @@ -0,0 +1,99 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.bean.response;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.*;
+
+import java.util.Date;
+import org.junit.Test;
+
+public class RuleResult4APITest {
+
+ @Test
+ public void getterAndSetter4RuleId(){
+ final String value = "ruleId";
+ RuleResult4API ruleResult4API = new RuleResult4API();
+ ruleResult4API.setRuleId(value);
+ assertThat(ruleResult4API.getRuleId(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4RuleName(){
+ final String value = "ruleName";
+ RuleResult4API ruleResult4API = new RuleResult4API();
+ ruleResult4API.setRuleName(value);
+ assertThat(ruleResult4API.getRuleName(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4Description(){
+ final String value = "desc";
+ RuleResult4API ruleResult4API = new RuleResult4API();
+ ruleResult4API.setDescription(value);
+ assertThat(ruleResult4API.getDescription(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4Content(){
+ final String value = "content";
+ RuleResult4API ruleResult4API = new RuleResult4API();
+ ruleResult4API.setContent(value);
+ assertThat(ruleResult4API.getContent(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4CreateTime(){
+ final Date value = new Date();
+ RuleResult4API ruleResult4API = new RuleResult4API();
+ ruleResult4API.setCreateTime(value);
+ assertThat(ruleResult4API.getCreateTime(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4Creator(){
+ final String value = "admin";
+ RuleResult4API ruleResult4API = new RuleResult4API();
+ ruleResult4API.setCreator(value);
+ assertThat(ruleResult4API.getCreator(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4UpdateTime(){
+ final Date value = new Date();
+ RuleResult4API ruleResult4API = new RuleResult4API();
+ ruleResult4API.setUpdateTime(value);
+ assertThat(ruleResult4API.getUpdateTime(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4Modifier(){
+ final String value = "admin";
+ RuleResult4API ruleResult4API = new RuleResult4API();
+ ruleResult4API.setModifier(value);
+ assertThat(ruleResult4API.getModifier(), equalTo(value));
+ }
+
+ @Test
+ public void getterAndSetter4Enabled(){
+ final int value = 0;
+ RuleResult4API ruleResult4API = new RuleResult4API();
+ ruleResult4API.setEnabled(value);
+ assertThat(ruleResult4API.getEnabled(), is(value));
+ }
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java new file mode 100644 index 0000000..b3cb93d --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java @@ -0,0 +1,56 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.onap.holmes.rulemgt.bolt.enginebolt;
+
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.rules.ExpectedException;
+import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.rule.PowerMockRule;
+
+@PrepareForTest({HttpClients.class, CloseableHttpClient.class})
+public class EngineServiceTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+ @Rule
+ public PowerMockRule powerMockRule = new PowerMockRule();
+ private EngineService engineService;
+ private HttpResponse httpResponseMock;
+ private CloseableHttpClient closeableHttpClient;
+ private CorrelationDeployRule4Engine correlationDeployRule4Engine;
+ private CloseableHttpResponse closeableHttpResponseMock;
+
+ @Before
+ public void setUp() {
+ engineService = new EngineService();
+ closeableHttpClient = PowerMock.createMock(CloseableHttpClient.class);
+ httpResponseMock = PowerMock.createMock(HttpResponse.class);
+ closeableHttpResponseMock = PowerMock.createMock(CloseableHttpResponse.class);
+ correlationDeployRule4Engine = new CorrelationDeployRule4Engine();
+ correlationDeployRule4Engine.setContent("{\"package\":\"test\"}");
+ correlationDeployRule4Engine.setEngineId("engine_id");
+ }
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java new file mode 100644 index 0000000..b63b106 --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java @@ -0,0 +1,183 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.bolt.enginebolt;
+
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+
+import javax.ws.rs.core.Response;
+import org.apache.http.StatusLine;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
+import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
+import org.onap.holmes.common.exception.CorrelationException;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.reflect.Whitebox;
+
+public class EngineWrapperTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+ private EngineWrapper engineWrapper = new EngineWrapper();
+ private EngineService engineServiceMock;
+ private Response response;
+ private StatusLine statusLineMock;
+
+ @Before
+ public void setUp() throws Exception {
+ engineServiceMock = PowerMock.createMock(EngineService.class);
+ response = PowerMock.createMock(Response.class);
+ statusLineMock = PowerMock.createMock(StatusLine.class);
+ Whitebox.setInternalState(engineWrapper, "engineService", engineServiceMock);
+ }
+
+ @Test
+ public void deployEngine_invoke_rule_deploy_exception() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Failed to call the rule deployment RESTful API.");
+
+ EasyMock.expect(engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class))).andThrow(
+ new RuntimeException(""));
+ PowerMock.replayAll();
+
+ engineWrapper.deployEngine(new CorrelationDeployRule4Engine());
+
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void deployEngine_http_status_not_ok() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Failed to deploy the rule!");
+
+ EasyMock.expect(engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))
+ .andReturn(response);
+ EasyMock.expect(response.getStatus()).andReturn(400);
+ PowerMock.replayAll();
+
+ engineWrapper.deployEngine(new CorrelationDeployRule4Engine());
+
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void deployEngine_parse_content_exception() throws Exception {
+ String content = "";
+
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Failed to parse the value returned by the engine management service.");
+ EasyMock.expect(engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))
+ .andReturn(response);
+ EasyMock.expect(response.getStatus()).andReturn(200);
+ EasyMock.expect(response.readEntity(String.class)).andReturn(content);
+ PowerMock.replayAll();
+
+ engineWrapper.deployEngine(new CorrelationDeployRule4Engine());
+
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void deployEngine_success() throws Exception {
+ String content = "{\"package\":\"test\"}";
+ EasyMock.expect(engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))
+ .andReturn(response);
+ EasyMock.expect(response.getStatus()).andReturn(200);
+ EasyMock.expect(response.readEntity(String.class)).andReturn(content);
+ PowerMock.replayAll();
+
+ String result = engineWrapper.deployEngine(new CorrelationDeployRule4Engine());
+
+ assertThat(result, equalTo("test"));
+
+ }
+
+ @Test
+ public void deleteRuleFromEngine_invoke_rule_delete_exception() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Failed to call the rule deleting RESTful API.");
+
+ EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class))).andThrow(
+ new RuntimeException(""));
+ PowerMock.replayAll();
+
+ engineWrapper.deleteRuleFromEngine("");
+
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void deleteRuleFromEngine_http_status_not_ok() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Failed to delete the rule!");
+
+ EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class)))
+ .andReturn(response);
+ EasyMock.expect(response.getStatus()).andReturn(400);
+
+ PowerMock.replayAll();
+
+ engineWrapper.deleteRuleFromEngine("");
+
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void deleteRuleFromEngine_success() throws Exception {
+ EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class)))
+ .andReturn(response);
+ EasyMock.expect(response.getStatus()).andReturn(200);
+
+ PowerMock.replayAll();
+
+ boolean result = engineWrapper.deleteRuleFromEngine("");
+
+ assertThat(result, equalTo(true));
+ }
+
+ @Test
+ public void checkRuleFromEngine_rule_delete_exception() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Failed to call the rule verification RESTful API.");
+
+ EasyMock.expect(engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class))).andThrow(
+ new RuntimeException(""));
+ PowerMock.replayAll();
+
+ engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine());
+
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void checkRuleFromEngine_success() throws Exception {
+ EasyMock.expect(engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))
+ .andReturn(response);
+ EasyMock.expect(response.getStatus()).andReturn(200);
+
+ PowerMock.replayAll();
+
+ boolean result = engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine());
+
+ assertThat(result, equalTo(true));
+ }
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java new file mode 100644 index 0000000..3854cdc --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java @@ -0,0 +1,161 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.db;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.holmes.common.api.entity.CorrelationRule;
+import org.onap.holmes.common.exception.CorrelationException;
+import org.onap.holmes.common.utils.DbDaoUtil;
+import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.modules.junit4.rule.PowerMockRule;
+import org.powermock.reflect.Whitebox;
+import org.skife.jdbi.v2.Handle;
+import org.skife.jdbi.v2.Query;
+
+
+public class CorrelationRuleQueryDaoTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Rule
+ public PowerMockRule powerMockRule = new PowerMockRule();
+ private DbDaoUtil dbDaoUtil;
+
+ private Handle handle;
+
+ private Query query;
+
+ private CorrelationRuleQueryDao correlationRuleQueryDao;
+ private RuleQueryCondition ruleQueryCondition;
+
+ @Before
+ public void setUp() throws Exception {
+ correlationRuleQueryDao = new CorrelationRuleQueryDao();
+
+ dbDaoUtil = PowerMock.createMock(DbDaoUtil.class);
+ handle = PowerMock.createMock(Handle.class);
+ query = PowerMock.createMock(Query.class);
+
+ Whitebox.setInternalState(correlationRuleQueryDao, "dbDaoUtil", dbDaoUtil);
+
+ ruleQueryCondition = createRuleQueryCondition();
+ }
+
+
+ @Test
+ public void getCorrelationRulesByCondition_db_exception() throws Exception {
+
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Failed to query the rule.");
+
+ EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);
+ EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);
+ EasyMock.expect(query.list()).andThrow(new RuntimeException()).anyTimes();
+ dbDaoUtil.close(handle);
+ EasyMock.expectLastCall();
+
+ PowerMock.replayAll();
+
+ correlationRuleQueryDao.getCorrelationRulesByCondition(ruleQueryCondition);
+
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void getCorrelationRulesByCondition_normal() throws Exception {
+ EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);
+ EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);
+ EasyMock.expect(query.list()).andReturn(createQueryResult()).anyTimes();
+ dbDaoUtil.close(handle);
+ EasyMock.expectLastCall();
+
+ PowerMock.replayAll();
+
+ List<CorrelationRule> result = correlationRuleQueryDao.getCorrelationRulesByCondition(ruleQueryCondition);
+ assertThat(result.size(), is(1));
+
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void getCorrelationRulesByCondition_get_where_sql_exception() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("An error occurred while building the query SQL.");
+
+ EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);
+ EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);
+ EasyMock.expect(query.list()).andReturn(createQueryResult()).anyTimes();
+ dbDaoUtil.close(handle);
+ EasyMock.expectLastCall();
+
+ PowerMock.replayAll();
+
+ correlationRuleQueryDao.getCorrelationRulesByCondition(null);
+
+ PowerMock.verifyAll();
+ }
+
+ private List<Map<String, Object>> createQueryResult() {
+ List<Map<String, Object>> list = new ArrayList<>();
+ Map<String, Object> value = new HashMap<>();
+ value.put("name", "Rule-001");
+ value.put("rid", "rule_" + System.currentTimeMillis());
+ value.put("description", "desc");
+ value.put("enable", 0);
+ value.put("templateID", 1);
+ value.put("engineId", "engine-001");
+ value.put("engineType", "engineType-001");
+ value.put("creator", "admin");
+ value.put("createTime", new Date());
+ value.put("updator", "admin");
+ value.put("updateTime", new Date());
+ value.put("params", new Properties());
+ value.put("domain", "Domain");
+ value.put("isManual", 0);
+ value.put("vendor", "Vendor");
+ value.put("content", "Contents");
+ value.put("package", "package");
+ list.add(value);
+ return list;
+ }
+
+ private RuleQueryCondition createRuleQueryCondition() {
+ RuleQueryCondition ruleQueryCondition = new RuleQueryCondition();
+ ruleQueryCondition.setRid("rule_" + System.currentTimeMillis());
+ ruleQueryCondition.setName("Rule-001");
+ ruleQueryCondition.setEnabled(0);
+ ruleQueryCondition.setCreator("admin");
+ ruleQueryCondition.setModifier("admin");
+ return ruleQueryCondition;
+ }
+
+}
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/mapper/CorrelationRuleMapperTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/mapper/CorrelationRuleMapperTest.java new file mode 100644 index 0000000..bcf56ca --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/mapper/CorrelationRuleMapperTest.java @@ -0,0 +1,52 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.db.mapper;
+
+import static org.easymock.EasyMock.expect;
+
+import java.sql.Date;
+import java.sql.ResultSet;
+import java.util.Properties;
+import org.junit.Test;
+import org.powermock.api.easymock.PowerMock;
+
+public class CorrelationRuleMapperTest {
+
+ @Test
+ public void map() throws Exception {
+ CorrelationRuleMapper mapper = new CorrelationRuleMapper();
+ ResultSet resultSet = PowerMock.createMock(ResultSet.class);
+ expect(resultSet.getString("name")).andReturn("");
+ expect(resultSet.getString("rid")).andReturn("");
+ expect(resultSet.getString("description")).andReturn("");
+ expect(resultSet.getInt("enable")).andReturn(0);
+ expect(resultSet.getInt("templateID")).andReturn(1);
+ expect(resultSet.getString("engineID")).andReturn("");
+ expect(resultSet.getString("engineType")).andReturn("");
+ expect(resultSet.getString("creator")).andReturn("");
+ expect(resultSet.getDate("createTime")).andReturn(new Date(System.currentTimeMillis()));
+ expect(resultSet.getString("updator")).andReturn("");
+ expect(resultSet.getDate("updateTime")).andReturn(new Date(System.currentTimeMillis()));
+ expect(resultSet.getObject("params")).andReturn(new Properties());
+ expect(resultSet.getString("content")).andReturn("");
+ expect(resultSet.getString("vendor")).andReturn("");
+ expect(resultSet.getString("package")).andReturn("");
+ PowerMock.replay(resultSet);
+ mapper.map(0, resultSet, null);
+ PowerMock.verify(resultSet);
+ }
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java new file mode 100644 index 0000000..dd68ad8 --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java @@ -0,0 +1,182 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.resources;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.WebApplicationException;
+import org.easymock.EasyMock;
+import org.eclipse.jetty.server.Request;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
+import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest;
+import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
+import org.onap.holmes.common.exception.CorrelationException;
+import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
+import org.onap.holmes.rulemgt.bean.request.RuleUpdateRequest;
+import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;
+import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.reflect.Whitebox;
+
+public class RuleMgtResourcesTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private HttpServletRequest request = PowerMock.createMock(HttpServletRequest.class);
+
+ private RuleMgtWrapper ruleMgtWrapper = PowerMock.createMock(RuleMgtWrapper.class);
+
+ private RuleMgtResources ruleMgtResources = new RuleMgtResources();
+
+ private Request requestMock = PowerMock.createMock(Request.class);
+
+ @Before
+ public void setUp() throws Exception {
+ Whitebox.setInternalState(ruleMgtResources, "ruleMgtWrapper", ruleMgtWrapper);
+ PowerMock.resetAll();
+ }
+
+ @Test
+ public void addCorrelationRule_correlation_exception() throws Exception {
+ thrown.expect(WebApplicationException.class);
+
+ final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();
+ EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest))
+ .andThrow(new CorrelationException(EasyMock.anyObject(String.class)));
+ EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
+ EasyMock.expect(request.getHeader("username")).andReturn("admin");
+ PowerMock.replayAll();
+ ruleMgtResources.addCorrelationRule(request, ruleCreateRequest);
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void addCorrelationRule_normal() throws Exception {
+ StringBuilder stringBuilder = new StringBuilder("http://localhost");
+ final RuleCreateRequest ruleCreateRequest = new RuleCreateRequest();
+ EasyMock.expect(ruleMgtWrapper.addCorrelationRule("admin",
+ ruleCreateRequest)).andReturn(new RuleAddAndUpdateResponse());
+ EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
+ EasyMock.expect(request.getHeader("username")).andReturn("admin");
+ PowerMock.replayAll();
+ ruleMgtResources.addCorrelationRule(request, ruleCreateRequest);
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void updateCorrelationRule_correlation_exception() throws Exception {
+ thrown.expect(WebApplicationException.class);
+
+ final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();
+ EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin", ruleUpdateRequest))
+ .andThrow(new CorrelationException(EasyMock.anyObject(String.class)));
+ EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
+ EasyMock.expect(request.getHeader("username")).andReturn("admin");
+ PowerMock.replayAll();
+ ruleMgtResources.updateCorrelationRule(request, ruleUpdateRequest);
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void updateCorrelationRule_normal() throws Exception {
+ final RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();
+ EasyMock.expect(ruleMgtWrapper.updateCorrelationRule("admin",
+ ruleUpdateRequest)).andReturn(new RuleAddAndUpdateResponse());
+ EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
+ EasyMock.expect(request.getHeader("username")).andReturn("admin");
+ PowerMock.replayAll();
+ ruleMgtResources.updateCorrelationRule(request, ruleUpdateRequest);
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void deleteCorrelationRule_correlation_exception() throws Exception {
+ thrown.expect(WebApplicationException.class);
+
+ final RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();
+ ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);
+ EasyMock.expectLastCall().andThrow(new CorrelationException(EasyMock.anyObject(String.class)));
+ EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
+ PowerMock.replayAll();
+ ruleMgtResources.deleteCorrelationRule(request, ruleDeleteRequest);
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void deleteCorrelationRule_normal() throws Exception {
+ final RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();
+ ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);
+ EasyMock.expectLastCall();
+ EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
+ PowerMock.replayAll();
+ ruleMgtResources.deleteCorrelationRule(request, ruleDeleteRequest);
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void getCorrelationRules_data_format_exception() throws Exception {
+ thrown.expect(WebApplicationException.class);
+
+ final String requestStr = "{\"ruleid\":\"rule_001\",\"rulename\":\"Rule-001\","
+ + "\"enabled\":0,\"creator\":\"admin\"}";
+ EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))
+ .andThrow(new CorrelationException(EasyMock.anyObject(String.class)));
+ EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);
+ PowerMock.replayAll();
+ ruleMgtResources.getCorrelationRules(request, requestStr);
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void getCorrelationRules_param_translate_exception() {
+ thrown.expect(WebApplicationException.class);
+
+ String queryRequest = "this is error param";
+ EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);
+
+ PowerMock.replayAll();
+ ruleMgtResources.getCorrelationRules(request, queryRequest);
+ PowerMock.verifyAll();
+
+ }
+
+ @Test
+ public void getCorrelationRules_normal_request_string_null() throws Exception {
+ EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))
+ .andReturn(new RuleQueryListResponse());
+ EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);
+ PowerMock.replayAll();
+ ruleMgtResources.getCorrelationRules(request, null);
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void getCorrelationRules_normal_request_string_enabled_missing() throws Exception {
+ final String requestStr = "{\"ruleid\":\"rule_001\",\"rulename\":\"Rule-001\","
+ + "\"creator\":\"admin\"}";
+ EasyMock.expect(ruleMgtWrapper.getCorrelationRuleByCondition(EasyMock.anyObject(RuleQueryCondition.class)))
+ .andReturn(new RuleQueryListResponse());
+ EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);
+ PowerMock.replayAll();
+ ruleMgtResources.getCorrelationRules(request, requestStr);
+ PowerMock.verifyAll();
+ }
+}
\ No newline at end of file diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java new file mode 100644 index 0000000..0c81b98 --- /dev/null +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java @@ -0,0 +1,411 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.rulemgt.wrapper;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
+import org.onap.holmes.rulemgt.db.CorrelationRuleDao;
+import org.onap.holmes.common.api.entity.CorrelationRule;
+import org.onap.holmes.common.exception.CorrelationException;
+import org.onap.holmes.common.utils.DbDaoUtil;
+import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
+import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
+import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest;
+import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
+import org.onap.holmes.rulemgt.bean.request.RuleUpdateRequest;
+import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;
+import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
+import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper;
+import org.onap.holmes.rulemgt.db.CorrelationRuleQueryDao;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.modules.junit4.rule.PowerMockRule;
+import org.powermock.reflect.Whitebox;
+
+public class RuleMgtWrapperTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+ @Rule
+ public PowerMockRule powerMockRule = new PowerMockRule();
+
+ private RuleMgtWrapper ruleMgtWrapper;
+
+ private EngineWrapper engineWrapperMock;
+
+ private DbDaoUtil dbDaoUtilMock;
+
+ private CorrelationRuleQueryDao correlationRuleQueryDaoMock;
+
+ private CorrelationRuleDao correlationRuleDaoMock;
+
+ private static final String USER_NAME = "admin";
+
+ @Before
+ public void setUp() throws Exception {
+
+ ruleMgtWrapper = new RuleMgtWrapper();
+
+ engineWrapperMock = PowerMock.createMock(EngineWrapper.class);
+ correlationRuleQueryDaoMock = PowerMock.createMock(CorrelationRuleQueryDao.class);
+ dbDaoUtilMock = PowerMock.createMock(DbDaoUtil.class);
+ correlationRuleDaoMock = PowerMock.createMock(CorrelationRuleDao.class);
+
+ Whitebox.setInternalState(ruleMgtWrapper, "daoUtil", dbDaoUtilMock);
+ Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleQueryDao", correlationRuleQueryDaoMock);
+ Whitebox.setInternalState(ruleMgtWrapper, "engineWarpper", engineWrapperMock);
+ Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleDao", correlationRuleDaoMock);
+
+ PowerMock.resetAll();
+ }
+
+ @Test
+ public void initDaoUtil_normal() {
+ ruleMgtWrapper.initDaoUtil();
+ }
+
+ @Test
+ public void addCorrelationRule_name_is_null() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("The name of the rule can not be empty.");
+
+ ruleMgtWrapper.addCorrelationRule(USER_NAME, createRuleCreateRequest(null, "This is a rule for testing.",
+ "Mocked contents.", 0));
+ }
+
+ @Test
+ public void addCorrelationRule_request_null() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("The request object can not be empty!");
+
+ ruleMgtWrapper.addCorrelationRule(USER_NAME, null);
+ }
+
+ @Test
+ public void addCorrelationRule_name_is_empty() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("The name of the rule can not be empty.");
+
+ ruleMgtWrapper.addCorrelationRule("admin", createRuleCreateRequest("", "This is a rule for testing.",
+ "Mocked contents.", 0));
+ }
+
+ @Test
+ public void addCorrelationRule_content_is_empty() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("The contents of the rule can not be empty!");
+
+ ruleMgtWrapper.addCorrelationRule("admin", createRuleCreateRequest("test", "This is a rule for testing.",
+ "", 0));
+ }
+
+ @Test
+ public void addCorrelationRule_enabled_is_off_limit() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Invalid rule status. Only 0 (disabled) and 1 (enabled) are allowed.");
+
+ ruleMgtWrapper.addCorrelationRule("admin", createRuleCreateRequest("test", "This is a rule for testing.",
+ "Mocked contents.", 3));
+ }
+
+ @Test
+ public void addCorrelationRule_duplicated_rule() throws Exception {
+
+ final String ruleName = "Rule-001";
+
+ RuleCreateRequest ruleCreateRequest = createRuleCreateRequest(ruleName, "This is a rule for testing.",
+ "Mocked contents.", 0);
+ CorrelationRule correlationRule = convertCreateRequest2CorrelationRule(ruleCreateRequest);
+
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("A rule with the same name already exists.");
+
+ EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(correlationRule);
+ PowerMock.replayAll();
+
+ ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest);
+
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void addCorrelationRule_normal() throws Exception {
+ final String ruleName = "Rule-001";
+
+ RuleCreateRequest ruleCreateRequest = createRuleCreateRequest(ruleName, "This is a rule for testing.",
+ "Mocked contents.", 1);
+
+ CorrelationRule correlationRuleRet = new CorrelationRule();
+ correlationRuleRet.setRid("rule_" + System.currentTimeMillis());
+
+ EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(null);
+ EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))
+ .andReturn(true);
+ EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))
+ .andReturn("package-001");
+ EasyMock.expect(correlationRuleDaoMock.saveRule(EasyMock.anyObject(CorrelationRule.class)))
+ .andReturn(correlationRuleRet);
+
+ PowerMock.replayAll();
+
+ RuleAddAndUpdateResponse response = ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest);
+ assertThat(response.getRuleId(), equalTo(correlationRuleRet.getRid()));
+
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void updateCorrelationRule_param_null() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("The request object can not be empty!");
+
+ ruleMgtWrapper.updateCorrelationRule(USER_NAME, null);
+ }
+
+ @Test
+ public void updateCorrelationRule_normal() throws Exception {
+ CorrelationRule oldCorrelationRule = new CorrelationRule();
+ oldCorrelationRule.setRid("rule_1");
+ oldCorrelationRule.setName("name");
+ oldCorrelationRule.setDescription("des1");
+ oldCorrelationRule.setContent("content");
+ oldCorrelationRule.setPackageName("testName");
+ oldCorrelationRule.setEnabled(1);
+ RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_1", "des2", "contetnt2", 1);
+
+ EasyMock.expect(correlationRuleDaoMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule);
+ EasyMock.expect(engineWrapperMock.deleteRuleFromEngine("testName")).andReturn(true);
+ correlationRuleDaoMock.updateRule(EasyMock.anyObject(CorrelationRule.class));
+ EasyMock.expectLastCall();
+ EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))
+ .andReturn(true);
+ EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))
+ .andReturn("packageName1");
+ PowerMock.replayAll();
+
+ ruleMgtWrapper.updateCorrelationRule(USER_NAME, ruleUpdateRequest);
+
+ PowerMock.verifyAll();
+
+ assertThat(oldCorrelationRule.getRid(), equalTo(ruleUpdateRequest.getRuleId()));
+ }
+
+ @Test
+ public void updateCorrelationRule_param_no_change() throws Exception {
+ CorrelationRule oldCorrelationRule = new CorrelationRule();
+ oldCorrelationRule.setRid("rule_1");
+ oldCorrelationRule.setName("name");
+ oldCorrelationRule.setDescription("des1");
+ oldCorrelationRule.setContent("content");
+ oldCorrelationRule.setPackageName("testName");
+ oldCorrelationRule.setEnabled(1);
+ RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_1", "des1", "content", 1);
+
+ EasyMock.expect(correlationRuleDaoMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule);
+
+ PowerMock.replayAll();
+
+ ruleMgtWrapper.updateCorrelationRule(USER_NAME, ruleUpdateRequest);
+
+ PowerMock.verifyAll();
+
+ assertThat(oldCorrelationRule.getRid(), equalTo(ruleUpdateRequest.getRuleId()));
+ }
+
+ @Test
+ public void updateCorrelationRule_rule_not_exist() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("You're trying to update a rule which does not exist in the system.");
+
+ EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(EasyMock.anyObject(String.class))).andReturn(null);
+
+ PowerMock.replayAll();
+
+ ruleMgtWrapper.updateCorrelationRule(USER_NAME, new RuleUpdateRequest());
+
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void deleteCorrelationRule_request_null() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("The request object can not be empty!");
+
+ ruleMgtWrapper.deleteCorrelationRule(null);
+ }
+
+ @Test
+ public void deleteCorrelationRule_rule_not_exit() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("You're trying to delete a rule which does not exist in the system.");
+
+ RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());
+
+ EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(
+ correlationRuleDaoMock).anyTimes();
+ EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(ruleDeleteRequest.getRuleId()))
+ .andReturn(null);
+
+ PowerMock.replayAll();
+
+ ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);
+
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void deleteCorrelationRule_normal() throws Exception {
+ RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis());
+ CorrelationRule correlationRule = new CorrelationRule();
+ correlationRule.setEnabled(1);
+ EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(ruleDeleteRequest.getRuleId()))
+ .andReturn(correlationRule);
+ EasyMock.expect(engineWrapperMock.deleteRuleFromEngine(EasyMock.anyObject(String.class))).andReturn(true);
+ correlationRuleDaoMock.deleteRule(EasyMock.anyObject(CorrelationRule.class));
+ EasyMock.expectLastCall();
+ PowerMock.replayAll();
+
+ ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);
+
+ PowerMock.verifyAll();
+ }
+
+ @Test
+ public void getCorrelationRuleByCondition_data_format_exception() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("An error occurred while building the query SQL.");
+
+ EasyMock.expect(correlationRuleQueryDaoMock.getCorrelationRulesByCondition(EasyMock.anyObject(
+ RuleQueryCondition.class)))
+ .andThrow(new CorrelationException("An error occurred while building the query SQL."));
+
+ PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);
+
+ ruleMgtWrapper.getCorrelationRuleByCondition(new RuleQueryCondition());
+
+ PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);
+ }
+
+ @Test
+ public void getCorrelationRuleByCondition_db_exception() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Failed to query the rule.");
+
+ EasyMock.expect(correlationRuleQueryDaoMock.getCorrelationRulesByCondition(EasyMock.anyObject(
+ RuleQueryCondition.class)))
+ .andThrow(new CorrelationException("Failed to query the rule."));
+
+ PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);
+
+ ruleMgtWrapper.getCorrelationRuleByCondition(new RuleQueryCondition());
+
+ PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);
+ }
+
+ @Test
+ public void getCorrelationRuleByCondition_normal() throws Exception {
+ List<CorrelationRule> correlationRuleList = new ArrayList<CorrelationRule>(10);
+ for (int i = 0; i < 10; ++i) {
+ CorrelationRule correlationRule = new CorrelationRule();
+ correlationRule.setContent("content" + i);
+ correlationRule.setName("name" + i);
+ correlationRule.setRid("rule_" + i);
+ correlationRule.setEngineType("engineType" + (i % 2 + 1));
+ correlationRule.setEngineID("engineId" + i);
+ correlationRule.setCreateTime(new Date());
+ correlationRule.setCreator(USER_NAME);
+ correlationRule.setDescription("description" + i);
+ correlationRule.setPackageName("package" + i);
+ correlationRuleList.add(correlationRule);
+ }
+
+ EasyMock.expect(correlationRuleQueryDaoMock.getCorrelationRulesByCondition(EasyMock.anyObject(
+ RuleQueryCondition.class))).andReturn(correlationRuleList);
+
+ PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);
+
+ RuleQueryListResponse response = ruleMgtWrapper.getCorrelationRuleByCondition(new RuleQueryCondition());
+
+ PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class);
+
+ assertThat(response.getTotalCount(), is(10));
+
+ for (int i = 0; i < 10; ++i) {
+ assertThat(response.getCorrelationRules().get(i).getRuleId(),
+ equalTo(correlationRuleList.get(i).getRid()));
+ }
+ }
+
+ private RuleCreateRequest createRuleCreateRequest(String ruleName, String description, String content,
+ int enabled) {
+ RuleCreateRequest rcr;
+ rcr = new RuleCreateRequest();
+ rcr.setRuleName(ruleName);
+ rcr.setDescription(description);
+ rcr.setContent(content);
+ rcr.setEnabled(enabled);
+ return rcr;
+ }
+
+ private RuleUpdateRequest createRuleUpdateRequest(String ruleId, String description, String content, int enabled) {
+ RuleUpdateRequest ruleUpdateRequest = new RuleUpdateRequest();
+ ruleUpdateRequest.setRuleId(ruleId);
+ ruleUpdateRequest.setDescription(description);
+ ruleUpdateRequest.setContent(content);
+ ruleUpdateRequest.setEnabled(enabled);
+ return ruleUpdateRequest;
+ }
+
+ private RuleDeleteRequest createRuleDeleteRequest(String ruleId) {
+ RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();
+ ruleDeleteRequest.setRuleId(ruleId);
+ return ruleDeleteRequest;
+ }
+
+ private CorrelationRule convertCreateRequest2CorrelationRule(RuleCreateRequest ruleCreateRequest) {
+ CorrelationRule correlationRule = new CorrelationRule();
+ correlationRule.setContent(ruleCreateRequest.getContent());
+ correlationRule.setDescription(ruleCreateRequest.getDescription());
+ correlationRule.setName(ruleCreateRequest.getRuleName());
+ correlationRule.setCreator(USER_NAME);
+ correlationRule.setModifier(USER_NAME);
+ correlationRule.setEnabled(ruleCreateRequest.getEnabled());
+ return correlationRule;
+ }
+
+ private CorrelationRule convertUpdateRequest2CorrelationRule(RuleUpdateRequest ruleUpdateRequest) {
+ CorrelationRule correlationRule = new CorrelationRule();
+ correlationRule.setRid(ruleUpdateRequest.getRuleId());
+ correlationRule.setContent(ruleUpdateRequest.getContent());
+ correlationRule.setDescription(ruleUpdateRequest.getDescription());
+ correlationRule.setEnabled(ruleUpdateRequest.getEnabled());
+ correlationRule.setUpdateTime(new Date());
+ correlationRule.setModifier(USER_NAME);
+ return correlationRule;
+ }
+}
\ No newline at end of file |