summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuangrongFu <fu.guangrong@zte.com.cn>2020-06-24 10:52:42 +0800
committerGuangrongFu <fu.guangrong@zte.com.cn>2020-06-24 10:52:42 +0800
commit3e5ddaee6984869b67dda89b7f8e1932a2b27045 (patch)
tree229f4df8a1f47e44167ade01545bae1c5dc0b0ae
parentb6bcfbcc8b7445a953b4d5963dc4ff93028362c5 (diff)
Upgraded to Java 11
Change-Id: Iee2bce6fad2076b1df093f1f978b2e78a64c6492 Issue-ID: HOLMES-302 Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
-rw-r--r--holmes-actions/pom.xml29
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/producer/MQProducer.java108
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java6
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java12
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java39
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java17
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/dmaap/PublisherTest.java45
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundleTest.java58
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/producer/MQProducerTest.java174
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java52
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java18
-rw-r--r--pom.xml57
12 files changed, 133 insertions, 482 deletions
diff --git a/holmes-actions/pom.xml b/holmes-actions/pom.xml
index 5449313..ebec435 100644
--- a/holmes-actions/pom.xml
+++ b/holmes-actions/pom.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Copyright 2017 ZTE Corporation. Licensed under the Apache License, Version
+<!-- 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
@@ -12,7 +12,7 @@
<parent>
<groupId>org.onap.holmes.common</groupId>
<artifactId>holmes-common-parent</artifactId>
- <version>1.2.13-SNAPSHOT</version>
+ <version>1.3.0-SNAPSHOT</version>
</parent>
<name>holmes-common-service</name>
@@ -20,6 +20,10 @@
<artifactId>holmes-actions</artifactId>
<dependencies>
<dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.onap.msb.java-sdk</groupId>
<artifactId>msb-java-sdk</artifactId>
<scope>provided</scope>
@@ -28,6 +32,14 @@
<groupId>com.eclipsesource.jaxrs</groupId>
<artifactId>jersey-all</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
@@ -35,10 +47,6 @@
<artifactId>geronimo-jms_1.1_spec</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>activemq-pool</artifactId>
- </dependency>
- <dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
</dependency>
@@ -73,6 +81,10 @@
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
@@ -110,11 +122,6 @@
</dependency>
<dependency>
<groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4-rule</artifactId>
<scope>test</scope>
</dependency>
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/producer/MQProducer.java b/holmes-actions/src/main/java/org/onap/holmes/common/producer/MQProducer.java
deleted file mode 100644
index 4bbffac..0000000
--- a/holmes-actions/src/main/java/org/onap/holmes/common/producer/MQProducer.java
+++ /dev/null
@@ -1,108 +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 java.io.Serializable;
-import javax.inject.Inject;
-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 lombok.NoArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.glassfish.hk2.api.IterableProvider;
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.common.api.stat.Alarm;
-import org.onap.holmes.common.api.stat.VesAlarm;
-import org.onap.holmes.common.constant.AlarmConst;
-import org.onap.holmes.common.api.entity.CorrelationResult;
-import org.onap.holmes.common.api.stat.AplusResult;
-import org.onap.holmes.common.config.MQConfig;
-import org.apache.activemq.ActiveMQConnectionFactory;
-
-@Service
-@Slf4j
-@NoArgsConstructor
-public class MQProducer {
-
- @Inject
- private IterableProvider<MQConfig> mqConfigProvider;
- private ConnectionFactory connectionFactory;
-
- public void init() {
-
- String brokerURL =
- "tcp://" + mqConfigProvider.get().getBrokerIp() + ":" + mqConfigProvider.get().getBrokerPort();
- connectionFactory = new ActiveMQConnectionFactory(mqConfigProvider.get().getBrokerUsername(),
- mqConfigProvider.get().getBrokerPassword(), brokerURL);
- }
-
- public void sendAlarmMQTopicMsg(VesAlarm alarm) {
- sendMQTopicMsg(alarm);
- }
-
- public void sendCorrelationMQTopicMsg(String ruleId, long createTimeL, Alarm parentAlarm,
- Alarm childAlarm) {
- CorrelationResult correlationResult = getCorrelationResult(ruleId, createTimeL, parentAlarm, childAlarm);
- sendMQTopicMsg(correlationResult);
- }
-
- private <T> void sendMQTopicMsg(T t) {
- Serializable msgEntity = (Serializable) t;
- Connection connection = null;
- Session session;
- Destination destination = null;
- MessageProducer messageProducer;
-
- try {
- connection = connectionFactory.createConnection();
- connection.start();
- session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
- if (t instanceof CorrelationResult) {
- destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARMS_CORRELATION);
- } else if (t instanceof VesAlarm) {
- destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARM);
- }
- messageProducer = session.createProducer(destination);
- ObjectMessage message = session.createObjectMessage(msgEntity);
- messageProducer.send(message);
- session.commit();
- } catch (Exception e) {
- log.error("Failed send correlation. " + e.getMessage(), e);
- } finally {
- if (connection != null) {
- try {
- connection.close();
- } catch (JMSException e) {
- log.error("Failed close connection. " + e.getMessage(), e);
- }
- }
- }
- }
-
- private CorrelationResult getCorrelationResult(String ruleId, long createTimeL, Alarm parentAlarm,
- Alarm childAlarm) {
- CorrelationResult correlationResult = new CorrelationResult();
- correlationResult.setRuleId(ruleId);
- correlationResult.setCreateTimeL(createTimeL);
- correlationResult.setResultType(AplusResult.APLUS_CORRELATION);
- correlationResult.setAffectedAlarms(new Alarm[]{parentAlarm, childAlarm});
- return correlationResult;
- }
-}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java
index a88519a..05792c5 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java
@@ -18,10 +18,11 @@ package org.onap.holmes.common.utils;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.jdbi.DBIFactory;
import io.dropwizard.setup.Environment;
-import lombok.extern.slf4j.Slf4j;
import org.jvnet.hk2.annotations.Service;
import org.skife.jdbi.v2.DBI;
import org.skife.jdbi.v2.Handle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
@@ -29,9 +30,10 @@ import javax.inject.Singleton;
@Singleton
@Service
-@Slf4j
public class DbDaoUtil {
+ private Logger log = LoggerFactory.getLogger(DbDaoUtil.class);
+
private DBI jdbi;
@Inject
private Environment environmentProvider;
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java
index 877a824..a849ab8 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.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.
@@ -16,8 +16,6 @@
package org.onap.holmes.common.utils;
-import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;
-
import lombok.extern.slf4j.Slf4j;
import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.config.MicroServiceConfig;
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
diff --git a/pom.xml b/pom.xml
index 6738052..9ad5f21 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,26 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Copyright 2017 ZTE Corporation. Licensed under the Apache License, Version
+<!-- 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. -->
-<!-- FM-ACTIVE POM DEFINITION -->
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.oparent</groupId>
<artifactId>oparent</artifactId>
- <version>2.1.0</version>
+ <version>3.0.0</version>
</parent>
<groupId>org.onap.holmes.common</groupId>
<artifactId>holmes-common-parent</artifactId>
<packaging>pom</packaging>
- <version>1.2.13-SNAPSHOT</version>
+ <version>1.3.0-SNAPSHOT</version>
<name>holmes-common</name>
<modules>
<module>holmes-actions</module>
@@ -29,22 +29,21 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- <maven.test.skip>false</maven.test.skip>
- <powermock.version>1.7.1</powermock.version>
<maven.test.failure.ignore>false</maven.test.failure.ignore>
+ <maven.test.skip>false</maven.test.skip>
+
<finalName>${project.artifactId}-${project.version}</finalName>
<release.dir>${basedir}/target</release.dir>
<bundle.name>${project.artifactId}-${project.version}</bundle.name>
- <pkgzip.dir>${basedir}/../release/pkgzip</pkgzip.dir>
- <excludesFile>**/*$*</excludesFile>
+
+ <powermock.version>2.0.7</powermock.version>
<stringtemplate.version>3.2.1</stringtemplate.version>
- <dropwizard.version>1.3.0</dropwizard.version>
- <swagger.version>1.5.3</swagger.version>
- <lombok.version>1.16.8</lombok.version>
- <jersey.version>2.22.2</jersey.version>
+ <dropwizard.version>2.0.9</dropwizard.version>
+ <swagger.version>1.6.1</swagger.version>
+ <lombok.version>1.18.4</lombok.version>
+ <jersey.version>2.31</jersey.version>
<slf4j.version>1.7.25</slf4j.version>
-
<jacoco.version>0.8.5</jacoco.version>
<sonar.coverage.jacoco.xmlReportPaths>
${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml
@@ -54,6 +53,11 @@
<dependencyManagement>
<dependencies>
<dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>1.2.3</version>
+ </dependency>
+ <dependency>
<groupId>org.onap.msb.java-sdk</groupId>
<artifactId>msb-java-sdk</artifactId>
<version>1.1.1</version>
@@ -79,23 +83,22 @@
<version>${dropwizard.version}</version>
<scope>provided</scope>
</dependency>
-
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-db</artifactId>
<version>${dropwizard.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-jdbi</artifactId>
- <version>${dropwizard.version}</version>
+ <version>2.0.0-rc9</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>${swagger.version}</version>
</dependency>
-
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
@@ -127,7 +130,7 @@
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
- <version>3.0</version>
+ <version>4.2</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -138,12 +141,6 @@
</dependency>
<dependency>
<groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito</artifactId>
- <version>${powermock.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4-rule</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
@@ -155,29 +152,19 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>activemq-broker</artifactId>
- <version>5.15.6</version>
- </dependency>
- <dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>activemq-pool</artifactId>
- <version>5.15.6</version>
- </dependency>
- <dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
- <version>4.5.3</version>
+ <version>4.5.12</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
- <version>27.1-jre</version>
+ <version>29.0-jre</version>
</dependency>
</dependencies>
</dependencyManagement>