-
Notifications
You must be signed in to change notification settings - Fork 3
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
9 changed files
with
399 additions
and
35 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...mations/src/main/java/uk/gov/sample/event/transformation/SampleArchiveTransformation.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.sample.event.transformation; | ||
|
||
import static uk.gov.justice.tools.eventsourcing.transformation.api.TransformAction.ARCHIVE; | ||
import static uk.gov.justice.tools.eventsourcing.transformation.api.TransformAction.NO_ACTION; | ||
|
||
import uk.gov.justice.services.core.enveloper.Enveloper; | ||
import uk.gov.justice.services.messaging.JsonEnvelope; | ||
import uk.gov.justice.tools.eventsourcing.transformation.api.EventTransformation; | ||
import uk.gov.justice.tools.eventsourcing.transformation.api.TransformAction; | ||
import uk.gov.justice.tools.eventsourcing.transformation.api.annotation.Transformation; | ||
|
||
|
||
@Transformation | ||
public class SampleArchiveTransformation implements EventTransformation { | ||
|
||
@Override | ||
public TransformAction actionFor(final JsonEnvelope event) { | ||
if (event.metadata().name().equalsIgnoreCase("sample.archive.events.name")) { | ||
return ARCHIVE; | ||
} | ||
return NO_ACTION; | ||
} | ||
|
||
@Override | ||
public void setEnveloper(Enveloper enveloper) { | ||
// Unused by test | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...nsformations/src/main/java/uk/gov/sample/event/transformation/SampleTransformationV2.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,37 @@ | ||
package uk.gov.sample.event.transformation; | ||
|
||
import static uk.gov.justice.tools.eventsourcing.transformation.api.TransformAction.NO_ACTION; | ||
import static uk.gov.justice.tools.eventsourcing.transformation.api.TransformAction.TRANSFORM; | ||
|
||
import uk.gov.justice.services.core.enveloper.Enveloper; | ||
import uk.gov.justice.services.messaging.JsonEnvelope; | ||
import uk.gov.justice.tools.eventsourcing.transformation.api.EventTransformation; | ||
import uk.gov.justice.tools.eventsourcing.transformation.api.TransformAction; | ||
import uk.gov.justice.tools.eventsourcing.transformation.api.annotation.Transformation; | ||
|
||
import java.util.stream.Stream; | ||
|
||
@Transformation | ||
public class SampleTransformationV2 implements EventTransformation { | ||
|
||
private Enveloper enveloper; | ||
|
||
@Override | ||
public TransformAction actionFor(JsonEnvelope event) { | ||
if (event.metadata().name().equalsIgnoreCase("sample.v2.events.name")){ | ||
return TRANSFORM; | ||
} | ||
return NO_ACTION; | ||
} | ||
|
||
@Override | ||
public Stream<JsonEnvelope> apply(JsonEnvelope event) { | ||
final JsonEnvelope transformedEnvelope = enveloper.withMetadataFrom(event, "sample.events.transformedName").apply(event.payload()); | ||
return Stream.of(transformedEnvelope); | ||
} | ||
|
||
@Override | ||
public void setEnveloper(Enveloper enveloper) { | ||
this.enveloper = enveloper; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...ons/src/test/java/uk/gov/sample/event/transformation/SampleArchiveTransformationTest.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,63 @@ | ||
package uk.gov.sample.event.transformation; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static uk.gov.justice.tools.eventsourcing.transformation.api.TransformAction.ARCHIVE; | ||
import static uk.gov.justice.tools.eventsourcing.transformation.api.TransformAction.NO_ACTION; | ||
|
||
import uk.gov.justice.services.messaging.JsonEnvelope; | ||
import uk.gov.justice.services.messaging.Metadata; | ||
import uk.gov.justice.tools.eventsourcing.transformation.api.EventTransformation; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import org.apache.commons.lang3.builder.EqualsBuilder; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class SampleArchiveTransformationTest { | ||
|
||
private SampleArchiveTransformation sampleTransformation = new SampleArchiveTransformation(); | ||
|
||
@Test | ||
public void shouldCreateInstanceOfEventTransformation() { | ||
assertTrue(sampleTransformation instanceof EventTransformation); | ||
} | ||
|
||
@Test | ||
public void shouldSetArchiveAction() { | ||
JsonEnvelope event = mock(JsonEnvelope.class); | ||
Metadata metadata = mock(Metadata.class); | ||
|
||
when(event.metadata()).thenReturn(metadata); | ||
when(event.metadata().name()).thenReturn("sample.archive.events.name"); | ||
|
||
assertTrue(sampleTransformation.actionFor(event) == ARCHIVE); | ||
} | ||
|
||
@Test | ||
public void shouldSetNoAction() { | ||
JsonEnvelope event = mock(JsonEnvelope.class); | ||
Metadata metadata = mock(Metadata.class); | ||
|
||
when(event.metadata()).thenReturn(metadata); | ||
when(event.metadata().name()).thenReturn("dummy.archive.events.name"); | ||
assertTrue(sampleTransformation.actionFor(event) == NO_ACTION); | ||
} | ||
|
||
|
||
@Test | ||
public void shouldCreateArchive() { | ||
SampleArchiveTransformation sampleTransformation = mock(SampleArchiveTransformation.class); | ||
JsonEnvelope event = mock(JsonEnvelope.class); | ||
|
||
when(sampleTransformation.apply(event)).thenReturn(Stream.of(event)); | ||
|
||
assertTrue(EqualsBuilder.reflectionEquals(event, sampleTransformation.apply(event).findFirst().get())); | ||
} | ||
|
||
|
||
} |
64 changes: 64 additions & 0 deletions
64
...rmations/src/test/java/uk/gov/sample/event/transformation/SampleTransformationV2Test.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,64 @@ | ||
package uk.gov.sample.event.transformation; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static uk.gov.justice.tools.eventsourcing.transformation.api.TransformAction.NO_ACTION; | ||
import static uk.gov.justice.tools.eventsourcing.transformation.api.TransformAction.TRANSFORM; | ||
|
||
import uk.gov.justice.services.messaging.JsonEnvelope; | ||
import uk.gov.justice.services.messaging.Metadata; | ||
import uk.gov.justice.tools.eventsourcing.transformation.api.EventTransformation; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import org.apache.commons.lang3.builder.EqualsBuilder; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class SampleTransformationV2Test { | ||
|
||
private SampleTransformationV2 sampleTransformation = new SampleTransformationV2(); | ||
|
||
@Test | ||
public void shouldCreateInstanceOfEventTransformation() { | ||
assertTrue(sampleTransformation instanceof EventTransformation); | ||
} | ||
|
||
@Test | ||
public void shouldSetTransformAction() { | ||
JsonEnvelope event = mock(JsonEnvelope.class); | ||
Metadata metadata = mock(Metadata.class); | ||
|
||
when(event.metadata()).thenReturn(metadata); | ||
when(event.metadata().name()).thenReturn("sample.v2.events.name"); | ||
|
||
assertTrue(sampleTransformation.actionFor(event)== TRANSFORM); | ||
} | ||
|
||
@Test | ||
public void shouldSetNoAction() { | ||
JsonEnvelope event = mock(JsonEnvelope.class); | ||
Metadata metadata = mock(Metadata.class); | ||
|
||
when(event.metadata()).thenReturn(metadata); | ||
when(event.metadata().name()).thenReturn("dummy.sample.v2.events.name"); | ||
|
||
assertTrue(sampleTransformation.actionFor(event) == NO_ACTION); | ||
} | ||
|
||
|
||
@Test | ||
public void shouldCreateTransformation() { | ||
SampleTransformation sampleTransformation = mock(SampleTransformation.class); | ||
JsonEnvelope event = mock(JsonEnvelope.class); | ||
|
||
when(sampleTransformation.apply(event)).thenReturn(Stream.of(event)); | ||
|
||
assertTrue(EqualsBuilder.reflectionEquals(event, sampleTransformation.apply(event).findFirst().get())); | ||
} | ||
|
||
|
||
} |
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
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
7 changes: 7 additions & 0 deletions
7
.../src/main/java/uk/gov/justice/tools/eventsourcing/transformation/api/TransformAction.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,7 @@ | ||
package uk.gov.justice.tools.eventsourcing.transformation.api; | ||
|
||
public enum TransformAction { | ||
TRANSFORM, | ||
ARCHIVE, | ||
NO_ACTION | ||
} |
Oops, something went wrong.