From 343089923ca1dafb6a530b77718df5e82926b557 Mon Sep 17 00:00:00 2001 From: "mark.j.leonard" Date: Fri, 17 Aug 2018 10:51:00 +0100 Subject: Explicitly initialise the EventCallback class Remove the @Autowired annotation on the Babel Service Client and pass this as a parameter so that Spring will inject the value. This ensures that the EventCallback is not initialised with a null value. Issue-ID: AAI-1501 Change-Id: Ic1a66bf61afec4f707162acf323b83a8a48e8f28 Signed-off-by: mark.j.leonard --- .../java/org/onap/aai/modelloader/notification/EventCallback.java | 6 +++--- .../onap/aai/modelloader/notification/NotificationPublisher.java | 1 - .../java/org/onap/aai/modelloader/service/ModelLoaderService.java | 4 +++- .../org/onap/aai/modelloader/notification/TestEventCallback.java | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java b/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java index 42f72ce..d7bccba 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java +++ b/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java @@ -22,6 +22,7 @@ package org.onap.aai.modelloader.notification; import java.util.ArrayList; import java.util.List; + import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.cl.mdc.MdcContext; @@ -36,7 +37,6 @@ import org.onap.sdc.api.consumer.INotificationCallback; import org.onap.sdc.api.notification.IArtifactInfo; import org.onap.sdc.api.notification.INotificationData; import org.slf4j.MDC; -import org.springframework.beans.factory.annotation.Autowired; public class EventCallback implements INotificationCallback { private static Logger logger = LoggerFactory.getInstance().getLogger(EventCallback.class.getName()); @@ -47,12 +47,12 @@ public class EventCallback implements INotificationCallback { private NotificationPublisher notificationPublisher; private IDistributionClient client; private ModelLoaderConfig config; - @Autowired private BabelServiceClientFactory babelServiceClientFactory; - public EventCallback(IDistributionClient client, ModelLoaderConfig config) { + public EventCallback(IDistributionClient client, ModelLoaderConfig config, BabelServiceClientFactory babelServiceClientFactory) { this.client = client; this.config = config; + this.babelServiceClientFactory = babelServiceClientFactory; } @Override diff --git a/src/main/java/org/onap/aai/modelloader/notification/NotificationPublisher.java b/src/main/java/org/onap/aai/modelloader/notification/NotificationPublisher.java index 4f552f7..7ad552b 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/NotificationPublisher.java +++ b/src/main/java/org/onap/aai/modelloader/notification/NotificationPublisher.java @@ -22,7 +22,6 @@ package org.onap.aai.modelloader.notification; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Paths; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.Properties; diff --git a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderService.java b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderService.java index f8ab60f..35d8ada 100644 --- a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderService.java +++ b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderService.java @@ -30,9 +30,11 @@ import java.util.List; import java.util.Properties; import java.util.Timer; import java.util.TimerTask; + import javax.annotation.PostConstruct; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; + import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.modelloader.config.ModelLoaderConfig; @@ -107,7 +109,7 @@ public class ModelLoaderService implements ModelLoaderInterface { // Initialize distribution client logger.debug(ModelLoaderMsgs.INITIALIZING, "Initializing distribution client..."); client = DistributionClientFactory.createDistributionClient(); - EventCallback callback = new EventCallback(client, config); + EventCallback callback = new EventCallback(client, config, babelClientFactory); IDistributionClientResult initResult = client.init(config, callback); diff --git a/src/test/java/org/onap/aai/modelloader/notification/TestEventCallback.java b/src/test/java/org/onap/aai/modelloader/notification/TestEventCallback.java index 1215a7b..eb326fd 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/TestEventCallback.java +++ b/src/test/java/org/onap/aai/modelloader/notification/TestEventCallback.java @@ -28,6 +28,7 @@ import static org.mockito.Mockito.when; import java.io.IOException; import java.util.List; import java.util.Properties; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -67,7 +68,7 @@ public class TestEventCallback { mockDistributionClient = mock(IDistributionClient.class); mockNotificationPublisher = mock(NotificationPublisher.class); - eventCallback = new EventCallback(mockDistributionClient, config); + eventCallback = new EventCallback(mockDistributionClient, config, null); Whitebox.setInternalState(eventCallback, "artifactDeploymentManager", mockArtifactDeploymentManager); Whitebox.setInternalState(eventCallback, "artifactDownloadManager", mockArtifactDownloadManager); -- cgit 1.2.3-korg