DcImporterService implements ApplicationListener<ActeHistoryEvent> { public Optional<String> getAccessTokenForDataOwner() { Optional<LocalAuthority> localAuthority = localAuthorityService.getBySiren(dataOwnerSiren); if(localAuthority.isPresent()) return externalRestService.getAccessTokenFromKernel(localAuthority.get()); else { LOGGER.warn("[getAccessTokenForDataOwner] Not found local authority for configured dataOwnerSiren {}", dataOwnerSiren); return Optional.empty(); } } @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 getAccessTokenForDataOwner() { LocalAuthority localAuthority = new LocalAuthority(); ReflectionTestUtils.setField(localAuthority, "uuid", "uuid-local-authority-one-test"); given(localAuthorityService.getBySiren("123456789")).willReturn(Optional.of(localAuthority)); given(externalRestService.getAccessTokenFromKernel(any())).willReturn(Optional.of("access-token")); Optional<String> accessToken = dcImporterService.getAccessTokenForDataOwner(); Assert.assertTrue(accessToken.isPresent()); }