From c97219de14ecb98e1e924ade229b8326c8683b5b Mon Sep 17 00:00:00 2001 From: Shaun Francis Date: Fri, 2 Nov 2018 13:49:54 +0000 Subject: [PATCH] Remove requirement for subscription decscriptor yaml --- CHANGELOG.md | 6 ++++- ...scriptionsDescriptorsRegistryProducer.java | 25 +++++++++++-------- ...ptionsDescriptorsRegistryProducerTest.java | 12 ++++----- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50cdfd3cc..dbdfbdcea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,12 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to ## [Unreleased] +### Changed +- Remove requirement to have a subscription-descriptor.yaml on the classpath + ### Added --event-publisher-process to event-store-bom +- event-publisher-process to event-store-bom +- New test-utils-event-store module to hold TestEventRepository moved from framework ## [1.0.0-M4] - 2018-10-31 diff --git a/event-sourcing/event-subscription-registry/src/main/java/uk/gov/justice/subscription/registry/SubscriptionsDescriptorsRegistryProducer.java b/event-sourcing/event-subscription-registry/src/main/java/uk/gov/justice/subscription/registry/SubscriptionsDescriptorsRegistryProducer.java index 99071e14f..2329f8019 100644 --- a/event-sourcing/event-subscription-registry/src/main/java/uk/gov/justice/subscription/registry/SubscriptionsDescriptorsRegistryProducer.java +++ b/event-sourcing/event-subscription-registry/src/main/java/uk/gov/justice/subscription/registry/SubscriptionsDescriptorsRegistryProducer.java @@ -1,6 +1,7 @@ package uk.gov.justice.subscription.registry; import static java.lang.String.format; +import static java.util.Collections.emptySet; import static java.util.stream.Collectors.toSet; import uk.gov.justice.subscription.SubscriptionsDescriptorParser; @@ -20,8 +21,8 @@ import org.slf4j.Logger; /** - * Producer for the {@link SubscriptionsDescriptorsRegistry} creates a single instance and returns the same - * instance. + * Producer for the {@link SubscriptionsDescriptorsRegistry} creates a single instance and returns + * the same instance. */ @ApplicationScoped public class SubscriptionsDescriptorsRegistryProducer { @@ -43,8 +44,8 @@ public class SubscriptionsDescriptorsRegistryProducer { logger.info(format("Subscription name in registry : %s", subscription.getName()))); /** - * Either creates the single instance of the {@link SubscriptionsDescriptorsRegistry} and returns it, or - * returns the previously created instance. + * Either creates the single instance of the {@link SubscriptionsDescriptorsRegistry} and + * returns it, or returns the previously created instance. * * @return the instance of the {@link SubscriptionsDescriptorsRegistry} */ @@ -54,15 +55,17 @@ public SubscriptionsDescriptorsRegistry subscriptionDescriptorRegistry() { try { final List subscriptionsDescriptorsPaths = yamlFileFinder.getSubscriptionsDescriptorsPaths(); - if (subscriptionsDescriptorsPaths.isEmpty()){ - throw new RegistryException("No event-sources.yaml files found!"); - } + if (subscriptionsDescriptorsPaths.isEmpty()) { + logger.info("Failed to find yaml/subscriptions-descriptor.yaml resources on the classpath"); + subscriptionsDescriptorsRegistry = new SubscriptionsDescriptorsRegistry(emptySet()); + } else { - final Set subscriptionsDescriptors = subscriptionsDescriptorParser - .getSubscriptionDescriptorsFrom(subscriptionsDescriptorsPaths) - .peek(logRegisteredSubscriptionNames).collect(toSet()); + final Set subscriptionsDescriptors = subscriptionsDescriptorParser + .getSubscriptionDescriptorsFrom(subscriptionsDescriptorsPaths) + .peek(logRegisteredSubscriptionNames).collect(toSet()); - subscriptionsDescriptorsRegistry = new SubscriptionsDescriptorsRegistry(subscriptionsDescriptors); + subscriptionsDescriptorsRegistry = new SubscriptionsDescriptorsRegistry(subscriptionsDescriptors); + } } catch (final IOException e) { throw new RegistryException("Failed to find yaml/subscriptions-descriptor.yaml resources on the classpath", e); } diff --git a/event-sourcing/event-subscription-registry/src/test/java/uk/gov/justice/subscription/registry/SubscriptionsDescriptorsRegistryProducerTest.java b/event-sourcing/event-subscription-registry/src/test/java/uk/gov/justice/subscription/registry/SubscriptionsDescriptorsRegistryProducerTest.java index ef6bcf17a..6dbd306e1 100644 --- a/event-sourcing/event-subscription-registry/src/test/java/uk/gov/justice/subscription/registry/SubscriptionsDescriptorsRegistryProducerTest.java +++ b/event-sourcing/event-subscription-registry/src/test/java/uk/gov/justice/subscription/registry/SubscriptionsDescriptorsRegistryProducerTest.java @@ -153,15 +153,13 @@ public void shouldThrowExceptionIfIOExceptionOccursWhenFindingSubscriptionDescri } @Test - public void shouldThrowExceptionIfIfNoSubscriptionDescriptorPathsUrlsFound() throws Exception { + public void shouldCreateSubscriptionsDescriptorsRegistryWithEmptySetAndLogIfNoSubscriptionYamls() throws Exception { when(yamlFileFinder.getEventSourcesPaths()).thenReturn(new ArrayList<>()); - try { - subscriptionsDescriptorsRegistryProducer.subscriptionDescriptorRegistry(); - fail(); - } catch (final RegistryException e) { - assertThat(e.getMessage(), is("No event-sources.yaml files found!")); - } + final SubscriptionsDescriptorsRegistry subscriptionsDescriptorsRegistry = subscriptionsDescriptorsRegistryProducer.subscriptionDescriptorRegistry(); + + assertThat(subscriptionsDescriptorsRegistry.subscriptionsDescriptors().size(), is(0)); + verify(logger).info("Failed to find yaml/subscriptions-descriptor.yaml resources on the classpath"); } } \ No newline at end of file