This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add builders for the yaml domain classes
- Loading branch information
amckenzie
committed
Mar 13, 2018
1 parent
390dc29
commit 7783f64
Showing
19 changed files
with
467 additions
and
17 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
30 changes: 30 additions & 0 deletions
30
generator-maven-test-utils/src/main/java/uk/gov/justice/domain/EventBuilder.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,30 @@ | ||
package uk.gov.justice.domain; | ||
|
||
import uk.gov.justice.domain.subscriptiondescriptor.Event; | ||
|
||
public class EventBuilder { | ||
|
||
private String name; | ||
private String schemaUri; | ||
|
||
private EventBuilder() {} | ||
|
||
|
||
public static EventBuilder event() { | ||
return new EventBuilder(); | ||
} | ||
|
||
public EventBuilder withName(final String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public EventBuilder withSchemaUri(final String schemaUri) { | ||
this.schemaUri = schemaUri; | ||
return this; | ||
} | ||
|
||
public Event build() { | ||
return new Event(name, schemaUri); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
generator-maven-test-utils/src/main/java/uk/gov/justice/domain/EventsourceBuilder.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,31 @@ | ||
package uk.gov.justice.domain; | ||
|
||
import uk.gov.justice.domain.subscriptiondescriptor.Eventsource; | ||
import uk.gov.justice.domain.subscriptiondescriptor.Location; | ||
|
||
public final class EventsourceBuilder { | ||
|
||
private String name; | ||
private Location location; | ||
|
||
private EventsourceBuilder() { | ||
} | ||
|
||
public static EventsourceBuilder eventsource() { | ||
return new EventsourceBuilder(); | ||
} | ||
|
||
public EventsourceBuilder withName(final String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public EventsourceBuilder withLocation(final Location location) { | ||
this.location = location; | ||
return this; | ||
} | ||
|
||
public Eventsource build() { | ||
return new Eventsource(name, location); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
generator-maven-test-utils/src/main/java/uk/gov/justice/domain/LocationBuilder.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,30 @@ | ||
package uk.gov.justice.domain; | ||
|
||
import uk.gov.justice.domain.subscriptiondescriptor.Location; | ||
|
||
public final class LocationBuilder { | ||
|
||
private String jmsUri; | ||
private String restUri; | ||
|
||
private LocationBuilder() { | ||
} | ||
|
||
public static LocationBuilder location() { | ||
return new LocationBuilder(); | ||
} | ||
|
||
public LocationBuilder withJmsUri(final String jmsUri) { | ||
this.jmsUri = jmsUri; | ||
return this; | ||
} | ||
|
||
public LocationBuilder withRestUri(final String restUri) { | ||
this.restUri = restUri; | ||
return this; | ||
} | ||
|
||
public Location build() { | ||
return new Location(jmsUri, restUri); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
generator-maven-test-utils/src/main/java/uk/gov/justice/domain/SubscriptionBuilder.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,46 @@ | ||
package uk.gov.justice.domain; | ||
|
||
import uk.gov.justice.domain.subscriptiondescriptor.Event; | ||
import uk.gov.justice.domain.subscriptiondescriptor.Eventsource; | ||
import uk.gov.justice.domain.subscriptiondescriptor.Subscription; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public final class SubscriptionBuilder { | ||
|
||
private String name; | ||
private final List<Event> events = new ArrayList<>(); | ||
private Eventsource eventsource; | ||
|
||
private SubscriptionBuilder() { | ||
} | ||
|
||
public static SubscriptionBuilder subscription() { | ||
return new SubscriptionBuilder(); | ||
} | ||
|
||
public SubscriptionBuilder withName(final String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public SubscriptionBuilder withEvent(final Event event) { | ||
this.events.add(event); | ||
return this; | ||
} | ||
|
||
public SubscriptionBuilder withEvents(final List<Event> events) { | ||
this.events.addAll(events); | ||
return this; | ||
} | ||
|
||
public SubscriptionBuilder withEventsource(final Eventsource eventsource) { | ||
this.eventsource = eventsource; | ||
return this; | ||
} | ||
|
||
public Subscription build() { | ||
return new Subscription(name, events, eventsource); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...r-maven-test-utils/src/main/java/uk/gov/justice/domain/SubscriptionDescriptorBuilder.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,51 @@ | ||
package uk.gov.justice.domain; | ||
|
||
import uk.gov.justice.domain.subscriptiondescriptor.Subscription; | ||
import uk.gov.justice.domain.subscriptiondescriptor.SubscriptionDescriptor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public final class SubscriptionDescriptorBuilder { | ||
|
||
private String specVersion; | ||
private String service; | ||
private String serviceComponent; | ||
private final List<Subscription> subscriptions = new ArrayList<>(); | ||
|
||
private SubscriptionDescriptorBuilder() { | ||
} | ||
|
||
public static SubscriptionDescriptorBuilder subscriptionDescriptor() { | ||
return new SubscriptionDescriptorBuilder(); | ||
} | ||
|
||
public SubscriptionDescriptorBuilder withSpecVersion(final String specVersion) { | ||
this.specVersion = specVersion; | ||
return this; | ||
} | ||
|
||
public SubscriptionDescriptorBuilder withService(final String service) { | ||
this.service = service; | ||
return this; | ||
} | ||
|
||
public SubscriptionDescriptorBuilder withServiceComponent(final String serviceComponent) { | ||
this.serviceComponent = serviceComponent; | ||
return this; | ||
} | ||
|
||
public SubscriptionDescriptorBuilder withSubscription(final Subscription subscription) { | ||
this.subscriptions.add(subscription); | ||
return this; | ||
} | ||
|
||
public SubscriptionDescriptorBuilder withSubscriptions(final List<Subscription> subscriptions) { | ||
this.subscriptions.addAll(subscriptions); | ||
return this; | ||
} | ||
|
||
public SubscriptionDescriptor build() { | ||
return new SubscriptionDescriptor(specVersion, service, serviceComponent, subscriptions); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...aven-test-utils/src/main/java/uk/gov/justice/domain/SubscriptionDescriptorDefBuilder.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,25 @@ | ||
package uk.gov.justice.domain; | ||
|
||
import uk.gov.justice.domain.subscriptiondescriptor.SubscriptionDescriptor; | ||
import uk.gov.justice.domain.subscriptiondescriptor.SubscriptionDescriptorDef; | ||
|
||
public final class SubscriptionDescriptorDefBuilder { | ||
|
||
private SubscriptionDescriptor subscriptionDescriptor; | ||
|
||
private SubscriptionDescriptorDefBuilder() { | ||
} | ||
|
||
public static SubscriptionDescriptorDefBuilder subscriptionDescriptorDef() { | ||
return new SubscriptionDescriptorDefBuilder(); | ||
} | ||
|
||
public SubscriptionDescriptorDefBuilder withSubscriptionDescriptor(final SubscriptionDescriptor subscriptionDescriptor) { | ||
this.subscriptionDescriptor = subscriptionDescriptor; | ||
return this; | ||
} | ||
|
||
public SubscriptionDescriptorDef build() { | ||
return new SubscriptionDescriptorDef(subscriptionDescriptor); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
generator-maven-test-utils/src/test/java/uk/gov/justice/domain/EventBuilderTest.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,27 @@ | ||
package uk.gov.justice.domain; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static uk.gov.justice.domain.EventBuilder.event; | ||
|
||
import uk.gov.justice.domain.subscriptiondescriptor.Event; | ||
|
||
import org.junit.Test; | ||
|
||
public class EventBuilderTest { | ||
|
||
@Test | ||
public void shouldBuildAnEvent() throws Exception { | ||
|
||
final String name = "event name"; | ||
final String schemaUri = "schemaUri"; | ||
|
||
final Event event = event() | ||
.withName(name) | ||
.withSchemaUri(schemaUri) | ||
.build(); | ||
|
||
assertThat(event.getName(), is(name)); | ||
assertThat(event.getSchemaUri(), is(schemaUri)); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
generator-maven-test-utils/src/test/java/uk/gov/justice/domain/EventsourceBuilderTest.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,29 @@ | ||
package uk.gov.justice.domain; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static uk.gov.justice.domain.EventsourceBuilder.eventsource; | ||
|
||
import uk.gov.justice.domain.subscriptiondescriptor.Eventsource; | ||
import uk.gov.justice.domain.subscriptiondescriptor.Location; | ||
|
||
import org.junit.Test; | ||
|
||
public class EventsourceBuilderTest { | ||
|
||
@Test | ||
public void shouldBuildAnEventsource() throws Exception { | ||
|
||
final String name = "name"; | ||
final Location location = mock(Location.class); | ||
|
||
final Eventsource eventsource = eventsource() | ||
.withName(name) | ||
.withLocation(location) | ||
.build(); | ||
|
||
assertThat(eventsource.getName(), is(name)); | ||
assertThat(eventsource.getLocation(), is(location)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
generator-maven-test-utils/src/test/java/uk/gov/justice/domain/LocationBuilderTest.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,27 @@ | ||
package uk.gov.justice.domain; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static uk.gov.justice.domain.LocationBuilder.location; | ||
|
||
import uk.gov.justice.domain.subscriptiondescriptor.Location; | ||
|
||
import org.junit.Test; | ||
|
||
public class LocationBuilderTest { | ||
|
||
@Test | ||
public void shouldBuildALocation() throws Exception { | ||
|
||
final String jmsUri = "jmsUri"; | ||
final String restUri = "restUri"; | ||
|
||
final Location location = location() | ||
.withJmsUri(jmsUri) | ||
.withRestUri(restUri) | ||
.build(); | ||
|
||
assertThat(location.getJmsUri(), is(jmsUri)); | ||
assertThat(location.getRestUri(), is(restUri)); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
generator-maven-test-utils/src/test/java/uk/gov/justice/domain/SubscriptionBuilderTest.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,59 @@ | ||
package uk.gov.justice.domain; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.hamcrest.CoreMatchers.hasItem; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static uk.gov.justice.domain.SubscriptionBuilder.subscription; | ||
|
||
import uk.gov.justice.domain.subscriptiondescriptor.Event; | ||
import uk.gov.justice.domain.subscriptiondescriptor.Eventsource; | ||
import uk.gov.justice.domain.subscriptiondescriptor.Subscription; | ||
|
||
import org.junit.Test; | ||
|
||
public class SubscriptionBuilderTest { | ||
|
||
|
||
@Test | ||
public void shouldBuildASubscription() throws Exception { | ||
|
||
final String name = "name"; | ||
final Event event_1 = mock(Event.class); | ||
final Event event_2 = mock(Event.class); | ||
final Eventsource eventsource = mock(Eventsource.class); | ||
|
||
final Subscription subscription = subscription() | ||
.withName(name) | ||
.withEvents(asList(event_1, event_2)) | ||
.withEventsource(eventsource) | ||
.build(); | ||
|
||
assertThat(subscription.getName(), is(name)); | ||
assertThat(subscription.getEventsource(), is(eventsource)); | ||
assertThat(subscription.getEvents(), hasItem(event_1)); | ||
assertThat(subscription.getEvents(), hasItem(event_2)); | ||
} | ||
|
||
@Test | ||
public void shouldBeAbleToAddEventsOneAtATime() throws Exception { | ||
|
||
final String name = "name"; | ||
final Event event_1 = mock(Event.class); | ||
final Event event_2 = mock(Event.class); | ||
final Eventsource eventsource = mock(Eventsource.class); | ||
|
||
final Subscription subscription = subscription() | ||
.withName(name) | ||
.withEvent(event_1) | ||
.withEvent(event_2) | ||
.withEventsource(eventsource) | ||
.build(); | ||
|
||
assertThat(subscription.getName(), is(name)); | ||
assertThat(subscription.getEventsource(), is(eventsource)); | ||
assertThat(subscription.getEvents(), hasItem(event_1)); | ||
assertThat(subscription.getEvents(), hasItem(event_2)); | ||
} | ||
} |
Oops, something went wrong.