@Test public void getAllWithSystemFragmentStringShouldReturnStaticSnitch() throws IOException { String serviceId = "fakeServiceId"; Mockito.when(discoveryClientMock.getServices()).thenReturn(Arrays.asList(serviceId)); Mockito.when(discoveryClientMock.getInstances(serviceId)).thenReturn(Arrays.asList(serviceInstanceMock)); Map<String, String> metadata = new HashMap<>(); final String fakeJsonThatWorks = "{ \"valid\" : true }"; final String url = "http: metadata.put(CereebroMetadata.KEY_SNITCH_SYSTEM_FRAGMENT_JSON, fakeJsonThatWorks); metadata.put(CereebroMetadata.KEY_SNITCH_URI, url); Mockito.when(serviceInstanceMock.getMetadata()).thenReturn(metadata); Mockito.when(serviceInstanceMock.getInstanceInfo()).thenReturn(instanceInfoMock); Mockito.when(objectMapperMock.readValue(fakeJsonThatWorks, SystemFragment.class)) .thenReturn(SystemFragment.empty()); List<Snitch> result = registry.getAll(); Assertions.assertThat(result.size()).isEqualTo(1); Snitch snitch = result.get(0); Assertions.assertThat(snitch).isInstanceOf(ServiceInstanceSnitch.class); Assertions.assertThat(URI.create("http: }
@Override public List<Snitch> getAll() { return discoveryClient.getServices().stream() .map(discoveryClient::getInstances) .flatMap(List::stream) .map(instance -> new ServiceInstanceSnitch(objectMapper, instance)) .collect(Collectors.toList()); }
DiscoveryClientSnitchRegistry implements SnitchRegistry { @Override public List<Snitch> getAll() { return discoveryClient.getServices().stream() .map(discoveryClient::getInstances) .flatMap(List::stream) .map(instance -> new ServiceInstanceSnitch(objectMapper, instance)) .collect(Collectors.toList()); } }
DiscoveryClientSnitchRegistry implements SnitchRegistry { @Override public List<Snitch> getAll() { return discoveryClient.getServices().stream() .map(discoveryClient::getInstances) .flatMap(List::stream) .map(instance -> new ServiceInstanceSnitch(objectMapper, instance)) .collect(Collectors.toList()); } DiscoveryClientSnitchRegistry(DiscoveryClient discoveryClient, ObjectMapper mapper); }
DiscoveryClientSnitchRegistry implements SnitchRegistry { @Override public List<Snitch> getAll() { return discoveryClient.getServices().stream() .map(discoveryClient::getInstances) .flatMap(List::stream) .map(instance -> new ServiceInstanceSnitch(objectMapper, instance)) .collect(Collectors.toList()); } DiscoveryClientSnitchRegistry(DiscoveryClient discoveryClient, ObjectMapper mapper); @Override List<Snitch> getAll(); }
DiscoveryClientSnitchRegistry implements SnitchRegistry { @Override public List<Snitch> getAll() { return discoveryClient.getServices().stream() .map(discoveryClient::getInstances) .flatMap(List::stream) .map(instance -> new ServiceInstanceSnitch(objectMapper, instance)) .collect(Collectors.toList()); } DiscoveryClientSnitchRegistry(DiscoveryClient discoveryClient, ObjectMapper mapper); @Override List<Snitch> getAll();  }