Skip to content

Commit

Permalink
DMP-4031: Capture DAR PC time in Notify response (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Edwards-cgi authored Nov 22, 2024
1 parent f11f0d4 commit f7e48d3
Show file tree
Hide file tree
Showing 19 changed files with 220 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import uk.gov.hmcts.darts.cache.token.config.impl.CachePropertiesImpl;
import uk.gov.hmcts.darts.cache.token.config.impl.SecurityPropertiesImpl;
import uk.gov.hmcts.darts.common.controllers.RootController;
import uk.gov.hmcts.darts.conf.ServiceTestConfiguration;
import uk.gov.hmcts.darts.config.CacheConfig;
import uk.gov.hmcts.darts.event.client.DarNotifyEventClient;
import uk.gov.hmcts.darts.event.config.DarNotifyEventConfiguration;
Expand All @@ -25,7 +26,9 @@
@WebMvcTest(RootController.class)
@Import({DarNotifyEventConfiguration.class, DarNotifyEventClient.class,
DarNotifyEventServiceImpl.class, CachePropertiesImpl.class, CacheConfig.class,
SecurityPropertiesImpl.class, TokenValidatorImpl.class, OauthTokenGenerator.class, RestTemplate.class})
SecurityPropertiesImpl.class, TokenValidatorImpl.class, OauthTokenGenerator.class, RestTemplate.class,
ServiceTestConfiguration.class
})
class GetWelcomeTest {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package uk.gov.hmcts.darts.conf;

import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;

import java.time.Clock;
import java.time.Instant;

@TestConfiguration
public class ServiceTestConfiguration {
@Bean
@Primary
public Clock clock() {
return Clock.fixed(Instant.now(), Clock.systemUTC().getZone());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import uk.gov.hmcts.darts.conf.ServiceTestConfiguration;
import uk.gov.hmcts.darts.testutils.stub.DarPcStub;

import java.time.Clock;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@AutoConfigureWireMock(port = 8090)
@SpringBootTest
@SpringBootTest(classes = ServiceTestConfiguration.class)
@ActiveProfiles({"int-test"})
@AutoConfigureMockMvc
class DarNotifyControllerTest {
Expand Down Expand Up @@ -48,22 +58,63 @@ class DarNotifyControllerTest {

@Autowired
private DarPcStub darPcStub;
@Autowired
private Clock clock;

@BeforeEach
void setup() {
darPcStub.reset();
}

@Test
void shouldSendDarNotifyEventSoapAction() throws Exception {
darPcStub.respondWithSuccessResponse();
@ExtendWith(OutputCaptureExtension.class)
void shouldSendDarNotifyEventSoapAction(CapturedOutput capturedOutput) throws Exception {
darPcStub.respondWithSuccessResponse(OffsetDateTime.now(clock));

mockMvc.perform(post("/events/dar-notify")
.contentType(APPLICATION_JSON_VALUE)
.content(VALID_NOTIFICATION_JSON))
.andExpect(status().is2xxSuccessful());

darPcStub.verifyNotificationReceivedWithBody(EXPECTED_DAR_PC_NOTIFICATION);
assertThat(capturedOutput)
.doesNotContain("Response time from DAR PC is outside max drift limits of");
}

@Test
@ExtendWith(OutputCaptureExtension.class)
void shouldSendDarNotifyEventSoapActionDarPcDateOutSideDriftLimitsRangeBehind(CapturedOutput capturedOutput) throws Exception {
OffsetDateTime responseDateTime = OffsetDateTime.now(clock).minusSeconds(90).truncatedTo(ChronoUnit.SECONDS);
darPcStub.respondWithSuccessResponse(responseDateTime);

mockMvc.perform(post("/events/dar-notify")
.contentType(APPLICATION_JSON_VALUE)
.content(VALID_NOTIFICATION_JSON))
.andExpect(status().is2xxSuccessful());

darPcStub.verifyNotificationReceivedWithBody(EXPECTED_DAR_PC_NOTIFICATION);
assertThat(capturedOutput)
.containsPattern("Response time from DAR PC is outside max drift limits of 1 minute 30 seconds. DAR PC Response time: "
+ responseDateTime.format(DateTimeFormatter.ISO_DATE_TIME)
+ ", Current time: [0-9\\-.T:]+Z for courthouse: York in courtroom: 1");
}

@Test
@ExtendWith(OutputCaptureExtension.class)
void shouldSendDarNotifyEventSoapActionDarPcDateOutSideDriftLimitsRangeAhead(CapturedOutput capturedOutput) throws Exception {
OffsetDateTime responseDateTime = OffsetDateTime.now(clock).plusMinutes(2).truncatedTo(ChronoUnit.SECONDS);
darPcStub.respondWithSuccessResponse(responseDateTime);

mockMvc.perform(post("/events/dar-notify")
.contentType(APPLICATION_JSON_VALUE)
.content(VALID_NOTIFICATION_JSON))
.andExpect(status().is2xxSuccessful());

darPcStub.verifyNotificationReceivedWithBody(EXPECTED_DAR_PC_NOTIFICATION);
assertThat(capturedOutput)
.containsPattern("Response time from DAR PC is outside max drift limits of 1 minute 30 seconds. DAR PC Response time: "
+ responseDateTime.format(DateTimeFormatter.ISO_DATE_TIME)
+ ", Current time: [0-9\\-.T:]+Z for courthouse: York in courtroom: 1");
}

@Test
Expand All @@ -77,5 +128,4 @@ void shouldHandleDarNotifyMalformedErrorResponse() throws Exception {

darPcStub.verifyNotificationReceivedWithBody(EXPECTED_DAR_PC_NOTIFICATION);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import uk.gov.hmcts.darts.testutils.stub.GetCourtLogsApiStub;
import uk.gov.hmcts.darts.testutils.stub.PostCourtLogsApiStub;
import uk.gov.hmcts.darts.testutils.stub.TokenStub;
import uk.gov.hmcts.darts.utilities.XmlParser;
import uk.gov.hmcts.darts.workflow.command.Command;
import uk.gov.hmcts.darts.workflow.command.CommandHolder;
import uk.gov.hmcts.darts.workflow.command.DeployRedisCommand;
Expand Down Expand Up @@ -77,9 +76,6 @@ public class IntegrationBase implements CommandHolder {
@Autowired
private Map<String, ContextRegistryClient> contextClients;

@Autowired
protected XmlParser parser;

private static String localhost;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.github.tomakehurst.wiremock.client.WireMock;
import org.springframework.stereotype.Component;

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalToXml;
import static com.github.tomakehurst.wiremock.client.WireMock.exactly;
Expand All @@ -23,9 +26,10 @@ public class DarPcStub {
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><DARNotifyEventResponse xmlns="http://www.VIQSoultions.com"><DARNotifyEventResult>1</DARNotifyEventResult></DARNotifyEventResponse></soap:Body></soap:Envelope>""";


public void respondWithSuccessResponse() {
public void respondWithSuccessResponse(OffsetDateTime responseDateTime) {
stubFor(post(urlEqualTo(BASE_API_URL)).willReturn(
aResponse().withHeader("Content-Type", "text/xml")
.withHeader("Date", responseDateTime.format(DateTimeFormatter.RFC_1123_DATE_TIME))
.withBody(DAR_PC_SUCCESS_RESPONSE)));
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/uk/gov/hmcts/darts/addaudio/AddAudioRoute.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
@RequiredArgsConstructor
@Slf4j
public class AddAudioRoute {
private final XmlParser xmlParser;
private final AudiosApi audiosClient;
private final AddAudioMapper addAudioMapper;
private final XmlWithFileMultiPartRequestHolder multiPartRequestHolder;
Expand All @@ -48,7 +47,7 @@ public DARTSResponse route(AddAudio addAudio) {
Audio addAudioLegacy;

try {
addAudioLegacy = xmlParser.unmarshal(audioXml, Audio.class);
addAudioLegacy = XmlParser.unmarshal(audioXml, Audio.class);

addAudioValidator.validate(addAudioLegacy);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class CasesRouteImpl implements CasesRoute {
@Value("${darts-gateway.addcase.validate}")
private boolean validateAddCase;
private final XmlValidator xmlValidator;
private final XmlParser xmlParser;
private final AddCaseMapper addCaseMapper;

private final CasesClient casesClient;
Expand All @@ -57,7 +56,7 @@ public DARTSResponse route(AddCase addCase) {
xmlValidator.validate(caseDocumentXmlStr, addCaseSchemaPath);
}

Case caseDocument = xmlParser.unmarshal(caseDocumentXmlStr, Case.class);
Case caseDocument = XmlParser.unmarshal(caseDocumentXmlStr, Case.class);
AddCaseRequest addCaseRequest = addCaseMapper.mapToDartsApi(caseDocument);

casesClient.casesPost(addCaseRequest);
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/uk/gov/hmcts/darts/config/ServiceConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import uk.gov.hmcts.darts.utilities.serializer.LocalDateTypeSerializer;
import uk.gov.hmcts.darts.utilities.serializer.OffsetDateTimeTypeSerializer;

import java.time.Clock;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
Expand Down Expand Up @@ -70,15 +71,20 @@ public static ObjectMapper getServiceObjectMapper() {
JavaTimeModule module = new JavaTimeModule();

module.addSerializer(LocalDateTime.class, new LocalDateTimeTypeSerializer())
.addSerializer(LocalDate.class, new LocalDateTypeSerializer())
.addSerializer(OffsetDateTime.class, new OffsetDateTimeTypeSerializer())
.addDeserializer(LocalDateTime.class, new LocalDateTimeTypeDeserializer())
.addDeserializer(LocalDate.class, new LocalDateTypeDeserializer())
.addDeserializer(OffsetDateTime.class, new OffsetDateTimeTypeDeserializer());
.addSerializer(LocalDate.class, new LocalDateTypeSerializer())
.addSerializer(OffsetDateTime.class, new OffsetDateTimeTypeSerializer())
.addDeserializer(LocalDateTime.class, new LocalDateTimeTypeDeserializer())
.addDeserializer(LocalDate.class, new LocalDateTypeDeserializer())
.addDeserializer(OffsetDateTime.class, new OffsetDateTimeTypeDeserializer());

return new ObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.registerModule(module);
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.registerModule(module);
}

@Bean
public Clock clock() {
return Clock.systemDefaultZone();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@
@Service
@Slf4j
public class AddCourtLogsRoute {

private final XmlParser xmlParser;
private final AddCourtLogsMapper mapper;
private final CourtLogsClient courtLogsClient;

public DARTSResponse route(String document) {

ResponseEntity<EventsResponse> response;

LogEntry logEntry = xmlParser.unmarshal(document, LogEntry.class);
LogEntry logEntry = XmlParser.unmarshal(document, LogEntry.class);
CourtLogsPostRequestBody postRequestBody = mapper.mapToApi(logEntry);

try {
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/uk/gov/hmcts/darts/dailylist/DailyListRoute.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
public class DailyListRoute {

private final DailyListsClient dailyListsClient;
private final XmlParser xmlParser;
private final DailyListRequestMapper dailyListRequestMapper;
private final XmlValidator xmlValidator;

Expand All @@ -58,15 +57,15 @@ public DARTSResponse handle(AddDocument addDocument, String type) {
}
}

DailyListStructure legacyDailyListObject = xmlParser.unmarshal(document.trim(), DailyListStructure.class);
DailyListStructure legacyDailyListObject = XmlParser.unmarshal(document.trim(), DailyListStructure.class);

DailyListJsonObject modernisedDailyList = dailyListRequestMapper.mapToEntity(legacyDailyListObject);

PostDailyListRequest postDailyListRequest = DailyListXmlRequestMapper.mapToPostDailyListRequest(
legacyDailyListObject,
document,
systemType.get().getModernisedSystemType(),
addDocument.getMessageId()
legacyDailyListObject,
document,
systemType.get().getModernisedSystemType(),
addDocument.getMessageId()
);

ResponseEntity<PostDailyListResponse> postDailyListResponse = dailyListsClient.dailylistsPost(
Expand Down
Loading

0 comments on commit f7e48d3

Please sign in to comment.