DcImporterService implements ApplicationListener<ActeHistoryEvent> { public ResponseEntity<?> newResource(String type, String project, Map<String, Object> properties, String accessToken) throws RestClientResponseException { HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType()); headers.add(HttpHeaders.AUTHORIZATION, "Bearer ".concat(accessToken)); headers.add("X-Datacore-Project", project); return restTemplate.postForEntity(dcImporterUrl.concat("/dc/type/{type}"), new HttpEntity<>(properties, headers), String.class, type); } @Autowired  DcImporterService(ExternalRestService externalRestService, LocalAuthorityService localAuthorityService, RestTemplate restTemplate, ActeService acteService); ResponseEntity<?> newResource(String type, String project, Map<String, Object> properties, String accessToken); Optional<String> getAccessTokenForDataOwner(); void sendPublicActeToDcImporter(Acte acte); @Override void onApplicationEvent(@NotNull ActeHistoryEvent event);  }
@Test public void newResource() { stubFor(post(urlPathEqualTo("/dc/type/legal:type_0")).willReturn(created())); ResponseEntity responseEntity = dcImporterService.newResource("legal:type_0", "test_0", this.resourceProperties(), "access-token-test"); WireMock.verify(postRequestedFor(urlPathEqualTo("/dc/type/legal:type_0")) .withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer access-token-test")) .withHeader(HttpHeaders.CONTENT_TYPE, equalTo(ContentType.APPLICATION_JSON.getMimeType())) .withHeader("X-Datacore-Project", equalTo("test_0")) .withRequestBody(equalToJson(this.resourceRequestBody()))); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.CREATED); }
@Test(expected = RestClientResponseException.class) public void newResourceThrowsException() { stubFor(post(urlPathEqualTo("/dc/type/legal:type_0")).willReturn(badRequest())); dcImporterService.newResource("legal:type_0", "test_0", this.resourceProperties(), "access-token-test"); WireMock.verify(postRequestedFor(urlPathEqualTo("/dc/type/legal:type_0")) .withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer access-token-test")) .withHeader(HttpHeaders.CONTENT_TYPE, equalTo(ContentType.APPLICATION_JSON.getMimeType())) .withHeader("X-Datacore-Project", equalTo("test_0")) .withRequestBody(equalToJson(this.resourceRequestBody()))); }