Upgraded to Java 11 74/109474/1
authorGuangrongFu <fu.guangrong@zte.com.cn>
Wed, 24 Jun 2020 02:52:42 +0000 (10:52 +0800)
committerGuangrongFu <fu.guangrong@zte.com.cn>
Wed, 24 Jun 2020 02:52:42 +0000 (10:52 +0800)
Change-Id: Iee2bce6fad2076b1df093f1f978b2e78a64c6492
Issue-ID: HOLMES-302
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
12 files changed:
holmes-actions/pom.xml
holmes-actions/src/main/java/org/onap/holmes/common/producer/MQProducer.java [deleted file]
holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java
holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java
holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java
holmes-actions/src/test/java/org/onap/holmes/common/dmaap/PublisherTest.java
holmes-actions/src/test/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundleTest.java
holmes-actions/src/test/java/org/onap/holmes/common/producer/MQProducerTest.java [deleted file]
holmes-actions/src/test/java/org/onap/holmes/common/utils/DbDaoUtilTest.java
holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java
pom.xml

index 5449313..ebec435 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
-<!-- Copyright 2017 ZTE Corporation. Licensed under the Apache License, Version\r
+<!-- Copyright 2017-2020 ZTE Corporation. Licensed under the Apache License, Version\r
        2.0 (the "License"); you may not use this file except in compliance with\r
        the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\r
        Unless required by applicable law or agreed to in writing, software distributed\r
     <parent>\r
         <groupId>org.onap.holmes.common</groupId>\r
         <artifactId>holmes-common-parent</artifactId>\r
-        <version>1.2.13-SNAPSHOT</version>\r
+        <version>1.3.0-SNAPSHOT</version>\r
     </parent>\r
 \r
     <name>holmes-common-service</name>\r
     <packaging>jar</packaging>\r
     <artifactId>holmes-actions</artifactId>\r
     <dependencies>\r
+        <dependency>\r
+            <groupId>ch.qos.logback</groupId>\r
+            <artifactId>logback-classic</artifactId>\r
+        </dependency>\r
         <dependency>\r
             <groupId>org.onap.msb.java-sdk</groupId>\r
             <artifactId>msb-java-sdk</artifactId>\r
                     <groupId>com.eclipsesource.jaxrs</groupId>\r
                     <artifactId>jersey-all</artifactId>\r
                 </exclusion>\r
+                <exclusion>\r
+                    <groupId>ch.qos.logback</groupId>\r
+                    <artifactId>logback-classic</artifactId>\r
+                </exclusion>\r
+                <exclusion>\r
+                    <groupId>org.slf4j</groupId>\r
+                    <artifactId>slf4j-api</artifactId>\r
+                </exclusion>\r
             </exclusions>\r
         </dependency>\r
         <dependency>\r
             <groupId>org.apache.geronimo.specs</groupId>\r
             <artifactId>geronimo-jms_1.1_spec</artifactId>\r
         </dependency>\r
-        <dependency>\r
-            <groupId>org.apache.activemq</groupId>\r
-            <artifactId>activemq-pool</artifactId>\r
-        </dependency>\r
         <dependency>\r
             <groupId>org.antlr</groupId>\r
             <artifactId>stringtemplate</artifactId>\r
                     <groupId>com.fasterxml.jackson.dataformat</groupId>\r
                     <artifactId>jackson-dataformat-xml</artifactId>\r
                 </exclusion>\r
+                <exclusion>\r
+                    <groupId>org.slf4j</groupId>\r
+                    <artifactId>slf4j-api</artifactId>\r
+                </exclusion>\r
             </exclusions>\r
         </dependency>\r
         <dependency>\r
             <artifactId>powermock-api-easymock</artifactId>\r
             <scope>test</scope>\r
         </dependency>\r
-        <dependency>\r
-            <groupId>org.powermock</groupId>\r
-            <artifactId>powermock-api-mockito</artifactId>\r
-            <scope>test</scope>\r
-        </dependency>\r
         <dependency>\r
             <groupId>org.powermock</groupId>\r
             <artifactId>powermock-module-junit4-rule</artifactId>\r
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 (file)
index 4bbffac..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/**\r
- * Copyright 2017 ZTE Corporation.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.onap.holmes.common.producer;\r
-\r
-import java.io.Serializable;\r
-import javax.inject.Inject;\r
-import javax.jms.Connection;\r
-import javax.jms.ConnectionFactory;\r
-import javax.jms.Destination;\r
-import javax.jms.JMSException;\r
-import javax.jms.MessageProducer;\r
-import javax.jms.ObjectMessage;\r
-import javax.jms.Session;\r
-import lombok.NoArgsConstructor;\r
-import lombok.extern.slf4j.Slf4j;\r
-import org.glassfish.hk2.api.IterableProvider;\r
-import org.jvnet.hk2.annotations.Service;\r
-import org.onap.holmes.common.api.stat.Alarm;\r
-import org.onap.holmes.common.api.stat.VesAlarm;\r
-import org.onap.holmes.common.constant.AlarmConst;\r
-import org.onap.holmes.common.api.entity.CorrelationResult;\r
-import org.onap.holmes.common.api.stat.AplusResult;\r
-import org.onap.holmes.common.config.MQConfig;\r
-import org.apache.activemq.ActiveMQConnectionFactory;\r
-\r
-@Service\r
-@Slf4j\r
-@NoArgsConstructor\r
-public class MQProducer {\r
-\r
-    @Inject\r
-    private IterableProvider<MQConfig> mqConfigProvider;\r
-    private ConnectionFactory connectionFactory;\r
-\r
-    public void init() {\r
-\r
-        String brokerURL =\r
-            "tcp://" + mqConfigProvider.get().getBrokerIp() + ":" + mqConfigProvider.get().getBrokerPort();\r
-        connectionFactory = new ActiveMQConnectionFactory(mqConfigProvider.get().getBrokerUsername(),\r
-            mqConfigProvider.get().getBrokerPassword(), brokerURL);\r
-    }\r
-\r
-    public void sendAlarmMQTopicMsg(VesAlarm alarm) {\r
-        sendMQTopicMsg(alarm);\r
-    }\r
-\r
-    public void sendCorrelationMQTopicMsg(String ruleId, long createTimeL, Alarm parentAlarm,\r
-            Alarm childAlarm) {\r
-        CorrelationResult correlationResult = getCorrelationResult(ruleId, createTimeL, parentAlarm, childAlarm);\r
-        sendMQTopicMsg(correlationResult);\r
-    }\r
-\r
-    private <T> void sendMQTopicMsg(T t) {\r
-        Serializable msgEntity = (Serializable) t;\r
-        Connection connection = null;\r
-        Session session;\r
-        Destination destination = null;\r
-        MessageProducer messageProducer;\r
-\r
-        try {\r
-            connection = connectionFactory.createConnection();\r
-            connection.start();\r
-            session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);\r
-            if (t instanceof CorrelationResult) {\r
-                destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARMS_CORRELATION);\r
-            } else if (t instanceof VesAlarm) {\r
-                destination = session.createTopic(AlarmConst.MQ_TOPIC_NAME_ALARM);\r
-            }\r
-            messageProducer = session.createProducer(destination);\r
-            ObjectMessage message = session.createObjectMessage(msgEntity);\r
-            messageProducer.send(message);\r
-            session.commit();\r
-        } catch (Exception e) {\r
-            log.error("Failed send correlation. " + e.getMessage(), e);\r
-        } finally {\r
-            if (connection != null) {\r
-                try {\r
-                    connection.close();\r
-                } catch (JMSException e) {\r
-                    log.error("Failed close connection. " + e.getMessage(), e);\r
-                }\r
-            }\r
-        }\r
-    }\r
-\r
-    private CorrelationResult getCorrelationResult(String ruleId, long createTimeL, Alarm parentAlarm,\r
-            Alarm childAlarm) {\r
-        CorrelationResult correlationResult = new CorrelationResult();\r
-        correlationResult.setRuleId(ruleId);\r
-        correlationResult.setCreateTimeL(createTimeL);\r
-        correlationResult.setResultType(AplusResult.APLUS_CORRELATION);\r
-        correlationResult.setAffectedAlarms(new Alarm[]{parentAlarm, childAlarm});\r
-        return correlationResult;\r
-    }\r
-}\r
index a88519a..05792c5 100644 (file)
@@ -18,10 +18,11 @@ package org.onap.holmes.common.utils;
 import io.dropwizard.db.DataSourceFactory;\r
 import io.dropwizard.jdbi.DBIFactory;\r
 import io.dropwizard.setup.Environment;\r
-import lombok.extern.slf4j.Slf4j;\r
 import org.jvnet.hk2.annotations.Service;\r
 import org.skife.jdbi.v2.DBI;\r
 import org.skife.jdbi.v2.Handle;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
 \r
 import javax.annotation.PostConstruct;\r
 import javax.inject.Inject;\r
@@ -29,9 +30,10 @@ import javax.inject.Singleton;
 \r
 @Singleton\r
 @Service\r
-@Slf4j\r
 public class DbDaoUtil {\r
 \r
+    private Logger log = LoggerFactory.getLogger(DbDaoUtil.class);\r
+\r
     private DBI jdbi;\r
     @Inject\r
     private Environment environmentProvider;\r
index 877a824..a849ab8 100644 (file)
@@ -1,12 +1,12 @@
 /**\r
- * Copyright 2017 ZTE Corporation.\r
- *\r
+ * Copyright 2017-2020 ZTE Corporation.\r
+ * <p>\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
+ * <p>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p>\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
@@ -16,8 +16,6 @@
 \r
 package org.onap.holmes.common.utils;\r
 \r
-import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;\r
-\r
 import lombok.extern.slf4j.Slf4j;\r
 import org.jvnet.hk2.annotations.Service;\r
 import org.onap.holmes.common.config.MicroServiceConfig;\r
index 7ce3fcf..15904d5 100644 (file)
@@ -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.
  */
 
 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"));
index aea9d96..a87ba67 100644 (file)
@@ -1,12 +1,12 @@
 /**\r
- * Copyright 2017 ZTE Corporation.\r
- *\r
+ * Copyright 2017-2020 ZTE Corporation.\r
+ * <p>\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
+ * <p>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p>\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
@@ -19,12 +19,12 @@ package org.onap.holmes.common.config;
 import org.apache.commons.lang3.StringUtils;\r
 import org.easymock.EasyMock;\r
 import org.junit.Ignore;\r
-import org.junit.Rule;\r
 import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
 import org.powermock.api.easymock.PowerMock;\r
 import org.powermock.core.classloader.annotations.PowerMockIgnore;\r
 import org.powermock.core.classloader.annotations.PrepareForTest;\r
-import org.powermock.modules.junit4.rule.PowerMockRule;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
 import org.powermock.reflect.internal.WhiteboxImpl;\r
 \r
 import static org.hamcrest.core.Is.is;\r
@@ -35,12 +35,11 @@ import static org.onap.holmes.common.config.MicroServiceConfig.*;
 \r
 @PrepareForTest(MicroServiceConfig.class)\r
 @PowerMockIgnore({"javax.ws.*"})\r
+@RunWith(PowerMockRunner.class)\r
 public class MicroServiceConfigTest {\r
 \r
     private static String ACTUAL_HOSTNAME = System.getenv(HOSTNAME);\r
 \r
-    @Rule\r
-    public PowerMockRule powerMockRule = new PowerMockRule();\r
 \r
     @Test\r
     public void getMsbServerAddrTest() {\r
index be9f74f..0e7fe3d 100644 (file)
@@ -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.
  */
 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();
 
index 740d92b..8cf044f 100644 (file)
@@ -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.
  */
 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 (file)
index 3fad981..0000000
+++ /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();
-
-    }
-} 
index e942eb4..dd42044 100644 (file)
@@ -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.
 
 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();
 
@@ -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);
 
index ab75e06..e6b6f9d 100644 (file)
@@ -1,12 +1,12 @@
 /**\r
- * Copyright 2017 ZTE Corporation.\r
- *\r
+ * Copyright 2017-2020 ZTE Corporation.\r
+ * <p>\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
+ * <p>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p>\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
@@ -17,8 +17,8 @@
 package org.onap.holmes.common.utils;\r
 \r
 import org.easymock.EasyMock;\r
-import org.junit.Rule;\r
 import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
 import org.onap.holmes.common.config.MicroServiceConfig;\r
 import org.onap.holmes.common.exception.CorrelationException;\r
 import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;\r
@@ -27,15 +27,13 @@ import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
 import org.powermock.api.easymock.PowerMock;\r
 import org.powermock.core.classloader.annotations.PowerMockIgnore;\r
 import org.powermock.core.classloader.annotations.PrepareForTest;\r
-import org.powermock.modules.junit4.rule.PowerMockRule;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
 \r
 @PrepareForTest({MicroServiceConfig.class, MSBServiceClient.class, MSBRegisterUtil.class})\r
 @PowerMockIgnore({"javax.ws.*"})\r
+@RunWith(PowerMockRunner.class)\r
 public class MSBRegisterUtilTest {\r
 \r
-    @Rule\r
-    public PowerMockRule powerMockRule = new PowerMockRule();\r
-\r
     private MSBRegisterUtil msbRegisterUtil = new MSBRegisterUtil();\r
 \r
     @Test\r
diff --git a/pom.xml b/pom.xml
index 6738052..9ad5f21 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -1,26 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
-<!-- Copyright 2017 ZTE Corporation. Licensed under the Apache License, Version\r
+<!-- Copyright 2017-2020 ZTE Corporation. Licensed under the Apache License, Version\r
        2.0 (the "License"); you may not use this file except in compliance with\r
        the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\r
        Unless required by applicable law or agreed to in writing, software distributed\r
        under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES\r
        OR CONDITIONS OF ANY KIND, either express or implied. See the License for\r
        the specific language governing permissions and limitations under the License. -->\r
-<!-- FM-ACTIVE POM DEFINITION -->\r
+\r
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
     <modelVersion>4.0.0</modelVersion>\r
     <parent>\r
         <groupId>org.onap.oparent</groupId>\r
         <artifactId>oparent</artifactId>\r
-        <version>2.1.0</version>\r
+        <version>3.0.0</version>\r
     </parent>\r
 \r
     <groupId>org.onap.holmes.common</groupId>\r
     <artifactId>holmes-common-parent</artifactId>\r
     <packaging>pom</packaging>\r
 \r
-    <version>1.2.13-SNAPSHOT</version>\r
+    <version>1.3.0-SNAPSHOT</version>\r
     <name>holmes-common</name>\r
     <modules>\r
         <module>holmes-actions</module>\r
     <properties>\r
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\r
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>\r
-        <maven.test.skip>false</maven.test.skip>\r
-        <powermock.version>1.7.1</powermock.version>\r
         <maven.test.failure.ignore>false</maven.test.failure.ignore>\r
+        <maven.test.skip>false</maven.test.skip>\r
+\r
         <finalName>${project.artifactId}-${project.version}</finalName>\r
         <release.dir>${basedir}/target</release.dir>\r
         <bundle.name>${project.artifactId}-${project.version}</bundle.name>\r
-        <pkgzip.dir>${basedir}/../release/pkgzip</pkgzip.dir>\r
-        <excludesFile>**/*$*</excludesFile>\r
+\r
+        <powermock.version>2.0.7</powermock.version>\r
 \r
         <stringtemplate.version>3.2.1</stringtemplate.version>\r
-        <dropwizard.version>1.3.0</dropwizard.version>\r
-        <swagger.version>1.5.3</swagger.version>\r
-        <lombok.version>1.16.8</lombok.version>\r
-        <jersey.version>2.22.2</jersey.version>\r
+        <dropwizard.version>2.0.9</dropwizard.version>\r
+        <swagger.version>1.6.1</swagger.version>\r
+        <lombok.version>1.18.4</lombok.version>\r
+        <jersey.version>2.31</jersey.version>\r
         <slf4j.version>1.7.25</slf4j.version>\r
-\r
         <jacoco.version>0.8.5</jacoco.version>\r
         <sonar.coverage.jacoco.xmlReportPaths>\r
             ${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml\r
 \r
     <dependencyManagement>\r
         <dependencies>\r
+            <dependency>\r
+                <groupId>ch.qos.logback</groupId>\r
+                <artifactId>logback-classic</artifactId>\r
+                <version>1.2.3</version>\r
+            </dependency>\r
             <dependency>\r
                 <groupId>org.onap.msb.java-sdk</groupId>\r
                 <artifactId>msb-java-sdk</artifactId>\r
                 <version>${dropwizard.version}</version>\r
                 <scope>provided</scope>\r
             </dependency>\r
-\r
             <dependency>\r
                 <groupId>io.dropwizard</groupId>\r
                 <artifactId>dropwizard-db</artifactId>\r
                 <version>${dropwizard.version}</version>\r
+                <scope>provided</scope>\r
             </dependency>\r
             <dependency>\r
                 <groupId>io.dropwizard</groupId>\r
                 <artifactId>dropwizard-jdbi</artifactId>\r
-                <version>${dropwizard.version}</version>\r
+                <version>2.0.0-rc9</version>\r
             </dependency>\r
             <dependency>\r
                 <groupId>io.swagger</groupId>\r
                 <artifactId>swagger-jersey2-jaxrs</artifactId>\r
                 <version>${swagger.version}</version>\r
             </dependency>\r
-\r
             <dependency>\r
                 <groupId>org.projectlombok</groupId>\r
                 <artifactId>lombok</artifactId>\r
             <dependency>\r
                 <groupId>org.easymock</groupId>\r
                 <artifactId>easymock</artifactId>\r
-                <version>3.0</version>\r
+                <version>4.2</version>\r
                 <scope>test</scope>\r
             </dependency>\r
             <dependency>\r
                 <version>${powermock.version}</version>\r
                 <scope>test</scope>\r
             </dependency>\r
-            <dependency>\r
-                <groupId>org.powermock</groupId>\r
-                <artifactId>powermock-api-mockito</artifactId>\r
-                <version>${powermock.version}</version>\r
-                <scope>test</scope>\r
-            </dependency>\r
             <dependency>\r
                 <groupId>org.powermock</groupId>\r
                 <artifactId>powermock-module-junit4-rule</artifactId>\r
                 <version>${powermock.version}</version>\r
                 <scope>test</scope>\r
             </dependency>\r
-            <dependency>\r
-                <groupId>org.apache.activemq</groupId>\r
-                <artifactId>activemq-broker</artifactId>\r
-                <version>5.15.6</version>\r
-            </dependency>\r
             <dependency>\r
                 <groupId>org.apache.geronimo.specs</groupId>\r
                 <artifactId>geronimo-jms_1.1_spec</artifactId>\r
                 <version>1.1.1</version>\r
             </dependency>\r
-            <dependency>\r
-                <groupId>org.apache.activemq</groupId>\r
-                <artifactId>activemq-pool</artifactId>\r
-                <version>5.15.6</version>\r
-            </dependency>\r
             <dependency>\r
                 <groupId>org.apache.httpcomponents</groupId>\r
                 <artifactId>httpclient</artifactId>\r
-                <version>4.5.3</version>\r
+                <version>4.5.12</version>\r
             </dependency>\r
             <dependency>\r
                 <groupId>com.google.guava</groupId>\r
                 <artifactId>guava</artifactId>\r
-                <version>27.1-jre</version>\r
+                <version>29.0-jre</version>\r
             </dependency>\r
         </dependencies>\r
     </dependencyManagement>\r