// Can't get this to work... again the annoying "HttpMediaTypeNotSupportedException: Content type // 'application/json' not supported" @Test @Ignore public void updateProposal_UpdatedPackageIsToBeSubmittedWhileExistingIsDraft_ShouldMakeRestCallAndPersistWithStatusSubmitted() throws Exception { final ProposedConceptPackage proposedConcept = new ProposedConceptPackage(); proposedConcept.setStatus(PackageStatus.DRAFT); final ProposedConceptService cpServiceMock = mock(ProposedConceptService.class); when(cpServiceMock.getProposedConceptPackageById(1)).thenReturn(proposedConcept); mockStatic(Context.class); when(Context.getService(ProposedConceptService.class)).thenReturn(cpServiceMock); final RestOperations restOperationsMock = mock(RestOperations.class); ReflectionTestUtils.setField( controller.getSubmitProposal(), "submissionRestTemplate", restOperationsMock); request = new MockHttpServletRequest("PUT", "/cpm/proposals/1"); request.addHeader("Accept", "application/json"); request.addHeader("Content-Type", "application/json"); final String payload = "{\"name\":\"test\",\"description\":\"test\",\"email\":\"[email protected]\",\"concepts\":[]}"; request.setContent(payload.getBytes()); adapter.handle(request, response, controller); verify(restOperationsMock) .postForObject( "http://localhost:8080/openmrs/ws/cpm/dictionarymanager/proposals", new SubmissionDto(), SubmissionResponseDto.class); assertThat(proposedConcept.getStatus(), equalTo(PackageStatus.SUBMITTED)); }
@Test public void testCreateConceptForm() throws Exception { request = new MockHttpServletRequest("GET", "/module/cpm/proposals.list"); final ModelAndView handle = adapter.handle(request, response, controller); assertEquals("/module/cpm/proposals", handle.getViewName()); assertEquals(200, response.getStatus()); }
/** * Passes the given request to a proper controller. * * @param request * @return * @throws Exception */ public MockHttpServletResponse handle(HttpServletRequest request) throws Exception { MockHttpServletResponse response = new MockHttpServletResponse(); HandlerExecutionChain handlerExecutionChain = null; for (DefaultAnnotationHandlerMapping handlerMapping : handlerMappings) { handlerExecutionChain = handlerMapping.getHandler(request); if (handlerExecutionChain != null) { break; } } Assert.assertNotNull("The request URI does not exist", handlerExecutionChain); handlerAdapter.handle(request, response, handlerExecutionChain.getHandler()); return response; }
/** * I couldn't figure out how to get the HttpMessageConverter to serialise the response so for now * just expecting the seralisation exception */ @Test public void testMonitorProposalsList() throws Exception { exception.expect(HttpMediaTypeNotAcceptableException.class); final List<ProposedConceptPackage> packageList = new ArrayList<ProposedConceptPackage>(); final ProposedConceptService cpServiceMock = mock(ProposedConceptService.class); when(cpServiceMock.getAllProposedConceptPackages()).thenReturn(packageList); mockStatic(Context.class); when(Context.getService(ProposedConceptService.class)).thenReturn(cpServiceMock); request = new MockHttpServletRequest("GET", "/cpm/proposals"); request.addHeader("Accept", "application/json"); request.addHeader("Content-Type", "application/json"); final ModelAndView handle = adapter.handle(request, response, controller); // assertEquals("/module/cpm/monitor", handle.getViewName()); // assertEquals(200, response.getStatus()); }