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

PRMT-4356 #53

Merged
merged 9 commits into from
Jan 15, 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
8 changes: 7 additions & 1 deletion .github/workflows/submit-dependency-graph.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Submit dependency graph
on:
push:
pull_request:
types: [closed]
branches: [main]

permissions:
contents: write
Expand All @@ -10,6 +12,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: '21'
- name: Setup Gradle to generate and submit dependency graphs
uses: gradle/gradle-build-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:11.0.17_8-jre-alpine
FROM eclipse-temurin:21.0.1_12-jre-alpine

RUN apk add --no-cache bash

Expand Down
2 changes: 1 addition & 1 deletion Dojofile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DOJO_DOCKER_IMAGE="nhsdev/openjdk-dojo:d186138d2093aeb801dcf7a331b5fda82082584d"
DOJO_DOCKER_IMAGE="nhsdev/openjdk-dojo:d802c6970c76fe02798b24e07a2084f5d434bcda"
2 changes: 1 addition & 1 deletion Dojofile-itest
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
DOJO_DOCKER_IMAGE="nhsdev/openjdk-dojo:d186138d2093aeb801dcf7a331b5fda82082584d"
DOJO_DOCKER_IMAGE="nhsdev/openjdk-dojo:d802c6970c76fe02798b24e07a2084f5d434bcda"
DOJO_DRIVER=docker-compose
DOJO_DOCKER_COMPOSE_FILE=docker-compose.yaml
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.springframework.boot' version '2.7.18'
id 'org.springframework.boot' version '3.2.1'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'jacoco'
Expand All @@ -9,7 +9,7 @@ plugins {

group = 'uk.nhs.prm.repo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
sourceCompatibility = '21'

configurations {
compileOnly {
Expand Down Expand Up @@ -70,7 +70,7 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-test'

testImplementation "org.mockito:mockito-core:3.+"
testImplementation 'com.github.tomakehurst:wiremock-jre8:2.35.1'
testImplementation 'com.github.tomakehurst:wiremock-standalone:3.0.1'
testImplementation 'org.awaitility:awaitility:4.2.0'
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.amazonaws.services.sqs.model.PurgeQueueRequest;
import com.amazonaws.services.sqs.model.ReceiveMessageRequest;
import com.github.tomakehurst.wiremock.WireMockServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -26,7 +28,12 @@
import java.util.List;
import java.util.concurrent.TimeUnit;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.delete;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.matching;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

Expand All @@ -37,6 +44,7 @@
@DirtiesContext
public class DeleteEhrIntegrationTest {

private static final Logger LOGGER = LogManager.getLogger(DeleteEhrIntegrationTest.class);
public static final String NHS_NUMBER = "9999567890";

@Autowired
Expand Down Expand Up @@ -80,16 +88,15 @@ private WireMockServer initializeWebServer() {
return wireMockServer;
}


@Test
void shouldPutTheEHRDeleteAuditMessageOntoTheAuditQueueWhenActiveSuspensionExistsInDBAndPDSReturnsAStatusCode200() {
activeSuspensionsDb.save(getActiveSuspensionsMessage());

sqs.sendMessage(reRegistrationsQueueUrl,getReRegistrationEvent().toJsonString());
sqs.sendMessage(reRegistrationsQueueUrl, getReRegistrationEvent().toJsonString());

await().atMost(20, TimeUnit.SECONDS).untilAsserted(()-> {
String messageBody = checkMessageInRelatedQueue(reRegistrationsAuditUrl).get(0).getBody();
System.out.println("Found message - " + messageBody);

assertThat(messageBody).contains("\"status\":\"ACTION:RE_REGISTRATION_EHR_DELETED\"");
assertThat(messageBody).contains("\"nemsMessageId\":\"someNemsId\"");
assertThat(messageBody).contains("\"conversationIds\":[\"2431d4ff-f760-4ab9-8cd8-a3fc47846762\",\"c184cc19-86e9-4a95-b5b5-2f156900bb3c\"]");
Expand All @@ -110,7 +117,7 @@ void shouldPutTheUnknownReRegistrationsAuditMessageOntoTheAuditQueueWhenActiveSu

private void stubResponses() {
setPds200SuccessState();
ehrRepo200Response();
ehrRepository200Response();
}

private void setPds200SuccessState() {
Expand All @@ -123,7 +130,7 @@ private void setPds200SuccessState() {
.withBody(getPdsResponseString().getBody())));
}

private void ehrRepo200Response() {
private void ehrRepository200Response() {
stubFor(delete(urlMatching("/patients/" + NHS_NUMBER))
.withHeader("Authorization", matching(authKey))
.willReturn(aResponse()
Expand All @@ -136,27 +143,30 @@ private void ehrRepo200Response() {
.withHeader("Content-Type", "application/json")));
}


private ReRegistrationEvent getReRegistrationEvent() {
String nemsMessageId = "someNemsId";
return new ReRegistrationEvent(NHS_NUMBER, "ABC123", nemsMessageId, "2017-11-01T15:00:33+00:00");
}

private List<Message> checkMessageInRelatedQueue(String queueUrl) {
System.out.println("checking sqs queue: " + queueUrl);
LOGGER.info("Checking SQS Queue: {}", queueUrl);

var requestForMessagesWithAttributes
= new ReceiveMessageRequest().withQueueUrl(queueUrl)
ReceiveMessageRequest requestForMessagesWithAttributes = new ReceiveMessageRequest()
.withQueueUrl(queueUrl)
.withMessageAttributeNames("traceId");
List<Message> messages = sqs.receiveMessage(requestForMessagesWithAttributes).getMessages();
System.out.printf("Found %s messages on queue: %s%n", messages.size(), queueUrl);

final List<Message> messages = sqs
.receiveMessage(requestForMessagesWithAttributes)
.getMessages();

LOGGER.info("Found {} messages on queue: {}", messages.size(), queueUrl);
assertThat(messages).hasSize(1);
return messages;
}

private ResponseEntity<String> getPdsResponseString() {
var pdsResponseString = "{\"nhsNumber\":\"" + NHS_NUMBER + "\",\"isSuspended\":false,\"currentOdsCode\":\"currentOdsCode\",\"managingOrganisation\":\"managingOrganisation\",\"recordETag\":\"etag\",\"isDeceased\":false}";
return new ResponseEntity<>(pdsResponseString, HttpStatus.OK);
String pdsAdaptorResponseString = "{\"nhsNumber\":\"" + NHS_NUMBER + "\",\"isSuspended\":false,\"currentOdsCode\":\"currentOdsCode\",\"managingOrganisation\":\"managingOrganisation\",\"recordETag\":\"etag\",\"isDeceased\":false}";
return new ResponseEntity<>(pdsAdaptorResponseString, HttpStatus.OK);
}

private ActiveSuspensionsMessage getActiveSuspensionsMessage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.amazonaws.services.sqs.model.CreateQueueRequest;
import com.amazonaws.services.sqs.model.GetQueueAttributesResult;
import com.amazonaws.services.sqs.model.QueueDoesNotExistException;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.TestConfiguration;
Expand All @@ -32,7 +33,6 @@
import software.amazon.awssdk.services.sns.model.SubscribeRequest;
import software.amazon.awssdk.services.sqs.SqsClient;

import javax.annotation.PostConstruct;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
Expand Down
Loading