CentreRegistryProvidersService implements EndpointProvidersService { protected List<EndpointProvider> parseEndpoints() throws IOException { final URL url = new URL(endpointsJsonUrl); try (InputStream is = url.openStream()) { final JSONTokener tokener = new JSONTokener(is); final JSONArray jsonArray = new JSONArray(tokener); final Map<Integer, List<EndpointProvider>> groupedByCentre = jsonArrayToObjectStream(jsonArray) .map(o -> o.getJSONObject("fields")) .map(o -> new EndpointProvider() .setKey(o.getInt("centre")) .setEndpointUrl(Lists.newArrayList(o.getString("uri")))) .collect(Collectors.groupingBy(EndpointProvider::getCentreKey)); return groupedByCentre.entrySet().stream() .map(set -> { return set.getValue().get(0) .setEndpointUrl( set.getValue().stream() .flatMap(e -> e.getEndpointUrls().stream()) .collect(Collectors.toList()) ); }) .collect(Collectors.toList()); } } CentreRegistryProvidersService(VloConfig vloConfig);  CentreRegistryProvidersService(String centresJsonUrl, String endpointsJsonUrl); @Override List<EndpointProvider> retrieveCentreEndpoints();  }
@Test public void testParseEndpoints() throws Exception { List<EndpointProvider> providers = instance.parseEndpoints(); assertNotNull(providers); assertEquals(39, providers.size()); providers.forEach(provider -> { assertNotNull(provider.getCentreKey()); assertNotNull(provider.getEndpointUrls()); }); assertTrue( providers.stream() .filter(provider -> provider.getCentreKey().equals(45) && provider.getEndpointUrls().size() == 1) .findAny() .isPresent()); }