Skip to content

Commit

Permalink
[#205] Implement getAllowedRejectMessage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan authored and blcham committed Nov 6, 2024
1 parent a38040b commit 55bac0c
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,6 +67,9 @@ public class PatientRecordControllerTest extends BaseControllerTestRunner {
@Mock
private ApplicationEventPublisher eventPublisherMock;

@Mock
private ConfigReader configReaderMock;

@Mock
private UserService userService;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 55bac0c

Please sign in to comment.