-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [PRMT-4462] Disabled HTML escaping. * [PRMT-4462] Added unit tests to verify that HTML is escaped. * [PRMT-4462] Unit test structure improvements, focusing on DRY code. * [PRMT-4462] Removed whitespace.
- Loading branch information
1 parent
7cc17fb
commit 5d86d89
Showing
7 changed files
with
107 additions
and
5 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
27 changes: 27 additions & 0 deletions
27
src/test/java/uk/nhs/prm/repo/re_registration/model/ActiveSuspensionsMessageTest.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.nhs.prm.repo.re_registration.model; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static uk.nhs.prm.repo.re_registration.utility.TestDataUtility.NHS_NUMBER; | ||
import static uk.nhs.prm.repo.re_registration.utility.TestDataUtility.UNESCAPED_HTML; | ||
import static uk.nhs.prm.repo.re_registration.utility.TestDataUtility.getRandomTimestamp; | ||
|
||
class ActiveSuspensionsMessageTest { | ||
@Test | ||
void Given_ActiveSuspensionsMessageContainingUnescapedHtml_When_ToJsonStringIsCalled_Then_ReturnValueShouldNotContainUnescapedHtml() { | ||
// Given | ||
final String timestamp = getRandomTimestamp(); | ||
final ActiveSuspensionsMessage activeSuspensionsMessage = new ActiveSuspensionsMessage( | ||
NHS_NUMBER, | ||
UNESCAPED_HTML, | ||
timestamp | ||
); | ||
|
||
// When | ||
final String json = activeSuspensionsMessage.toJsonString(); | ||
|
||
// Then | ||
assertFalse(json.contains(UNESCAPED_HTML)); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/test/java/uk/nhs/prm/repo/re_registration/model/AuditMessageTest.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,26 @@ | ||
package uk.nhs.prm.repo.re_registration.model; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static uk.nhs.prm.repo.re_registration.utility.TestDataUtility.UNESCAPED_HTML; | ||
|
||
class AuditMessageTest { | ||
@Test | ||
void Given_AuditMessageContainingUnescapedHtml_When_ToJsonStringIsCalled_Then_ReturnValueShouldNotContainUnescapedHtml() { | ||
// Given | ||
final String nemsMessageId = UUID.randomUUID().toString(); | ||
final AuditMessage auditMessage = new AuditMessage( | ||
nemsMessageId, | ||
UNESCAPED_HTML | ||
); | ||
|
||
// When | ||
final String json = auditMessage.toJsonString(); | ||
|
||
// Then | ||
assertFalse(json.contains(UNESCAPED_HTML)); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/java/uk/nhs/prm/repo/re_registration/model/ReRegistrationEventTest.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.nhs.prm.repo.re_registration.model; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static uk.nhs.prm.repo.re_registration.utility.TestDataUtility.NHS_NUMBER; | ||
import static uk.nhs.prm.repo.re_registration.utility.TestDataUtility.UNESCAPED_HTML; | ||
import static uk.nhs.prm.repo.re_registration.utility.TestDataUtility.getRandomOdsCode; | ||
import static uk.nhs.prm.repo.re_registration.utility.TestDataUtility.getRandomTimestamp; | ||
|
||
class ReRegistrationEventTest { | ||
@Test | ||
void Given_ReRegistrationEventContainingUnescapedHtml_When_ToJsonStringIsCalled_Then_ReturnValueShouldNotContainUnescapedHtml() { | ||
// Given | ||
final String timestamp = getRandomTimestamp(); | ||
final String odsCode = getRandomOdsCode(); | ||
final ReRegistrationEvent reRegistrationEvent = new ReRegistrationEvent( | ||
NHS_NUMBER, | ||
odsCode, | ||
UNESCAPED_HTML, | ||
timestamp | ||
); | ||
|
||
// When | ||
final String json = reRegistrationEvent.toJsonString(); | ||
|
||
// Then | ||
assertFalse(json.contains(UNESCAPED_HTML)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/uk/nhs/prm/repo/re_registration/utility/TestDataUtility.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,21 @@ | ||
package uk.nhs.prm.repo.re_registration.utility; | ||
|
||
|
||
import org.joda.time.DateTime; | ||
import wiremock.org.apache.commons.lang3.RandomStringUtils; | ||
|
||
public final class TestDataUtility { | ||
public static String UNESCAPED_HTML = "<!DOCTYPE html><html lang='en'><head></head><body></body></html>"; | ||
|
||
public static String NHS_NUMBER = "9745812541"; | ||
|
||
public static String getRandomTimestamp() { | ||
return DateTime.now().toDateTimeISO().toString(); | ||
} | ||
|
||
public static String getRandomOdsCode() { | ||
return RandomStringUtils.randomAlphanumeric(6); | ||
} | ||
|
||
private TestDataUtility() { } | ||
} |