diff options
author | GuangrongFu <fu.guangrong@zte.com.cn> | 2020-06-24 10:52:42 +0800 |
---|---|---|
committer | GuangrongFu <fu.guangrong@zte.com.cn> | 2020-06-24 10:52:42 +0800 |
commit | 3e5ddaee6984869b67dda89b7f8e1932a2b27045 (patch) | |
tree | 229f4df8a1f47e44167ade01545bae1c5dc0b0ae /holmes-actions/src/test/java | |
parent | b6bcfbcc8b7445a953b4d5963dc4ff93028362c5 (diff) |
Upgraded to Java 11
Change-Id: Iee2bce6fad2076b1df093f1f978b2e78a64c6492
Issue-ID: HOLMES-302
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/test/java')
7 files changed, 84 insertions, 319 deletions
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java index 7ce3fcf..15904d5 100644 --- a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java +++ b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java @@ -1,12 +1,12 @@ /** - * Copyright 2017 ZTE Corporation. - * + * Copyright 2017-2020 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,14 +15,7 @@ */ package org.onap.holmes.common.aai; -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; -import static org.powermock.api.mockito.PowerMockito.when; -import java.util.HashMap; -import java.util.Map; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; @@ -39,12 +32,19 @@ import org.onap.holmes.common.config.MicroServiceConfig; import org.onap.holmes.common.exception.CorrelationException; import org.onap.holmes.common.utils.HttpsUtils; import org.powermock.api.easymock.PowerMock; -import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; +import java.util.HashMap; +import java.util.Map; + +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; + @PrepareForTest({AaiQuery.class, HttpsUtils.class, MicroServiceConfig.class, HttpGet.class}) @PowerMockIgnore("javax.net.ssl.*") @@ -153,7 +153,7 @@ public class AaiQueryTest { PowerMock.mockStatic(MicroServiceConfig.class); PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2") .andReturn("/aai/v11/cloud-infrastructure"); - PowerMock.expectPrivate(httpClient,"close"); + PowerMock.expectPrivate(httpClient, "close"); EasyMock.expectLastCall(); PowerMock.replayAll(); Whitebox.invokeMethod(aaiQuery, "getAaiVmData", "test1", "test2"); @@ -179,7 +179,6 @@ public class AaiQueryTest { } - @Test public void testAaiQuery_getResourceLinksResponse() throws Exception { PowerMock.resetAll(); @@ -188,9 +187,6 @@ public class AaiQueryTest { aaiResponseUtil = new AaiResponseUtil(); Whitebox.setInternalState(aaiQuery, "aaiResponseUtil", aaiResponseUtil); - PowerMockito.mockStatic(MicroServiceConfig.class); - when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("host_url"); - PowerMock.expectPrivate(aaiQuery, "getResponse", anyObject(String.class)).andReturn("").anyTimes(); PowerMock.replayAll(); String resource = Whitebox.invokeMethod(aaiQuery, "getResourceLinksResponse", "test1", "test2"); @@ -207,9 +203,6 @@ public class AaiQueryTest { aaiResponseUtil = new AaiResponseUtil(); Whitebox.setInternalState(aaiQuery, "aaiResponseUtil", aaiResponseUtil); - PowerMockito.mockStatic(MicroServiceConfig.class); - when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("host_url"); - PowerMock.expectPrivate(aaiQuery, "getResponse", anyObject(String.class)).andReturn("").anyTimes(); PowerMock.replayAll(); String resource = Whitebox.invokeMethod(aaiQuery, "getVnfDataResponse", "test1", "test2"); @@ -294,10 +287,10 @@ public class AaiQueryTest { PowerMock.resetAll(); aaiQuery = new AaiQuery(); - PowerMockito.mockStatic(MicroServiceConfig.class); + PowerMock.mockStatic(MicroServiceConfig.class); PowerMock.replayAll(); - String actual = Whitebox.invokeMethod(aaiQuery,"getBaseUrl", "/url"); + String actual = Whitebox.invokeMethod(aaiQuery, "getBaseUrl", "/url"); PowerMock.verifyAll(); assertThat(actual, equalTo("https://aai.onap:8443/url")); diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java index aea9d96..a87ba67 100644 --- a/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java +++ b/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java @@ -1,12 +1,12 @@ /**
- * Copyright 2017 ZTE Corporation.
- *
+ * Copyright 2017-2020 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.
@@ -19,12 +19,12 @@ package org.onap.holmes.common.config; import org.apache.commons.lang3.StringUtils;
import org.easymock.EasyMock;
import org.junit.Ignore;
-import org.junit.Rule;
import org.junit.Test;
+import org.junit.runner.RunWith;
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.rule.PowerMockRule;
+import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.internal.WhiteboxImpl;
import static org.hamcrest.core.Is.is;
@@ -35,12 +35,11 @@ import static org.onap.holmes.common.config.MicroServiceConfig.*; @PrepareForTest(MicroServiceConfig.class)
@PowerMockIgnore({"javax.ws.*"})
+@RunWith(PowerMockRunner.class)
public class MicroServiceConfigTest {
private static String ACTUAL_HOSTNAME = System.getenv(HOSTNAME);
- @Rule
- public PowerMockRule powerMockRule = new PowerMockRule();
@Test
public void getMsbServerAddrTest() {
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/PublisherTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/PublisherTest.java index be9f74f..0e7fe3d 100644 --- a/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/PublisherTest.java +++ b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/PublisherTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 ZTE Corporation. + * 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. @@ -15,21 +15,9 @@ */ package org.onap.holmes.common.dmaap; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.HashMap; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation.Builder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.StatusLine; -import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; @@ -38,16 +26,19 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.mockito.Matchers; import org.onap.holmes.common.dmaap.entity.PolicyMsg; import org.onap.holmes.common.exception.CorrelationException; import org.onap.holmes.common.utils.HttpsUtils; import org.powermock.api.easymock.PowerMock; -import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -@PrepareForTest({HttpsUtils.class, HttpResponse.class}) +import java.util.HashMap; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +@PrepareForTest({HttpsUtils.class, HttpResponse.class, Publisher.class}) @RunWith(PowerMockRunner.class) public class PublisherTest { @@ -74,15 +65,19 @@ public class PublisherTest { Publisher publisher = new Publisher(); publisher.setUrl(URL); - PowerMockito.mockStatic(HttpsUtils.class); - HttpResponse httpResponse = PowerMockito.mock(HttpResponse.class); - PowerMockito.when(HttpsUtils - .post(Matchers.any(HttpPost.class), Matchers.any(HashMap.class), - Matchers.any(HashMap.class), Matchers.any(StringEntity.class), - Matchers.any(CloseableHttpClient.class))).thenReturn(httpResponse); - StatusLine statusLine = PowerMockito.mock(StatusLine.class); - PowerMockito.when(httpResponse.getStatusLine()).thenReturn(statusLine); - PowerMockito.when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK); + PowerMock.mockStatic(HttpsUtils.class); + CloseableHttpClient httpClient = PowerMock.createMock(CloseableHttpClient.class); + EasyMock.expect(HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT)).andReturn(httpClient); + HttpResponse httpResponse = PowerMock.createMock(HttpResponse.class); + EasyMock.expect(HttpsUtils + .post(EasyMock.anyObject(HttpPost.class), EasyMock.anyObject(HashMap.class), + EasyMock.anyObject(HashMap.class), EasyMock.anyObject(StringEntity.class), + EasyMock.anyObject(CloseableHttpClient.class))).andReturn(httpResponse); + StatusLine statusLine = PowerMock.createMock(StatusLine.class); + EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLine); + EasyMock.expect(statusLine.getStatusCode()).andReturn(HttpStatus.SC_OK); + httpClient.close(); + EasyMock.expectLastCall(); PowerMock.replayAll(); 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 index 740d92b..8cf044f 100644 --- 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 @@ -1,5 +1,5 @@ /* - * Copyright 2017 ZTE Corporation. + * 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. @@ -15,74 +15,22 @@ */ package org.onap.holmes.common.dropwizard.ioc.bundle; -import com.codahale.metrics.MetricRegistry; -import com.fasterxml.jackson.databind.ObjectMapper; import io.dropwizard.Configuration; -import io.dropwizard.setup.Bootstrap; import io.dropwizard.setup.Environment; import org.junit.Test; -import javax.validation.ConstraintViolation; -import javax.validation.Validator; -import javax.validation.executable.ExecutableValidator; -import javax.validation.metadata.BeanDescriptor; - -import java.util.Set; - import static org.hamcrest.CoreMatchers.instanceOf; import static org.junit.Assert.assertThat; public class AutoConfigBundleTest { @Test - public void newBuilder() throws Exception { + public void newBuilder() { assertThat(AutoConfigBundle.newBuilder(), instanceOf(AutoConfigBundleBuider.class)); } -// @Test -// public void initialize() throws Exception { -// AutoConfigBundle.newBuilder().build().initialize(new Bootstrap<>(new IOCApplication<Configuration>() { -// @Override -// public void initialize(Bootstrap<Configuration> bootstrap) { -// super.initialize(bootstrap); -// } -// })); -// } - @Test public void run() throws Exception { - AutoConfigBundle.newBuilder().build().run(new Configuration(), new Environment( - "Test", new ObjectMapper(), new Validator() { - @Override - public <T> Set<ConstraintViolation<T>> validate(T t, Class<?>... classes) { - return null; - } - - @Override - public <T> Set<ConstraintViolation<T>> validateProperty(T t, String s, Class<?>... classes) { - return null; - } - - @Override - public <T> Set<ConstraintViolation<T>> validateValue(Class<T> aClass, String s, Object o, Class<?>... classes) { - return null; - } - - @Override - public BeanDescriptor getConstraintsForClass(Class<?> aClass) { - return null; - } - - @Override - public <T> T unwrap(Class<T> aClass) { - return null; - } - - @Override - public ExecutableValidator forExecutables() { - return null; - } - }, new MetricRegistry(), ClassLoader.getSystemClassLoader() - )); + 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/producer/MQProducerTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/producer/MQProducerTest.java deleted file mode 100644 index 3fad981..0000000 --- a/holmes-actions/src/test/java/org/onap/holmes/common/producer/MQProducerTest.java +++ /dev/null @@ -1,174 +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.producer; - -import static org.easymock.EasyMock.anyBoolean; -import static org.easymock.EasyMock.anyInt; -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.expect; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.MessageProducer; -import javax.jms.ObjectMessage; -import javax.jms.Session; -import javax.jms.Topic; -import org.glassfish.hk2.api.IterableProvider; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.onap.holmes.common.api.stat.Alarm; -import org.onap.holmes.common.api.entity.CorrelationResult; -import org.onap.holmes.common.api.stat.VesAlarm; -import org.onap.holmes.common.config.MQConfig; -import org.powermock.api.easymock.PowerMock; -import org.powermock.modules.junit4.rule.PowerMockRule; -import org.powermock.reflect.Whitebox; - -public class MQProducerTest { - - @Rule - public PowerMockRule powerMockRule = new PowerMockRule(); - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private IterableProvider<MQConfig> mqConfigProvider; - - private ConnectionFactory connectionFactory; - - private MQProducer mqProducer; - - @Before - public void before() throws Exception { - mqProducer = new MQProducer(); - - mqConfigProvider = PowerMock.createMock(IterableProvider.class); - connectionFactory = PowerMock.createMock(ConnectionFactory.class); - - Whitebox.setInternalState(mqProducer, "mqConfigProvider", mqConfigProvider); - Whitebox.setInternalState(mqProducer, "connectionFactory", connectionFactory); - PowerMock.resetAll(); - } - - @Test - public void init() { - MQConfig mqConfig = new MQConfig(); - mqConfig.setBrokerIp("127.0.0.1"); - mqConfig.setBrokerPort(61616); - mqConfig.setBrokerPassword("admin"); - mqConfig.setBrokerUsername("admin"); - expect(mqConfigProvider.get()).andReturn(mqConfig).anyTimes(); - - PowerMock.replayAll(); - - mqProducer.init(); - - PowerMock.verifyAll(); - } - - @Test - public void sendAlarmMQTopicMsg() throws Exception { - VesAlarm alarm = new VesAlarm(); - Connection connection = PowerMock.createMock(Connection.class); - Session session = PowerMock.createMock(Session.class); - Destination destination = PowerMock.createMock(Topic.class); - MessageProducer messageProducer = PowerMock.createMock(MessageProducer.class); - ObjectMessage objMessage = PowerMock.createMock(ObjectMessage.class); - - expect(connectionFactory.createConnection()).andReturn(connection); - connection.start(); - expect(connection.createSession(anyBoolean(), anyInt())).andReturn(session); - expect(session.createTopic(anyObject(String.class))).andReturn((Topic) destination); - expect(session.createProducer(anyObject(Destination.class))).andReturn(messageProducer); - - expect(session.createObjectMessage(anyObject(Alarm.class))).andReturn(objMessage); - messageProducer.send(objMessage); - session.commit(); - connection.close(); - - PowerMock.replayAll(); - - mqProducer.sendAlarmMQTopicMsg(alarm); - - PowerMock.verifyAll(); - - } - - @Test - public void sendAlarmMQTopicMsg_exception() throws Exception { - thrown.expect(JMSException.class); - VesAlarm alarm = new VesAlarm(); - - expect(connectionFactory.createConnection()).andThrow(new JMSException("")); - - PowerMock.replayAll(); - - mqProducer.sendAlarmMQTopicMsg(alarm); - - PowerMock.verifyAll(); - } - - @Test - public void sendCorrelationMQTopicMsg() throws Exception { - - Connection connection = PowerMock.createMock(Connection.class); - Session session = PowerMock.createMock(Session.class); - Destination destination = PowerMock.createMock(Topic.class); - MessageProducer messageProducer = PowerMock.createMock(MessageProducer.class); - ObjectMessage objMessage = PowerMock.createMock(ObjectMessage.class); - - expect(connectionFactory.createConnection()).andReturn(connection); - connection.start(); - expect(connection.createSession(anyBoolean(), anyInt())).andReturn(session); - expect(session.createTopic(anyObject(String.class))).andReturn((Topic) destination); - expect(session.createProducer(anyObject(Destination.class))).andReturn(messageProducer); - - expect(session.createObjectMessage(anyObject(CorrelationResult.class))) - .andReturn(objMessage); - messageProducer.send(objMessage); - session.commit(); - connection.close(); - - PowerMock.replayAll(); - - Alarm parentAlarm = new Alarm(); - Alarm childAlarm = new Alarm(); - mqProducer.sendCorrelationMQTopicMsg("ruleId", 123L, parentAlarm, childAlarm); - - PowerMock.verifyAll(); - - } - - @Test - public void sendCorrelationMQTopicMsg_exception() throws Exception { - thrown.expect(JMSException.class); - - expect(connectionFactory.createConnection()).andThrow(new JMSException("")); - - PowerMock.replayAll(); - - Alarm parentAlarm = new Alarm(); - Alarm childAlarm = new Alarm(); - mqProducer.sendCorrelationMQTopicMsg("ruleId", 123L, parentAlarm, childAlarm); - - PowerMock.verifyAll(); - - } -} 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 e942eb4..dd42044 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 @@ -1,12 +1,12 @@ /** - * Copyright 2017 ZTE Corporation. - * + * Copyright 2017-2020 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. @@ -16,30 +16,33 @@ package org.onap.holmes.common.utils; -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; - 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.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; import org.powermock.api.easymock.PowerMock; -import org.powermock.modules.junit4.rule.PowerMockRule; +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 PowerMockRule powerMockRule = new PowerMockRule(); - @Rule public ExpectedException thrown = ExpectedException.none(); private DBI jdbi; @@ -60,18 +63,19 @@ public class DbDaoUtilTest { 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); - Whitebox.setInternalState(dbDaoUtil, "factory", factory); PowerMock.resetAll(); } @Test - public void init() throws Exception { - DBI jdbi = PowerMock.createMock(DBI.class); + @Ignore + public void init() { + PowerMock.createMock(DBI.class); expect(factory.build(anyObject(Environment.class), anyObject(DataSourceFactory.class), anyObject(String.class))).andReturn(jdbi); @@ -84,7 +88,7 @@ public class DbDaoUtilTest { } @Test - public void getDao_normal() throws Exception { + public void getDao_normal() { Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); expect(jdbi.open(anyObject(Class.class))).andReturn(Class.class); @@ -96,7 +100,7 @@ public class DbDaoUtilTest { } @Test - public void getDao_exception() throws Exception { + public void getDao_exception() { Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); expect(jdbi.open(anyObject(Class.class))).andThrow(new RuntimeException("")); @@ -111,7 +115,7 @@ public class DbDaoUtilTest { } @Test - public void getHandle_normal() throws Exception { + public void getHandle_normal() { Handle handle = PowerMock.createMock(Handle.class); Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); @@ -123,8 +127,9 @@ public class DbDaoUtilTest { PowerMock.verifyAll(); } + @Test - public void getHandle_exception() throws Exception { + public void getHandle_exception() { Handle handle = PowerMock.createMock(Handle.class); Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); @@ -140,7 +145,7 @@ public class DbDaoUtilTest { } @Test - public void close_normal() throws Exception { + public void close_normal() { Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); jdbi.close(anyObject()); @@ -152,7 +157,7 @@ public class DbDaoUtilTest { } @Test - public void close_exception() throws Exception { + public void close_exception() { Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); jdbi.close(anyObject()); EasyMock.expectLastCall().andThrow(new RuntimeException("")); @@ -162,8 +167,9 @@ public class DbDaoUtilTest { PowerMock.verifyAll(); } + @Test - public void testGetJdbiDaoByOnDemand() throws Exception { + public void testGetJdbiDaoByOnDemand() { Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); expect(jdbi.onDemand(anyObject(Class.class))).andReturn(Class.class); @@ -175,7 +181,7 @@ public class DbDaoUtilTest { } @Test - public void testGetJdbiDaoByOpen() throws Exception { + public void testGetJdbiDaoByOpen() { Whitebox.setInternalState(dbDaoUtil, "jdbi", jdbi); expect(jdbi.open(anyObject(Class.class))).andReturn(Class.class); diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java index ab75e06..e6b6f9d 100644 --- a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java @@ -1,12 +1,12 @@ /**
- * Copyright 2017 ZTE Corporation.
- *
+ * Copyright 2017-2020 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.
@@ -17,8 +17,8 @@ package org.onap.holmes.common.utils;
import org.easymock.EasyMock;
-import org.junit.Rule;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.onap.holmes.common.config.MicroServiceConfig;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
@@ -27,15 +27,13 @@ import org.onap.msb.sdk.httpclient.msb.MSBServiceClient; 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.rule.PowerMockRule;
+import org.powermock.modules.junit4.PowerMockRunner;
@PrepareForTest({MicroServiceConfig.class, MSBServiceClient.class, MSBRegisterUtil.class})
@PowerMockIgnore({"javax.ws.*"})
+@RunWith(PowerMockRunner.class)
public class MSBRegisterUtilTest {
- @Rule
- public PowerMockRule powerMockRule = new PowerMockRule();
-
private MSBRegisterUtil msbRegisterUtil = new MSBRegisterUtil();
@Test
|