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

Am 2937 Preferable remove idam dependency int tests #1672

Merged
merged 25 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
499b820
AM-2937 Remove IDAM Dependency from Integration Tests - RefreshContro…
mikebrownccd Nov 23, 2023
a6ff7cb
attempt to remove docker IDAM but fails
mikebrownccd Nov 24, 2023
1216497
RefreshControllerIntegrationTest working with docker IDAM off. Variou…
mikebrownccd Nov 29, 2023
31f3ed2
Merge branch 'master' into AM-2937_Remove_IDAM_Dependency_Int_Tests
mikebrownccd Nov 29, 2023
f73a922
RefreshControllerIntegrationTest and V2 working, V2 now uses IDAM wir…
mikebrownccd Nov 29, 2023
afa457a
WelcomeControllerIntegrationTest welcomeApiTest,S11,S12,S13,S16,S17 p…
mikebrownccd Nov 29, 2023
5aa2edb
WelcomeControllerIntegrationTest passing, roleAssignmentApp url set i…
mikebrownccd Nov 30, 2023
872fea0
SwaggerPublisher Int Test converted to Junit 5, remove unused imports
mikebrownccd Nov 30, 2023
8389bb3
Merge branch 'master' into AM-2937_Remove_IDAM_Dependency_Int_Tests
mikebrownccd Nov 30, 2023
2f87e38
gradle config changed so just integration tests have useJUnitPlatform…
mikebrownccd Nov 30, 2023
37e880f
Merge branch 'master' into AM-2937_Remove_IDAM_Dependency_Int_Tests
mikebrownccd Dec 4, 2023
d052882
Merge branch 'master' into AM-2937_Remove_IDAM_Dependency_Int_Tests
mikebrownccd Dec 7, 2023
b133479
code cleanup
mikebrownccd Dec 7, 2023
11fc9d8
Revert "code cleanup"
mikebrownccd Dec 7, 2023
7316408
greyed out unused stubs commented out, unused imports removed
mikebrownccd Dec 7, 2023
4894472
commented out code removed
mikebrownccd Dec 7, 2023
bcca91f
@TestConfiguration Configuration commented out
mikebrownccd Dec 7, 2023
459ab22
Revert "@TestConfiguration Configuration commented out"
mikebrownccd Dec 7, 2023
3082558
crdPublisher and jrdPublisher commented out
mikebrownccd Dec 7, 2023
8786866
Revert "crdPublisher and jrdPublisher commented out"
mikebrownccd Dec 7, 2023
ae270ed
commented out possibly unused stubs
mikebrownccd Dec 7, 2023
bb6957c
commented out stubs removed, unused imports removed
mikebrownccd Dec 7, 2023
62ccecf
getRoleAssignmentRequestResource commented out
mikebrownccd Dec 7, 2023
bc3aa63
commented out getRoleAssignmentRequestResource removed, unused import…
mikebrownccd Dec 7, 2023
6191ea1
Merge branch 'master' into AM-2937_Remove_IDAM_Dependency_Int_Tests
mikebrownccd Dec 11, 2023
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
21 changes: 21 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ sourceSets {
}
}

idea {
module {
// config to allow Intelij to mark test source and resource files correctly to help linting tools
testSources.from(java.sourceSets.functionalTest.java.srcDirs)
testSources.from(java.sourceSets.integrationTest.java.srcDirs)
testSources.from(java.sourceSets.smokeTest.java.srcDirs)
testSources.from(java.sourceSets.contractTest.java.srcDirs)
testResources.from(java.sourceSets.functionalTest.resources.srcDirs)
testResources.from(java.sourceSets.integrationTest.resources.srcDirs)
testResources.from(java.sourceSets.smokeTest.resources.srcDirs)
testResources.from(java.sourceSets.contractTest.resources.srcDirs)
}
}

tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Werror"
}
Expand Down Expand Up @@ -298,6 +312,13 @@ repositories {
}
}

tasks.named('integration') {
useJUnitPlatform()

testLogging {
exceptionFormat = 'full'
}
}

dependencies {
implementation(group: 'org.springframework.boot', name:'spring-boot-starter-web', version: versions.springBoot) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package uk.gov.hmcts.reform.orgrolemapping.config;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
Expand Down Expand Up @@ -33,7 +33,7 @@ public class SwaggerPublisher extends BaseTest {
@Inject
private WebApplicationContext wac;

@Before
@BeforeEach
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,34 @@

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.BeforeClass;
import org.junit.runner.RunWith;
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;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
import org.springframework.test.context.junit4.SpringRunner;
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;
Expand All @@ -26,9 +40,17 @@
import java.sql.SQLException;
import java.util.Properties;

@RunWith(SpringRunner.class)
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;

@ContextConfiguration(initializers = {BaseTest.WireMockServerInitializer.class})
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@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();

@MockBean
Expand All @@ -51,10 +73,20 @@ public abstract class BaseTest {
@MockBean(name = "getSubscriptionClient1")
private SubscriptionClient getSubscriptionClient1;

@BeforeClass
public static void init() {
@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
}

Expand Down Expand Up @@ -88,4 +120,31 @@ public void contextDestroyed() throws SQLException {
}
}
}

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
@@ -1,11 +1,11 @@
package uk.gov.hmcts.reform.orgrolemapping.controller;

import org.jetbrains.annotations.NotNull;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -30,6 +30,7 @@
import uk.gov.hmcts.reform.orgrolemapping.apihelper.Constants;
import uk.gov.hmcts.reform.orgrolemapping.controller.advice.exception.UnauthorizedServiceException;
import uk.gov.hmcts.reform.orgrolemapping.controller.utils.MockUtils;
import uk.gov.hmcts.reform.orgrolemapping.controller.utils.WiremockFixtures;
import uk.gov.hmcts.reform.orgrolemapping.data.RefreshJobEntity;
import uk.gov.hmcts.reform.orgrolemapping.domain.model.Appointment;
import uk.gov.hmcts.reform.orgrolemapping.domain.model.CaseWorkerProfilesResponse;
Expand Down Expand Up @@ -63,10 +64,10 @@
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
Expand All @@ -90,6 +91,8 @@ public class RefreshControllerIntegrationTest extends BaseTest {

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

private final WiremockFixtures wiremockFixtures = new WiremockFixtures();

private static final String REFRESH_JOB_RECORDS_QUERY = "SELECT job_id, status, user_ids, linked_job_id,"
+ " comments, log FROM refresh_jobs where job_id=?";
private static final String AUTHORISED_SERVICE = "am_role_assignment_refresh_batch";
Expand Down Expand Up @@ -140,18 +143,18 @@ public class RefreshControllerIntegrationTest extends BaseTest {
StandardCharsets.UTF_8
);

@Before
@BeforeEach
public void setUp() throws Exception {
template = new JdbcTemplate(ds);
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
MockitoAnnotations.openMocks(this);
doReturn(authentication).when(securityContext).getAuthentication();
SecurityContextHolder.setContext(securityContext);
doReturn(true).when(featureConditionEvaluation).preHandle(any(),any(),any());
MockUtils.setSecurityAuthorities(authentication, MockUtils.ROLE_CASEWORKER);
wiremockFixtures.resetRequests();
}

@Ignore("Intermittent AM-2919")
@Disabled("Intermittent AM-2919")
@Test
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_refresh_jobs.sql"})
public void shouldProcessRefreshRoleAssignmentsWithJobIdToComplete() throws Exception {
Expand Down Expand Up @@ -180,7 +183,7 @@ public void shouldProcessRefreshRoleAssignmentsWithJobIdToComplete() throws Exce
assertNotNull(refreshJob.getLog());
}

@Ignore("Intermittent AM-2919")
@Disabled("Intermittent AM-2919")
@Test
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_refresh_jobs.sql"})
public void shouldProcessRefreshRoleAssignmentsWithJobIdToAborted() throws Exception {
Expand All @@ -207,7 +210,7 @@ public void shouldProcessRefreshRoleAssignmentsWithJobIdToAborted() throws Excep
assertThat(refreshJob.getLog(),containsString(String.join(",", refreshJob.getUserIds())));
}

@Ignore("Intermittent AM-2919")
@Disabled("Intermittent AM-2919")
@Test
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_refresh_jobs.sql"})
public void shouldProcessRefreshRoleAssignmentsWithJobIdToAborted_status422() throws Exception {
Expand All @@ -234,7 +237,7 @@ public void shouldProcessRefreshRoleAssignmentsWithJobIdToAborted_status422() th
assertThat(refreshJob.getLog(),containsString(String.join(",", refreshJob.getUserIds())));
}

@Ignore("Intermittent AM-2919")
@Disabled("Intermittent AM-2919")
@Test
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_refresh_jobs.sql"})
public void shouldProcessRefreshRoleAssignmentsWithJobIdToPartialComplete() throws Exception {
Expand All @@ -261,7 +264,7 @@ public void shouldProcessRefreshRoleAssignmentsWithJobIdToPartialComplete() thro
assertThat(refreshJob.getLog(), containsString(String.join(",", refreshJob.getUserIds())));
}

@Ignore("Intermittent AM-2919")
@Disabled("Intermittent AM-2919")
@Test
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_refresh_jobs.sql"})
public void shouldProcessRefreshRoleAssignmentsWithJobIdToPartialComplete_status422() throws Exception {
Expand All @@ -288,7 +291,7 @@ public void shouldProcessRefreshRoleAssignmentsWithJobIdToPartialComplete_status
assertThat(refreshJob.getLog(), containsString(String.join(",", refreshJob.getUserIds())));
}

@Ignore("Intermittent AM-2919")
@Disabled("Intermittent AM-2919")
@Test
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_refresh_jobs.sql"})
public void shouldProcessRefreshRoleAssignmentsWithFailedUsersToComplete() throws Exception {
Expand Down Expand Up @@ -373,7 +376,7 @@ public void shouldFailProcessRefreshRoleAssignmentsWithOutJobID() throws Excepti
.andReturn();
}

@Ignore("Intermittent AM-2919")
@Disabled("Intermittent AM-2919")
@Test
public void shouldFailProcessRefreshRoleAssignmentsWithInvalidServiceToken() throws Exception {
logger.info("Refresh request rejected with invalid service token");
Expand All @@ -391,7 +394,7 @@ public void shouldFailProcessRefreshRoleAssignmentsWithInvalidServiceToken() thr
assertThat(result.getResolvedException().getMessage(), equalTo(UNAUTHORIZED_SERVICE));
}

@Ignore("Intermittent AM-2919")
@Disabled("Intermittent AM-2919")
@Test
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_refresh_jobs.sql"})
public void shouldProcessRefreshRoleAssignmentsWithJobIdToComplete_retryFail() throws Exception {
Expand All @@ -416,7 +419,7 @@ public void shouldProcessRefreshRoleAssignmentsWithJobIdToComplete_retryFail() t
assertEquals("NEW", refreshJob.getStatus());// failed process should change the status to IN-PROGRESS
}

@Ignore("Intermittent AM-2919")
@Disabled("Intermittent AM-2919")
@Test
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_refresh_jobs.sql"})
public void shouldProcessRefreshRoleAssignmentsWithJobIdToComplete_CRDRetry() throws Exception {
Expand Down
Loading