From e750c9a0ebe08a80e43558583fcb4773967e257b Mon Sep 17 00:00:00 2001 From: adamg-hmcts <159780146+adamg-hmcts@users.noreply.github.com> Date: Thu, 16 Jan 2025 14:22:34 +0000 Subject: [PATCH] Add event for TTL migration (#4273) --- .../event/SystemSetTimeToLive.java | 35 +++++++++++++++++++ .../event/SystemSetTimeToLiveTest.java | 34 ++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/main/java/uk/gov/hmcts/divorce/systemupdate/event/SystemSetTimeToLive.java create mode 100644 src/test/java/uk/gov/hmcts/divorce/systemupdate/event/SystemSetTimeToLiveTest.java diff --git a/src/main/java/uk/gov/hmcts/divorce/systemupdate/event/SystemSetTimeToLive.java b/src/main/java/uk/gov/hmcts/divorce/systemupdate/event/SystemSetTimeToLive.java new file mode 100644 index 00000000000..65d24294d12 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/divorce/systemupdate/event/SystemSetTimeToLive.java @@ -0,0 +1,35 @@ +package uk.gov.hmcts.divorce.systemupdate.event; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import uk.gov.hmcts.ccd.sdk.api.CCDConfig; +import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder; +import uk.gov.hmcts.divorce.divorcecase.model.CaseData; +import uk.gov.hmcts.divorce.divorcecase.model.State; +import uk.gov.hmcts.divorce.divorcecase.model.UserRole; + +import static uk.gov.hmcts.divorce.common.ccd.CcdPageConfiguration.NEVER_SHOW; +import static uk.gov.hmcts.divorce.divorcecase.model.State.Draft; +import static uk.gov.hmcts.divorce.divorcecase.model.UserRole.SYSTEMUPDATE; +import static uk.gov.hmcts.divorce.divorcecase.model.access.Permissions.CREATE_READ_UPDATE; + +@Component +@Slf4j +@RequiredArgsConstructor +public class SystemSetTimeToLive implements CCDConfig { + + public static final String SYSTEM_SET_TTL = "system-set-ttl"; + + @Override + public void configure(final ConfigBuilder configBuilder) { + configBuilder + .event(SYSTEM_SET_TTL) + .forStates(Draft) + .showCondition(NEVER_SHOW) + .name("System set TTL") + .description("System set TTL") + .grant(CREATE_READ_UPDATE, SYSTEMUPDATE); + } +} + diff --git a/src/test/java/uk/gov/hmcts/divorce/systemupdate/event/SystemSetTimeToLiveTest.java b/src/test/java/uk/gov/hmcts/divorce/systemupdate/event/SystemSetTimeToLiveTest.java new file mode 100644 index 00000000000..81fc24316aa --- /dev/null +++ b/src/test/java/uk/gov/hmcts/divorce/systemupdate/event/SystemSetTimeToLiveTest.java @@ -0,0 +1,34 @@ +package uk.gov.hmcts.divorce.systemupdate.event; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.ccd.sdk.ConfigBuilderImpl; +import uk.gov.hmcts.ccd.sdk.api.Event; +import uk.gov.hmcts.divorce.divorcecase.model.CaseData; +import uk.gov.hmcts.divorce.divorcecase.model.State; +import uk.gov.hmcts.divorce.divorcecase.model.UserRole; + +import static org.assertj.core.api.Assertions.assertThat; +import static uk.gov.hmcts.divorce.systemupdate.event.SystemSetTimeToLive.SYSTEM_SET_TTL; +import static uk.gov.hmcts.divorce.testutil.ConfigTestUtil.createCaseDataConfigBuilder; +import static uk.gov.hmcts.divorce.testutil.ConfigTestUtil.getEventsFrom; + +@ExtendWith(MockitoExtension.class) +class SystemSetTimeToLiveTest { + + @InjectMocks + private SystemSetTimeToLive systemSetTimeToLive; + + @Test + void shouldAddConfigurationToConfigBuilder() { + final ConfigBuilderImpl configBuilder = createCaseDataConfigBuilder(); + + systemSetTimeToLive.configure(configBuilder); + + assertThat(getEventsFrom(configBuilder).values()) + .extracting(Event::getId) + .contains(SYSTEM_SET_TTL); + } +}