Skip to content

Commit

Permalink
Merge branch 'master' into AM-3058_FTA_ET_JudicialOrgRoles
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnayler authored Dec 13, 2023
2 parents bb56067 + 800abe1 commit 1ab0df3
Show file tree
Hide file tree
Showing 20 changed files with 150 additions and 96 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ dependencies {
exclude group: 'org.asynchttpclient', module: 'async-http-client-netty-utils'
}
implementation group: 'com.azure', name: 'azure-core', version: '1.45.1'
implementation group: 'com.azure', name: 'azure-messaging-servicebus', version: '7.13.4'
implementation group: 'com.azure', name: 'azure-messaging-servicebus', version: '7.14.7'
implementation group: 'io.projectreactor', name: 'reactor-core', version: '3.5.11'
implementation group: 'commons-cli', name: 'commons-cli', version: '1.4'
implementation group: 'com.launchdarkly', name: 'launchdarkly-java-server-sdk', version: versions.launchDarklySdk
Expand Down Expand Up @@ -683,3 +683,7 @@ rootProject.tasks.named("processFunctionalTestResources") {
rootProject.tasks.named("processIntegrationTestResources") {
duplicatesStrategy = 'include'
}

rootProject.tasks.named("processContractTestResources") {
duplicatesStrategy = 'include'
}
2 changes: 1 addition & 1 deletion infrastructure/.terraform-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.4
1.6.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package uk.gov.hmcts.reform.orgrolemapping;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.lang.NonNull;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.support.TestPropertySourceUtils;
import uk.gov.hmcts.reform.orgrolemapping.controller.BaseTest;
import uk.gov.hmcts.reform.orgrolemapping.controller.utils.WiremockFixtures;

@ContextConfiguration(initializers = {BaseTestContract.WireMockServerInitializer.class})
@ActiveProfiles("ctest")
public abstract class BaseTestContract extends BaseTest {

public static class WireMockServerInitializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {

private final WiremockFixtures wiremockFixtures = new WiremockFixtures();

@Override
public void initialize(@NonNull ConfigurableApplicationContext applicationContext) {

TestPropertySourceUtils.addInlinedPropertiesToEnvironment(
applicationContext,
"wiremock.server.port=" + WIRE_MOCK_SERVER.port()
);

try {
wiremockFixtures.stubIdamConfig();
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}

applicationContext.addApplicationListener((ApplicationListener<ContextClosedEvent>) event -> {
if (WIRE_MOCK_SERVER.isRunning()) {
WIRE_MOCK_SERVER.shutdown();
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDMessagingConfiguration;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDTopicConsumer;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDTopicPublisher;
Expand All @@ -32,13 +30,10 @@
import uk.gov.hmcts.reform.orgrolemapping.servicebus.JRDTopicPublisher;

@ExtendWith(PactConsumerTestExt.class)
@ExtendWith(SpringExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@PactTestFor(providerName = "am_roleAssignment_deleteAssignment")
@PactFolder("pacts")
@SpringBootTest
public class OrgRoleMappingConsumerTestForAdvanceDelete {

public class OrgRoleMappingConsumerTestForAdvanceDelete extends BaseTestContract {
private static final String RAS_SEARCH_QUERY_ROLE_ASSIGNMENT_URL = "/am/role-assignments/query";
private static final String RAS_ADVANCE_DELETE = RAS_SEARCH_QUERY_ROLE_ASSIGNMENT_URL + "/delete";
private static final String ACTOR_ID_ADV = "14a21569-eb80-4681-b62c-6ae2ed069e5f";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.orgrolemapping.feignclients.RASFeignClient;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDTopicConsumer;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDTopicPublisher;
Expand All @@ -47,12 +45,10 @@

@Slf4j
@ExtendWith(PactConsumerTestExt.class)
@ExtendWith(SpringExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@PactTestFor(providerName = "am_roleAssignment_createAssignment")
@PactFolder("pacts")
@SpringBootTest
public class OrgRoleMappingConsumerTestForCreate {
public class OrgRoleMappingConsumerTestForCreate extends BaseTestContract {

private static final String RAS_CREATE_ROLE_ASSIGNMENT_URL = "/am/role-assignments";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDTopicConsumer;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDTopicPublisher;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.JRDMessagingConfiguration;
Expand All @@ -35,12 +33,10 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

@ExtendWith(PactConsumerTestExt.class)
@ExtendWith(SpringExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@PactTestFor(providerName = "am_roleAssignment_deleteAssignment")
@PactFolder("pacts")
@SpringBootTest
public class OrgRoleMappingConsumerTestForDelete {
public class OrgRoleMappingConsumerTestForDelete extends BaseTestContract {

private static final String ACTOR_ID = "704c8b1c-e89b-436a-90f6-953b1dc40157";
private static final String AM_RAS_URL = "/am/role-assignments";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDTopicConsumer;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDTopicPublisher;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.JRDMessagingConfiguration;
Expand All @@ -42,12 +40,10 @@
import static org.hamcrest.MatcherAssert.assertThat;

@ExtendWith(PactConsumerTestExt.class)
@ExtendWith(SpringExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@PactTestFor(providerName = "am_roleAssignment_getAssignment")
@PactFolder("pacts")
@SpringBootTest
public class OrgRoleMappingConsumerTestForGetActorById {
public class OrgRoleMappingConsumerTestForGetActorById extends BaseTestContract {

private static final String ACTOR_ID = "23486";
private static final String RAS_GET_ACTOR_BY_ID = "/am/role-assignments/actors/" + ACTOR_ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDMessagingConfiguration;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDTopicConsumer;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDTopicPublisher;
Expand All @@ -46,12 +44,10 @@

@Slf4j
@ExtendWith(PactConsumerTestExt.class)
@ExtendWith(SpringExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@PactTestFor(providerName = "am_roleAssignment_queryAssignment")
@PactFolder("pacts")
@SpringBootTest
public class OrgRoleMappingConsumerTestForSearchQuery {
public class OrgRoleMappingConsumerTestForSearchQuery extends BaseTestContract {

private static final String ACTOR_ID = "234873";
private static final String ACTOR_ID_ADV = "14a21569-eb80-4681-b62c-6ae2ed069e5f";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDMessagingConfiguration;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDTopicConsumer;
import uk.gov.hmcts.reform.orgrolemapping.servicebus.CRDTopicPublisher;
Expand All @@ -42,12 +40,10 @@

@Slf4j
@ExtendWith(PactConsumerTestExt.class)
@ExtendWith(SpringExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@PactTestFor(providerName = "am_roleAssignment_getRoles")
@PactFolder("pacts")
@SpringBootTest
public class OrgRoleMappingConsumerTestForStaticRoles {
public class OrgRoleMappingConsumerTestForStaticRoles extends BaseTestContract {

@MockBean
CRDTopicConsumer topicConsumer;
Expand Down
18 changes: 18 additions & 0 deletions src/contractTest/resources/application-ctest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
spring:
security:
oauth2:
client:
provider:
oidc:
issuer-uri: http://localhost:${wiremock.server.port:5000}/o

idam:
s2s-auth:
url: http://localhost:${wiremock.server.port:4502}
api.url: http://localhost:${wiremock.server.port:5000}

feign:
client:
config:
roleAssignmentApp:
url: http://localhost:${wiremock.server.port:4096}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import uk.gov.hmcts.reform.orgrolemapping.controller.BaseTest;
import uk.gov.hmcts.reform.orgrolemapping.controller.BaseTestIntegration;

import javax.inject.Inject;
import java.io.OutputStream;
Expand All @@ -26,7 +26,7 @@
// NB: hide testing-support endpoint from Swagger Publish
"testing.support.enabled=false"
})
public class SwaggerPublisher extends BaseTest {
public class SwaggerPublisher extends BaseTestIntegration {

private MockMvc mockMvc;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
package uk.gov.hmcts.reform.orgrolemapping.controller;

import com.azure.messaging.servicebus.ServiceBusSenderClient;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.microsoft.azure.servicebus.SubscriptionClient;
import com.opentable.db.postgres.embedded.EmbeddedPostgres;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.ApplicationContextInitializer;
Expand All @@ -23,15 +14,11 @@
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
import org.springframework.lang.NonNull;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.support.TestPropertySourceUtils;
import uk.gov.hmcts.reform.orgrolemapping.controller.utils.WiremockFixtures;


import javax.annotation.PreDestroy;
import javax.sql.DataSource;
import java.io.IOException;
Expand All @@ -40,18 +27,9 @@
import java.sql.SQLException;
import java.util.Properties;

import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;

@ContextConfiguration(initializers = {BaseTest.WireMockServerInitializer.class})
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration(initializers = {BaseTestIntegration.WireMockServerInitializer.class})
@ActiveProfiles("itest")
@EnableConfigurationProperties
public abstract class BaseTest {

public static final WireMockServer WIRE_MOCK_SERVER = new WireMockServer(options().dynamicPort());

protected static final ObjectMapper mapper = new ObjectMapper();
public abstract class BaseTestIntegration extends BaseTest {

@MockBean
@Qualifier("crdPublisher")
Expand All @@ -61,35 +39,6 @@ public abstract class BaseTest {
@Qualifier("jrdPublisher")
ServiceBusSenderClient serviceBusSenderClientJrd;

@MockBean(name = "jrdConsumer")
private SubscriptionClient jrdConsumer;

@MockBean(name = "crdConsumer")
private SubscriptionClient crdConsumer;

@MockBean(name = "getSubscriptionClient")
private SubscriptionClient getSubscriptionClient;

@MockBean(name = "getSubscriptionClient1")
private SubscriptionClient getSubscriptionClient1;

@MockBean(name = "clientRegistrationRepository")
private ClientRegistrationRepository getClientRegistrationRepository;

@MockBean(name = "reactiveClientRegistrationRepository")
private ReactiveClientRegistrationRepository getReactiveClientRegistrationRepository;

static {
if (!WIRE_MOCK_SERVER.isRunning()) {
WIRE_MOCK_SERVER.start();
}

mapper.registerModule(new JavaTimeModule());
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
// Force re-initialisation of base types for each test suite
}

@TestConfiguration
static class Configuration {
Connection connection;
Expand All @@ -111,7 +60,7 @@ public DataSource dataSource(@Autowired EmbeddedPostgres pg) throws Exception {
connection = DriverManager.getConnection(pg.getJdbcUrl("postgres"), props);
return new SingleConnectionDataSource(connection, true);
}


@PreDestroy
public void contextDestroyed() throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
@TestPropertySource(properties = {
"refresh.Job.authorisedServices=am_org_role_mapping_service,am_role_assignment_refresh_batch",
"feign.client.config.jrdClient.v2Active=false"})
public class RefreshControllerIntegrationTest extends BaseTest {
public class RefreshControllerIntegrationTest extends BaseTestIntegration {

private static final Logger logger = LoggerFactory.getLogger(RefreshControllerIntegrationTest.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
@TestPropertySource(properties = {
"refresh.Job.authorisedServices=am_org_role_mapping_service,am_role_assignment_refresh_batch",
"feign.client.config.jrdClient.v2Active=true"})
public class RefreshControllerIntegrationV2Test extends BaseTest {
public class RefreshControllerIntegrationV2Test extends BaseTestIntegration {

private static final Logger logger = LoggerFactory.getLogger(RefreshControllerIntegrationV2Test.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"dbFeature.flags.enable=iac_jrd_1_0",
"testing.support.enabled=true" // NB: needed for OrgMappingController (needs removing in AM-2877)
})
public class WelcomeControllerIntegrationTest extends BaseTest {
public class WelcomeControllerIntegrationTest extends BaseTestIntegration {

private static final Logger logger = LoggerFactory.getLogger(WelcomeControllerIntegrationTest.class);

Expand Down
Loading

0 comments on commit 1ab0df3

Please sign in to comment.