Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ out
/bin/create-env-file.sh
/bin/substitutions.json
.env
/bin/setup-env.sh
/bin/setup-azurite.sh
/bin/setup-sftp.sh
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ plugins {
id 'checkstyle'
id 'jacoco'
id 'io.spring.dependency-management' version '1.1.7'
id 'org.springframework.boot' version '3.5.5'
id 'org.owasp.dependencycheck' version '12.1.3'
id 'org.springframework.boot' version '4.0.6'
id 'org.owasp.dependencycheck' version '12.2.2'
id 'java-library'
id 'maven-publish'
id 'com.github.ben-manes.versions' version '0.52.0'
id 'com.github.ben-manes.versions' version '0.54.0'
}

def buildNumber = System.getenv("RELEASE_VERSION")?: "DEV-SNAPSHOT"
Expand Down Expand Up @@ -172,11 +172,14 @@ dependencyManagement {

dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign', version: '4.3.2'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-json'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign', version: '5.0.1'
implementation group: 'io.github.openfeign', name: 'feign-jackson', version: '13.12'
implementation group: 'commons-io', name: 'commons-io', version: '2.22.0'
implementation group: 'org.springframework.retry', name: 'spring-retry', version: '2.0.12'

implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.17.1'

testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
testImplementation group: 'com.github.tomakehurst', name: 'wiremock-jre8-standalone', version: '3.0.1'

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.sendletter.api.SendLetterApi;
import uk.gov.hmcts.reform.sendletter.api.proxy.SendLetterApiProxy;
import uk.gov.hmcts.reform.sendletter.config.TestObjectMapperConfig;
import uk.gov.hmcts.reform.sendletter.healthcheck.SendLetterHealthApi;
import uk.gov.hmcts.reform.sendletter.healthcheck.SendLetterHealthIndicator;

Expand All @@ -19,7 +20,10 @@
@EnableAutoConfiguration
@ExtendWith(SpringExtension.class)
@SpringBootTest(
classes = SendLetterAutoConfiguration.class,
classes = {
SendLetterAutoConfiguration.class,
TestObjectMapperConfig.class
},
properties = {
"send-letter.url=localhost"
}
Expand All @@ -44,4 +48,6 @@ public void haveApi() {
assertThat(context.getBeanNamesForType(RetryTemplate.class)).hasSize(1);
assertThat(context.getBeanNamesForType(SendLetterApi.class)).hasSize(1);
}

// ObjectMapper bean now provided by shared TestObjectMapperConfig
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
import uk.gov.hmcts.reform.sendletter.api.exception.ClientHttpErrorException;
import uk.gov.hmcts.reform.sendletter.api.exception.ServerHttpErrorException;
import uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3;
import uk.gov.hmcts.reform.sendletter.config.TestObjectMapperConfig;

import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.UUID;

import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -41,7 +43,7 @@
@EnableAutoConfiguration
@ExtendWith(SpringExtension.class)
@SpringBootTest(
classes = {SendLetterAutoConfiguration.class},
classes = {SendLetterAutoConfiguration.class, TestObjectMapperConfig.class},
properties = {
"send-letter.url=localhost:6401"
}
Expand Down Expand Up @@ -182,24 +184,27 @@ public void testDuplicateLetterRequestError() {


private void stubScenarios() {
wireMockServer.stubFor(get(urlMatching(
"/letters/" + expectedSendLetterResponse.letterId + "\\" + getRequestParameters()))
.inScenario("Letter search")
.whenScenarioStateIs(STARTED).willReturn(WireMock.aResponse().withStatus(404))
.willSetStateTo("Letter found"));

wireMockServer.stubFor(get(urlMatching(
"/letters/" + expectedSendLetterResponse.letterId + "\\" + getRequestParameters()))
.inScenario("Letter search")
.whenScenarioStateIs("Letter found")
.willReturn(WireMock.aResponse().withStatus(200).withBody(letterStatus)));

wireMockServer.stubFor(get(urlPathEqualTo("/letters/" + expectedSendLetterResponse.letterId))
.withQueryParam("include-additional-info", equalTo("false"))
.withQueryParam("check-duplicate", equalTo("true"))
.inScenario("Letter search")
.whenScenarioStateIs(STARTED)
.willReturn(WireMock.aResponse().withStatus(404))
.willSetStateTo("Letter found"));

wireMockServer.stubFor(get(urlPathEqualTo("/letters/" + expectedSendLetterResponse.letterId))
.withQueryParam("include-additional-info", equalTo("false"))
.withQueryParam("check-duplicate", equalTo("true"))
.inScenario("Letter search")
.whenScenarioStateIs("Letter found")
.willReturn(WireMock.aResponse().withStatus(200).withBody(letterStatus)));
}

private void stubSingleCallWithStatus(HttpStatus status) {
wireMockServer.stubFor(get(urlMatching(
"/letters/" + expectedSendLetterResponse.letterId + "\\" + getRequestParameters()))
.willReturn(WireMock.aResponse().withStatus(status.value()).withBody(letterStatus)));
wireMockServer.stubFor(get(urlPathEqualTo("/letters/" + expectedSendLetterResponse.letterId))
.withQueryParam("include-additional-info", equalTo("false"))
.withQueryParam("check-duplicate", equalTo("true"))
.willReturn(WireMock.aResponse().withStatus(status.value()).withBody(letterStatus)));
}

private void verifyInvocationCount(int count) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import uk.gov.hmcts.reform.sendletter.api.LetterWithPdfsRequest;
import uk.gov.hmcts.reform.sendletter.api.SendLetterResponse;
import uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3;
import uk.gov.hmcts.reform.sendletter.config.TestObjectMapperConfig;

import java.util.Collections;
import java.util.UUID;
Expand All @@ -28,7 +29,7 @@
@EnableAutoConfiguration
@ExtendWith(SpringExtension.class)
@SpringBootTest(
classes = SendLetterAutoConfiguration.class,
classes = {SendLetterAutoConfiguration.class, TestObjectMapperConfig.class},
properties = {
"send-letter.url=localhost:6400"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package uk.gov.hmcts.reform.sendletter.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TestObjectMapperConfig {
@Bean
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
return mapper;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.boot.actuate.health.Status;
import org.springframework.boot.health.contributor.Status;


/**
* Internal health model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.health.contributor.Health;
import org.springframework.boot.health.contributor.HealthIndicator;


/**
* Send letter health indicator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.Status;
import org.springframework.boot.health.contributor.Health;
import org.springframework.boot.health.contributor.HealthIndicator;
import org.springframework.boot.health.contributor.Status;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
Expand Down