Skip to content

Commit

Permalink
Allow whitespace differences when comparing expected and actual XML (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianclay authored Dec 3, 2024
1 parent 23e4676 commit c1674a6
Showing 1 changed file with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
import uk.nhs.adaptors.gp2gp.ehr.utils.BloodPressureValidator;
import uk.nhs.adaptors.gp2gp.utils.ResourceTestFileUtils;

import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -110,46 +110,49 @@ public void tearDown() {
@ParameterizedTest
@MethodSource("testArgs")
public void When_TransformingResourceToEhrComp_Expect_CorrectValuesToBeExtracted(String stubEhrComponentMapperXml, String inputBundle,
String output) throws IOException {
String output) {
setupMock(ResourceTestFileUtils.getFileContent(stubEhrComponentMapperXml));
String bundle = ResourceTestFileUtils.getFileContent(inputBundle);
String expectedOutput = ResourceTestFileUtils.getFileContent(output);
Bundle parsedBundle = fhirParseService.parseResource(bundle, Bundle.class);

var translatedOutput = nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(parsedBundle).get(0);
assertThat(translatedOutput).isEqualTo(expectedOutput);
assertThat(translatedOutput).isEqualToIgnoringWhitespace(expectedOutput);
}

@ParameterizedTest
@MethodSource("endedAllergiesArgs")
public void When_TransformingEndedAllergyListToEhrComp_Expect_CorrectValuesToBeExtracted(String inputBundle, String output)
throws IOException {
public void When_TransformingEndedAllergyListToEhrComp_Expect_CorrectValuesToBeExtracted(String inputBundle, String output) {
setupMock(ResourceTestFileUtils.getFileContent(ALLERGY_INTOLERANCE_XML));
String bundle = ResourceTestFileUtils.getFileContent(inputBundle);
String expectedOutput = ResourceTestFileUtils.getFileContent(output);
Bundle parsedBundle = fhirParseService.parseResource(bundle, Bundle.class);

var translatedOutput = nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(parsedBundle);
assertThat(translatedOutput.size()).isEqualTo(2);
assertThat(translatedOutput.get(0)).isEqualTo(expectedOutput);
assertThat(translatedOutput.get(1)).isEqualTo(expectedOutput);
assertAll(
() -> assertThat(translatedOutput.size()).isEqualTo(2),
() -> assertThat(translatedOutput.get(0)).isEqualToIgnoringWhitespace(expectedOutput),
() -> assertThat(translatedOutput.get(1)).isEqualToIgnoringWhitespace(expectedOutput)
);
}

@Test
public void When_TransformingContainedResourceToEhrComp_WithSupportedComponent_Expect_CorrectValuesExtracted() throws IOException {
public void When_TransformingContainedResourceToEhrComp_WithSupportedComponent_Expect_CorrectValuesExtracted() {
setupMock(ResourceTestFileUtils.getFileContent(OBSERVATION_STATEMENT_XML));
String bundle = ResourceTestFileUtils.getFileContent(CONTAINED_MISCELLANEOUS_RECORDS_BUNDLE);
String expectedOutput = ResourceTestFileUtils.getFileContent(EXPECTED_MISCELLANEOUS_RECORDS_OUTPUT);
Bundle parsedBundle = fhirParseService.parseResource(bundle, Bundle.class);

List<String> translatedOutput = nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(parsedBundle);

assertThat(translatedOutput.size()).isOne();
assertThat(translatedOutput.get(0)).isEqualToIgnoringWhitespace(expectedOutput);
assertAll(
() -> assertThat(translatedOutput.size()).isOne(),
() -> assertThat(translatedOutput.get(0)).isEqualToIgnoringWhitespace(expectedOutput)
);
}

@Test
public void When_TransformingContainedResourceToEhrComp_WithUnsupportedComponent_Expect_ComponentNotMapped() throws IOException {
public void When_TransformingContainedResourceToEhrComp_WithUnsupportedComponent_Expect_ComponentNotMapped() {
nonConsultationResourceMapper = new NonConsultationResourceMapper(
messageContext,
randomIdGeneratorService,
Expand All @@ -166,22 +169,22 @@ public void When_TransformingContainedResourceToEhrComp_WithUnsupportedComponent

List<String> translatedOutput = nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(parsedBundle);

assertThat(translatedOutput.isEmpty()).isTrue();
assertThat(translatedOutput).isEmpty();

}

@Test
public void When_TransformingResourceToEhrComp_Expect_IgnoredResourceToBeIgnored() throws IOException {
public void When_TransformingResourceToEhrComp_Expect_IgnoredResourceToBeIgnored() {
setupMock(ResourceTestFileUtils.getFileContent("")); // empty filePath provided as this isn't expected to return anything
String bundle = ResourceTestFileUtils.getFileContent(UNCATAGORISED_IGNORED_RESOURCE_BUNDLE);
Bundle parsedBundle = fhirParseService.parseResource(bundle, Bundle.class);

var translatedOutput = nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(parsedBundle);
assertThat(translatedOutput.isEmpty()).isTrue();
assertThat(translatedOutput).isEmpty();
}

@Test
public void When_TransformingResourcesToEhrComp_Expect_ObservationToBeProcessedLast() throws IOException {
public void When_TransformingResourcesToEhrComp_Expect_ObservationToBeProcessedLast() {
// ARRANGE
setupMock("<MappedResourceStub/>");
String bundle = ResourceTestFileUtils.getFileContent(DIAGNOSTIC_REPORT_AFTER_OBSERVATION_BUNDLE);
Expand Down

0 comments on commit c1674a6

Please sign in to comment.