diff --git a/build.gradle b/build.gradle index b1fe87a6..fdc65072 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ apply { } dependencies { - implementation('uk.gov.hmcts.cp:api-cp-crime-hearing-case-event-subscription:1.1.3') + implementation('uk.gov.hmcts.cp:api-cp-crime-hearing-case-event-subscription:1.1.4') // This is proving to be a real puzzle. This is actually included in the api published pom // ( though with scope of "runtime" ) diff --git a/src/main/java/uk/gov/hmcts/cp/subscription/controllers/SubscriptionController.java b/src/main/java/uk/gov/hmcts/cp/subscription/controllers/SubscriptionController.java index 4e51ee27..0d23e739 100644 --- a/src/main/java/uk/gov/hmcts/cp/subscription/controllers/SubscriptionController.java +++ b/src/main/java/uk/gov/hmcts/cp/subscription/controllers/SubscriptionController.java @@ -5,6 +5,7 @@ import org.owasp.encoder.Encode; import org.slf4j.MDC; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RestController; @@ -12,6 +13,8 @@ import uk.gov.hmcts.cp.openapi.api.SubscriptionApi; import uk.gov.hmcts.cp.openapi.model.ClientSubscription; import uk.gov.hmcts.cp.openapi.model.ClientSubscriptionRequest; +import uk.gov.hmcts.cp.openapi.model.EventTypeResponse; +import uk.gov.hmcts.cp.subscription.services.EventTypeService; import uk.gov.hmcts.cp.subscription.services.SubscriptionService; import java.util.UUID; @@ -24,6 +27,7 @@ public class SubscriptionController implements SubscriptionApi { private final SubscriptionService subscriptionService; + private final EventTypeService eventTypeService; @Override public ResponseEntity createClientSubscription( @@ -68,4 +72,12 @@ public ResponseEntity deleteClientSubscription( subscriptionService.deleteSubscription(clientSubscriptionId, clientId); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } + + @Override + public ResponseEntity getEventTypes() { + final EventTypeResponse eventTypes = eventTypeService.getAllEventTypes(); + return ResponseEntity.ok() + .contentType(MediaType.APPLICATION_JSON) + .body(eventTypes); + } } diff --git a/src/main/java/uk/gov/hmcts/cp/subscription/entities/EventTypeEntity.java b/src/main/java/uk/gov/hmcts/cp/subscription/entities/EventTypeEntity.java new file mode 100644 index 00000000..db50c521 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/cp/subscription/entities/EventTypeEntity.java @@ -0,0 +1,33 @@ +package uk.gov.hmcts.cp.subscription.entities; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "event_type") +@Getter +@Builder(toBuilder = true) +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode +public class EventTypeEntity { + + @Id + private Long id; + + @Column(name = "event_name") + private String eventName; + + @Column(name = "display_name") + private String displayName; + + @Column(name = "category") + private String category; +} diff --git a/src/main/java/uk/gov/hmcts/cp/subscription/mappers/EventTypeMapper.java b/src/main/java/uk/gov/hmcts/cp/subscription/mappers/EventTypeMapper.java new file mode 100644 index 00000000..7b49fdf3 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/cp/subscription/mappers/EventTypeMapper.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.cp.subscription.mappers; + +import org.mapstruct.Mapper; +import uk.gov.hmcts.cp.openapi.model.EventTypeResponse; +import uk.gov.hmcts.cp.openapi.model.EventTypePayload; +import uk.gov.hmcts.cp.subscription.entities.EventTypeEntity; + +import java.util.List; + +@Mapper(componentModel = "spring") +public interface EventTypeMapper { + + List map(List eventTypeEntities); + + default EventTypeResponse mapToEventTypes(final List eventTypeEntities) { + return EventTypeResponse.builder() + .events(map(eventTypeEntities)) + .build(); + } +} diff --git a/src/main/java/uk/gov/hmcts/cp/subscription/repositories/EventTypeRepository.java b/src/main/java/uk/gov/hmcts/cp/subscription/repositories/EventTypeRepository.java new file mode 100644 index 00000000..0db25d5a --- /dev/null +++ b/src/main/java/uk/gov/hmcts/cp/subscription/repositories/EventTypeRepository.java @@ -0,0 +1,11 @@ +package uk.gov.hmcts.cp.subscription.repositories; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +import uk.gov.hmcts.cp.subscription.entities.EventTypeEntity; + +@Repository +public interface EventTypeRepository extends JpaRepository { + + +} diff --git a/src/main/java/uk/gov/hmcts/cp/subscription/services/EventTypeService.java b/src/main/java/uk/gov/hmcts/cp/subscription/services/EventTypeService.java new file mode 100644 index 00000000..0f1f4257 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/cp/subscription/services/EventTypeService.java @@ -0,0 +1,25 @@ +package uk.gov.hmcts.cp.subscription.services; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.cp.openapi.model.EventTypeResponse; +import uk.gov.hmcts.cp.subscription.entities.EventTypeEntity; +import uk.gov.hmcts.cp.subscription.mappers.EventTypeMapper; +import uk.gov.hmcts.cp.subscription.repositories.EventTypeRepository; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Slf4j +public class EventTypeService { + + private final EventTypeRepository eventTypeRepository; + private final EventTypeMapper eventTypeMapper; + + public EventTypeResponse getAllEventTypes() { + final List eventTypeEntityList = eventTypeRepository.findAll(); + return eventTypeMapper.mapToEventTypes(eventTypeEntityList); + } +} diff --git a/src/main/resources/db/migration/V1.005__add_event_type_table.sql b/src/main/resources/db/migration/V1.005__add_event_type_table.sql new file mode 100644 index 00000000..39e969c1 --- /dev/null +++ b/src/main/resources/db/migration/V1.005__add_event_type_table.sql @@ -0,0 +1,50 @@ +CREATE TABLE event_type ( + id integer PRIMARY KEY NOT NULL, + event_name VARCHAR(128) NOT NULL UNIQUE, + display_name VARCHAR(256) NOT NULL, + category VARCHAR(64) NOT NULL +); + +CREATE UNIQUE INDEX idx_event_type_event_name ON event_type(event_name); + +INSERT INTO event_type (id, event_name, display_name, category) VALUES (1, 'PRISON_COURT_REGISTER_GENERATED', 'Prison court register', 'REGISTER'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (2, 'WEE_Layout5', 'Warrant Supplement', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (3, 'NEE_DetentionOnRecommendationForDeportation', 'Detention on Recommendation for Deportation', 'NOTICE'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (4, 'OEE_MedicalRemandAdditionalDetails', 'Medical Remand - Additional Details', 'ORDER'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (5, 'WEE_RemandAfterBailAppealByProsecutor', 'Remand Warrant After Bail Appeal by Prosecutor', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (6, 'WEE_CustodialSentence', 'Warrant for Custodial Sentence', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (7, 'WEE_CustodialSentenceWitness', 'Warrant for Custodial Sentence (Witness)', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (8, 'WEE_CommittalToCrownCourtForConsiderationOfTheQuestionOfBailOnAChargeOfMurder', 'Warrant of Committal to Crown Court for Consideration of the Question of Bail on a Charge of Murder', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (9, 'WEE_CommittalToCrownCourtForSentence', 'Warrant of Committal to Crown Court for Sentence', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (10, 'WEE_SendingToCrownCourtForTrial', 'Warrant of Sending to Crown Court for Trial', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (11, 'OEE_BailAppealEndOfCustody', 'Bail Appeal - End of Custody', 'ORDER'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (12, 'WEE_CommitmentPendingTransferToServiceCustody', 'Warrant of Commitment Pending Transfer to Service Custody', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (13, 'WEE_NonPaymentOfMoneyOwedCivilDebt', 'Warrant of Committal for Non-Payment of Money Owed Civil Debt,', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (14, 'WEE_CustodyWarrantOnDischargeOfExtraditionPendingAppeal', 'Custody Warrant on Discharge of Extradition Pending Appeal', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (15, 'WEE_CustodyWarrantOnDischargeOfExtraditionPendingAppealPart2', 'Custody Warrant on Discharge of Extradition Pending Appeal (Part 2)', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (16, 'WEE_CustodyWarrantOnExtradition', 'Custody Warrant on Extradition', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (17, 'WEE_CustodyWarrantOnExtraditionCategory2Territory', 'Custody Warrant on Extradition – Category 2 Territory', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (18, 'WEE_CustodyWarrantOnExtraditionWithConsent', 'Custody Warrant on Extradition (Part 1)', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (19, 'WEE_CustodyWarrantOnExtraditionWithBailDirection', 'Custody Warrant on Extradition (with Bail Direction)', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (20, 'WEE_CustodyWarrantOnExtraditionWithBailDirectionWithConsent', 'Custody Warrant on Extradition with Bail Direction', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (21, 'WEE_CustodyWarrantOnExtraditionWithBailDirectionCategory2Territory', 'Custody Warrant on Extradition (with Bail Direction) – Category 2 Territory', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (22, 'WEE_CustodyWarrantSendingToSecretaryOfStateCategory2Territory', 'Custody Warrant Sending to Secretary of State – Category 2 Territory', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (23, 'WEE_CustodyWarrantSendingToSecretaryOfStateOnConsentCategory2Territory', 'Custody Warrant Sending to Secretary of State on Consent – Category 2 Territory', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (24, 'WEE_CustodyWarrantWithBailDirectionOnDischargeOfExtraditionPendingAppeal', 'Custody Warrant with Bail Direction on Discharge of Extradition Pending Appeal', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (25, 'WEE_CustodyWarrantWithBailDirectionOnDischargeOfExtraditionPendingAppealPart2', 'Custody Warrant with Bail Direction on Discharge of Extradition Pending Appeal (Part 2)', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (26, 'WEE_CustodyWarrantWithBailDirectionSendingToSecretaryOfStateCategory2Territory', 'Custody Warrant with Bail Direction Sending to Secretary of State – Category 2 Territory', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (27, 'WEE_CustodyWarrantWithBailDirectionSendingToSecretaryOfStateOnConsentCategory2Territory', 'Custody Warrant with Bail Direction Sending to Secretary of State on Consent – Category 2 Territory', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (28, 'WEE_ExtraditionRemandAfterBailAppealByProsecutor', 'Remand Warrant After Bail Appeal by Prosecutor - Extradition', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (29, 'WEE_ExtraditionSupplementToCustodyWarrant', 'Supplement to Custody Warrant on Extradition', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (30, 'OBE_TerminationOfFootballBanning', 'Application for Termination of Football Banning Order', 'ORDER'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (31, 'OBE_ChangeOfFootballBanning', 'Change of Football Banning Order', 'ORDER'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (32, 'NEE_FootballBanning', 'Notice of Football Banning Order', 'NOTICE'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (33, 'WEE_Remand', 'Remand Warrant', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (34, 'WXE_RemandWarrantYouthDetentionAccommodation', 'Remand Warrant - Youth Detention Accommodation', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (35, 'OXE_DetentionAndTraining', 'Detention and Training Order', 'ORDER'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (36, 'WEE_InjunctionDetention', 'Injunction Warrant of Detention', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (37, 'OPE_SupervisionOnBreachOfDetentionAndTraining', 'Supervision on Breach of Detention and Training Order', 'ORDER'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (38, 'WEE_CommittalToCrownCourtAuthorityToHoldInYouthDetentionAccommodation', 'Warrant of Committal to Crown Court - Authority to Hold in Youth Detention Accommodation', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (39, 'WEE_Detention', 'Warrant of Detention', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (40, 'WEE_DetentionInYouthDetentionAccommodationBreach', 'Warrant of Detention in Youth Detention Accommodation (Breach)', 'WARRANT'); +INSERT INTO event_type (id, event_name, display_name, category) VALUES (41, 'WEE_SendingToCrownCourtAuthorityToHoldInYouthDetentionAccommodation', 'Warrant of Sending to Crown Court - Authority to Hold in Youth Detention Accommodation', 'WARRANT'); \ No newline at end of file diff --git a/src/test/java/uk/gov/hmcts/cp/subscription/integration/IntegrationTestBase.java b/src/test/java/uk/gov/hmcts/cp/subscription/integration/IntegrationTestBase.java index 8a8846fc..7da169bd 100644 --- a/src/test/java/uk/gov/hmcts/cp/subscription/integration/IntegrationTestBase.java +++ b/src/test/java/uk/gov/hmcts/cp/subscription/integration/IntegrationTestBase.java @@ -17,6 +17,7 @@ import uk.gov.hmcts.cp.subscription.integration.helpers.JwtHelper; import uk.gov.hmcts.cp.subscription.model.EntityEventType; import uk.gov.hmcts.cp.subscription.repositories.DocumentMappingRepository; +import uk.gov.hmcts.cp.subscription.repositories.EventTypeRepository; import uk.gov.hmcts.cp.subscription.repositories.SubscriptionRepository; import uk.gov.hmcts.cp.subscription.services.ClockService; @@ -51,6 +52,9 @@ public abstract class IntegrationTestBase { @Autowired protected DocumentMappingRepository documentMappingRepository; + @Autowired + protected EventTypeRepository eventTypeRepository; + @Autowired protected ClockService clockService; diff --git a/src/test/java/uk/gov/hmcts/cp/subscription/integration/controllers/SubscriptionEventTypeGetControllerIntegrationTest.java b/src/test/java/uk/gov/hmcts/cp/subscription/integration/controllers/SubscriptionEventTypeGetControllerIntegrationTest.java new file mode 100644 index 00000000..51f2e972 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/cp/subscription/integration/controllers/SubscriptionEventTypeGetControllerIntegrationTest.java @@ -0,0 +1,41 @@ +package uk.gov.hmcts.cp.subscription.integration.controllers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.springframework.test.web.servlet.MvcResult; +import uk.gov.hmcts.cp.openapi.model.EventTypePayload; +import uk.gov.hmcts.cp.openapi.model.EventTypeResponse; +import uk.gov.hmcts.cp.subscription.integration.IntegrationTestBase; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +class SubscriptionEventTypeGetControllerIntegrationTest extends IntegrationTestBase { + + public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + @Test + void get_subscription_should_return_expected() throws Exception { + EventTypePayload expectedEventType1 = EventTypePayload.builder() + .eventName("PRISON_COURT_REGISTER_GENERATED") + .displayName("Prison court register") + .category("REGISTER") + .build(); + EventTypePayload expectedEventType2 = EventTypePayload.builder() + .eventName("WEE_Layout5") + .displayName("Warrant Supplement") + .category("WARRANT") + .build(); + + MvcResult result = mockMvc.perform(get("/event-types")) + .andDo(print()) + .andExpect(status().isOk()) + .andReturn(); + + EventTypeResponse getEventTypes = OBJECT_MAPPER.readValue(result.getResponse().getContentAsString(), EventTypeResponse.class); + assertThat(getEventTypes.getEvents().size()).isEqualTo(41); + assertThat(getEventTypes.getEvents()).contains(expectedEventType1, expectedEventType2); + } +} \ No newline at end of file diff --git a/src/test/java/uk/gov/hmcts/cp/subscription/integration/repositories/EventTypeRepositoryTest.java b/src/test/java/uk/gov/hmcts/cp/subscription/integration/repositories/EventTypeRepositoryTest.java new file mode 100644 index 00000000..ae358258 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/cp/subscription/integration/repositories/EventTypeRepositoryTest.java @@ -0,0 +1,33 @@ +package uk.gov.hmcts.cp.subscription.integration.repositories; + +import org.junit.jupiter.api.Test; +import org.springframework.transaction.annotation.Transactional; +import uk.gov.hmcts.cp.subscription.entities.EventTypeEntity; +import uk.gov.hmcts.cp.subscription.integration.IntegrationTestBase; + +import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; + +class EventTypeRepositoryTest extends IntegrationTestBase { + + @Transactional + @Test + void findAllEventTypes_should_return_document() { + EventTypeEntity entity1 = EventTypeEntity.builder() + .id(1L) + .eventName("PRISON_COURT_REGISTER_GENERATED") + .displayName("Prison court register") + .category("REGISTER") + .build(); + EventTypeEntity entity2 = EventTypeEntity.builder() + .id(2L) + .eventName("WEE_Layout5") + .displayName("Warrant Supplement") + .category("WARRANT") + .build(); + + List found = eventTypeRepository.findAll(); + assertThat(found.size()).isEqualTo(41); + assertThat(found).contains(entity1, entity2); + } +} diff --git a/src/test/java/uk/gov/hmcts/cp/subscription/mappers/EventTypeMapperTest.java b/src/test/java/uk/gov/hmcts/cp/subscription/mappers/EventTypeMapperTest.java new file mode 100644 index 00000000..50a8eb3c --- /dev/null +++ b/src/test/java/uk/gov/hmcts/cp/subscription/mappers/EventTypeMapperTest.java @@ -0,0 +1,35 @@ +package uk.gov.hmcts.cp.subscription.mappers; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.cp.openapi.model.EventTypePayload; +import uk.gov.hmcts.cp.openapi.model.EventTypeResponse; +import uk.gov.hmcts.cp.subscription.entities.EventTypeEntity; + +import java.util.List; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +class EventTypeMapperTest { + + EventTypeMapper eventTypeMapper = new EventTypeMapperImpl(); + + @Test + void entity_should_map_to_payload() { + EventTypeEntity entity = EventTypeEntity.builder() + .id(1L) + .eventName("PRISON_COURT_REGISTER_GENERATED") + .displayName("Prison court register") + .category("REGISTER") + .build(); + + EventTypeResponse eventTypes = eventTypeMapper.mapToEventTypes(List.of(entity)); + assertThat(eventTypes.getEvents().size()).isEqualTo(1); + + EventTypePayload eventType = eventTypes.getEvents().getFirst(); + assertThat(eventType.getEventName()).isEqualTo("PRISON_COURT_REGISTER_GENERATED"); + assertThat(eventType.getDisplayName()).isEqualTo("Prison court register"); + assertThat(eventType.getCategory()).isEqualTo("REGISTER"); + } + + +} \ No newline at end of file diff --git a/src/test/java/uk/gov/hmcts/cp/subscription/services/EventTypeServiceTest.java b/src/test/java/uk/gov/hmcts/cp/subscription/services/EventTypeServiceTest.java new file mode 100644 index 00000000..e005df29 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/cp/subscription/services/EventTypeServiceTest.java @@ -0,0 +1,48 @@ +package uk.gov.hmcts.cp.subscription.services; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.cp.openapi.model.EventTypeResponse; +import uk.gov.hmcts.cp.subscription.entities.EventTypeEntity; +import uk.gov.hmcts.cp.subscription.mappers.EventTypeMapper; +import uk.gov.hmcts.cp.subscription.repositories.EventTypeRepository; + +import java.util.List; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class EventTypeServiceTest { + + @Mock + private EventTypeRepository eventTypeRepository; + + @Mock + private EventTypeMapper eventTypeMapper; + + @InjectMocks + private EventTypeService eventTypeService; + + @Test + void all_event_types_should_be_returned() { + EventTypeEntity entity = Mockito.mock(EventTypeEntity.class); + List entityList = List.of(entity); + + EventTypeResponse eventTypes = Mockito.mock(EventTypeResponse.class); + + when(eventTypeRepository.findAll()).thenReturn(entityList); + when(eventTypeMapper.mapToEventTypes(entityList)).thenReturn(eventTypes); + + eventTypeService.getAllEventTypes(); + + verify(eventTypeRepository).findAll(); + verify(eventTypeMapper).mapToEventTypes(entityList); + + } +} \ No newline at end of file diff --git a/src/test/java/uk/gov/hmcts/cp/subscription/unit/controllers/SubscriptionControllerTest.java b/src/test/java/uk/gov/hmcts/cp/subscription/unit/controllers/SubscriptionControllerTest.java index 2ace44f8..6659ee71 100644 --- a/src/test/java/uk/gov/hmcts/cp/subscription/unit/controllers/SubscriptionControllerTest.java +++ b/src/test/java/uk/gov/hmcts/cp/subscription/unit/controllers/SubscriptionControllerTest.java @@ -13,6 +13,7 @@ import uk.gov.hmcts.cp.openapi.model.NotificationEndpoint; import uk.gov.hmcts.cp.subscription.controllers.SubscriptionController; import uk.gov.hmcts.cp.filters.ClientIdResolutionFilter; +import uk.gov.hmcts.cp.subscription.services.EventTypeService; import uk.gov.hmcts.cp.subscription.services.SubscriptionService; import java.util.List; @@ -29,6 +30,9 @@ class SubscriptionControllerTest { @Mock SubscriptionService subscriptionService; + @Mock + EventTypeService eventTypeService; + @InjectMocks SubscriptionController subscriptionController; @@ -86,4 +90,11 @@ void delete_controller_should_call_service() { verify(subscriptionService).deleteSubscription(subscriptionId, TEST_CLIENT_UUID); assertThat(result.getStatusCode().value()).isEqualTo(204); } + + @Test + void get_event_types_controller_should_call_event_type_service() { + var result = subscriptionController.getEventTypes(); + verify(eventTypeService).getAllEventTypes(); + assertThat(result.getStatusCode().value()).isEqualTo(200); + } } \ No newline at end of file