summaryrefslogtreecommitdiffstats
path: root/rulemgt/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'rulemgt/src/test/java')
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapperTest.java45
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/send/RuleAllocationTest.java63
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java25
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java61
4 files changed, 169 insertions, 25 deletions
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
index cc8c047..0664db7 100644
--- 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
@@ -64,12 +64,13 @@ public class EngineWrapperTest {
thrown.expectMessage("Failed to call the rule deployment RESTful API.");
EasyMock.expect(
- engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))
+ engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class),
+ EasyMock.anyObject(String.class)))
.andThrow(
new RuntimeException(""));
PowerMock.replayAll();
- engineWrapper.deployEngine(new CorrelationDeployRule4Engine());
+ engineWrapper.deployEngine(new CorrelationDeployRule4Engine(),"10.96.33.34");
PowerMock.verifyAll();
}
@@ -80,13 +81,14 @@ public class EngineWrapperTest {
thrown.expectMessage("Failed to deploy the rule!");
EasyMock.expect(
- engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))
+ engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class),
+ EasyMock.anyObject(String.class)))
.andReturn(httpResponse);
EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLineMock);
EasyMock.expect(statusLineMock.getStatusCode()).andReturn(400);
PowerMock.replayAll();
- engineWrapper.deployEngine(new CorrelationDeployRule4Engine());
+ engineWrapper.deployEngine(new CorrelationDeployRule4Engine(),"10.96.33.34");
PowerMock.verifyAll();
}
@@ -100,14 +102,15 @@ public class EngineWrapperTest {
thrown.expectMessage(
"Failed to parse the value returned by the engine management service.");
EasyMock.expect(
- engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))
+ engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class),
+ EasyMock.anyObject(String.class)))
.andReturn(httpResponse);
EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLineMock);
EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);
PowerMockito.when(HttpsUtils.extractResponseEntity(httpResponse)).thenReturn(content);
PowerMock.replayAll();
- engineWrapper.deployEngine(new CorrelationDeployRule4Engine());
+ engineWrapper.deployEngine(new CorrelationDeployRule4Engine(),"10.96.33.34");
PowerMock.verifyAll();
}
@@ -118,14 +121,15 @@ public class EngineWrapperTest {
String content = "{\"packageName\":\"test\"}";
PowerMockito.mockStatic(HttpsUtils.class);
EasyMock.expect(
- engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))
+ engineServiceMock.deploy(EasyMock.anyObject(CorrelationDeployRule4Engine.class),
+ EasyMock.anyObject(String.class)))
.andReturn(httpResponse);
EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLineMock);
EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);
PowerMockito.when(HttpsUtils.extractResponseEntity(httpResponse)).thenReturn(content);
PowerMock.replayAll();
- String result = engineWrapper.deployEngine(new CorrelationDeployRule4Engine());
+ String result = engineWrapper.deployEngine(new CorrelationDeployRule4Engine(),"10.96.33.34");
assertThat(result, equalTo("test"));
@@ -136,11 +140,12 @@ public class EngineWrapperTest {
thrown.expect(CorrelationException.class);
thrown.expectMessage("Failed to call the rule deleting RESTful API.");
- EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class))).andThrow(
+ EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class),
+ EasyMock.anyObject(String.class))).andThrow(
new RuntimeException(""));
PowerMock.replayAll();
- engineWrapper.deleteRuleFromEngine("");
+ engineWrapper.deleteRuleFromEngine("","10.96.33.34");
PowerMock.verifyAll();
}
@@ -150,28 +155,30 @@ public class EngineWrapperTest {
thrown.expect(CorrelationException.class);
thrown.expectMessage("Failed to delete the rule!");
- EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class)))
+ EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class),
+ EasyMock.anyObject(String.class)))
.andReturn(httpResponse);
EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLineMock);
EasyMock.expect(statusLineMock.getStatusCode()).andReturn(400);
PowerMock.replayAll();
- engineWrapper.deleteRuleFromEngine("");
+ engineWrapper.deleteRuleFromEngine("","10.96.33.34");
PowerMock.verifyAll();
}
@Test
public void deleteRuleFromEngine_success() throws Exception {
- EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class)))
+ EasyMock.expect(engineServiceMock.delete(EasyMock.anyObject(String.class),
+ EasyMock.anyObject(String.class)))
.andReturn(httpResponse);
EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLineMock);
EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);
PowerMock.replayAll();
- boolean result = engineWrapper.deleteRuleFromEngine("");
+ boolean result = engineWrapper.deleteRuleFromEngine("","10.96.33.34");
assertThat(result, equalTo(true));
}
@@ -182,12 +189,13 @@ public class EngineWrapperTest {
thrown.expectMessage("Failed to call the rule verification RESTful API.");
EasyMock.expect(
- engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))
+ engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class),
+ EasyMock.anyObject(String.class)))
.andThrow(
new RuntimeException(""));
PowerMock.replayAll();
- engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine());
+ engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine(),"10.96.33.34");
PowerMock.verifyAll();
}
@@ -195,14 +203,15 @@ public class EngineWrapperTest {
@Test
public void checkRuleFromEngine_success() throws Exception {
EasyMock.expect(
- engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))
+ engineServiceMock.check(EasyMock.anyObject(CorrelationCheckRule4Engine.class),
+ EasyMock.anyObject(String.class)))
.andReturn(httpResponse);
EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLineMock);
EasyMock.expect(statusLineMock.getStatusCode()).andReturn(200);
PowerMock.replayAll();
- boolean result = engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine());
+ boolean result = engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine(),"10.96.33.34");
assertThat(result, equalTo(true));
}
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/send/RuleAllocationTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/send/RuleAllocationTest.java
new file mode 100644
index 0000000..24c5f3a
--- /dev/null
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/send/RuleAllocationTest.java
@@ -0,0 +1,63 @@
+/**
+* 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.send;
+
+
+import org.junit.Test;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.reflect.Whitebox;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class RuleAllocationTest {
+
+ private RuleAllocation ruleAllocation = new RuleAllocation();
+ @Test
+ public void extendCompareIpTest() throws Exception{
+ List<String> newList = new ArrayList<>();
+ newList.add("10.96.33.34");
+ newList.add("10.74.65.24");
+
+ List<String> oldList = new ArrayList<>();
+ oldList.add("10.96.33.34");
+ List<String> extendIp = Whitebox.invokeMethod(ruleAllocation,"extendCompareIp",newList,oldList);
+
+ PowerMock.verifyAll();
+
+ assertThat(extendIp.get(0),equalTo("10.74.65.24"));
+ }
+
+ @Test
+ public void destroyCompareIpTest() throws Exception{
+ List<String> newList = new ArrayList<>();
+ newList.add("10.96.33.34");
+
+ List<String> oldList = new ArrayList<>();
+ oldList.add("10.96.33.34");
+ oldList.add("10.74.65.24");
+ List<String> destoryIp = Whitebox.invokeMethod(ruleAllocation,"destroyCompareIp",newList,oldList);
+
+ PowerMock.verifyAll();
+
+ assertThat(destoryIp.get(0),equalTo("10.74.65.24"));
+ }
+
+}
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
index d448e40..4b3e60f 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java
@@ -28,7 +28,6 @@ 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;
@@ -43,6 +42,7 @@ 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.onap.holmes.rulemgt.send.Ip4AddingRule;
import org.powermock.api.easymock.PowerMock;
import org.powermock.modules.junit4.rule.PowerMockRule;
import org.powermock.reflect.Whitebox;
@@ -64,6 +64,8 @@ public class RuleMgtWrapperTest {
private CorrelationRuleDao correlationRuleDaoMock;
+ private Ip4AddingRule ip4AddingRuleMock;
+
private static final String USER_NAME = "admin";
@Before
@@ -75,11 +77,13 @@ public class RuleMgtWrapperTest {
correlationRuleQueryDaoMock = PowerMock.createMock(CorrelationRuleQueryDao.class);
dbDaoUtilMock = PowerMock.createMock(DbDaoUtil.class);
correlationRuleDaoMock = PowerMock.createMock(CorrelationRuleDao.class);
+ ip4AddingRuleMock = PowerMock.createMock(Ip4AddingRule.class);
Whitebox.setInternalState(ruleMgtWrapper, "daoUtil", dbDaoUtilMock);
Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleQueryDao", correlationRuleQueryDaoMock);
Whitebox.setInternalState(ruleMgtWrapper, "engineWarpper", engineWrapperMock);
Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleDao", correlationRuleDaoMock);
+ Whitebox.setInternalState(ruleMgtWrapper,"ip4AddingRule", ip4AddingRuleMock);
PowerMock.resetAll();
}
@@ -165,9 +169,12 @@ public class RuleMgtWrapperTest {
correlationRuleRet.setRid("rule_" + System.currentTimeMillis());
EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(null);
- EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))
+ EasyMock.expect(ip4AddingRuleMock.getEngineIp4AddRule()).andReturn("10.96.33.34");
+ EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)
+ , EasyMock.anyObject(String.class)))
.andReturn(true);
- EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))
+ EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)
+ , EasyMock.anyObject(String.class)))
.andReturn("package-001");
EasyMock.expect(correlationRuleDaoMock.saveRule(EasyMock.anyObject(CorrelationRule.class)))
.andReturn(correlationRuleRet);
@@ -198,15 +205,18 @@ public class RuleMgtWrapperTest {
oldCorrelationRule.setPackageName("testName");
oldCorrelationRule.setEnabled(1);
oldCorrelationRule.setClosedControlLoopName("cl-name");
+ oldCorrelationRule.setEngineInstance("10.96.33.34");
RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_1", "cl-name", "des2", "contetnt2", 1);
EasyMock.expect(correlationRuleDaoMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule);
- EasyMock.expect(engineWrapperMock.deleteRuleFromEngine("testName")).andReturn(true);
+ EasyMock.expect(engineWrapperMock.deleteRuleFromEngine("testName", "10.96.33.34")).andReturn(true);
correlationRuleDaoMock.updateRule(EasyMock.anyObject(CorrelationRule.class));
EasyMock.expectLastCall();
- EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)))
+ EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class)
+ , EasyMock.anyObject(String.class)))
.andReturn(true);
- EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)))
+ EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class)
+ , EasyMock.anyObject(String.class)))
.andReturn("packageName1");
PowerMock.replayAll();
@@ -288,7 +298,8 @@ public class RuleMgtWrapperTest {
correlationRule.setEnabled(1);
EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(ruleDeleteRequest.getRuleId()))
.andReturn(correlationRule);
- EasyMock.expect(engineWrapperMock.deleteRuleFromEngine(EasyMock.anyObject(String.class))).andReturn(true);
+ EasyMock.expect(engineWrapperMock.deleteRuleFromEngine(EasyMock.anyObject(String.class)
+ , EasyMock.anyObject(String.class))).andReturn(true);
correlationRuleDaoMock.deleteRule(EasyMock.anyObject(CorrelationRule.class));
EasyMock.expectLastCall();
PowerMock.replayAll();
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java
new file mode 100644
index 0000000..b07efe9
--- /dev/null
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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 org.easymock.EasyMock;
+import org.hamcrest.core.IsNull;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.holmes.common.api.entity.CorrelationRule;
+import org.onap.holmes.rulemgt.db.CorrelationRuleDao;
+import org.powermock.api.easymock.PowerMock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class RuleQueryWrapperTest {
+ private CorrelationRuleDao correlationRuleDao;
+ private RuleQueryWrapper ruleQueryWrapper;
+
+ @Before
+ public void setUp() {
+ correlationRuleDao = PowerMock.createMock(CorrelationRuleDao.class);
+ ruleQueryWrapper = PowerMock.createMock(RuleQueryWrapper.class);
+ }
+
+ @Test
+ public void queryRuleByEnable() throws Exception{
+ int enable = 0;
+ EasyMock.expect(ruleQueryWrapper.queryRuleByEnable(EasyMock.anyInt())).andReturn(new ArrayList<CorrelationRule>());
+ PowerMock.replayAll();
+ List<CorrelationRule> correlationRules = ruleQueryWrapper.queryRuleByEnable(enable);
+ PowerMock.verifyAll();
+ Assert.assertThat(correlationRules, IsNull.<List<CorrelationRule>>notNullValue());
+ }
+
+ @Test
+ public void queryRuleByEngineInstance() throws Exception{
+ String engineInstance = "10.96.33.34";
+ EasyMock.expect(ruleQueryWrapper.queryRuleByEngineInstance(EasyMock.anyObject(String.class))).andReturn(new ArrayList<CorrelationRule>());
+ PowerMock.replayAll();
+ List<CorrelationRule> correlationRules = ruleQueryWrapper.queryRuleByEngineInstance(engineInstance);
+ PowerMock.verifyAll();
+ Assert.assertThat(correlationRules, IsNull.<List<CorrelationRule>>notNullValue());
+ }
+}