diff --git a/openespi-common/src/main/java/org/greenbuttonalliance/espi/common/service/impl/NotificationServiceImpl.java b/openespi-common/src/main/java/org/greenbuttonalliance/espi/common/service/impl/NotificationServiceImpl.java index 327b14ae..f96e11fe 100644 --- a/openespi-common/src/main/java/org/greenbuttonalliance/espi/common/service/impl/NotificationServiceImpl.java +++ b/openespi-common/src/main/java/org/greenbuttonalliance/espi/common/service/impl/NotificationServiceImpl.java @@ -28,7 +28,6 @@ import org.greenbuttonalliance.espi.common.service.SubscriptionService; import org.greenbuttonalliance.espi.common.uri.EspiBatchUri; import org.greenbuttonalliance.espi.common.xml.BatchListXmlCodec; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -54,26 +53,18 @@ public class NotificationServiceImpl implements NotificationService { private final SubscriptionService subscriptionService; /** - * Production constructor. Builds a standalone {@link RestClient} for posting ESPI - * {@code BatchList} notifications to Third Party {@code thirdPartyNotifyUri} endpoints. - * Replaces the legacy {@code RestTemplate} (#158). + * Builds the {@link RestClient} once from the autoconfigured {@link RestClient.Builder} for + * posting ESPI {@code BatchList} notifications to Third Party {@code thirdPartyNotifyUri} + * endpoints. Replaces the legacy {@code RestTemplate} (#158). + * + *
This is the sole constructor, so Spring selects it for injection without {@code @Autowired}. + * Tests pass their own {@code RestClient.builder()} (e.g. pointed at a stub receiver).
*/ - @Autowired - public NotificationServiceImpl(AuthorizationRepository authorizationRepository, - AuthorizationService authorizationService, - SubscriptionService subscriptionService) { - this(RestClient.create(), authorizationRepository, authorizationService, subscriptionService); - } - - /** - * Test/seam constructor allowing a pre-configured {@link RestClient} (e.g. pointed at a - * stub receiver) to be injected. - */ - public NotificationServiceImpl(RestClient restClient, + public NotificationServiceImpl(RestClient.Builder restClientBuilder, AuthorizationRepository authorizationRepository, AuthorizationService authorizationService, SubscriptionService subscriptionService) { - this.restClient = restClient; + this.restClient = restClientBuilder.build(); this.authorizationRepository = authorizationRepository; this.authorizationService = authorizationService; this.subscriptionService = subscriptionService; diff --git a/openespi-common/src/test/java/org/greenbuttonalliance/espi/common/service/impl/NotificationServiceImplWireContractTest.java b/openespi-common/src/test/java/org/greenbuttonalliance/espi/common/service/impl/NotificationServiceImplWireContractTest.java index 8bfbd070..456c71d8 100644 --- a/openespi-common/src/test/java/org/greenbuttonalliance/espi/common/service/impl/NotificationServiceImplWireContractTest.java +++ b/openespi-common/src/test/java/org/greenbuttonalliance/espi/common/service/impl/NotificationServiceImplWireContractTest.java @@ -107,7 +107,7 @@ void notifyPostsConformantBatchList() throws Exception { // repositories/services are unused by the subscription notify path NotificationServiceImpl service = - new NotificationServiceImpl(RestClient.create(), null, null, null); + new NotificationServiceImpl(RestClient.builder(), null, null, null); service.notify(subscription, start, end);