RightsService { public List<String> getRights() { List<String> rights = new ArrayList<>(); modulesService.activeBusinessApplications().forEach(application -> { InstanceInfo instanceInfo = application.getInstances().get(0); String serviceName = modulesService.extractServiceName(application.getName()); try { String[] response = restTemplate.getForObject(this.buildRightsEndpointUrl(serviceName), String[].class); rights.addAll(Arrays.asList(Objects.requireNonNull(response))); } catch(RestClientException e) { LOGGER.warn("[getRights] An error occured in module {} : {}", application.getName(), e.getMessage()); } }); return rights; } @Autowired  RightsService(RestTemplateBuilder builder, ModulesService modulesService, DiscoveryUtils discoveryUtils); List<String> getRights();  }
@Test public void getRights() { InstanceInfo instanceInfoActe = this.instanceInfo("acte", "acte-service", "BUSINESS"); InstanceInfo instanceInfoPes = this.instanceInfo("pes", "pes-service", "BUSINESS"); InstanceInfo instanceInfoConvocation = this.instanceInfo("convocation", "convocation-service", "BUSINESS"); Application applicationActe = this.application(instanceInfoActe, "acte-service"); Application applicationPes = this.application(instanceInfoPes, "pes-service"); Application applicationConvocation = this.application(instanceInfoConvocation, "convocation-service"); List<Application> applications = new ArrayList<>(); applications.add(applicationActe); applications.add(applicationPes); applications.add(applicationConvocation); given(modulesService.activeBusinessApplications()).willReturn(applications); List<String> rights = rightsService.getRights(); Assert.assertEquals(6, rights.size()); }
@Test public void getRightsWithoutPESModuleInstance() { InstanceInfo instanceInfoActe = this.instanceInfo("acte", "acte-service", "BUSINESS"); InstanceInfo instanceInfoConvocation = this.instanceInfo("convocation", "convocation-service", "BUSINESS"); Application applicationActe = this.application(instanceInfoActe, "acte-service"); Application applicationConvocation = this.application(instanceInfoConvocation, "convocation-service"); List<Application> applications = new ArrayList<>(); applications.add(applicationActe); applications.add(applicationConvocation); given(modulesService.activeBusinessApplications()).willReturn(applications); List<String> rights = rightsService.getRights(); WireMock.verify(2, getRequestedFor(urlPathMatching("/api/(acte|convocation)/rights"))); Assert.assertEquals(5, rights.size()); }