Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the process of fixing the integration tests a lot easier #526

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions gp2gp-translator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@ communication with the incumbent system via MHS Adaptor and data cleanup.
```

### How to run integration tests:
*Integration tests require running database and queue. Make sure GP2GP Translator application is off,
because if it's not, it will steal the message from the MHS Queue before the application started by tests have a chance to grab it.*

Integration tests require running database and queue.
Make sure GP2GP Translator application is off, because if it's not, it will steal the message from the `inbound` queue
before the application started by tests have a chance to grab it.

Running tests form the terminal:
```shell script
./gradlew integrationTest
```

You can also run tests from IntelliJ, just remember to set the database password
inside the `gp2gp-translator/src/integrationTest/resources/application.yml` file (or set GP2GP_TRANSLATOR_USER_DB_PASSWORD variable).

If your get lots of integration tests failures within the fixtures you can set the `BaseEhrHandler.OVERWRITE_EXPECTED_JSON`
to `true` to regenerate them.
Once regenerated, review the changes made using `git diff` or similar.

## Troubleshooting

### gradle-wrapper.jar doesn't exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
@AutoConfigureMockMvc
public class E2EMappingIT extends BaseEhrHandler {

private static final boolean OVERWRITE_EXPECTED_JSON = false;
private static final String PSS_ADAPTOR_URL = "https://PSSAdaptor/";
private static final String EBXML_PART_PATH = "/xml/RCMR_IN030000UK06/ebxml_part.xml";
//these are programming language special characters, not to be confused with line endings
Expand Down Expand Up @@ -316,7 +315,7 @@ protected void verifyBundle(String path, List<String> ignoredFields) throws JSON
var odsCodeToBeReplaced = getOdsToBeReplaced(expectedBundle);

if (OVERWRITE_EXPECTED_JSON) {
overwriteExpectJson(patientMigrationRequest.getBundleResource());
overwriteExpectJson(path, patientMigrationRequest.getBundleResource());
}

var bundle = fhirParserService.parseResource(patientMigrationRequest.getBundleResource(), Bundle.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static uk.nhs.adaptors.common.util.FileUtil.readResourceAsString;
import static uk.nhs.adaptors.common.enums.MigrationStatus.EHR_EXTRACT_REQUEST_ACCEPTED;
import static uk.nhs.adaptors.common.enums.MigrationStatus.MIGRATION_COMPLETED;
import static uk.nhs.adaptors.pss.util.BaseEhrHandler.OVERWRITE_EXPECTED_JSON;
import static uk.nhs.adaptors.pss.util.JsonPathIgnoreGeneratorUtil.generateJsonPathIgnores;

import java.io.PrintWriter;
Expand Down Expand Up @@ -49,7 +50,6 @@
@AutoConfigureMockMvc
public class EhrExtractHandlingIT {

private static final boolean OVERWRITE_EXPECTED_JSON = false;
private static final int NHS_NUMBER_MIN_MAX_LENGTH = 10;
private static final String EBXML_PART_PATH = "/xml/RCMR_IN030000UK06/ebxml_part.xml";
private static final String NHS_NUMBER_PLACEHOLDER = "{{nhsNumber}}";
Expand Down Expand Up @@ -173,7 +173,7 @@ private void verifyBundle(String path) throws JSONException {
var expectedBundle = readResourceAsString(path).replace(NHS_NUMBER_PLACEHOLDER, patientNhsNumber);

if (OVERWRITE_EXPECTED_JSON) {
overwriteExpectJson(patientMigrationRequest.getBundleResource());
overwriteExpectJson(path, patientMigrationRequest.getBundleResource());
}

var bundle = fhirParserService.parseResource(patientMigrationRequest.getBundleResource(), Bundle.class);
Expand All @@ -199,8 +199,8 @@ private void assertBundleContent(String actual, String expected, List<String> ig
}

@SneakyThrows
private void overwriteExpectJson(String newExpected) {
try (PrintWriter printWriter = new PrintWriter("src/integrationTest/resources/json/expectedBundle.json", StandardCharsets.UTF_8)) {
private void overwriteExpectJson(String path, String newExpected) {
try (PrintWriter printWriter = new PrintWriter("src/integrationTest/resources/" + path, StandardCharsets.UTF_8)) {
printWriter.print(newExpected);
}
fail("Re-run the tests with OVERWRITE_EXPECTED_JSON=false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

@Getter
public abstract class BaseEhrHandler {
private static final boolean OVERWRITE_EXPECTED_JSON = false;
public static final boolean OVERWRITE_EXPECTED_JSON = false;

private List<String> ignoredJsonPaths;
private static final int NHS_NUMBER_MIN_MAX_LENGTH = 10;
Expand Down Expand Up @@ -106,7 +106,7 @@ protected void verifyBundle(String path) throws JSONException {
var expectedBundle = readResourceAsString(path).replace(NHS_NUMBER_PLACEHOLDER, patientNhsNumber);

if (OVERWRITE_EXPECTED_JSON) {
overwriteExpectJson(patientMigrationRequest.getBundleResource());
overwriteExpectJson(path, patientMigrationRequest.getBundleResource());
}

var bundle = fhirParserService.parseResource(patientMigrationRequest.getBundleResource(), Bundle.class);
Expand All @@ -118,8 +118,8 @@ protected void verifyBundle(String path) throws JSONException {
}

@SneakyThrows
protected void overwriteExpectJson(String newExpected) {
try (PrintWriter printWriter = new PrintWriter("src/integrationTest/resources/json/expectedBundle.json", StandardCharsets.UTF_8)) {
protected void overwriteExpectJson(String path, String newExpected) {
try (PrintWriter printWriter = new PrintWriter("src/integrationTest/resources/" + path, StandardCharsets.UTF_8)) {
printWriter.print(newExpected);
}
fail("Re-run the tests with OVERWRITE_EXPECTED_JSON=false");
Expand Down
Loading