From 55bac0cf508f92c693a58ae6c79a6f24278d1851 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Thu, 24 Oct 2024 15:47:28 +0200 Subject: [PATCH] [#205] Implement getAllowedRejectMessage tests --- .../rest/PatientRecordControllerTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java b/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java index a82504ef..138ba96e 100644 --- a/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java +++ b/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java @@ -15,8 +15,10 @@ import cz.cvut.kbss.study.persistence.dao.util.RecordSort; import cz.cvut.kbss.study.rest.event.PaginatedResultRetrievedEvent; import cz.cvut.kbss.study.rest.util.RestUtils; +import cz.cvut.kbss.study.service.ConfigReader; import cz.cvut.kbss.study.service.PatientRecordService; import cz.cvut.kbss.study.service.UserService; +import cz.cvut.kbss.study.util.ConfigParam; import cz.cvut.kbss.study.util.Constants; import cz.cvut.kbss.study.util.IdentificationUtils; import org.junit.jupiter.api.BeforeEach; @@ -65,6 +67,9 @@ public class PatientRecordControllerTest extends BaseControllerTestRunner { @Mock private ApplicationEventPublisher eventPublisherMock; + @Mock + private ConfigReader configReaderMock; + @Mock private UserService userService; @@ -487,4 +492,30 @@ void exportRecordsPublishesPagingEvent() throws Exception { final PaginatedResultRetrievedEvent event = captor.getValue(); assertEquals(page, event.getPage()); } + + @Test + void getAllowedRejectMessageTrue() throws Exception { + String expectedValue = "true"; + when(configReaderMock.getConfig(ConfigParam.RECORDS_ALLOWED_REJECT_MESSAGE)).thenReturn(expectedValue); + final MvcResult result = mockMvc.perform(get("/records/allowedRejectMessage").param("institution", user.getInstitution().toString())).andReturn(); + + final String body = objectMapper.readValue(result.getResponse().getContentAsString(), + new TypeReference<>() { + }); + assertEquals(result.getResponse().getStatus(), HttpStatus.OK.value()); + assertEquals(expectedValue, body); + } + + @Test + void getAllowedRejectMessageFalse() throws Exception { + String expectedValue = "false"; + when(configReaderMock.getConfig(ConfigParam.RECORDS_ALLOWED_REJECT_MESSAGE)).thenReturn(expectedValue); + final MvcResult result = mockMvc.perform(get("/records/allowedRejectMessage").param("institution", user.getInstitution().toString())).andReturn(); + + final String body = objectMapper.readValue(result.getResponse().getContentAsString(), + new TypeReference<>() { + }); + assertEquals(result.getResponse().getStatus(), HttpStatus.OK.value()); + assertEquals(expectedValue, body); + } }