Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RunWith(SpringRunner.class)
- @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
- public class Vezba_A_ExamControllerTest {
- @MockBean
- private ExamService mExamService;
- private static final Long EXAM_ID = 1l;
- private static final String STUDENT_ID = "sw61-2018";
- @Autowired
- private TestRestTemplate testRestTemplate;
- @Test
- public void applyForExam_ExamNotFoundException_404_NotFound() throws Exception {
- Mockito.when(mExamService.examApplication(STUDENT_ID, EXAM_ID)).thenThrow(ExamNotFoundException.class);
- String url = "/exams/" + EXAM_ID + "?identificationNumber=" + STUDENT_ID;
- ResponseEntity<ExamNotFoundException> responseEntity = testRestTemplate.getForEntity(url, ExamNotFoundException.class);
- assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
- assertNotNull(responseEntity.getBody());
- }
- @Test
- public void applyForExam_StudentNotFoundException_404_NotFound() throws Exception {
- Mockito.when(mExamService.examApplication(STUDENT_ID, EXAM_ID)).thenThrow(StudentNotFoundException.class);
- String url = "/exams/" + EXAM_ID + "?identificationNumber=" + STUDENT_ID;
- ResponseEntity<StudentNotFoundException> responseEntity = testRestTemplate.getForEntity(url, StudentNotFoundException.class);
- assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
- assertNotNull(responseEntity.getBody());
- }
- @Test
- public void applyForExam_InvalidDate_400_BadRequest() throws Exception {
- Mockito.when(mExamService.examApplication(STUDENT_ID, EXAM_ID)).thenReturn(false);
- String url = "/exams/" + EXAM_ID + "?identificationNumber=" + STUDENT_ID;
- ResponseEntity<Boolean> responseEntity = testRestTemplate.getForEntity(url, Boolean.class);
- assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
- assertNotNull(responseEntity.getBody());
- assertFalse(responseEntity.getBody());
- }
- @Test
- public void applyForExam_200_OK() throws Exception {
- Mockito.when(mExamService.examApplication(STUDENT_ID, EXAM_ID)).thenReturn(true);
- String url = "/exams/" + EXAM_ID + "?identificationNumber=" + STUDENT_ID;
- ResponseEntity<Boolean> responseEntity = testRestTemplate.getForEntity(url, Boolean.class);
- assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
- assertNotNull(responseEntity.getBody());
- assertTrue(responseEntity.getBody());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement