This repository has been archived by the owner on Aug 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
...src/main/java/uk/gov/justice/subscription/jms/parser/SubscriptionFileParserException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...ator/src/test/java/uk/gov/justice/subscription/jms/parser/EventSourcesFileParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package uk.gov.justice.subscription.jms.parser; | ||
|
||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.emptyList; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.fail; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import uk.gov.justice.subscription.domain.eventsource.EventSources; | ||
import uk.gov.justice.subscription.yaml.parser.YamlFileValidator; | ||
import uk.gov.justice.subscription.yaml.parser.YamlParser; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class EventSourcesFileParserTest { | ||
|
||
@Mock | ||
private YamlParser yamlParser; | ||
|
||
@Mock | ||
private YamlFileValidator yamlFileValidator; | ||
|
||
@InjectMocks | ||
private EventSourcesFileParser eventSourcesFileParser; | ||
|
||
@Test | ||
public void shouldReturnSingleEventSources() { | ||
final Path baseDir = mock(Path.class); | ||
final Path resolvedPath = mock(Path.class); | ||
|
||
final Path eventSourcePath = mock(Path.class); | ||
final Path subscriptionDescriptorPath = mock(Path.class); | ||
final List<Path> pathList = asList(eventSourcePath, subscriptionDescriptorPath); | ||
|
||
final EventSources eventSources = mock(EventSources.class); | ||
|
||
when(subscriptionDescriptorPath.endsWith("event-sources.yaml")).thenReturn(false); | ||
when(eventSourcePath.endsWith("event-sources.yaml")).thenReturn(true); | ||
|
||
when(baseDir.resolve(eventSourcePath)).thenReturn(resolvedPath); | ||
when(yamlParser.parseYamlFrom(resolvedPath, EventSources.class)).thenReturn(eventSources); | ||
|
||
|
||
final EventSources expectedEventSources = eventSourcesFileParser.getEventSources(baseDir, pathList); | ||
|
||
assertThat(expectedEventSources, is(eventSources)); | ||
} | ||
|
||
@Test | ||
public void shouldThrowExceptionIfMoreThanOneEventSourcesPresent() { | ||
final Path baseDir = mock(Path.class); | ||
final Path resolvedPath = mock(Path.class); | ||
|
||
final Path eventSourcePath = mock(Path.class); | ||
final Path subscriptionDescriptorPath = mock(Path.class); | ||
final List<Path> pathList = asList(eventSourcePath, eventSourcePath, subscriptionDescriptorPath); | ||
|
||
final EventSources eventSources = mock(EventSources.class); | ||
|
||
when(subscriptionDescriptorPath.endsWith("event-sources.yaml")).thenReturn(false); | ||
when(eventSourcePath.endsWith("event-sources.yaml")).thenReturn(true); | ||
|
||
when(baseDir.resolve(eventSourcePath)).thenReturn(resolvedPath); | ||
when(yamlParser.parseYamlFrom(resolvedPath, EventSources.class)).thenReturn(eventSources); | ||
|
||
try { | ||
eventSourcesFileParser.getEventSources(baseDir, pathList); | ||
fail(); | ||
} catch (final SubscriptionFileParserException e) { | ||
assertThat(e.getMessage(), is("More then one event-sources.yaml files found!")); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldThrowExceptionIfNoEventSourcesPresent() { | ||
final Path baseDir = mock(Path.class); | ||
|
||
try { | ||
eventSourcesFileParser.getEventSources(baseDir, emptyList()); | ||
fail(); | ||
} catch (final SubscriptionFileParserException e) { | ||
assertThat(e.getMessage(), is("No event-sources.yaml files found!")); | ||
} | ||
} | ||
} |