-
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.
GPE-2851 add feature to specify if a stream needs to be transformed, …
…deactivated aand backup to be retained
- Loading branch information
Deepak Halale
committed
Jun 21, 2018
1 parent
3dcfefd
commit fd41e6d
Showing
30 changed files
with
939 additions
and
421 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
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
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
52 changes: 52 additions & 0 deletions
52
.../src/main/java/uk/gov/sample/event/transformation/SampleCustomActionOnTransformation.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,52 @@ | ||
package uk.gov.sample.event.transformation; | ||
|
||
import static com.google.common.collect.Lists.newArrayList; | ||
import static uk.gov.justice.tools.eventsourcing.transformation.api.Action.DEACTIVATE; | ||
import static uk.gov.justice.tools.eventsourcing.transformation.api.Action.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.Action; | ||
import uk.gov.justice.tools.eventsourcing.transformation.api.EventTransformation; | ||
import uk.gov.justice.tools.eventsourcing.transformation.api.annotation.Transformation; | ||
|
||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
@Transformation | ||
public class SampleCustomActionOnTransformation implements EventTransformation { | ||
|
||
private static final List<String> EVENTS_TO_DEACTIVATE = newArrayList( | ||
"sample.event.to.deactivate", | ||
"sample.event2.to.deactivate" | ||
); | ||
|
||
private static final String EVENT_NAME_ENDS_WITH = ".archived.old.release"; | ||
|
||
private Enveloper enveloper; | ||
|
||
@Override | ||
public Stream<JsonEnvelope> apply(final JsonEnvelope event) { | ||
final String restoredEventName = event.metadata().name().replace(EVENT_NAME_ENDS_WITH, ""); | ||
|
||
final JsonEnvelope transformedEnvelope = enveloper.withMetadataFrom(event, restoredEventName).apply(event.payload()); | ||
return Stream.of(transformedEnvelope); | ||
} | ||
|
||
@Override | ||
public Action actionFor(final JsonEnvelope event) { | ||
if (EVENTS_TO_DEACTIVATE.contains(event.metadata().name().toLowerCase())) { | ||
return DEACTIVATE; | ||
} else if (event.metadata().name().toLowerCase().endsWith(EVENT_NAME_ENDS_WITH)) { | ||
return new Action(true, true, false); | ||
} | ||
|
||
return NO_ACTION; | ||
} | ||
|
||
@Override | ||
public void setEnveloper(final Enveloper enveloper) { | ||
this.enveloper = enveloper; | ||
} | ||
|
||
} |
14 changes: 7 additions & 7 deletions
14
...ormation/SampleArchiveTransformation.java → ...ation/SampleDeactivateTransformation.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
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
63 changes: 0 additions & 63 deletions
63
...ons/src/test/java/uk/gov/sample/event/transformation/SampleArchiveTransformationTest.java
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
.../test/java/uk/gov/sample/event/transformation/SampleCustomActionOnTransformationTest.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,83 @@ | ||
package uk.gov.sample.event.transformation; | ||
|
||
import static java.util.UUID.randomUUID; | ||
import static java.util.stream.Collectors.toList; | ||
import static javax.json.Json.createObjectBuilder; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.collection.IsCollectionWithSize.hasSize; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.hamcrest.core.IsInstanceOf.instanceOf; | ||
import static uk.gov.justice.services.messaging.JsonEnvelope.envelopeFrom; | ||
import static uk.gov.justice.services.messaging.spi.DefaultJsonMetadata.metadataBuilder; | ||
import static uk.gov.justice.services.test.utils.core.enveloper.EnveloperFactory.createEnveloper; | ||
import static uk.gov.justice.tools.eventsourcing.transformation.api.Action.DEACTIVATE; | ||
import static uk.gov.justice.tools.eventsourcing.transformation.api.Action.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.Action; | ||
import uk.gov.justice.tools.eventsourcing.transformation.api.EventTransformation; | ||
|
||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class SampleCustomActionOnTransformationTest { | ||
|
||
private SampleCustomActionOnTransformation underTest = new SampleCustomActionOnTransformation(); | ||
|
||
private Enveloper enveloper = createEnveloper(); | ||
|
||
@Before | ||
public void setup() { | ||
underTest.setEnveloper(enveloper); | ||
} | ||
|
||
@Test | ||
public void shouldCreateInstanceOfEventTransformation() { | ||
assertThat(underTest, is(instanceOf(EventTransformation.class))); | ||
} | ||
|
||
@Test | ||
public void shouldSetCustomActionForEventsThatMatch() { | ||
final JsonEnvelope event = buildEnvelope("sample.event.name.archived.old.release"); | ||
|
||
assertThat(underTest.actionFor(event), is(new Action(true, true, false))); | ||
} | ||
|
||
@Test | ||
public void shouldSetDeactivateActionForEventsThatMatch() { | ||
final JsonEnvelope event = buildEnvelope("sample.event.to.deactivate"); | ||
|
||
assertThat(underTest.actionFor(event), is(DEACTIVATE)); | ||
} | ||
|
||
@Test | ||
public void shouldSetNoActionForEventsThatDoNotMatch() { | ||
final JsonEnvelope event = buildEnvelope("dummy.sample.event.name"); | ||
|
||
assertThat(underTest.actionFor(event), is(NO_ACTION)); | ||
} | ||
|
||
@Test | ||
public void shouldCreateTransformation() { | ||
final JsonEnvelope event = buildEnvelope("sample.event.name.archived.old.release"); | ||
|
||
final Stream<JsonEnvelope> transformedStream = underTest.apply(event); | ||
|
||
final List<JsonEnvelope> transformedEvents = transformedStream.collect(toList()); | ||
assertThat(transformedEvents, hasSize(1)); | ||
assertThat(transformedEvents.get(0).metadata().name(), is("sample.event.name")); | ||
assertThat(transformedEvents.get(0).payloadAsJsonObject().getString("field"), | ||
is(event.payloadAsJsonObject().getString("field"))); | ||
} | ||
|
||
private JsonEnvelope buildEnvelope(final String eventName) { | ||
return envelopeFrom( | ||
metadataBuilder().withId(randomUUID()).withName(eventName), | ||
createObjectBuilder().add("field", "value").build()); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
.../src/test/java/uk/gov/sample/event/transformation/SampleDeactivateTransformationTest.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,47 @@ | ||
package uk.gov.sample.event.transformation; | ||
|
||
import static java.util.UUID.randomUUID; | ||
import static javax.json.Json.createObjectBuilder; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.hamcrest.core.IsInstanceOf.instanceOf; | ||
import static org.junit.Assert.assertThat; | ||
import static uk.gov.justice.services.messaging.JsonEnvelope.envelopeFrom; | ||
import static uk.gov.justice.services.messaging.spi.DefaultJsonMetadata.metadataBuilder; | ||
import static uk.gov.justice.tools.eventsourcing.transformation.api.Action.DEACTIVATE; | ||
import static uk.gov.justice.tools.eventsourcing.transformation.api.Action.NO_ACTION; | ||
|
||
import uk.gov.justice.services.messaging.JsonEnvelope; | ||
import uk.gov.justice.tools.eventsourcing.transformation.api.EventTransformation; | ||
|
||
import org.junit.Test; | ||
|
||
public class SampleDeactivateTransformationTest { | ||
|
||
private SampleDeactivateTransformation underTest = new SampleDeactivateTransformation(); | ||
|
||
@Test | ||
public void shouldCreateInstanceOfEventTransformation() { | ||
assertThat(underTest, instanceOf(EventTransformation.class)); | ||
} | ||
|
||
@Test | ||
public void shouldSetDeactivateAction() { | ||
final JsonEnvelope event = buildEnvelope("sample.deactivate.events.name"); | ||
|
||
assertThat(underTest.actionFor(event), is(DEACTIVATE)); | ||
} | ||
|
||
@Test | ||
public void shouldSetNoAction() { | ||
final JsonEnvelope event = buildEnvelope("dummy.deactivate.events.name"); | ||
|
||
assertThat(underTest.actionFor(event), is(NO_ACTION)); | ||
} | ||
|
||
private JsonEnvelope buildEnvelope(final String eventName) { | ||
return envelopeFrom( | ||
metadataBuilder().withId(randomUUID()).withName(eventName), | ||
createObjectBuilder().add("field", "value").build()); | ||
} | ||
|
||
} |
Oops, something went wrong.