Skip to content

Commit

Permalink
Merge c97219d into d44469d
Browse files Browse the repository at this point in the history
  • Loading branch information
mapingo committed Nov 2, 2018
2 parents d44469d + c97219d commit 6c7c138
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -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}
*/
Expand All @@ -54,15 +55,17 @@ public SubscriptionsDescriptorsRegistry subscriptionDescriptorRegistry() {
try {
final List<URL> 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<SubscriptionsDescriptor> subscriptionsDescriptors = subscriptionsDescriptorParser
.getSubscriptionDescriptorsFrom(subscriptionsDescriptorsPaths)
.peek(logRegisteredSubscriptionNames).collect(toSet());
final Set<SubscriptionsDescriptor> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit 6c7c138

Please sign in to comment.