diff options
Diffstat (limited to 'rulemgt/src/test/java')
20 files changed, 119 insertions, 333 deletions
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java index 8e4a6fe..0687731 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2020 ZTE Corporation. + * Copyright 2020-2022 ZTE Corporation. * <p> * 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 @@ -22,15 +22,12 @@ import org.onap.holmes.common.utils.MsbRegister; import org.onap.msb.sdk.discovery.entity.MicroServiceInfo; import org.powermock.api.easymock.PowerMock; import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.internal.WhiteboxImpl; import java.util.concurrent.TimeUnit; @RunWith(PowerMockRunner.class) @PrepareForTest(MicroServiceConfig.class) -@SuppressStaticInitializationFor("org.onap.holmes.common.utils.CommonUtils") public class InitializerTest { @Test @@ -49,7 +46,7 @@ public class InitializerTest { setReadyFlagAfter(3); - WhiteboxImpl.invokeMethod(initializer, "init"); + initializer.run(null); TimeUnit.SECONDS.sleep(6); diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAllocatorTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAllocatorTest.java index 04be2e0..561f5d5 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAllocatorTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAllocatorTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2017-2020 ZTE Corporation. + * Copyright 2017-2021 ZTE Corporation. * <p> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,24 +17,17 @@ package org.onap.holmes.rulemgt; -import org.glassfish.hk2.api.ServiceLocator; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; -import org.junit.runner.RunWith; import org.onap.holmes.common.api.entity.CorrelationRule; -import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder; -import org.onap.holmes.common.utils.DbDaoUtil; import org.onap.holmes.rulemgt.bolt.enginebolt.EngineWrapper; -import org.onap.holmes.rulemgt.db.CorrelationRuleDao; +import org.onap.holmes.rulemgt.db.CorrelationRuleService; import org.onap.holmes.rulemgt.tools.EngineTools; import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper; import org.onap.holmes.rulemgt.wrapper.RuleQueryWrapper; import org.powermock.api.easymock.PowerMock; import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; import java.util.ArrayList; import java.util.Calendar; @@ -44,17 +37,15 @@ import java.util.stream.Collectors; import static org.easymock.EasyMock.*; import static org.onap.holmes.rulemgt.RuleAllocator.ENABLE; -@RunWith(PowerMockRunner.class) -@PrepareForTest({ServiceLocator.class, RuleMgtWrapper.class, RuleQueryWrapper.class, EngineWrapper.class, - EngineTools.class, DbDaoUtil.class, ServiceLocatorHolder.class}) +@PrepareForTest({RuleMgtWrapper.class, RuleQueryWrapper.class, EngineWrapper.class, + EngineTools.class}) public class RuleAllocatorTest { private RuleMgtWrapper ruleMgtWrapperMock; private RuleQueryWrapper ruleQueryWrapperMock; private EngineWrapper engineWrapperMock; private EngineTools engineToolsMock; - private DbDaoUtil dbDaoUtilMock; - private CorrelationRuleDao correlationRuleDaoMock; + private CorrelationRuleService correlationRuleServiceMock; private List<CorrelationRule> rules; private List<String> existingIps; @@ -65,8 +56,7 @@ public class RuleAllocatorTest { ruleQueryWrapperMock = PowerMock.createMock(RuleQueryWrapper.class); engineWrapperMock = PowerMock.createMock(EngineWrapper.class); engineToolsMock = PowerMock.createMock(EngineTools.class); - dbDaoUtilMock = PowerMock.createMock(DbDaoUtil.class); - correlationRuleDaoMock = PowerMock.createMock(CorrelationRuleDao.class); + correlationRuleServiceMock = PowerMock.createMock(CorrelationRuleService.class); rules = new ArrayList<>(); for (int i = 0; i < 20; ++i) { @@ -107,7 +97,6 @@ public class RuleAllocatorTest { ipListFromMsb.addAll(newEngineInstances); ipListFromMsb.addAll(existingIps); - expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(correlationRuleDaoMock); expect(engineToolsMock.getInstanceList()).andReturn(ipListFromMsb); expect(engineToolsMock.getLegacyEngineInstances()).andReturn(existingIps); expect(ruleQueryWrapperMock.queryRuleByEnable(ENABLE)).andReturn(rules.stream() @@ -124,13 +113,13 @@ public class RuleAllocatorTest { expect(ruleMgtWrapperMock.deployRule2Engine(anyObject(CorrelationRule.class), anyObject(String.class))).andReturn("").anyTimes(); - correlationRuleDaoMock.updateRule(anyObject(CorrelationRule.class)); + correlationRuleServiceMock.updateRule(anyObject(CorrelationRule.class)); expectLastCall().anyTimes(); PowerMock.replayAll(); RuleAllocator ruleAllocator = new RuleAllocator(ruleMgtWrapperMock, ruleQueryWrapperMock, - engineWrapperMock, engineToolsMock, dbDaoUtilMock); + engineWrapperMock, engineToolsMock, correlationRuleServiceMock); ruleAllocator.allocateRules(); PowerMock.verifyAll(); @@ -144,7 +133,6 @@ public class RuleAllocatorTest { ipListFromMsb.addAll(existingIps); ipListFromMsb.remove(0); - expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn(correlationRuleDaoMock); expect(engineToolsMock.getInstanceList()).andReturn(ipListFromMsb); expect(engineToolsMock.getLegacyEngineInstances()).andReturn(existingIps); for (String ip : existingIps) { @@ -153,13 +141,13 @@ public class RuleAllocatorTest { } expect(ruleMgtWrapperMock.deployRule2Engine(anyObject(CorrelationRule.class), anyString())).andReturn("anyId").times(2); - correlationRuleDaoMock.updateRule(anyObject(CorrelationRule.class)); + correlationRuleServiceMock.updateRule(anyObject(CorrelationRule.class)); expectLastCall().times(2); PowerMock.replayAll(); RuleAllocator ruleAllocator = new RuleAllocator(ruleMgtWrapperMock, ruleQueryWrapperMock, - engineWrapperMock, engineToolsMock, dbDaoUtilMock); + engineWrapperMock, engineToolsMock, correlationRuleServiceMock); ruleAllocator.allocateRules(); diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAppConfigTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAppConfigTest.java deleted file mode 100644 index d411603..0000000 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/RuleAppConfigTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/**
- * 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 index e292e16..e5b42fe 100644 --- 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 @@ -16,11 +16,11 @@ package org.onap.holmes.rulemgt.bean.request;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
import org.junit.Test;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
public class CorrelationCheckRule4EngineTest {
@Test
public void getterAndSetter4Content(){
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 index 418ff41..82ad66d 100644 --- 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 @@ -16,11 +16,11 @@ package org.onap.holmes.rulemgt.bean.request;
-import static org.junit.Assert.*;
-import static org.hamcrest.core.IsEqual.equalTo;
-
import org.junit.Test;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
public class CorrelationDeployRule4EngineTest {
@Test
public void getterAndSetter4Content(){
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 index e616a71..52f7b50 100644 --- 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 @@ -17,11 +17,11 @@ package org.onap.holmes.rulemgt.bean.request;
+import org.junit.Test;
+
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import org.junit.Test;
-
public class CorrelationRestRequestTest {
@Test
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 index 54fa132..7fb874e 100644 --- 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 @@ -16,11 +16,11 @@ package org.onap.holmes.rulemgt.bean.request;
+import org.junit.Test;
+
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
-import org.junit.Test;
+import static org.junit.Assert.assertThat;
public class RuleCreateRequestTest {
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 index 3d49b2f..97bcd5c 100644 --- 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 @@ -16,11 +16,11 @@ package org.onap.holmes.rulemgt.bean.request;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
import org.junit.Test;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
public class RuleDeleteRequestTest {
@Test
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 index 36d5024..9488faa 100644 --- 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 @@ -16,11 +16,11 @@ package org.onap.holmes.rulemgt.bean.request;
+import org.junit.Test;
+
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
-import org.junit.Test;
+import static org.junit.Assert.assertThat;
public class RuleQueryConditionTest {
@Test
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 index 9f24c0c..f693c76 100644 --- 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 @@ -16,11 +16,11 @@ package org.onap.holmes.rulemgt.bean.request;
+import org.junit.Test;
+
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
-import org.junit.Test;
+import static org.junit.Assert.assertThat;
public class RuleUpdateRequestTest {
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 index a7db0fe..f36fdb4 100644 --- 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 @@ -16,11 +16,11 @@ package org.onap.holmes.rulemgt.bean.response;
-import static org.junit.Assert.*;
-import static org.hamcrest.core.IsEqual.equalTo;
-
import org.junit.Test;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
public class RuleAddAndUpdateResponseTest {
@Test
public void getterAndSetter4RuleId(){
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 index fa423db..aaa62f5 100644 --- 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 @@ -16,13 +16,14 @@ 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 org.junit.Test;
import java.util.ArrayList;
import java.util.List;
-import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
public class RuleQueryListResponseTest {
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 index 2c006ab..0953d10 100644 --- 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 @@ -16,12 +16,13 @@ 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 org.junit.Test;
import java.util.Date;
-import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
public class RuleResult4APITest {
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 6bfb387..5e7eb19 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 @@ -33,6 +33,7 @@ import static org.easymock.EasyMock.*; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
+import static org.powermock.api.easymock.PowerMock.createMock;
import static org.powermock.api.easymock.PowerMock.*;
@RunWith(PowerMockRunner.class)
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryServiceTest.java index 0e97e3a..a2bd863 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDaoTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryServiceTest.java @@ -17,6 +17,10 @@ package org.onap.holmes.rulemgt.db;
import org.easymock.EasyMock;
+import org.jdbi.v3.core.Handle;
+import org.jdbi.v3.core.Jdbi;
+import org.jdbi.v3.core.result.ResultIterable;
+import org.jdbi.v3.core.statement.Query;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -24,14 +28,11 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith;
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.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
-import org.skife.jdbi.v2.Handle;
-import org.skife.jdbi.v2.Query;
import java.util.*;
@@ -39,30 +40,28 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({DbDaoUtil.class, Handle.class, Query.class})
-public class CorrelationRuleQueryDaoTest {
+@PrepareForTest({Handle.class, Query.class})
+public class CorrelationRuleQueryServiceTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
-
- private DbDaoUtil dbDaoUtil;
-
private Handle handle;
-
private Query query;
-
- private CorrelationRuleQueryDao correlationRuleQueryDao;
+ private ResultIterable resultIterable;
+ private CorrelationRuleQueryService correlationRuleQueryDao;
private RuleQueryCondition ruleQueryCondition;
+ private Jdbi jdbi;
@Before
public void setUp() throws Exception {
- correlationRuleQueryDao = new CorrelationRuleQueryDao();
+ correlationRuleQueryDao = new CorrelationRuleQueryService();
- dbDaoUtil = PowerMock.createMock(DbDaoUtil.class);
+ jdbi = PowerMock.createMock(Jdbi.class);
handle = PowerMock.createMock(Handle.class);
query = PowerMock.createMock(Query.class);
+ resultIterable = PowerMock.createMock(ResultIterable.class);
- Whitebox.setInternalState(correlationRuleQueryDao, "dbDaoUtil", dbDaoUtil);
+ Whitebox.setInternalState(correlationRuleQueryDao, "jdbi", jdbi);
ruleQueryCondition = createRuleQueryCondition();
}
@@ -74,10 +73,10 @@ public class CorrelationRuleQueryDaoTest { thrown.expect(CorrelationException.class);
thrown.expectMessage("Failed to query the rule.");
- EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);
+ EasyMock.expect(jdbi.open()).andReturn(handle);
EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);
- EasyMock.expect(query.list()).andThrow(new RuntimeException()).anyTimes();
- dbDaoUtil.close(handle);
+ EasyMock.expect(query.mapToMap()).andThrow(new RuntimeException()).anyTimes();
+ handle.close();
EasyMock.expectLastCall();
PowerMock.replayAll();
@@ -89,10 +88,11 @@ public class CorrelationRuleQueryDaoTest { @Test
public void getCorrelationRulesByCondition_normal() throws Exception {
- EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);
+ EasyMock.expect(jdbi.open()).andReturn(handle);
EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);
- EasyMock.expect(query.list()).andReturn(createQueryResult()).anyTimes();
- dbDaoUtil.close(handle);
+ EasyMock.expect(query.mapToMap()).andReturn(resultIterable);
+ EasyMock.expect(resultIterable.list()).andReturn(createQueryResult());
+ handle.close();
EasyMock.expectLastCall();
PowerMock.replayAll();
@@ -108,10 +108,11 @@ public class CorrelationRuleQueryDaoTest { thrown.expect(CorrelationException.class);
thrown.expectMessage("An error occurred while building the query SQL.");
- EasyMock.expect(dbDaoUtil.getHandle()).andReturn(handle);
+ EasyMock.expect(jdbi.open()).andReturn(handle);
EasyMock.expect(handle.createQuery(EasyMock.anyObject(String.class))).andReturn(query);
- EasyMock.expect(query.list()).andReturn(createQueryResult()).anyTimes();
- dbDaoUtil.close(handle);
+ EasyMock.expect(query.mapToMap()).andReturn(resultIterable);
+ EasyMock.expect(resultIterable.list()).andReturn(createQueryResult());
+ handle.close();
EasyMock.expectLastCall();
PowerMock.replayAll();
@@ -128,16 +129,16 @@ public class CorrelationRuleQueryDaoTest { value.put("rid", "rule_" + System.currentTimeMillis());
value.put("description", "desc");
value.put("enable", 0);
- value.put("templateID", 1L);
- value.put("engineId", "engine-001");
- value.put("engineType", "engineType-001");
+ value.put("templateid", 1L);
+ value.put("engineid", "engine-001");
+ value.put("enginetype", "engineType-001");
value.put("creator", "admin");
- value.put("createTime", new Date());
+ value.put("createtime", new Date());
value.put("updator", "admin");
- value.put("updateTime", new Date());
+ value.put("updatetime", new Date());
value.put("params", new Properties());
value.put("domain", "Domain");
- value.put("isManual", 0);
+ value.put("ismanual", 0);
value.put("vendor", "Vendor");
value.put("content", "Contents");
value.put("package", "package");
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java index 0f0f81a..396c2c1 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java @@ -28,20 +28,15 @@ import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse; import org.onap.holmes.rulemgt.bean.response.RuleResult4API; import org.powermock.api.easymock.PowerMock; import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; -import java.util.HashMap; -import java.util.Map; - import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertThat; @RunWith(PowerMockRunner.class) @PrepareForTest({JerseyClient.class}) -@SuppressStaticInitializationFor({"org.onap.holmes.common.utils.JerseyClient"}) public class ConfigFileScanningTaskTest { @Rule diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java deleted file mode 100644 index b6e7149..0000000 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Copyright 2017-2021 ZTE Corporation. - * <p> - * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * 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.dcae; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.holmes.common.dcae.DcaeConfigurationQuery; -import org.onap.holmes.common.dcae.entity.DcaeConfigurations; -import org.onap.holmes.common.dcae.entity.Rule; -import org.onap.holmes.common.utils.JerseyClient; -import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse; -import org.onap.holmes.rulemgt.bean.response.RuleResult4API; -import org.powermock.api.easymock.PowerMock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import java.util.ArrayList; -import java.util.List; - -import static org.easymock.EasyMock.*; -import static org.powermock.api.easymock.PowerMock.*; - -@RunWith(PowerMockRunner.class) -@SuppressStaticInitializationFor("org.onap.holmes.common.utils.JerseyClient") -@PrepareForTest({DcaeConfigurationPolling.class, DcaeConfigurationQuery.class}) -public class DcaeConfigurationPollingTest { - - @Test - public void run() throws Exception { - DcaeConfigurations dcaeConfigurations = new DcaeConfigurations(); - dcaeConfigurations.addDefaultRule(new Rule("test", "clName", "contents", 1)); - mockStatic(DcaeConfigurationQuery.class); - expect(DcaeConfigurationQuery.getDcaeConfigurations(anyObject(String.class))).andReturn(dcaeConfigurations); - DcaeConfigurationPolling dcaeConfigurationPolling = new DcaeConfigurationPolling("localhost"); - - Whitebox.setInternalState(dcaeConfigurationPolling, "url", "http://127.0.0.1"); - - RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse(); - List<RuleResult4API> ruleResult4APIList = new ArrayList<RuleResult4API>() { - { - add(new RuleResult4API()); - } - }; - ruleQueryListResponse.setCorrelationRules(ruleResult4APIList); - ruleQueryListResponse.setTotalCount(ruleResult4APIList.size()); - - JerseyClient mockedJerseyClient = PowerMock.createMock(JerseyClient.class); - PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.get(anyString(), anyObject())).andReturn(ruleQueryListResponse); - - PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.delete(anyString())).andReturn("true"); - - PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.header(anyString(), anyString())).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.put(anyString(), anyObject())).andReturn("true"); - - replayAll(); - - dcaeConfigurationPolling.run(); - - verifyAll(); - } - - @Test - public void run_identical_contents() throws Exception { - DcaeConfigurations dcaeConfigurations = new DcaeConfigurations(); - dcaeConfigurations.addDefaultRule(new Rule("test", "clName", "contents", 1)); - mockStatic(DcaeConfigurationQuery.class); - expect(DcaeConfigurationQuery.getDcaeConfigurations(anyObject(String.class))).andReturn(dcaeConfigurations).times(2); - DcaeConfigurationPolling dcaeConfigurationPolling = new DcaeConfigurationPolling("localhost"); - - Whitebox.setInternalState(dcaeConfigurationPolling, "url", "http://127.0.0.1"); - - RuleQueryListResponse ruleQueryListResponse = new RuleQueryListResponse(); - List<RuleResult4API> ruleResult4APIList = new ArrayList<RuleResult4API>() { - { - add(new RuleResult4API()); - } - }; - ruleQueryListResponse.setCorrelationRules(ruleResult4APIList); - ruleQueryListResponse.setTotalCount(ruleResult4APIList.size()); - JerseyClient mockedJerseyClient = PowerMock.createMock(JerseyClient.class); - PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.get(anyString(), anyObject())).andReturn(ruleQueryListResponse); - - PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.delete(anyString())).andReturn("true"); - - PowerMock.expectNew(JerseyClient.class).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.header(anyString(), anyString())).andReturn(mockedJerseyClient); - expect(mockedJerseyClient.put(anyString(), anyObject())).andReturn("true"); - - replayAll(); - - dcaeConfigurationPolling.run(); - dcaeConfigurationPolling.run(); - - verifyAll(); - } -}
\ 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 index a35f6b8..a515196 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java @@ -1,5 +1,5 @@ /**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,25 +17,28 @@ package org.onap.holmes.rulemgt.resources;
import com.google.gson.JsonSyntaxException;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.WebApplicationException;
+import jakarta.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.junit.runner.RunWith;
+import org.onap.holmes.common.exception.CorrelationException;
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.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
import org.powermock.api.easymock.PowerMock;
+import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
+import javax.servlet.http.HttpServletRequest;
+
+@RunWith(PowerMockRunner.class)
public class RuleMgtResourcesTest {
@Rule
@@ -47,8 +50,6 @@ public class RuleMgtResourcesTest { private RuleMgtResources ruleMgtResources = new RuleMgtResources();
- private Request requestMock = PowerMock.createMock(Request.class);
-
@Before
public void setUp() throws Exception {
Whitebox.setInternalState(ruleMgtResources, "ruleMgtWrapper", ruleMgtWrapper);
@@ -63,7 +64,6 @@ public class RuleMgtResourcesTest { 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);
@@ -76,7 +76,6 @@ public class RuleMgtResourcesTest { 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);
@@ -90,7 +89,6 @@ public class RuleMgtResourcesTest { 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);
@@ -102,7 +100,6 @@ public class RuleMgtResourcesTest { 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);
@@ -115,10 +112,9 @@ public class RuleMgtResourcesTest { final String ruleId = "mockedRule";
ruleMgtWrapper.deleteCorrelationRule(EasyMock.anyObject(RuleDeleteRequest.class));
- EasyMock.expectLastCall().andThrow(new CorrelationException(EasyMock.anyObject(String.class)));
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
+ EasyMock.expectLastCall().andThrow(new CorrelationException("any string"));
PowerMock.replayAll();
- ruleMgtResources.deleteCorrelationRule(request, ruleId);
+ ruleMgtResources.deleteCorrelationRule(ruleId);
PowerMock.verifyAll();
}
@@ -127,9 +123,8 @@ public class RuleMgtResourcesTest { final String ruleId = "mockedRule";
ruleMgtWrapper.deleteCorrelationRule(EasyMock.anyObject(RuleDeleteRequest.class));
EasyMock.expectLastCall();
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
PowerMock.replayAll();
- ruleMgtResources.deleteCorrelationRule(request, ruleId);
+ ruleMgtResources.deleteCorrelationRule(ruleId);
PowerMock.verifyAll();
}
@@ -140,10 +135,9 @@ public class RuleMgtResourcesTest { 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);
+ .andThrow(new CorrelationException("any string"));
PowerMock.replayAll();
- ruleMgtResources.getCorrelationRules(request, requestStr);
+ ruleMgtResources.getCorrelationRules(requestStr);
PowerMock.verifyAll();
}
@@ -152,10 +146,9 @@ public class RuleMgtResourcesTest { thrown.expect(JsonSyntaxException.class);
String queryRequest = "this is error param";
- EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);
PowerMock.replayAll();
- ruleMgtResources.getCorrelationRules(request, queryRequest);
+ ruleMgtResources.getCorrelationRules(queryRequest);
PowerMock.verifyAll();
}
@@ -164,9 +157,8 @@ public class RuleMgtResourcesTest { 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);
+ ruleMgtResources.getCorrelationRules(null);
PowerMock.verifyAll();
}
@@ -176,9 +168,8 @@ public class RuleMgtResourcesTest { + "\"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);
+ ruleMgtResources.getCorrelationRules(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 index 626b91d..1ba93d4 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 @@ -22,19 +22,16 @@ 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.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.*; 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.CorrelationRuleDao; -import org.onap.holmes.rulemgt.db.CorrelationRuleQueryDao; +import org.onap.holmes.rulemgt.db.CorrelationRuleQueryService; +import org.onap.holmes.rulemgt.db.CorrelationRuleService; import org.onap.holmes.rulemgt.tools.EngineTools; import org.powermock.api.easymock.PowerMock; -import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; import java.util.ArrayList; @@ -46,7 +43,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -@RunWith(PowerMockRunner.class) public class RuleMgtWrapperTest { @Rule @@ -56,42 +52,33 @@ public class RuleMgtWrapperTest { private EngineWrapper engineWrapperMock; - private DbDaoUtil dbDaoUtilMock; + private CorrelationRuleQueryService correlationRuleQueryDaoMock; - private CorrelationRuleQueryDao correlationRuleQueryDaoMock; - - private CorrelationRuleDao correlationRuleDaoMock; + private CorrelationRuleService correlationRuleServiceMock; private EngineTools engineToolsMock; private static final String USER_NAME = "admin"; @Before - public void setUp() throws Exception { + public void setUp() { ruleMgtWrapper = new RuleMgtWrapper(); engineWrapperMock = PowerMock.createMock(EngineWrapper.class); - correlationRuleQueryDaoMock = PowerMock.createMock(CorrelationRuleQueryDao.class); - dbDaoUtilMock = PowerMock.createMock(DbDaoUtil.class); - correlationRuleDaoMock = PowerMock.createMock(CorrelationRuleDao.class); + correlationRuleQueryDaoMock = PowerMock.createMock(CorrelationRuleQueryService.class); + correlationRuleServiceMock = PowerMock.createMock(CorrelationRuleService.class); engineToolsMock = PowerMock.createMock(EngineTools.class); - Whitebox.setInternalState(ruleMgtWrapper, "daoUtil", dbDaoUtilMock); + Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleService", correlationRuleServiceMock); Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleQueryDao", correlationRuleQueryDaoMock); Whitebox.setInternalState(ruleMgtWrapper, "engineWarpper", engineWrapperMock); - Whitebox.setInternalState(ruleMgtWrapper, "correlationRuleDao", correlationRuleDaoMock); Whitebox.setInternalState(ruleMgtWrapper,"engineTools", engineToolsMock); 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."); @@ -147,7 +134,7 @@ public class RuleMgtWrapperTest { thrown.expect(CorrelationException.class); thrown.expectMessage("A rule with the same name already exists."); - EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(correlationRule); + EasyMock.expect(correlationRuleServiceMock.queryRuleByRuleName(ruleName)).andReturn(correlationRule); PowerMock.replayAll(); ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest); @@ -166,7 +153,7 @@ public class RuleMgtWrapperTest { CorrelationRule correlationRuleRet = new CorrelationRule(); correlationRuleRet.setRid("rule_" + System.currentTimeMillis()); - EasyMock.expect(correlationRuleDaoMock.queryRuleByRuleName(ruleName)).andReturn(null); + EasyMock.expect(correlationRuleServiceMock.queryRuleByRuleName(ruleName)).andReturn(null); EasyMock.expect(engineToolsMock.getEngineWithLeastRules()).andReturn("127.0.0.1"); EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class) , EasyMock.anyObject(String.class))) @@ -174,12 +161,13 @@ public class RuleMgtWrapperTest { EasyMock.expect(engineWrapperMock.deployEngine(EasyMock.anyObject(CorrelationDeployRule4Engine.class) , EasyMock.anyObject(String.class))) .andReturn("package-001"); - EasyMock.expect(correlationRuleDaoMock.saveRule(EasyMock.anyObject(CorrelationRule.class))) + EasyMock.expect(correlationRuleServiceMock.saveRule(EasyMock.anyObject(CorrelationRule.class))) .andReturn(correlationRuleRet); PowerMock.replayAll(); RuleAddAndUpdateResponse response = ruleMgtWrapper.addCorrelationRule("admin", ruleCreateRequest); + PowerMock.verifyAll(); assertThat(response.getRuleId(), equalTo(correlationRuleRet.getRid())); @@ -206,10 +194,10 @@ public class RuleMgtWrapperTest { oldCorrelationRule.setEngineInstance("127.0.0.1"); RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_1", "cl-name", "des2", "contetnt2", 1); - EasyMock.expect(correlationRuleDaoMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule); + EasyMock.expect(correlationRuleServiceMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule); EasyMock.expect(engineToolsMock.getInstanceList()).andReturn(Arrays.asList("127.0.0.1", "127.0.0.2")).times(2); EasyMock.expect(engineWrapperMock.deleteRuleFromEngine("testName", "127.0.0.1")).andReturn(true); - correlationRuleDaoMock.updateRule(EasyMock.anyObject(CorrelationRule.class)); + correlationRuleServiceMock.updateRule(EasyMock.anyObject(CorrelationRule.class)); EasyMock.expectLastCall(); EasyMock.expect(engineWrapperMock.checkRuleFromEngine(EasyMock.anyObject(CorrelationCheckRule4Engine.class) , EasyMock.anyObject(String.class))) @@ -239,7 +227,7 @@ public class RuleMgtWrapperTest { oldCorrelationRule.setEngineInstance("127.0.0.1"); RuleUpdateRequest ruleUpdateRequest = createRuleUpdateRequest("rule_1", "cl-name", "des1", "content", 1); - EasyMock.expect(correlationRuleDaoMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule); + EasyMock.expect(correlationRuleServiceMock.queryRuleByRid("rule_1")).andReturn(oldCorrelationRule); EasyMock.expect(engineToolsMock.getInstanceList()).andReturn(Arrays.asList("127.0.0.1", "127.0.0.2")); PowerMock.replayAll(); @@ -256,7 +244,7 @@ public class RuleMgtWrapperTest { 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); + EasyMock.expect(correlationRuleServiceMock.queryRuleByRid(EasyMock.anyObject(String.class))).andReturn(null); PowerMock.replayAll(); @@ -280,9 +268,7 @@ public class RuleMgtWrapperTest { RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis()); - EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(CorrelationRuleDao.class)).andReturn( - correlationRuleDaoMock).anyTimes(); - EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(ruleDeleteRequest.getRuleId())) + EasyMock.expect(correlationRuleServiceMock.queryRuleByRid(ruleDeleteRequest.getRuleId())) .andReturn(null); PowerMock.replayAll(); @@ -297,11 +283,11 @@ public class RuleMgtWrapperTest { RuleDeleteRequest ruleDeleteRequest = createRuleDeleteRequest("rule_" + System.currentTimeMillis()); CorrelationRule correlationRule = new CorrelationRule(); correlationRule.setEnabled(1); - EasyMock.expect(correlationRuleDaoMock.queryRuleByRid(ruleDeleteRequest.getRuleId())) + EasyMock.expect(correlationRuleServiceMock.queryRuleByRid(ruleDeleteRequest.getRuleId())) .andReturn(correlationRule); EasyMock.expect(engineWrapperMock.deleteRuleFromEngine(EasyMock.anyObject(String.class) , EasyMock.anyObject(String.class))).andReturn(true); - correlationRuleDaoMock.deleteRule(EasyMock.anyObject(CorrelationRule.class)); + correlationRuleServiceMock.deleteRule(EasyMock.anyObject(CorrelationRule.class)); EasyMock.expectLastCall(); PowerMock.replayAll(); @@ -319,11 +305,11 @@ public class RuleMgtWrapperTest { RuleQueryCondition.class))) .andThrow(new CorrelationException("An error occurred while building the query SQL.")); - PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class); + PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class); ruleMgtWrapper.getCorrelationRuleByCondition(new RuleQueryCondition()); - PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class); + PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class); } @Test @@ -335,11 +321,11 @@ public class RuleMgtWrapperTest { RuleQueryCondition.class))) .andThrow(new CorrelationException("Failed to query the rule.")); - PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class); + PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class); ruleMgtWrapper.getCorrelationRuleByCondition(new RuleQueryCondition()); - PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class); + PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class); } @Test @@ -362,11 +348,11 @@ public class RuleMgtWrapperTest { EasyMock.expect(correlationRuleQueryDaoMock.getCorrelationRulesByCondition(EasyMock.anyObject( RuleQueryCondition.class))).andReturn(correlationRuleList); - PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class); + PowerMock.replay(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class); RuleQueryListResponse response = ruleMgtWrapper.getCorrelationRuleByCondition(new RuleQueryCondition()); - PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryDao.class); + PowerMock.verify(correlationRuleQueryDaoMock, CorrelationRuleQueryService.class); assertThat(response.getTotalCount(), is(10)); 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 index 4c7b1a0..8bb7e7a 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/wrapper/RuleQueryWrapperTest.java @@ -22,7 +22,7 @@ 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.onap.holmes.rulemgt.db.jdbi.CorrelationRuleDao; import org.powermock.api.easymock.PowerMock; import java.util.ArrayList; |