@Test public void testGetCommand_ReturnsResponseContainingCommandStateDtoOfSpecifiedJob() { // Setup Integer jobId = 1; CommandJob job = createCommandJob(jobId, createImportCommand(), new Date(1l)); CommandJobService mockCommandJobService = createMock(CommandJobService.class); expect(mockCommandJobService.getCommand(jobId)).andReturn(job).atLeastOnce(); WebShellResource sut = new WebShellResource(); sut.setCommandJobService(mockCommandJobService); replay(mockCommandJobService); // Exercise Response response = sut.getCommand(jobId); // Verify mocks verify(mockCommandJobService); // Verify that the HTTP response code was OK (200) and that the body contains // the CommandStateDto of the specified task. assertThat(response).isNotNull(); assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode()); assertThat(response.getEntity()).isNotNull(); assertThat(containsDtoForJob(response, job)).isTrue(); }
@Test public void testGetCommand_ReturnsNotFoundResponseIfJobDoesNotExist() { // Setup Integer bogusJobId = 1; CommandJobService mockCommandJobService = createMockCommandJobService(); expect(mockCommandJobService.getCommand(bogusJobId)).andReturn(null).atLeastOnce(); WebShellResource sut = new WebShellResource(); sut.setCommandJobService(mockCommandJobService); replay(mockCommandJobService); // Exercise Response response = sut.getCommand(bogusJobId); // Verify mocks verify(mockCommandJobService); // Verify that the HTTP response code was NOT FOUND (404). assertThat(response.getStatus()).isEqualTo(Response.Status.NOT_FOUND.getStatusCode()); }