Skip to content

Commit

Permalink
Fixing failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahesh Subramanian committed Oct 7, 2019
1 parent cca964f commit 5bd3833
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The stream-transformation-tool is a tool to support transformations of the event
* stream-transformation-tool-api - API exposing the externally facing components of the repository
* stream-transformation-fraction - Swarm fraction for bootstrapping the Swarm Application
* stream-transformation-service - The internal implementation of the transformation process
* stream-transformation-tool-anonymise - Java API to anonymise event data through transformation

# How to Build the Event-Tool

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static uk.gov.justice.tools.eventsourcing.anonymization.constants.StringPattern.EMAIL_PATTERN;
import static uk.gov.justice.tools.eventsourcing.anonymization.constants.StringPattern.NI_NUMBER_PATTERN;
import static uk.gov.justice.tools.eventsourcing.anonymization.util.FileUtil.getFileContentsAsString;
import static uk.gov.justice.tools.eventsourcing.anonymization.util.MatcherUtil.assertStringIsAnonymisedButOfLength;
import static uk.gov.justice.tools.eventsourcing.anonymization.util.MatcherUtil.assertStringIsAnonymisedButOfSameLength;

import java.io.StringReader;
Expand All @@ -29,7 +30,7 @@ public void shouldAnonymiseJsonObjectPayload() {
final JsonObject exampleObject = anonymisedPayload.getJsonObject("example");
assertThat(exampleObject.getString("attributeUUID"), is("9b42e998-158a-4683-8073-8e9453fe6cc9"));
assertThat(exampleObject.getString("attributeString"), is("Warwick Justice Centre")); // should not anonymise
assertStringIsAnonymisedButOfSameLength(exampleObject.getString("attributeStringEmail"), "test123@mail.com", of(EMAIL_PATTERN));
assertStringIsAnonymisedButOfLength(exampleObject.getString("attributeStringEmail"), "test123@mail.com", 14, of(EMAIL_PATTERN));
assertStringIsAnonymisedButOfSameLength(exampleObject.getString("attributeStringNiNumber"), "SC208978A", of(NI_NUMBER_PATTERN));
assertThat(exampleObject.getString("attributeDate"), is("2017-05-19"));
assertThat(exampleObject.getJsonArray("attributeArraySimple").getJsonObject(0).getString("arrayAttributeUUID"), is("1905c665-a146-4efc-a01b-d7f035820656"));
Expand All @@ -38,7 +39,7 @@ public void shouldAnonymiseJsonObjectPayload() {
assertThat(complexArray.getInt(1), is(1));
assertThat(complexArray.getBoolean(2), is(true));
assertThat(complexArray.getJsonObject(3).getString("arrayAttributeString"), is("abcdef"));
assertStringIsAnonymisedButOfSameLength(complexArray.getString(4), "test234@mail.com", of(EMAIL_PATTERN));
assertStringIsAnonymisedButOfLength(complexArray.getString(4), "test234@mail.com", 14, of(EMAIL_PATTERN));
assertStringIsAnonymisedButOfSameLength(complexArray.getString(5), "SC208979B", of(NI_NUMBER_PATTERN));

}
Expand Down Expand Up @@ -71,10 +72,10 @@ public void shouldAnonymiseJsonArrayPayload() {
assertThat(anonymisedJsonArray.getBoolean(2), is(true));
assertStringIsAnonymisedButOfSameLength(anonymisedJsonArray.getJsonObject(3).getString("stringAttributeAnonymise"), "abcdef");
assertThat(anonymisedJsonArray.getJsonObject(3).getString("stringAttributeDoNotAnonymise"), is("mnopqr"));
assertStringIsAnonymisedButOfSameLength(anonymisedJsonArray.getJsonObject(3).getString("attributeStringEmail"), "test123@mail.com", of(EMAIL_PATTERN));
assertStringIsAnonymisedButOfLength(anonymisedJsonArray.getJsonObject(3).getString("attributeStringEmail"), "test123@mail.com", 14, of(EMAIL_PATTERN));
assertStringIsAnonymisedButOfSameLength(anonymisedJsonArray.getJsonObject(3).getString("attributeStringNiNumber"), "SC208978A", of(NI_NUMBER_PATTERN));
assertThat(anonymisedJsonArray.getJsonArray(4), is(createArrayBuilder().add(1).add(2).add(3).build()));
assertStringIsAnonymisedButOfSameLength(anonymisedJsonArray.getString(5), "test2345@mail.com", of(EMAIL_PATTERN));
assertStringIsAnonymisedButOfLength(anonymisedJsonArray.getString(5), "test2345@mail.com", 14, of(EMAIL_PATTERN));
assertStringIsAnonymisedButOfSameLength(anonymisedJsonArray.getString(6), "SC208979B", of(NI_NUMBER_PATTERN));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Optional;
import java.util.regex.Pattern;


public class MatcherUtil {

private MatcherUtil() {
Expand All @@ -24,4 +23,10 @@ public static void assertStringIsAnonymisedButOfSameLength(final String actualVa
assertThat(actualValue.length(), is(expectedValue.length()));
optionalPattern.ifPresent(op -> assertTrue(op.matcher(actualValue).matches()));
}
}

public static void assertStringIsAnonymisedButOfLength(final String actualValue, final String expectedValue, final int length, final Optional<Pattern> optionalPattern) {
assertFalse(actualValue.equalsIgnoreCase(expectedValue));
assertThat(actualValue.length(), is(length));
optionalPattern.ifPresent(op -> assertTrue(op.matcher(actualValue).matches()));
}
}

0 comments on commit 5bd3833

Please sign in to comment.