diff options
Diffstat (limited to 'rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper')
-rw-r--r-- | rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleMgtWrapperTest.java | 25 | ||||
-rw-r--r-- | rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java | 61 |
2 files changed, 79 insertions, 7 deletions
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()); + } +} |