summaryrefslogtreecommitdiffstats
path: root/engine-d/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'engine-d/src/test/java/org')
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/EngineDActiveAppTest.java43
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/db/AlarmInfoDaoTest.java54
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/dmaap/DMaaPAlarmPollingTest.java37
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/dmaap/SubscriberActionTest.java4
-rw-r--r--engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.java68
5 files changed, 186 insertions, 20 deletions
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/EngineDActiveAppTest.java b/engine-d/src/test/java/org/onap/holmes/engine/EngineDActiveAppTest.java
index 2c6cdb7..4f8aa2b 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/EngineDActiveAppTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/EngineDActiveAppTest.java
@@ -15,9 +15,52 @@
*/
package org.onap.holmes.engine;
+import org.easymock.EasyMock;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.holmes.common.config.MicroServiceConfig;
+import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
+import org.onap.msb.sdk.discovery.entity.Node;
+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 static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+@PrepareForTest(MicroServiceConfig.class)
+@RunWith(PowerMockRunner.class)
public class EngineDActiveAppTest {
+
public static void main(String[] args) throws Exception {
String filePath = "C:\\engine-d.yml";
new EngineDActiveApp().run(new String[]{"server", filePath});
}
+
+ @Test
+ public void testCreateMicroServiceInfo() throws Exception {
+ EngineDActiveApp engineDActiveApp = new EngineDActiveApp();
+ PowerMock.mockStatic(MicroServiceConfig.class);
+ String[] serviceAddrInfo = new String[2];
+ serviceAddrInfo[0] = "10.74.216.82";
+ serviceAddrInfo[1] = "80";
+ EasyMock.expect(MicroServiceConfig.getMicroServiceIpAndPort()).andReturn(serviceAddrInfo);
+ EasyMock.expectLastCall();
+ PowerMock.replayAll();
+
+ MicroServiceInfo msinfo = Whitebox.invokeMethod(engineDActiveApp,"createMicroServiceInfo");
+
+ PowerMock.verifyAll();
+
+ assertThat(msinfo.getServiceName(), equalTo("holmes-engine-mgmt"));
+ assertThat(msinfo.getVersion(), equalTo("v1"));
+ assertThat(msinfo.getUrl(), equalTo("/api/holmes-engine-mgmt/v1"));
+ assertThat(msinfo.getProtocol(), equalTo("REST"));
+ assertThat(msinfo.getVisualRange(), equalTo("0|1"));
+ assertThat(msinfo.isEnable_ssl(), is(true));
+ assertThat(msinfo.getNodes().toArray(new Node[0])[0].getIp(), equalTo(serviceAddrInfo[0]));
+ assertThat(msinfo.getNodes().toArray(new Node[0])[0].getPort(), equalTo(serviceAddrInfo[1]));
+ }
}
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
new file mode 100644
index 0000000..9945322
--- /dev/null
+++ b/engine-d/src/test/java/org/onap/holmes/engine/db/AlarmInfoDaoTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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.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;
+import java.util.List;
+
+public class AlarmInfoDaoTest {
+
+
+ private AlarmInfoDao alarmInfoDao;
+
+ @Before
+ public void setUp() {
+ alarmInfoDao = PowerMock.createMock(AlarmInfoDao.class);
+ }
+
+ @Test
+ public void queryAllAlarm() throws Exception {
+
+ EasyMock.expect(alarmInfoDao.queryAllAlarm()).andReturn(new ArrayList<AlarmInfo>());
+ PowerMock.replayAll();
+
+ List<AlarmInfo> alarmInfoList = alarmInfoDao.queryAllAlarm();
+ PowerMock.verifyAll();
+ Assert.assertThat(alarmInfoList, IsNull.<List<AlarmInfo>>notNullValue());
+ }
+}
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 f4804f3..896a384 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
@@ -15,6 +15,7 @@
*/
package org.onap.holmes.engine.dmaap;
+import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.*;
@@ -22,25 +23,31 @@ 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.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})
+@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;
@Before
public void setUp() {
subscriber = PowerMock.createMock(Subscriber.class);
droolsEngine = PowerMock.createMock(DroolsEngine.class);
- dMaaPAlarmPolling = new DMaaPAlarmPolling(subscriber, droolsEngine);
+ alarmInfoDao = PowerMock.createMock(AlarmInfoDao.class);
+ dMaaPAlarmPolling = new DMaaPAlarmPolling(subscriber, droolsEngine,alarmInfoDao);
PowerMock.replayAll();
}
@@ -52,4 +59,30 @@ public class DMaaPAlarmPollingTest {
assertThat(field.get(dMaaPAlarmPolling), equalTo(false));
}
+ @Test
+ public void testGetAlarmInfo() throws Exception {
+ VesAlarm vesAlarm = new VesAlarm();
+ vesAlarm.setAlarmIsCleared(1);
+ vesAlarm.setSourceName("sourceName");
+ vesAlarm.setSourceId("sourceId");
+ vesAlarm.setStartEpochMicrosec(1L);
+ vesAlarm.setLastEpochMicrosec(1L);
+ vesAlarm.setEventName("eventName");
+ vesAlarm.setEventId("eventId");
+ vesAlarm.setRootFlag(0);
+
+ PowerMock.replayAll();
+ AlarmInfo alarmInfo = Whitebox.invokeMethod(dMaaPAlarmPolling,"getAlarmInfo",vesAlarm);
+ PowerMock.verifyAll();
+
+ assertThat(alarmInfo.getAlarmIsCleared(), is(1));
+ assertThat(alarmInfo.getSourceName(), equalTo("sourceName"));
+ assertThat(alarmInfo.getSourceId(), equalTo("sourceId"));
+ assertThat(alarmInfo.getStartEpochMicroSec(), is(1L));
+ assertThat(alarmInfo.getLastEpochMicroSec(), is(1L));
+ assertThat(alarmInfo.getEventName(), equalTo("eventName"));
+ assertThat(alarmInfo.getEventId(), equalTo("eventId"));
+ assertThat(alarmInfo.getRootFlag(), is(0));
+ }
+
} \ No newline at end of file
diff --git a/engine-d/src/test/java/org/onap/holmes/engine/dmaap/SubscriberActionTest.java b/engine-d/src/test/java/org/onap/holmes/engine/dmaap/SubscriberActionTest.java
index 7f5d56e..247962f 100644
--- a/engine-d/src/test/java/org/onap/holmes/engine/dmaap/SubscriberActionTest.java
+++ b/engine-d/src/test/java/org/onap/holmes/engine/dmaap/SubscriberActionTest.java
@@ -30,9 +30,9 @@ public class SubscriberActionTest {
public void setUp() {
subscriberAction = new SubscriberAction();
HashMap<String, DMaaPAlarmPolling> dMaaPAlarmPollingHashMap = new HashMap<>();
- DMaaPAlarmPolling dMaaPAlarmPolling = new DMaaPAlarmPolling(null, null);
+ DMaaPAlarmPolling dMaaPAlarmPolling = new DMaaPAlarmPolling(null, null,null);
dMaaPAlarmPollingHashMap.put("test", dMaaPAlarmPolling);
- DMaaPAlarmPolling dMaaPAlarmPolling1 = new DMaaPAlarmPolling(null, null);
+ DMaaPAlarmPolling dMaaPAlarmPolling1 = new DMaaPAlarmPolling(null, null,null);
dMaaPAlarmPollingHashMap.put("testTopic", dMaaPAlarmPolling1);
Whitebox.setInternalState(subscriberAction, "pollingTasks", dMaaPAlarmPollingHashMap);
PowerMock.replayAll();
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 3325efa..71ef172 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
@@ -16,13 +16,7 @@
package org.onap.holmes.engine.manager;
-import static org.easymock.EasyMock.anyInt;
-import static org.easymock.EasyMock.expect;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
+import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -35,15 +29,26 @@ import org.kie.api.builder.KieRepository;
import org.kie.api.io.KieResources;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
-import org.onap.holmes.common.api.stat.VesAlarm;
-import org.onap.holmes.engine.request.DeployRuleRequest;
+import org.onap.holmes.common.api.entity.AlarmInfo;
import org.onap.holmes.common.api.entity.CorrelationRule;
+import org.onap.holmes.common.api.stat.VesAlarm;
import org.onap.holmes.common.constant.AlarmConst;
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.request.DeployRuleRequest;
import org.onap.holmes.engine.wrapper.RuleMgtWrapper;
import org.powermock.api.easymock.PowerMock;
import org.powermock.reflect.Whitebox;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
public class DroolsEngineTest {
@Rule
@@ -60,9 +65,12 @@ public class DroolsEngineTest {
private KieResources resources;
private KieRepository kieRepository;
+ private AlarmInfoDao alarmInfoDaoMock;
private DroolsEngine droolsEngine;
+ private DbDaoUtil dbDaoUtilMock;
+
@Before
public void setUp() throws Exception {
droolsEngine = new DroolsEngine();
@@ -76,9 +84,9 @@ public class DroolsEngineTest {
kieBase = kieContainer.getKieBase();
kieSession = kieContainer.newKieSession();
- ruleMgtWrapper = PowerMock.createMock(RuleMgtWrapper.class);
+ alarmInfoDaoMock = PowerMock.createMock(AlarmInfoDao.class);
+ dbDaoUtilMock = PowerMock.createMock(DbDaoUtil.class);
- Whitebox.setInternalState(droolsEngine, "ruleMgtWrapper", ruleMgtWrapper);
Whitebox.setInternalState(droolsEngine, "kieBase", kieBase);
Whitebox.setInternalState(droolsEngine, "kieSession", kieSession);
@@ -89,6 +97,9 @@ public class DroolsEngineTest {
Whitebox.setInternalState(droolsEngine, "resources", resources);
Whitebox.setInternalState(droolsEngine, "kieRepository", kieRepository);
+ Whitebox.setInternalState(droolsEngine, "daoUtil", dbDaoUtilMock);
+ Whitebox.setInternalState(droolsEngine, "alarmInfoDao", alarmInfoDaoMock);
+
PowerMock.resetAll();
}
@@ -102,13 +113,12 @@ public class DroolsEngineTest {
rule.setPackageName("org.onap.holmes");
rules.add(rule);
- expect(ruleMgtWrapper.queryRuleByEnable(anyInt())).andReturn(rules);
+// expect(ruleMgtWrapper.queryRuleByEnable(anyInt())).andReturn(rules);
+ List<AlarmInfo> alarmInfoList = new ArrayList<AlarmInfo>();
+ EasyMock.expect(dbDaoUtilMock.getJdbiDaoByOnDemand(AlarmInfoDao.class)).andReturn(alarmInfoDaoMock).anyTimes();
+ EasyMock.expect(alarmInfoDaoMock.queryAllAlarm()).andReturn(alarmInfoList).anyTimes();
PowerMock.replayAll();
- Method method = DroolsEngine.class.getDeclaredMethod("init");
- method.setAccessible(true);
- method.invoke(droolsEngine);
-
PowerMock.verifyAll();
}
@@ -198,4 +208,30 @@ public class DroolsEngineTest {
public void stop() throws Exception {
droolsEngine.stop();
}
+
+ @Test
+ public void testConvertAlarmInfo2VesAlarm() throws Exception {
+ AlarmInfo alarmInfo = new AlarmInfo();
+ alarmInfo.setEventId("eventId");
+ alarmInfo.setEventName("eventName");
+ alarmInfo.setStartEpochMicroSec(1L);
+ alarmInfo.setLastEpochMicroSec(1L);
+ alarmInfo.setSourceId("sourceId");
+ alarmInfo.setSourceName("sourceName");
+ alarmInfo.setRootFlag(0);
+ alarmInfo.setAlarmIsCleared(1);
+
+ PowerMock.replayAll();
+ VesAlarm vesAlarm = Whitebox.invokeMethod(droolsEngine,"convertAlarmInfo2VesAlarm",alarmInfo);
+ PowerMock.verifyAll();
+
+ assertThat(vesAlarm.getAlarmIsCleared(), is(1));
+ assertThat(vesAlarm.getSourceName(), equalTo("sourceName"));
+ assertThat(vesAlarm.getSourceId(), equalTo("sourceId"));
+ assertThat(vesAlarm.getStartEpochMicrosec(), is(1L));
+ assertThat(vesAlarm.getLastEpochMicrosec(), is(1L));
+ assertThat(vesAlarm.getEventName(), equalTo("eventName"));
+ assertThat(vesAlarm.getEventId(), equalTo("eventId"));
+ assertThat(vesAlarm.getRootFlag(), is(0));
+ }
}