// 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)); }
void submitProposedConcept(final ProposedConceptPackage conceptPackage) { checkNotNull(submissionRestTemplate); // // Could not figure out how to get Spring to send a basic authentication request using the // "proper" object approach // see: https://github.com/johnsyweb/openmrs-cpm/wiki/Gotchas // AdministrationService service = Context.getAdministrationService(); SubmissionDto submission = submissionDtoFactory.create(conceptPackage); HttpHeaders headers = httpHeaderFactory.create( service.getGlobalProperty(CpmConstants.SETTINGS_USER_NAME_PROPERTY), service.getGlobalProperty(CpmConstants.SETTINGS_PASSWORD_PROPERTY)); // headers = createHeaders(service.getGlobalProperty(CpmConstants.SETTINGS_USER_NAME_PROPERTY), // service.getGlobalProperty(CpmConstants.SETTINGS_PASSWORD_PROPERTY)); final HttpEntity requestEntity = new HttpEntity<SubmissionDto>(submission, headers); final String url = service.getGlobalProperty(CpmConstants.SETTINGS_URL_PROPERTY) + "/ws/cpm/dictionarymanager/proposals"; ResponseEntity responseEntity = submissionRestTemplate.exchange( url, HttpMethod.POST, requestEntity, SubmissionResponseDto.class); // final SubmissionResponseDto result = // submissionRestTemplate.postForObject("http://localhost:8080/openmrs/ws/cpm/dictionarymanager/proposals", submission, SubmissionResponseDto.class); // // TODO: Find out how to determine success/failure for the submission returned by // dictionarymanagercontroller if (responseEntity == null || !responseEntity.getStatusCode().equals(HttpStatus.SC_OK)) { // throw new ConceptProposalSubmissionException("Error in submitting proposed // concept"); log.error("REsponseEntity status code is " + responseEntity.getStatusCode()); } conceptPackage.setStatus(PackageStatus.SUBMITTED); Context.getService(ProposedConceptService.class).saveProposedConceptPackage(conceptPackage); }