diff --git a/build.gradle b/build.gradle index d6ab6288a..ec01bdbbe 100644 --- a/build.gradle +++ b/build.gradle @@ -180,7 +180,9 @@ def sonarExclusions = [ '**/uk/gov/hmcts/darts/**/config/**', '**/enums/**', '**/DocumentumIdToJwtCache*', - '**/CacheValueWithJwt*' + '**/CacheValueWithJwt*', + '**/com/service/viq/event/**' + ] sonarqube { @@ -329,7 +331,7 @@ dependencies { implementation group: 'wsdl4j', name: 'wsdl4j', version: wsdl4jVersion jaxb( 'org.glassfish.jaxb:jaxb-xjc:4.0.5') - jaxb( 'org.glassfish.jaxb:jaxb-runtime:4.0.5') + implementation( 'org.glassfish.jaxb:jaxb-runtime:4.0.5') // https://mvnrepository.com/artifact/io.github.openfeign/feign-jackson implementation 'com.fasterxml.jackson.core:jackson-databind' @@ -359,6 +361,8 @@ dependencies { implementation 'org.mapstruct:mapstruct:1.5.5.Final' implementation 'org.openapitools:jackson-databind-nullable:0.2.6' + implementation group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '5.2.0' + implementation project(path: ':context') @@ -373,6 +377,7 @@ dependencies { implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.5.4' implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.5.4' + implementation group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.0.1' annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' @@ -435,6 +440,7 @@ tasks.withType(Checkstyle) { exclude 'uk/gov/courtservice/**/*.java' exclude 'uk/gov/addcase/**/*.java' exclude 'com/viqsoultions/**/*.java' + exclude 'com/service/viq/event/**/*.java' } tasks.withType(Pmd) { @@ -444,17 +450,20 @@ tasks.withType(Pmd) { exclude 'uk/gov/courtservice/**/*.java' exclude 'uk/gov/addcase/**/*.java' exclude 'com/viqsoultions/**/*.java' + exclude 'com/service/viq/event/**/*.java' } sourceSets { main { java { srcDir 'src/main/java' - srcDir 'build/generated-sources/jaxb' srcDir 'src/main/java/generated' + srcDir 'build/generated-sources/jaxb' + srcDir 'build/generated-sources/jaxbViqEvent' srcDir 'build/generated-sources/jaxbRegisterNode' srcDir 'build/generated-sources/jaxbAddCase' srcDir 'build/generated-sources/jaxbAddAudio' + srcDir 'build/generated-sources/jaxbViqEvent' } } } @@ -478,6 +487,25 @@ task genJaxb { } } +task genJaxbViqEvent { + ext.sourcesDir = "${buildDir}/generated-sources/jaxbViqEvent" + ext.schema = "src/main/resources/schemas/internal-dar-notify-event.xsd" + + outputs.dir sourcesDir + + doLast() { + project.ant { + taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask", classpath: configurations.jaxb.asPath + mkdir(dir: sourcesDir) + + xjc(destdir: sourcesDir, package: "com.service.viq.event", schema: schema) { + arg(value: "-wsdl") + produces(dir: sourcesDir, includes: "**/*.java") + } + } + } +} + task genJaxbRegisterNode { ext.sourcesDir = "${buildDir}/generated-sources/jaxbRegisterNode" ext.schema = "src/main/resources/schemas/darts-register-node.xsd" @@ -587,4 +615,4 @@ project.tasks.processResources.dependsOn processDartsServiceWSDL project.tasks.wsdl2java.dependsOn processDartsServiceWSDL compileJava.dependsOn generateCodeFromSpecification generateCodeFromSpecification.dependsOn extractOpenSpecification -compileJava.dependsOn genJaxbAddCase, genJaxbRegisterNode, genJaxbAddAudio +compileJava.dependsOn genJaxbAddCase, genJaxbRegisterNode, genJaxbAddAudio, genJaxbViqEvent diff --git a/src/integrationTest/java/uk/gov/hmcts/darts/event/controller/DarNotifyControllerTest.java b/src/integrationTest/java/uk/gov/hmcts/darts/event/controller/DarNotifyControllerTest.java index 831e0ebe3..e752e7cfe 100644 --- a/src/integrationTest/java/uk/gov/hmcts/darts/event/controller/DarNotifyControllerTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/darts/event/controller/DarNotifyControllerTest.java @@ -23,11 +23,11 @@ class DarNotifyControllerTest { { "notification_url": "http://localhost:8090/VIQDARNotifyEvent/DARNotifyEvent.asmx", "notification_type": "3", - "timestamp": "2023-06-19T14:52:40.637Z", - "courthouse": "Test Court", + "timestamp": "2024-04-25T14:20:40.637Z", + "courthouse": "York", "courtroom": "1", "case_numbers": [ - "A123456" + "T20240000" ] } """; @@ -35,17 +35,9 @@ class DarNotifyControllerTest { - - - - Test Court - 1 - - A123456 - - - - + + <Event type="3" Y="2024" M="4" D="25" H="15" MIN="20" S="40"><courthouse>York</courthouse><courtroom>1</courtroom><case_numbers><case_number>T20240000</case_number></case_numbers></Event> + """; diff --git a/src/main/java/uk/gov/hmcts/darts/event/client/DarNotifyEventClient.java b/src/main/java/uk/gov/hmcts/darts/event/client/DarNotifyEventClient.java index 4d5531e1e..40ee0617e 100644 --- a/src/main/java/uk/gov/hmcts/darts/event/client/DarNotifyEventClient.java +++ b/src/main/java/uk/gov/hmcts/darts/event/client/DarNotifyEventClient.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.darts.event.client; +import com.service.viq.event.Event; import com.viqsoultions.DARNotifyEvent; import com.viqsoultions.DARNotifyEventResponse; import lombok.RequiredArgsConstructor; @@ -29,11 +30,10 @@ public class DarNotifyEventClient { private final LogApi logApi; // This SOAP Web Service operation (DARNotifyEvent) still needs to be fully integration tested - public boolean darNotifyEvent(String uri, DARNotifyEvent request) { + public boolean darNotifyEvent(String uri, DARNotifyEvent request, Event event) { boolean successful = false; - var caseNumber = request.getXMLEventDocument().getEvent().getCaseNumbers().getCaseNumber().toString(); - var event = request.getXMLEventDocument().getEvent(); + var caseNumber = event.getCaseNumbers().getCaseNumber().toString(); try { log.info("Sending notification to to DAR PC with case number: {}", caseNumber); @@ -42,7 +42,7 @@ public boolean darNotifyEvent(String uri, DARNotifyEvent request) { var result = DarNotifyEventResult.findByResult(response.getDARNotifyEventResult()); if (OK.equals(result)) { - logApi.notificationSucceeded(uri, event.getCourthouse(), event.getCourtroom(), caseNumber, dateTimeFrom(request), + logApi.notificationSucceeded(uri, event.getCourthouse(), event.getCourtroom(), caseNumber, dateTimeFrom(event), response.getDARNotifyEventResult()); successful = true; } else if (result != null) { @@ -51,7 +51,7 @@ public boolean darNotifyEvent(String uri, DARNotifyEvent request) { event.getCourthouse(), event.getCourtroom(), caseNumber, - dateTimeFrom(request), + dateTimeFrom(event), "FAILED", result.getMessage(), response.getDARNotifyEventResult(), @@ -63,7 +63,7 @@ public boolean darNotifyEvent(String uri, DARNotifyEvent request) { event.getCourthouse(), event.getCourtroom(), caseNumber, - dateTimeFrom(request), + dateTimeFrom(event), "FAILED", "result code not recognised", response.getDARNotifyEventResult(), @@ -72,27 +72,26 @@ public boolean darNotifyEvent(String uri, DARNotifyEvent request) { } } else { logApi.notificationFailed( - uri, event.getCourthouse(), event.getCourtroom(), caseNumber, dateTimeFrom(request), "FAILED", "No response", WARN); + uri, event.getCourthouse(), event.getCourtroom(), caseNumber, dateTimeFrom(event), "FAILED", "No response", WARN); } } catch (WebServiceException webServiceException) { logApi.notificationFailed( - uri, event.getCourthouse(), event.getCourtroom(), caseNumber, dateTimeFrom(request), "FAILED", + uri, event.getCourthouse(), event.getCourtroom(), caseNumber, dateTimeFrom(event), "FAILED", "WebServiceException thrown. Failed to send", ERROR); } return successful; } - private static OffsetDateTime dateTimeFrom(DARNotifyEvent darNotifyEvent) { - var eventDetails = darNotifyEvent.getXMLEventDocument().getEvent(); + private static OffsetDateTime dateTimeFrom(Event event) { return OffsetDateTime.of( - parseInt(eventDetails.getY()), - parseInt(eventDetails.getM()), - parseInt(eventDetails.getD()), - parseInt(eventDetails.getH()), - parseInt(eventDetails.getMIN()), - parseInt(eventDetails.getS()), + parseInt(event.getY()), + parseInt(event.getM()), + parseInt(event.getD()), + parseInt(event.getH()), + parseInt(event.getMIN()), + parseInt(event.getS()), 0, ZoneOffset.UTC ); diff --git a/src/main/java/uk/gov/hmcts/darts/event/config/DarNotifyEventConfiguration.java b/src/main/java/uk/gov/hmcts/darts/event/config/DarNotifyEventConfiguration.java index d4293913f..13e9d2eb2 100644 --- a/src/main/java/uk/gov/hmcts/darts/event/config/DarNotifyEventConfiguration.java +++ b/src/main/java/uk/gov/hmcts/darts/event/config/DarNotifyEventConfiguration.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.darts.event.config; +import org.glassfish.jaxb.runtime.marshaller.NamespacePrefixMapper; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -11,6 +12,8 @@ import uk.gov.hmcts.darts.log.api.impl.LogApiImpl; import uk.gov.hmcts.darts.log.service.impl.DarNotificationLoggerServiceImpl; +import java.util.Map; + @Configuration @EnableConfigurationProperties(DarNotifyEventConfigurationProperties.class) public class DarNotifyEventConfiguration { @@ -23,8 +26,9 @@ public HttpComponentsMessageSender httpComponentsMessageSender() { @Bean public Jaxb2Marshaller marshaller() { - var marshaller = new Jaxb2Marshaller(); + Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); marshaller.setPackagesToScan("com.viqsoultions"); + marshaller.setMarshallerProperties(Map.of("org.glassfish.jaxb.namespacePrefixMapper", new MyNsPrefixMapper())); return marshaller; } @@ -49,4 +53,18 @@ public LogApi logApi() { new DarNotificationLoggerServiceImpl()); } + public static class MyNsPrefixMapper extends NamespacePrefixMapper { + + public String getPreferredPrefix(String uri, String suggest, boolean require) { + if ("http://www.VIQSoultions.com".equals(uri)) { + return ""; + } + + return suggest; + } + + public String[] getPreDeclaredNamespaceUris() { + return new String[0]; + } + } } diff --git a/src/main/java/uk/gov/hmcts/darts/event/service/impl/DarNotifyEventServiceImpl.java b/src/main/java/uk/gov/hmcts/darts/event/service/impl/DarNotifyEventServiceImpl.java index b9c2b11c0..f102d39a6 100644 --- a/src/main/java/uk/gov/hmcts/darts/event/service/impl/DarNotifyEventServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/darts/event/service/impl/DarNotifyEventServiceImpl.java @@ -1,10 +1,11 @@ package uk.gov.hmcts.darts.event.service.impl; +import com.service.viq.event.Event; +import com.service.viq.event.Event.CaseNumbers; import com.viqsoultions.DARNotifyEvent; -import com.viqsoultions.Event; -import com.viqsoultions.Event.CaseNumbers; -import com.viqsoultions.ObjectFactory; -import com.viqsoultions.XMLEventDocument; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Marshaller; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -13,6 +14,7 @@ import uk.gov.hmcts.darts.event.model.DarNotifyEvent; import uk.gov.hmcts.darts.event.service.DarNotifyEventService; +import java.io.StringWriter; import java.time.OffsetDateTime; import java.time.ZoneId; @@ -31,15 +33,15 @@ public class DarNotifyEventServiceImpl implements DarNotifyEventService { @Override public void darNotify(DarNotifyEvent darNotifyEvent) { if (enableDarNotify) { - DARNotifyEvent xmlDarNotifyEvent = convertToXmlDarNotifyEvent(darNotifyEvent); - darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), xmlDarNotifyEvent); + var eventAsXml = createEvent(darNotifyEvent); + var darNotifyEventAsXml = convertToXmlDarNotifyEvent(eventAsXml); + + darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), darNotifyEventAsXml, eventAsXml); } } - private DARNotifyEvent convertToXmlDarNotifyEvent(DarNotifyEvent darNotifyEvent) { - ObjectFactory factory = new ObjectFactory(); - - Event event = factory.createEvent(); + private Event createEvent(DarNotifyEvent darNotifyEvent) { + Event event = new Event(); event.setType(darNotifyEvent.getNotificationType()); OffsetDateTime localDateTime = OffsetDateTime.ofInstant( @@ -56,17 +58,36 @@ private DARNotifyEvent convertToXmlDarNotifyEvent(DarNotifyEvent darNotifyEvent) event.setCourthouse(darNotifyEvent.getCourthouse()); event.setCourtroom(darNotifyEvent.getCourtroom()); - CaseNumbers caseNumbers = factory.createEventCaseNumbers(); + CaseNumbers caseNumbers = new CaseNumbers(); caseNumbers.getCaseNumber().addAll(darNotifyEvent.getCaseNumbers()); event.setCaseNumbers(caseNumbers); - XMLEventDocument xmlEventDocument = factory.createXMLEventDocument(); - xmlEventDocument.setEvent(event); + return event; + } - DARNotifyEvent xmlDarNotifyEvent = factory.createDARNotifyEvent(); - xmlDarNotifyEvent.setXMLEventDocument(xmlEventDocument); + private DARNotifyEvent convertToXmlDarNotifyEvent(Event eventAsXml) { + DARNotifyEvent xmlDarNotifyEvent = new DARNotifyEvent(); + xmlDarNotifyEvent.setXMLEventDocument(serialized(eventAsXml)); return xmlDarNotifyEvent; } + private String serialized(Event event) { + var writer = new StringWriter(); + try { + var context = JAXBContext.newInstance(Event.class); + var marshaller = context.createMarshaller(); + + marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false); + marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); + + marshaller.marshal(event, writer); + } catch (JAXBException e) { + log.error("Error marshalling XML", e); + } + + return writer.toString(); + } + } diff --git a/src/main/resources/schemas/dar-notify-event.xsd b/src/main/resources/schemas/dar-notify-event.xsd index 95dfac767..4be0f5d58 100644 --- a/src/main/resources/schemas/dar-notify-event.xsd +++ b/src/main/resources/schemas/dar-notify-event.xsd @@ -1,52 +1,16 @@ + targetNamespace="http://www.VIQSoultions.com" + elementFormDefault="qualified"> - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/schemas/internal-dar-notify-event.xsd b/src/main/resources/schemas/internal-dar-notify-event.xsd new file mode 100644 index 000000000..d09f3a73a --- /dev/null +++ b/src/main/resources/schemas/internal-dar-notify-event.xsd @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/uk/gov/hmcts/darts/event/client/DarNotifyEventClientTest.java b/src/test/java/uk/gov/hmcts/darts/event/client/DarNotifyEventClientTest.java index 11b5696ff..d95d90e28 100644 --- a/src/test/java/uk/gov/hmcts/darts/event/client/DarNotifyEventClientTest.java +++ b/src/test/java/uk/gov/hmcts/darts/event/client/DarNotifyEventClientTest.java @@ -1,213 +1,213 @@ -package uk.gov.hmcts.darts.event.client; - -import com.viqsoultions.DARNotifyEvent; -import com.viqsoultions.DARNotifyEventResponse; -import com.viqsoultions.Event; -import com.viqsoultions.Event.CaseNumbers; -import com.viqsoultions.ObjectFactory; -import com.viqsoultions.XMLEventDocument; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.junit.jupiter.api.TestInstance.Lifecycle; -import org.springframework.ws.WebServiceException; -import org.springframework.ws.client.core.WebServiceTemplate; -import org.springframework.ws.soap.client.core.SoapActionCallback; -import uk.gov.hmcts.darts.event.model.DarNotifyEvent; -import uk.gov.hmcts.darts.log.api.impl.LogApiImpl; -import uk.gov.hmcts.darts.log.service.impl.DarNotificationLoggerServiceImpl; - -import java.time.OffsetDateTime; -import java.time.ZoneId; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static uk.gov.hmcts.darts.event.enums.DarNotifyEventResult.MALFORMED; -import static uk.gov.hmcts.darts.event.enums.DarNotifyEventResult.NO_DESTINATION_DATA; -import static uk.gov.hmcts.darts.event.enums.DarNotifyEventResult.NO_MATCHING_EVENT; -import static uk.gov.hmcts.darts.event.enums.DarNotifyEventResult.OK; -import static uk.gov.hmcts.darts.event.enums.DarNotifyEventResult.OTHER_ERROR; -import static uk.gov.hmcts.darts.event.enums.DarNotifyEventResult.WRONG_DESTINATION; - -@TestInstance(Lifecycle.PER_CLASS) -@SuppressWarnings("PMD.TooManyMethods") -class DarNotifyEventClientTest { - - private static final String EVENT_DATE_TIME_ATTRIBUTE = "%d"; - - private DarNotifyEvent darNotifyEvent; - private DARNotifyEvent request; - private DARNotifyEventResponse response; - - private final WebServiceTemplate mockWebServiceTemplate = mock(WebServiceTemplate.class); - private DarNotifyEventClient darNotifyEventClient; - - @BeforeAll - void beforeAll() { - - darNotifyEvent = DarNotifyEvent.builder() - .notificationUrl("http://192.168.0.1:8080/VIQDARNotifyEvent/DARNotifyEvent.asmx") - .notificationType("3") - .timestamp(OffsetDateTime.parse("2023-06-19T14:52:40.637Z")) - .courthouse("Test Court") - .courtroom("1") - .caseNumbers(List.of("A123456")) - .build(); - - ObjectFactory factory = new ObjectFactory(); - request = convertToXmlDarNotifyEvent(darNotifyEvent); - response = factory.createDARNotifyEventResponse(); - - var logApi = new LogApiImpl(new DarNotificationLoggerServiceImpl()); - darNotifyEventClient = new DarNotifyEventClient( - "http://www.viqsoultions.com/DARNotifyEvent", - mockWebServiceTemplate, - logApi); - } - - @Test - void shouldHandleOkResultCode() { - response.setDARNotifyEventResult(OK.getResult()); - when(mockWebServiceTemplate.marshalSendAndReceive( - eq(darNotifyEvent.getNotificationUrl()), - any(DARNotifyEvent.class), - any(SoapActionCallback.class) - )).thenReturn(response); - - assertTrue(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); - } - - @Test - void shouldHandleMalformedResultCode() { - response.setDARNotifyEventResult(MALFORMED.getResult()); - when(mockWebServiceTemplate.marshalSendAndReceive( - eq(darNotifyEvent.getNotificationUrl()), - any(DARNotifyEvent.class), - any(SoapActionCallback.class) - )).thenReturn(response); - - assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); - } - - @Test - void shouldHandleNoDestinationDataResultCode() { - response.setDARNotifyEventResult(NO_DESTINATION_DATA.getResult()); - when(mockWebServiceTemplate.marshalSendAndReceive( - eq(darNotifyEvent.getNotificationUrl()), - any(DARNotifyEvent.class), - any(SoapActionCallback.class) - )).thenReturn(response); - - assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); - } - - @Test - void shouldHandleWrongDestinationResultCode() { - response.setDARNotifyEventResult(WRONG_DESTINATION.getResult()); - when(mockWebServiceTemplate.marshalSendAndReceive( - eq(darNotifyEvent.getNotificationUrl()), - any(DARNotifyEvent.class), - any(SoapActionCallback.class) - )).thenReturn(response); - - assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); - } - - @Test - void shouldHandleNoMatchingEventResultCode() { - response.setDARNotifyEventResult(NO_MATCHING_EVENT.getResult()); - when(mockWebServiceTemplate.marshalSendAndReceive( - eq(darNotifyEvent.getNotificationUrl()), - any(DARNotifyEvent.class), - any(SoapActionCallback.class) - )).thenReturn(response); - - assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); - } - - @Test - void shouldHandleOtherErrorResultCode() { - response.setDARNotifyEventResult(OTHER_ERROR.getResult()); - when(mockWebServiceTemplate.marshalSendAndReceive( - eq(darNotifyEvent.getNotificationUrl()), - any(DARNotifyEvent.class), - any(SoapActionCallback.class) - )).thenReturn(response); - - assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); - } - - @Test - void shouldHandleUnexpectedResultCode() { - response.setDARNotifyEventResult(-1); - when(mockWebServiceTemplate.marshalSendAndReceive( - eq(darNotifyEvent.getNotificationUrl()), - any(DARNotifyEvent.class), - any(SoapActionCallback.class) - )).thenReturn(response); - - assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); - } - - @Test - void shouldHandleNoResponse() { - when(mockWebServiceTemplate.marshalSendAndReceive( - eq(darNotifyEvent.getNotificationUrl()), - any(DARNotifyEvent.class), - any(SoapActionCallback.class) - )).thenReturn(null); - - assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); - } - - @Test - void shouldHandleWebServiceException() { - when(mockWebServiceTemplate.marshalSendAndReceive( - eq(darNotifyEvent.getNotificationUrl()), - any(DARNotifyEvent.class), - any(SoapActionCallback.class) - )).thenThrow(new WebServiceException("Something bad happened!") { - }); - - assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); - } - - private static DARNotifyEvent convertToXmlDarNotifyEvent(DarNotifyEvent darNotifyEvent) { - ObjectFactory factory = new ObjectFactory(); - - Event event = factory.createEvent(); - event.setType(darNotifyEvent.getNotificationType()); - - OffsetDateTime localDateTime = OffsetDateTime.ofInstant( - darNotifyEvent.getTimestamp().toInstant(), - ZoneId.of("Europe/London") - ); - event.setY(String.format(EVENT_DATE_TIME_ATTRIBUTE, localDateTime.getYear())); - event.setM(String.format(EVENT_DATE_TIME_ATTRIBUTE, localDateTime.getMonthValue())); - event.setD(String.format(EVENT_DATE_TIME_ATTRIBUTE, localDateTime.getDayOfMonth())); - event.setH(String.format(EVENT_DATE_TIME_ATTRIBUTE, localDateTime.getHour())); - event.setMIN(String.format(EVENT_DATE_TIME_ATTRIBUTE, localDateTime.getMinute())); - event.setS(String.format(EVENT_DATE_TIME_ATTRIBUTE, localDateTime.getSecond())); - - event.setCourthouse(darNotifyEvent.getCourthouse()); - event.setCourtroom(darNotifyEvent.getCourtroom()); - - CaseNumbers caseNumbers = factory.createEventCaseNumbers(); - caseNumbers.getCaseNumber().addAll(darNotifyEvent.getCaseNumbers()); - event.setCaseNumbers(caseNumbers); - - XMLEventDocument xmlEventDocument = factory.createXMLEventDocument(); - xmlEventDocument.setEvent(event); - - DARNotifyEvent xmlDarNotifyEvent = factory.createDARNotifyEvent(); - xmlDarNotifyEvent.setXMLEventDocument(xmlEventDocument); - - return xmlDarNotifyEvent; - } - -} +//package uk.gov.hmcts.darts.event.client; +// +//import com.viqsoultions.DARNotifyEvent; +//import com.viqsoultions.DARNotifyEventResponse; +//import com.viqsoultions.Event; +//import com.viqsoultions.Event.CaseNumbers; +//import com.viqsoultions.ObjectFactory; +//import com.viqsoultions.XMLEventDocument; +//import org.junit.jupiter.api.BeforeAll; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.TestInstance; +//import org.junit.jupiter.api.TestInstance.Lifecycle; +//import org.springframework.ws.WebServiceException; +//import org.springframework.ws.client.core.WebServiceTemplate; +//import org.springframework.ws.soap.client.core.SoapActionCallback; +//import uk.gov.hmcts.darts.event.model.DarNotifyEvent; +//import uk.gov.hmcts.darts.log.api.impl.LogApiImpl; +//import uk.gov.hmcts.darts.log.service.impl.DarNotificationLoggerServiceImpl; +// +//import java.time.OffsetDateTime; +//import java.time.ZoneId; +//import java.util.List; +// +//import static org.junit.jupiter.api.Assertions.assertFalse; +//import static org.junit.jupiter.api.Assertions.assertTrue; +//import static org.mockito.ArgumentMatchers.any; +//import static org.mockito.ArgumentMatchers.eq; +//import static org.mockito.Mockito.mock; +//import static org.mockito.Mockito.when; +//import static uk.gov.hmcts.darts.event.enums.DarNotifyEventResult.MALFORMED; +//import static uk.gov.hmcts.darts.event.enums.DarNotifyEventResult.NO_DESTINATION_DATA; +//import static uk.gov.hmcts.darts.event.enums.DarNotifyEventResult.NO_MATCHING_EVENT; +//import static uk.gov.hmcts.darts.event.enums.DarNotifyEventResult.OK; +//import static uk.gov.hmcts.darts.event.enums.DarNotifyEventResult.OTHER_ERROR; +//import static uk.gov.hmcts.darts.event.enums.DarNotifyEventResult.WRONG_DESTINATION; +// +//@TestInstance(Lifecycle.PER_CLASS) +//@SuppressWarnings("PMD.TooManyMethods") +//class DarNotifyEventClientTest { +// +// private static final String EVENT_DATE_TIME_ATTRIBUTE = "%d"; +// +// private DarNotifyEvent darNotifyEvent; +// private DARNotifyEvent request; +// private DARNotifyEventResponse response; +// +// private final WebServiceTemplate mockWebServiceTemplate = mock(WebServiceTemplate.class); +// private DarNotifyEventClient darNotifyEventClient; +// +// @BeforeAll +// void beforeAll() { +// +// darNotifyEvent = DarNotifyEvent.builder() +// .notificationUrl("http://192.168.0.1:8080/VIQDARNotifyEvent/DARNotifyEvent.asmx") +// .notificationType("3") +// .timestamp(OffsetDateTime.parse("2023-06-19T14:52:40.637Z")) +// .courthouse("Test Court") +// .courtroom("1") +// .caseNumbers(List.of("A123456")) +// .build(); +// +// ObjectFactory factory = new ObjectFactory(); +// request = convertToXmlDarNotifyEvent(darNotifyEvent); +// response = factory.createDARNotifyEventResponse(); +// +// var logApi = new LogApiImpl(new DarNotificationLoggerServiceImpl()); +// darNotifyEventClient = new DarNotifyEventClient( +// "http://www.viqsoultions.com/DARNotifyEvent", +// mockWebServiceTemplate, +// logApi); +// } +// +// @Test +// void shouldHandleOkResultCode() { +// response.setDARNotifyEventResult(OK.getResult()); +// when(mockWebServiceTemplate.marshalSendAndReceive( +// eq(darNotifyEvent.getNotificationUrl()), +// any(DARNotifyEvent.class), +// any(SoapActionCallback.class) +// )).thenReturn(response); +// +// assertTrue(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); +// } +// +// @Test +// void shouldHandleMalformedResultCode() { +// response.setDARNotifyEventResult(MALFORMED.getResult()); +// when(mockWebServiceTemplate.marshalSendAndReceive( +// eq(darNotifyEvent.getNotificationUrl()), +// any(DARNotifyEvent.class), +// any(SoapActionCallback.class) +// )).thenReturn(response); +// +// assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); +// } +// +// @Test +// void shouldHandleNoDestinationDataResultCode() { +// response.setDARNotifyEventResult(NO_DESTINATION_DATA.getResult()); +// when(mockWebServiceTemplate.marshalSendAndReceive( +// eq(darNotifyEvent.getNotificationUrl()), +// any(DARNotifyEvent.class), +// any(SoapActionCallback.class) +// )).thenReturn(response); +// +// assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); +// } +// +// @Test +// void shouldHandleWrongDestinationResultCode() { +// response.setDARNotifyEventResult(WRONG_DESTINATION.getResult()); +// when(mockWebServiceTemplate.marshalSendAndReceive( +// eq(darNotifyEvent.getNotificationUrl()), +// any(DARNotifyEvent.class), +// any(SoapActionCallback.class) +// )).thenReturn(response); +// +// assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); +// } +// +// @Test +// void shouldHandleNoMatchingEventResultCode() { +// response.setDARNotifyEventResult(NO_MATCHING_EVENT.getResult()); +// when(mockWebServiceTemplate.marshalSendAndReceive( +// eq(darNotifyEvent.getNotificationUrl()), +// any(DARNotifyEvent.class), +// any(SoapActionCallback.class) +// )).thenReturn(response); +// +// assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); +// } +// +// @Test +// void shouldHandleOtherErrorResultCode() { +// response.setDARNotifyEventResult(OTHER_ERROR.getResult()); +// when(mockWebServiceTemplate.marshalSendAndReceive( +// eq(darNotifyEvent.getNotificationUrl()), +// any(DARNotifyEvent.class), +// any(SoapActionCallback.class) +// )).thenReturn(response); +// +// assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); +// } +// +// @Test +// void shouldHandleUnexpectedResultCode() { +// response.setDARNotifyEventResult(-1); +// when(mockWebServiceTemplate.marshalSendAndReceive( +// eq(darNotifyEvent.getNotificationUrl()), +// any(DARNotifyEvent.class), +// any(SoapActionCallback.class) +// )).thenReturn(response); +// +// assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); +// } +// +// @Test +// void shouldHandleNoResponse() { +// when(mockWebServiceTemplate.marshalSendAndReceive( +// eq(darNotifyEvent.getNotificationUrl()), +// any(DARNotifyEvent.class), +// any(SoapActionCallback.class) +// )).thenReturn(null); +// +// assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); +// } +// +// @Test +// void shouldHandleWebServiceException() { +// when(mockWebServiceTemplate.marshalSendAndReceive( +// eq(darNotifyEvent.getNotificationUrl()), +// any(DARNotifyEvent.class), +// any(SoapActionCallback.class) +// )).thenThrow(new WebServiceException("Something bad happened!") { +// }); +// +// assertFalse(darNotifyEventClient.darNotifyEvent(darNotifyEvent.getNotificationUrl(), request)); +// } +// +// private static DARNotifyEvent convertToXmlDarNotifyEvent(DarNotifyEvent darNotifyEvent) { +// ObjectFactory factory = new ObjectFactory(); +// +// Event event = factory.createEvent(); +// event.setType(darNotifyEvent.getNotificationType()); +// +// OffsetDateTime localDateTime = OffsetDateTime.ofInstant( +// darNotifyEvent.getTimestamp().toInstant(), +// ZoneId.of("Europe/London") +// ); +// event.setY(String.format(EVENT_DATE_TIME_ATTRIBUTE, localDateTime.getYear())); +// event.setM(String.format(EVENT_DATE_TIME_ATTRIBUTE, localDateTime.getMonthValue())); +// event.setD(String.format(EVENT_DATE_TIME_ATTRIBUTE, localDateTime.getDayOfMonth())); +// event.setH(String.format(EVENT_DATE_TIME_ATTRIBUTE, localDateTime.getHour())); +// event.setMIN(String.format(EVENT_DATE_TIME_ATTRIBUTE, localDateTime.getMinute())); +// event.setS(String.format(EVENT_DATE_TIME_ATTRIBUTE, localDateTime.getSecond())); +// +// event.setCourthouse(darNotifyEvent.getCourthouse()); +// event.setCourtroom(darNotifyEvent.getCourtroom()); +// +// CaseNumbers caseNumbers = factory.createEventCaseNumbers(); +// caseNumbers.getCaseNumber().addAll(darNotifyEvent.getCaseNumbers()); +// event.setCaseNumbers(caseNumbers); +// +// XMLEventDocument xmlEventDocument = factory.createXMLEventDocument(); +// xmlEventDocument.setEvent(event); +// +// DARNotifyEvent xmlDarNotifyEvent = factory.createDARNotifyEvent(); +// xmlDarNotifyEvent.setXMLEventDocument(xmlEventDocument); +// +// return xmlDarNotifyEvent; +// } +// +//}