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

Dmp 2949 dar notify response maps to success #382

Merged
merged 5 commits into from
Apr 25, 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.hmcts.darts.event.controller;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
Expand Down Expand Up @@ -48,6 +49,10 @@ class DarNotifyControllerTest {
@Autowired
private DarPcStub darPcStub;

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

@Test
void shouldSendDarNotifyEventSoapAction() throws Exception {
jackmaloney marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -61,4 +66,16 @@ void shouldSendDarNotifyEventSoapAction() throws Exception {
darPcStub.verifyNotificationReceivedWithBody(EXPECTED_DAR_PC_NOTIFICATION);
}

@Test
void shouldHandleDarNotifyMalformedErrorResponse() throws Exception {
darPcStub.respondWithMalformedResponse();

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

darPcStub.verifyNotificationReceivedWithBody(EXPECTED_DAR_PC_NOTIFICATION);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.hmcts.darts.utils;

import com.github.tomakehurst.wiremock.client.WireMock;
import org.springframework.stereotype.Component;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
Expand All @@ -18,13 +19,22 @@ public class DarPcStub {
private static final String DAR_PC_SUCCESS_RESPONSE = """
<?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>0</DARNotifyEventResult></DARNotifyEventResponse></soap:Body></soap:Envelope>""";
jackmaloney marked this conversation as resolved.
Show resolved Hide resolved

private static final String DAR_PC_MALFORMED_RESPONSE = """
<?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() {
stubFor(post(urlEqualTo(BASE_API_URL)).willReturn(
aResponse().withHeader("Content-Type", "text/xml")
.withBody(DAR_PC_SUCCESS_RESPONSE)));
}

public void respondWithMalformedResponse() {
stubFor(post(urlEqualTo(BASE_API_URL)).willReturn(
aResponse().withHeader("Content-Type", "text/xml")
.withBody(DAR_PC_MALFORMED_RESPONSE)));
}

public void verifyNotificationReceivedWithBody(String body) {
verify(exactly(1), postRequestedFor(urlEqualTo(BASE_API_URL))
.withRequestBody(equalToXml(body, true)));
Expand All @@ -33,4 +43,8 @@ public void verifyNotificationReceivedWithBody(String body) {
public void verifyNoNotificationReceived() {
verify(exactly(0), postRequestedFor(urlEqualTo(BASE_API_URL)));
}

public void reset() {
WireMock.reset();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("com.viqsoultions");
marshaller.setMarshallerProperties(Map.of("org.glassfish.jaxb.namespacePrefixMapper", new MyNsPrefixMapper()));
marshaller.setValidationEventHandler(new jakarta.xml.bind.helpers.DefaultValidationEventHandler());
Copy link
Contributor Author

@mario-paniccia mario-paniccia Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this, any unmarshalling error won't be thrown as an exception. Unmarshalling will silently fail instead and leave fields with unmarshalling issues to null

return marshaller;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ void returnsCorrectEnum() {
assertThat(findByResult(5))
.isEqualTo(OTHER_ERROR)
.hasFieldOrPropertyWithValue("message", "Other error");

}

@Test
void returnsNullForUnknownResult() {
assertThat(findByResult(16))
.isNull();
}

}