summaryrefslogtreecommitdiffstats
path: root/engine-d/src/test
diff options
context:
space:
mode:
authorGuangrongFu <fu.guangrong@zte.com.cn>2021-12-18 15:08:14 +0800
committerGuangrong Fu <fu.guangrong@zte.com.cn>2022-08-11 18:51:35 +0800
commitc4bd70c1f74cd04c441f76de4359e166a089660a (patch)
tree634a0da7181a1fa8030fb6beb14d8a7d2f6d86c3 /engine-d/src/test
parent61da3e3d053548815054384e5e18750e87463ee9 (diff)
Switched from Dropwizard to Springboot
Issue-ID: HOLMES-511 Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn> Change-Id: I72b53ad4073e0a07a4c6a234781dc0d139584dda
Diffstat (limited to 'engine-d/src/test')
-rw-r--r--engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java1
-rw-r--r--engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java26
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/EnginedAppConfigTest.java60
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/InitializerTest.java5
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/db/AlarmInfoDaoTest.java14
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/db/CorrelationRuleDaoTest.java1
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/dcae/ConfigFileScanningTaskTest.java19
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPollingTest.java33
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.java156
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java33
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/wrapper/RuleMgtWrapperTest.java29
11 files changed, 138 insertions, 239 deletions
diff --git a/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java b/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java
index ded50b0..9f5fd0f 100644
--- a/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java
@@ -19,7 +19,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.onap.holmes.common.api.stat.AlarmAdditionalField;
import org.onap.holmes.common.api.stat.VesAlarm;
import org.powermock.core.classloader.annotations.PrepareForTest;
diff --git a/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java b/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java
index 339a23e..96794ce 100644
--- a/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java
@@ -15,25 +15,23 @@
*/
package org.onap.holmes.dsa.dmaappolling;
-import org.glassfish.hk2.api.ServiceLocator;
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.stat.AlarmAdditionalField;
import org.onap.holmes.common.api.stat.VesAlarm;
-import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.JerseyClient;
+import org.onap.holmes.common.utils.SpringContextUtil;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.util.ArrayList;
-import java.util.List;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import static org.easymock.EasyMock.*;
@@ -41,7 +39,7 @@ import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({ServiceLocatorHolder.class, JerseyClient.class})
+@PrepareForTest({SpringContextUtil.class, JerseyClient.class})
@PowerMockIgnore("javax.net.ssl.*")
public class SubscriberTest {
@@ -52,10 +50,8 @@ public class SubscriberTest {
@Before
public void init() {
- PowerMock.mockStatic(ServiceLocatorHolder.class);
- ServiceLocator serviceLocator = PowerMock.createMock(ServiceLocator.class);
- expect(ServiceLocatorHolder.getLocator()).andReturn(serviceLocator).anyTimes();
- expect(serviceLocator.getService(DMaaPResponseUtil.class)).andReturn(util).anyTimes();
+ PowerMock.mockStatic(SpringContextUtil.class);
+ expect(SpringContextUtil.getBean(DMaaPResponseUtil.class)).andReturn(util).anyTimes();
}
@Test
@@ -77,9 +73,9 @@ public class SubscriberTest {
vesAlarm.setStartEpochMicrosec(500L);
vesAlarm.setVersion("4.0");
Map alarmAdditionalFields = new HashMap<String, String>();
- alarmAdditionalFields.put("addInfo", "addInfo");
- vesAlarm.setAlarmAdditionalInformation(alarmAdditionalFields);
- vesAlarm.setAlarmCondition("alarmCondition");
+ alarmAdditionalFields.put("addInfo", "addInfo");
+ vesAlarm.setAlarmAdditionalInformation(alarmAdditionalFields);
+ vesAlarm.setAlarmCondition("alarmCondition");
vesAlarm.setAlarmInterfaceA("alarmInterfaceA");
vesAlarm.setEventCategory("eventCategory");
vesAlarm.setEventSeverity("eventSeverity");
@@ -161,9 +157,9 @@ public class SubscriberTest {
vesAlarm.setStartEpochMicrosec(500L);
vesAlarm.setVersion("4.0");
Map alarmAdditionalFields = new HashMap<String, String>();
- alarmAdditionalFields.put("addInfo", "addInfo");
- vesAlarm.setAlarmAdditionalInformation(alarmAdditionalFields);
- vesAlarm.setAlarmCondition("alarmCondition");
+ alarmAdditionalFields.put("addInfo", "addInfo");
+ vesAlarm.setAlarmAdditionalInformation(alarmAdditionalFields);
+ vesAlarm.setAlarmCondition("alarmCondition");
vesAlarm.setAlarmInterfaceA("alarmInterfaceA");
vesAlarm.setEventCategory("eventCategory");
vesAlarm.setEventSeverity("eventSeverity");
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/EnginedAppConfigTest.java b/engine-d/src/test/java/org/onap/holmes/engine/EnginedAppConfigTest.java
deleted file mode 100644
index c550b37..0000000
--- a/engine-d/src/test/java/org/onap/holmes/engine/EnginedAppConfigTest.java
+++ /dev/null
@@ -1,60 +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.engine;
-
-import io.dropwizard.db.DataSourceFactory;
-import org.hamcrest.core.IsEqual;
-import org.hamcrest.core.IsNull;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.powermock.api.easymock.PowerMock;
-
-public class EnginedAppConfigTest {
-
- private EngineDAppConfig engineAppConfig;
-
- @Before
- public void setUp() {
- engineAppConfig = new EngineDAppConfig();
- }
-
- @Test
- public void getDataSourceFactory() {
- Assert.assertThat(engineAppConfig.getDataSourceFactory(), IsNull.<DataSourceFactory>notNullValue());
- }
-
- @Test
- public void setDataSourceFactory() {
- DataSourceFactory database = new DataSourceFactory();
- engineAppConfig.setDataSourceFactory(database);
- Assert.assertThat(engineAppConfig.getDataSourceFactory(), IsEqual.equalTo(database));
- }
-
- @Test
- public void getApidescription() {
- final String apidescription = "Holmes rule management rest API";
- Assert.assertThat(engineAppConfig.getApidescription(), IsEqual.equalTo(apidescription));
- }
-
- @Test
- public void setApidescription() {
- final String apidescription = "set api description";
- engineAppConfig.setApidescription(apidescription);
- Assert.assertThat(engineAppConfig.getApidescription(), IsEqual.equalTo(apidescription));
- }
-}
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/InitializerTest.java b/engine-d/src/test/java/org/onap/holmes/engine/InitializerTest.java
index 788c3ae..4dec23d 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/InitializerTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/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
@@ -23,7 +23,6 @@ import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.internal.WhiteboxImpl;
import java.util.concurrent.TimeUnit;
@@ -47,7 +46,7 @@ public class InitializerTest {
setReadyFlagAfter(3);
- WhiteboxImpl.invokeMethod(initializer, "init");
+ initializer.run(null);
TimeUnit.SECONDS.sleep(6);
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/db/AlarmInfoDaoTest.java b/engine-d/src/test/java/org/onap/holmes/engine/db/AlarmInfoDaoTest.java
index 9945322..0eb9049 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/db/AlarmInfoDaoTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/db/AlarmInfoDaoTest.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,15 +17,11 @@
package org.onap.holmes.engine.db;
import org.easymock.EasyMock;
-import org.hamcrest.core.IsNot;
import org.hamcrest.core.IsNull;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.onap.holmes.common.api.entity.AlarmInfo;
-import org.onap.holmes.common.exception.AlarmInfoException;
import org.powermock.api.easymock.PowerMock;
import java.util.ArrayList;
@@ -34,20 +30,20 @@ import java.util.List;
public class AlarmInfoDaoTest {
- private AlarmInfoDao alarmInfoDao;
+ private AlarmInfoDaoService alarmInfoDaoService;
@Before
public void setUp() {
- alarmInfoDao = PowerMock.createMock(AlarmInfoDao.class);
+ alarmInfoDaoService = PowerMock.createMock(AlarmInfoDaoService.class);
}
@Test
public void queryAllAlarm() throws Exception {
- EasyMock.expect(alarmInfoDao.queryAllAlarm()).andReturn(new ArrayList<AlarmInfo>());
+ EasyMock.expect(alarmInfoDaoService.queryAllAlarm()).andReturn(new ArrayList<AlarmInfo>());
PowerMock.replayAll();
- List<AlarmInfo> alarmInfoList = alarmInfoDao.queryAllAlarm();
+ List<AlarmInfo> alarmInfoList = alarmInfoDaoService.queryAllAlarm();
PowerMock.verifyAll();
Assert.assertThat(alarmInfoList, IsNull.<List<AlarmInfo>>notNullValue());
}
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/db/CorrelationRuleDaoTest.java b/engine-d/src/test/java/org/onap/holmes/engine/db/CorrelationRuleDaoTest.java
index 128f58a..01fb585 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/db/CorrelationRuleDaoTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/db/CorrelationRuleDaoTest.java
@@ -22,6 +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.engine.db.jdbi.CorrelationRuleDao;
import org.powermock.api.easymock.PowerMock;
import java.util.ArrayList;
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/dcae/ConfigFileScanningTaskTest.java b/engine-d/src/test/java/org/onap/holmes/engine/dcae/ConfigFileScanningTaskTest.java
index b663133..7f01aa4 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/dcae/ConfigFileScanningTaskTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/dcae/ConfigFileScanningTaskTest.java
@@ -17,15 +17,15 @@
package org.onap.holmes.engine.dcae;
import org.easymock.EasyMock;
-import org.glassfish.hk2.api.ServiceLocator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.holmes.common.dcae.DcaeConfigurationsCache;
-import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;
+import org.onap.holmes.common.utils.SpringContextUtil;
import org.onap.holmes.dsa.dmaappolling.DMaaPResponseUtil;
import org.onap.holmes.dsa.dmaappolling.Subscriber;
import org.onap.holmes.engine.dmaap.SubscriberAction;
import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
@@ -33,16 +33,16 @@ import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
@RunWith(PowerMockRunner.class)
+@PrepareForTest({SpringContextUtil.class})
public class ConfigFileScanningTaskTest {
@Test
public void run() {
- ServiceLocator mockedSl = PowerMock.createMock(ServiceLocator.class);
+ PowerMock.mockStatic(SpringContextUtil.class);
SubscriberAction mockedSa = PowerMock.createMock(SubscriberAction.class);
- ServiceLocatorHolder.setLocator(mockedSl);
- EasyMock.expect(mockedSl.getService(SubscriberAction.class)).andReturn(mockedSa);
+ EasyMock.expect(SpringContextUtil.getBean(SubscriberAction.class)).andReturn(mockedSa);
// This is invoked while executing new Subscriber().
- EasyMock.expect(mockedSl.getService(DMaaPResponseUtil.class)).andReturn(new DMaaPResponseUtil());
+ EasyMock.expect(SpringContextUtil.getBean(DMaaPResponseUtil.class)).andReturn(new DMaaPResponseUtil());
mockedSa.addSubscriber(EasyMock.anyObject(Subscriber.class));
EasyMock.expectLastCall();
@@ -60,13 +60,12 @@ public class ConfigFileScanningTaskTest {
@Test
public void run_config_not_changed() {
- ServiceLocator mockedSl = PowerMock.createMock(ServiceLocator.class);
+ PowerMock.mockStatic(SpringContextUtil.class);
SubscriberAction mockedSa = PowerMock.createMock(SubscriberAction.class);
- ServiceLocatorHolder.setLocator(mockedSl);
// mocked objects will be only used once
- EasyMock.expect(mockedSl.getService(SubscriberAction.class)).andReturn(mockedSa);
+ EasyMock.expect(SpringContextUtil.getBean(SubscriberAction.class)).andReturn(mockedSa);
// This is invoked while executing new Subscriber().
- EasyMock.expect(mockedSl.getService(DMaaPResponseUtil.class)).andReturn(new DMaaPResponseUtil());
+ EasyMock.expect(SpringContextUtil.getBean(DMaaPResponseUtil.class)).andReturn(new DMaaPResponseUtil());
mockedSa.addSubscriber(EasyMock.anyObject(Subscriber.class));
EasyMock.expectLastCall();
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPollingTest.java b/engine-d/src/test/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPollingTest.java
index 74765f5..e809cd8 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPollingTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPollingTest.java
@@ -1,12 +1,12 @@
/**
- * Copyright 2017 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.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <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.
@@ -15,39 +15,40 @@
*/
package org.onap.holmes.engine.dmaap;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
-
-import java.lang.reflect.Field;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.holmes.common.api.entity.AlarmInfo;
import org.onap.holmes.common.api.stat.VesAlarm;
import org.onap.holmes.dsa.dmaappolling.Subscriber;
-import org.onap.holmes.engine.db.AlarmInfoDao;
+import org.onap.holmes.engine.db.AlarmInfoDaoService;
import org.onap.holmes.engine.manager.DroolsEngine;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
-@PrepareForTest({Subscriber.class, DroolsEngine.class,DMaaPAlarmPolling.class})
+import java.lang.reflect.Field;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+@PrepareForTest({Subscriber.class, DroolsEngine.class, DMaaPAlarmPolling.class})
@RunWith(PowerMockRunner.class)
public class DMaaPAlarmPollingTest {
private DMaaPAlarmPolling dMaaPAlarmPolling;
private Subscriber subscriber;
private DroolsEngine droolsEngine;
- private AlarmInfoDao alarmInfoDao;
+ private AlarmInfoDaoService alarmInfoDaoService;
@Before
public void setUp() {
subscriber = PowerMock.createMock(Subscriber.class);
droolsEngine = PowerMock.createMock(DroolsEngine.class);
- alarmInfoDao = PowerMock.createMock(AlarmInfoDao.class);
- dMaaPAlarmPolling = new DMaaPAlarmPolling(subscriber, droolsEngine,alarmInfoDao);
+ alarmInfoDaoService = PowerMock.createMock(AlarmInfoDaoService.class);
+ dMaaPAlarmPolling = new DMaaPAlarmPolling(subscriber, droolsEngine, alarmInfoDaoService);
PowerMock.replayAll();
}
@@ -72,7 +73,7 @@ public class DMaaPAlarmPollingTest {
vesAlarm.setRootFlag(0);
PowerMock.replayAll();
- AlarmInfo alarmInfo = Whitebox.invokeMethod(dMaaPAlarmPolling,"getAlarmInfo",vesAlarm);
+ AlarmInfo alarmInfo = Whitebox.invokeMethod(dMaaPAlarmPolling, "getAlarmInfo", vesAlarm);
PowerMock.verifyAll();
assertThat(alarmInfo.getAlarmIsCleared(), is(1));
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.java b/engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.java
index cb28faa..31f1817 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.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.
@@ -16,7 +16,6 @@
package org.onap.holmes.engine.manager;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -26,11 +25,10 @@ import org.onap.holmes.common.api.stat.VesAlarm;
import org.onap.holmes.common.config.MicroServiceConfig;
import org.onap.holmes.common.dmaap.store.ClosedLoopControlNameCache;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
-import org.onap.holmes.engine.db.AlarmInfoDao;
+import org.onap.holmes.engine.db.AlarmInfoDaoService;
+import org.onap.holmes.engine.db.CorrelationRuleDaoService;
import org.onap.holmes.engine.request.DeployRuleRequest;
import org.onap.holmes.engine.wrapper.RuleMgtWrapper;
-import org.powermock.api.easymock.PowerMock;
import org.powermock.reflect.Whitebox;
import java.util.ArrayList;
@@ -47,33 +45,31 @@ public class DroolsEngineTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- private RuleMgtWrapper ruleMgtWrapper;
+ private RuleMgtWrapper ruleMgtWrapperMock;
private DroolsEngine droolsEngine;
- private DbDaoUtil dbDaoUtilStub;
+ private AlarmInfoDaoService alarmInfoDaoServiceStub;
+
+ private CorrelationRuleDaoService correlationRuleDaoServiceStub;
private ClosedLoopControlNameCache closedLoopControlNameCache;
public DroolsEngineTest() throws Exception {
System.setProperty(MicroServiceConfig.HOSTNAME, "127.0.0.1:80");
droolsEngine = new DroolsEngine();
- ruleMgtWrapper = new RuleMgtWrapperStub();
- dbDaoUtilStub = new DbDaoUtilStub();
+ alarmInfoDaoServiceStub = new AlarmInfoDaoServiceStub();
+ droolsEngine.setAlarmInfoDaoService(alarmInfoDaoServiceStub);
+ correlationRuleDaoServiceStub = new CorrelationRuleDaoServiceStub();
+ ruleMgtWrapperMock = new RuleMgtWrapperStub(correlationRuleDaoServiceStub);
closedLoopControlNameCache = new ClosedLoopControlNameCache();
droolsEngine.setClosedLoopControlNameCache(closedLoopControlNameCache);
- droolsEngine.setDaoUtil(dbDaoUtilStub);
- droolsEngine.setRuleMgtWrapper(ruleMgtWrapper);
+ droolsEngine.setRuleMgtWrapper(ruleMgtWrapperMock);
- Whitebox.invokeMethod(droolsEngine, "init");
+ Whitebox.invokeMethod(droolsEngine, "run", null);
System.clearProperty(MicroServiceConfig.HOSTNAME);
}
- @Before
- public void setUp() throws Exception {
- PowerMock.resetAll();
- }
-
@Test
public void deployRule_rule_is_null() throws CorrelationException {
thrown.expect(NullPointerException.class);
@@ -241,78 +237,74 @@ public class DroolsEngineTest {
assertThat(packages.contains("packageCheck"), is(true));
}
-}
-
-class RuleMgtWrapperStub extends RuleMgtWrapper {
- private List<CorrelationRule> rules;
-
- public RuleMgtWrapperStub() {
- rules = new ArrayList<>();
- CorrelationRule rule = new CorrelationRule();
- rule.setEnabled(1);
- rule.setContent("package org.onap.holmes;");
- rule.setPackageName("UT");
- rule.setClosedControlLoopName(UUID.randomUUID().toString());
- rule.setEngineInstance("127.0.0.1");
- rules.add(rule);
- }
-
- public List<CorrelationRule> getRules() {
- return rules;
- }
-
- public void setRules(List<CorrelationRule> rules) {
- this.rules = rules;
- }
- @Override
- public List<CorrelationRule> queryRuleByEnable(int enabled) throws CorrelationException {
- return rules.stream().filter(rule -> rule.getEnabled() == enabled).collect(Collectors.toList());
+ class RuleMgtWrapperStub extends RuleMgtWrapper {
+ private List<CorrelationRule> rules;
+
+ public RuleMgtWrapperStub(CorrelationRuleDaoService correlationRuleDaoService) {
+ super(correlationRuleDaoService);
+ rules = new ArrayList<>();
+ CorrelationRule rule = new CorrelationRule();
+ rule.setEnabled(1);
+ rule.setContent("package org.onap.holmes;");
+ rule.setPackageName("UT");
+ rule.setClosedControlLoopName(UUID.randomUUID().toString());
+ rule.setEngineInstance("127.0.0.1");
+ rules.add(rule);
+ }
+
+ public List<CorrelationRule> getRules() {
+ return rules;
+ }
+
+ public void setRules(List<CorrelationRule> rules) {
+ this.rules = rules;
+ }
+
+ @Override
+ public List<CorrelationRule> queryRuleByEnable(int enabled) throws CorrelationException {
+ return rules.stream().filter(rule -> rule.getEnabled() == enabled).collect(Collectors.toList());
+ }
}
-}
-class AlarmInfoDaoStub extends AlarmInfoDao {
-
- private List<AlarmInfo> alarms;
-
- public AlarmInfoDaoStub() {
- alarms = new ArrayList<>();
- AlarmInfo info = new AlarmInfo();
- info.setEventId("eventId");
- info.setEventName("eventName");
- info.setStartEpochMicroSec(1L);
- info.setLastEpochMicroSec(1L);
- info.setSourceId("sourceId");
- info.setSourceName("sourceName");
- info.setRootFlag(0);
- info.setAlarmIsCleared(1);
- alarms.add(info);
+ class AlarmInfoDaoServiceStub extends AlarmInfoDaoService {
+
+ private List<AlarmInfo> alarms;
+
+ public AlarmInfoDaoServiceStub() {
+ alarms = new ArrayList<>();
+ AlarmInfo info = new AlarmInfo();
+ info.setEventId("eventId");
+ info.setEventName("eventName");
+ info.setStartEpochMicroSec(1L);
+ info.setLastEpochMicroSec(1L);
+ info.setSourceId("sourceId");
+ info.setSourceName("sourceName");
+ info.setRootFlag(0);
+ info.setAlarmIsCleared(1);
+ alarms.add(info);
+ }
+
+ @Override
+ public AlarmInfo saveAlarm(AlarmInfo alarmInfo) {
+ alarms.add(alarmInfo);
+ return alarmInfo;
+ }
+
+ @Override
+ public List<AlarmInfo> queryAllAlarm() {
+ return alarms;
+ }
+
+ @Override
+ public void deleteAlarm(AlarmInfo alarmInfo) {
+
+ }
}
- @Override
- protected String addAlarm(AlarmInfo alarmInfo) {
- alarms.add(alarmInfo);
- return null;
- }
-
- @Override
- protected List<AlarmInfo> queryAlarm() {
- return alarms;
- }
+ class CorrelationRuleDaoServiceStub extends CorrelationRuleDaoService {
- @Override
- protected int deleteAlarmByAlarmIsCleared(String alarmName, String sourceName, String sourceId) {
- return 1;
}
}
-class DbDaoUtilStub extends DbDaoUtil {
- private AlarmInfoDao dao = new AlarmInfoDaoStub();
- @Override
- public <T> T getJdbiDaoByOnDemand(Class<T> daoClazz) {
-
- return (T) dao;
-
- }
-}
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java b/engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java
index aa2052d..f4ad483 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java
@@ -26,11 +26,8 @@ import org.onap.holmes.engine.manager.DroolsEngine;
import org.onap.holmes.engine.request.CompileRuleRequest;
import org.onap.holmes.engine.request.DeployRuleRequest;
import org.powermock.api.easymock.PowerMock;
-import org.powermock.reflect.Whitebox;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.WebApplicationException;
-import java.util.Locale;
+import jakarta.ws.rs.WebApplicationException;
import static org.easymock.EasyMock.*;
@@ -47,23 +44,20 @@ public class EngineResourcesTest {
closedLoopControlNameCache = new ClosedLoopControlNameCache();
engineResources = new EngineResources();
engineResources.setClosedLoopControlNameCache(closedLoopControlNameCache);
-
- Whitebox.setInternalState(engineResources,"droolsEngine", droolsEngine);
+ engineResources.setDroolsEngine(droolsEngine);
PowerMock.resetAll();
}
@Test
public void deployRule_exception() throws CorrelationException {
DeployRuleRequest deployRuleRequest = new DeployRuleRequest();
- HttpServletRequest httpRequest = PowerMock.createMock(HttpServletRequest.class);
thrown.expect(WebApplicationException.class);
- expect(httpRequest.getHeader("language-option")).andReturn("en_US");
expect(droolsEngine.deployRule(anyObject(DeployRuleRequest.class))).
andThrow(new CorrelationException(""));
PowerMock.replayAll();
- engineResources.deployRule(deployRuleRequest, httpRequest);
+ engineResources.deployRule(deployRuleRequest);
PowerMock.verifyAll();
}
@@ -72,66 +66,55 @@ public class EngineResourcesTest {
DeployRuleRequest deployRuleRequest = new DeployRuleRequest();
deployRuleRequest.setContent("package packageName;\n\nimport xxx.xxx.xxx;");
deployRuleRequest.setLoopControlName("loopControlName");
- HttpServletRequest httpRequest = PowerMock.createMock(HttpServletRequest.class);
- expect(httpRequest.getHeader("language-option")).andReturn("en_US");
expect(droolsEngine.deployRule(anyObject(DeployRuleRequest.class))).andReturn("packageName");
PowerMock.replayAll();
- engineResources.deployRule(deployRuleRequest, httpRequest);
+ engineResources.deployRule(deployRuleRequest);
PowerMock.verifyAll();
}
@Test
public void undeployRule_exception() throws CorrelationException {
String packageName = "packageName";
- HttpServletRequest httpRequest = PowerMock.createMock(HttpServletRequest.class);
thrown.expect(WebApplicationException.class);
- expect(httpRequest.getHeader("language-option")).andReturn("en_US");
droolsEngine.undeployRule(anyObject(String.class));
expectLastCall().andThrow(new CorrelationException(""));
PowerMock.replayAll();
- engineResources.undeployRule(packageName, httpRequest);
+ engineResources.undeployRule(packageName);
PowerMock.verifyAll();
}
@Test
public void undeployRule_normal() throws CorrelationException {
String packageName = "packageName";
- HttpServletRequest httpRequest = PowerMock.createMock(HttpServletRequest.class);
- expect(httpRequest.getHeader("language-option")).andReturn("en_US");
droolsEngine.undeployRule(anyObject(String.class));
PowerMock.replayAll();
- engineResources.undeployRule(packageName, httpRequest);
+ engineResources.undeployRule(packageName);
PowerMock.verifyAll();
}
@Test
public void compileRule_exception() throws CorrelationException {
CompileRuleRequest compileRuleRequest = new CompileRuleRequest();
- HttpServletRequest httpRequest = PowerMock.createMock(HttpServletRequest.class);
thrown.expect(WebApplicationException.class);
- expect(httpRequest.getHeader("language-option")).andReturn("en_US");
droolsEngine.compileRule(anyObject(String.class));
expectLastCall().andThrow(new CorrelationException(""));
PowerMock.replayAll();
- engineResources.compileRule(compileRuleRequest, httpRequest);
+ engineResources.compileRule(compileRuleRequest);
PowerMock.verifyAll();
}
@Test
public void compileRule_normal() throws CorrelationException {
CompileRuleRequest compileRuleRequest = new CompileRuleRequest();
- HttpServletRequest httpRequest = PowerMock.createMock(HttpServletRequest.class);
-
- expect(httpRequest.getHeader("language-option")).andReturn("en_US");
droolsEngine.compileRule(anyObject(String.class));
PowerMock.replayAll();
- engineResources.compileRule(compileRuleRequest, httpRequest);
+ engineResources.compileRule(compileRuleRequest);
PowerMock.verifyAll();
}
}
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/wrapper/RuleMgtWrapperTest.java b/engine-d/src/test/java/org/onap/holmes/engine/wrapper/RuleMgtWrapperTest.java
index cd7aff4..05fb7b5 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/wrapper/RuleMgtWrapperTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/wrapper/RuleMgtWrapperTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2021 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,45 +16,38 @@
package org.onap.holmes.engine.wrapper;
-import static org.easymock.EasyMock.anyInt;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.expect;
-
-import java.util.ArrayList;
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.engine.db.CorrelationRuleDao;
+import org.onap.holmes.engine.db.CorrelationRuleDaoService;
import org.powermock.api.easymock.PowerMock;
-import org.powermock.reflect.Whitebox;
+
+import java.util.ArrayList;
+
+import static org.easymock.EasyMock.anyInt;
+import static org.easymock.EasyMock.expect;
public class RuleMgtWrapperTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- private DbDaoUtil daoUtil;
+ private CorrelationRuleDaoService correlationRuleDaoService;
private RuleMgtWrapper ruleMgtWrapper;
@Before
public void setUp() {
- daoUtil = PowerMock.createMock(DbDaoUtil.class);
- ruleMgtWrapper = new RuleMgtWrapper();
+ correlationRuleDaoService = PowerMock.createMock(CorrelationRuleDaoService.class);
+ ruleMgtWrapper = new RuleMgtWrapper(correlationRuleDaoService);
- Whitebox.setInternalState(ruleMgtWrapper, "daoUtil", daoUtil);
PowerMock.resetAll();
}
@Test
public void queryRuleByEnable_normal() throws CorrelationException {
int enable = 3;
-
- CorrelationRuleDao correlationRuleDao = PowerMock.createMock(CorrelationRuleDao.class);
- expect(daoUtil.getJdbiDaoByOnDemand(anyObject(Class.class))).andReturn(correlationRuleDao);
- expect(correlationRuleDao.queryRuleByRuleEnable(anyInt())).andReturn(new ArrayList<CorrelationRule>());
+ expect(correlationRuleDaoService.queryRuleByRuleEnable(anyInt())).andReturn(new ArrayList());
PowerMock.replayAll();
ruleMgtWrapper.queryRuleByEnable(enable);
PowerMock.verifyAll();