LocalesService { public String getJsonTranslation(String module, String lng, String ns) { if (module.equals("api-gateway")) { return LocalFileUtils.getLocalFile(String.join("/","public/locales",lng, ns.concat(".json"))); } if(modulesService.moduleHaveInstance(module)) { try { return Objects.requireNonNull(restTemplate.getForObject(this.buildLocalesEndpointUrl(module, lng, ns), String.class)); } catch (RestClientException e) { LOGGER.warn("[getJsonTranslation] An error occured in module {} : {}", module, e.getMessage()); } } else { LOGGER.warn("Module {} not have instance", module); } return ""; } LocalesService(RestTemplateBuilder builder, DiscoveryUtils discoveryUtils, ModulesService modulesService); String getJsonTranslation(String module, String lng, String ns);  }
@Test public void getApiGatewayJsonTranslation() { String jsonTranslation = localesService.getJsonTranslation("api-gateway", "fr", "api-gateway"); verifyZeroInteractions(discoveryUtils); verifyZeroInteractions(modulesService); assertThat(jsonTranslation, notNullValue()); }
@Test public void getExternalModuleJsonTranslation() { stubFor(get(urlPathMatching("/api/pes/locales/fr/pes.json")) .willReturn(ok("{ \"field\": \"value\" }") .withHeader("Content-Type", "application/json"))); given(modulesService.moduleHaveInstance(matches("pes"))).willReturn(true); given(discoveryUtils.getServiceUrlByName(matches("pes"))).willReturn("http: String jsonTranslation = localesService.getJsonTranslation("pes", "fr", "pes"); assertEquals(jsonTranslation, "{ \"field\": \"value\" }"); }