summaryrefslogtreecommitdiffstats
path: root/holmes-actions/src/test/java
diff options
context:
space:
mode:
authorGuangrongFu <fu.guangrong@zte.com.cn>2021-12-18 15:07:55 +0800
committerGuangrong Fu <fu.guangrong@zte.com.cn>2022-08-08 15:34:43 +0800
commit0c795a78a515168eb600744bf43906d4fd195b30 (patch)
tree1d10e40a4e7c88bb27d2ab419890d524ae8b0b45 /holmes-actions/src/test/java
parent0ed4589721f3acd3778c470be233ada0d545599f (diff)
Switched from Dropwizard to Springboot
Issue-ID: HOLMES-511 Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn> Change-Id: If845dcc835ca4812d550b842fd861626265b4cf1
Diffstat (limited to 'holmes-actions/src/test/java')
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java121
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/config/MQConfigTest.java28
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundleTest.java36
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/engine/dao/EngineEntityMapperTest.java2
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/engine/service/impl/EngineEntityServiceImplTest.java12
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/utils/AlarmInfoMapperTest.java12
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/utils/CorrelationRuleMapperTest.java2
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java151
8 files changed, 19 insertions, 345 deletions
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java
deleted file mode 100644
index 822d74c..0000000
--- a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java
+++ /dev/null
@@ -1,121 +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.common.api.entity;
-
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
-
-import java.util.Date;
-import org.junit.Test;
-import org.junit.Before;
-import org.junit.After;
-
-public class AlarmsCorrelationTest {
-
- private AlarmsCorrelation alarmsCorrelation;
-
- @Before
- public void before() throws Exception {
- alarmsCorrelation = new AlarmsCorrelation();
- }
-
- @After
- public void after() throws Exception {
-
- }
-
-
- @Test
- public void getterAndSetter4RuleId() throws Exception {
- final String ruleId = "ruleId";
- alarmsCorrelation.setRuleId(ruleId);
- assertThat(alarmsCorrelation.getRuleId(), equalTo(ruleId));
- }
-
-
- @Test
- public void getterAndSetter4RuleInfo() throws Exception {
- final String ruleInfo = "ruleInfo";
- alarmsCorrelation.setRuleInfo(ruleInfo);
- assertThat(alarmsCorrelation.getRuleInfo(), equalTo(ruleInfo));
- }
-
-
- @Test
- public void getterAndSetter4ResultType() throws Exception {
- final byte resultType = 1;
- alarmsCorrelation.setResultType(resultType);
- assertThat(alarmsCorrelation.getResultType(), equalTo(resultType));
- }
-
-
- @Test
- public void getterAndSetter4CreateTime() throws Exception {
- final Date createTime = new Date();
- alarmsCorrelation.setCreateTime(createTime);
- assertThat(alarmsCorrelation.getCreateTime(), equalTo(createTime));
- }
-
-
- @Test
- public void getterAndSetter4ParentAlarmId() throws Exception {
- final long pad = 11L;
- alarmsCorrelation.setParentAlarmId(pad);
- assertThat(alarmsCorrelation.getParentAlarmId(), equalTo(pad));
- }
-
-
- @Test
- public void getterAndSetter4ChildAlarmId() throws Exception {
- final long childAlarmId = 11L;
- alarmsCorrelation.setChildAlarmId(childAlarmId);
- assertThat(alarmsCorrelation.getChildAlarmId(), equalTo(childAlarmId));
- }
-
-
- @Test
- public void getterAndSetter4Reserve1() throws Exception {
- final long reserve1 = 11L;
- alarmsCorrelation.setReserve1(reserve1);
- assertThat(alarmsCorrelation.getReserve1(), equalTo(reserve1));
- }
-
-
- @Test
- public void getterAndSetter4Reserve2() throws Exception {
- final long reserve2 = 11L;
- alarmsCorrelation.setReserve2(reserve2);
- assertThat(alarmsCorrelation.getReserve2(), equalTo(reserve2));
- }
-
-
- @Test
- public void getterAndSetter4Reserve3() throws Exception {
- final long reserve3 = 11L;
- alarmsCorrelation.setReserve3(reserve3);
- assertThat(alarmsCorrelation.getReserve3(), equalTo(reserve3));
- }
-
- @Test
- public void testToString() throws Exception {
- final AlarmsCorrelation alarmsCorrelationTemp = new AlarmsCorrelation();
- String ruleId = "ruleId";
- alarmsCorrelationTemp.setRuleId(ruleId);
- alarmsCorrelation.setRuleId(ruleId);
- assertThat(alarmsCorrelation.toString(), equalTo(alarmsCorrelationTemp.toString()));
- }
-}
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/config/MQConfigTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/config/MQConfigTest.java
deleted file mode 100644
index cc9dced..0000000
--- a/holmes-actions/src/test/java/org/onap/holmes/common/config/MQConfigTest.java
+++ /dev/null
@@ -1,28 +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.common.config;
-
-import org.junit.Test;
-import org.junit.Before;
-import org.junit.After;
-
-public class MQConfigTest {
- @Test
- public void testNewClass() {
- MQConfig mqConfig= new MQConfig();
- }
-}
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundleTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundleTest.java
deleted file mode 100644
index 8cf044f..0000000
--- a/holmes-actions/src/test/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundleTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2017-2020 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.common.dropwizard.ioc.bundle;
-
-import io.dropwizard.Configuration;
-import io.dropwizard.setup.Environment;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertThat;
-
-public class AutoConfigBundleTest {
- @Test
- public void newBuilder() {
- assertThat(AutoConfigBundle.newBuilder(), instanceOf(AutoConfigBundleBuider.class));
- }
-
- @Test
- public void run() throws Exception {
- AutoConfigBundle.newBuilder().build().run(new Configuration(), new Environment("Test"));
- }
-
-} \ No newline at end of file
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/engine/dao/EngineEntityMapperTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/engine/dao/EngineEntityMapperTest.java
index 99b14ab..b201495 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/engine/dao/EngineEntityMapperTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/engine/dao/EngineEntityMapperTest.java
@@ -44,7 +44,7 @@ public class EngineEntityMapperTest {
PowerMock.replay(rsMock);
- EngineEntity entity = mapper.map(0, rsMock, null);
+ EngineEntity entity = mapper.map( rsMock, null);
PowerMock.verify(rsMock);
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/engine/service/impl/EngineEntityServiceImplTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/engine/service/impl/EngineEntityServiceImplTest.java
index 21a4025..cb16650 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/engine/service/impl/EngineEntityServiceImplTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/engine/service/impl/EngineEntityServiceImplTest.java
@@ -16,23 +16,21 @@
package org.onap.holmes.common.engine.service.impl;
-import com.google.common.base.CharMatcher;
-import org.junit.Before;
+import org.jdbi.v3.core.Jdbi;
import org.junit.Test;
import org.onap.holmes.common.engine.dao.EngineEntityDao;
import org.onap.holmes.common.engine.entity.EngineEntity;
import org.onap.holmes.common.engine.service.EngineEntityService;
-import org.onap.holmes.common.utils.DbDaoUtil;
+import org.onap.holmes.common.database.DbDaoUtil;
import java.util.*;
-import static com.google.common.base.Predicates.notNull;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.*;
public class EngineEntityServiceImplTest {
- private EngineEntityService service = new EngineEntityServiceImpl(new DbDaoUtilStub());
+ private EngineEntityService service = new EngineEntityServiceImpl(new DbDaoUtilStub(null));
@Test
public void getLegacyEngines() {
@@ -78,6 +76,10 @@ public class EngineEntityServiceImplTest {
class DbDaoUtilStub extends DbDaoUtil {
private EngineEntityDao dao = new EngineEntityDaoStub();
+ public DbDaoUtilStub(Jdbi jdbi) {
+ super(jdbi);
+ }
+
@Override
public <T> T getJdbiDaoByOnDemand(Class<T> daoClazz) {
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/AlarmInfoMapperTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/AlarmInfoMapperTest.java
index 3d36def..9ea0057 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/utils/AlarmInfoMapperTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/AlarmInfoMapperTest.java
@@ -1,12 +1,12 @@
/**
* Copyright 2017 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.
@@ -33,13 +33,13 @@ public class AlarmInfoMapperTest {
expect(resultSet.getString("eventname")).andReturn("");
expect(resultSet.getString("sourceid")).andReturn("");
expect(resultSet.getString("sourcename")).andReturn("");
- expect(resultSet.getInt("sequence")).andReturn(0);
+ expect(resultSet.getInt("sequence")).andReturn(0);
expect(resultSet.getLong("startepochmicrosec")).andReturn(0L);
expect(resultSet.getLong("lastepochmicrosec")).andReturn(0L);
expect(resultSet.getInt("alarmiscleared")).andReturn(0);
expect(resultSet.getInt("rootflag")).andReturn(0);
PowerMock.replay(resultSet);
- mapper.map(0, resultSet, null);
+ mapper.map(resultSet, null);
PowerMock.verify(resultSet);
}
}
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/CorrelationRuleMapperTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/CorrelationRuleMapperTest.java
index c18c828..9ea92ca 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/utils/CorrelationRuleMapperTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/CorrelationRuleMapperTest.java
@@ -49,7 +49,7 @@ public class CorrelationRuleMapperTest {
expect(resultSet.getString("ctrlloop")).andReturn("");
expect(resultSet.getString("engineinstance")).andReturn("");
PowerMock.replay(resultSet);
- mapper.map(0, resultSet, null);
+ mapper.map(resultSet, null);
PowerMock.verify(resultSet);
}
} \ No newline at end of file
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java
index dd42044..696de45 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java
@@ -16,161 +16,29 @@
package org.onap.holmes.common.utils;
-import io.dropwizard.db.DataSourceFactory;
-import io.dropwizard.jdbi.DBIFactory;
-import io.dropwizard.setup.Environment;
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Ignore;
+import org.jdbi.v3.core.Jdbi;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
+import org.onap.holmes.common.database.DbDaoUtil;
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.DBI;
-import org.skife.jdbi.v2.Handle;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.expect;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({DbDaoUtil.class, DBIFactory.class, DBI.class})
public class DbDaoUtilTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- private DBI jdbi;
-
- private Environment environmentProvider;
-
- private DataSourceFactory dataSourceFactoryProvider;
-
- private DbDaoUtil dbDaoUtil;
-
- private DBIFactory factory;
-
- @Before
- public void before() throws Exception {
- dbDaoUtil = new DbDaoUtil();
-
- jdbi = PowerMock.createMock(DBI.class);
- environmentProvider = PowerMock.createMock(Environment.class);
- dataSourceFactoryProvider = PowerMock.createMock(DataSourceFactory.class);
- factory = PowerMock.createMock(DBIFactory.class);
- PowerMock.expectNew(DBIFactory.class).andReturn(factory);
-
- Whitebox.setInternalState(dbDaoUtil, "environmentProvider", environmentProvider);
- Whitebox.setInternalState(dbDaoUtil, "dataSourceFactoryProvider",
- dataSourceFactoryProvider);
-
- PowerMock.resetAll();
- }
-
- @Test
- @Ignore
- public void init() {
- PowerMock.createMock(DBI.class);
-
- expect(factory.build(anyObject(Environment.class), anyObject(DataSourceFactory.class),
- anyObject(String.class))).andReturn(jdbi);
-
- PowerMock.replayAll();
-
- dbDaoUtil.init();
-
- PowerMock.verifyAll();
- }
-
- @Test
- public void getDao_normal() {
- Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
- expect(jdbi.open(anyObject(Class.class))).andReturn(Class.class);
-
- PowerMock.replayAll();
-
- dbDaoUtil.getDao(String.class);
-
- PowerMock.verifyAll();
- }
-
- @Test
- public void getDao_exception() {
- Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
-
- expect(jdbi.open(anyObject(Class.class))).andThrow(new RuntimeException(""));
-
- PowerMock.replayAll();
-
- Object o = dbDaoUtil.getDao(String.class);
-
- PowerMock.verifyAll();
-
- assertThat(o, equalTo(null));
- }
-
- @Test
- public void getHandle_normal() {
- Handle handle = PowerMock.createMock(Handle.class);
-
- Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
- expect(jdbi.open()).andReturn(handle);
-
- PowerMock.replayAll();
-
- dbDaoUtil.getHandle();
-
- PowerMock.verifyAll();
- }
-
- @Test
- public void getHandle_exception() {
- Handle handle = PowerMock.createMock(Handle.class);
-
- Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
- expect(jdbi.open()).andThrow(new RuntimeException(""));
-
- PowerMock.replayAll();
-
- Handle handle1 = dbDaoUtil.getHandle();
-
- PowerMock.verifyAll();
-
- assertThat(handle1, equalTo(null));
- }
-
- @Test
- public void close_normal() {
- Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
- jdbi.close(anyObject());
-
- PowerMock.replayAll();
-
- dbDaoUtil.close(new Object());
-
- PowerMock.verifyAll();
- }
-
- @Test
- public void close_exception() {
- Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
- jdbi.close(anyObject());
- EasyMock.expectLastCall().andThrow(new RuntimeException(""));
- PowerMock.replayAll();
-
- dbDaoUtil.close(new Object());
-
- PowerMock.verifyAll();
- }
@Test
public void testGetJdbiDaoByOnDemand() {
- Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
+ Jdbi jdbi = PowerMock.createMock(Jdbi.class);
+ DbDaoUtil dbDaoUtil = new DbDaoUtil(jdbi);
expect(jdbi.onDemand(anyObject(Class.class))).andReturn(Class.class);
PowerMock.replayAll();
@@ -180,15 +48,4 @@ public class DbDaoUtilTest {
PowerMock.verifyAll();
}
- @Test
- public void testGetJdbiDaoByOpen() {
- Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi);
- expect(jdbi.open(anyObject(Class.class))).andReturn(Class.class);
-
- PowerMock.replayAll();
-
- dbDaoUtil.getJdbiDaoByOpen(String.class);
-
- PowerMock.verifyAll();
- }
}