Search in sources :

Example 11 with DefaultServiceInstance

use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.

the class ApplicationDiscoveryListenerTest method test_matching_pattern.

@Test
public void test_matching_pattern() {
    when(discovery.getServices()).thenReturn(asList("service", "rabbit-1", "rabbit-2"));
    when(discovery.getInstances("service")).thenReturn(Collections.singletonList((ServiceInstance) new DefaultServiceInstance("service", "localhost", 80, false)));
    listener.setServices(singleton("ser*"));
    listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));
    Collection<Application> applications = registry.getApplications();
    assertEquals(1, applications.size());
    assertEquals("service", applications.iterator().next().getName());
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 12 with DefaultServiceInstance

use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.

the class ApplicationDiscoveryListenerTest method test_matching.

@Test
public void test_matching() {
    when(discovery.getServices()).thenReturn(Collections.singletonList("service"));
    when(discovery.getInstances("service")).thenReturn(Collections.singletonList((ServiceInstance) new DefaultServiceInstance("service", "localhost", 80, false)));
    listener.setServices(singleton("notService"));
    listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));
    assertEquals(0, registry.getApplications().size());
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Test(org.junit.Test)

Example 13 with DefaultServiceInstance

use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.

the class DefaultServiceInstanceConverterTest method test_convert_with_metadata.

@Test
public void test_convert_with_metadata() {
    ServiceInstance service = new DefaultServiceInstance("test", "localhost", 80, false);
    Map<String, String> metadata = new HashMap<>();
    metadata.put("health.path", "ping");
    metadata.put("management.context-path", "mgmt");
    metadata.put("management.port", "1234");
    service.getMetadata().putAll(metadata);
    Application application = new DefaultServiceInstanceConverter().convert(service);
    assertThat(application.getId(), nullValue());
    assertThat(application.getName(), is("test"));
    assertThat(application.getServiceUrl(), is("http://localhost:80"));
    assertThat(application.getManagementUrl(), is("http://localhost:1234/mgmt"));
    assertThat(application.getHealthUrl(), is("http://localhost:1234/mgmt/ping"));
    assertThat(application.getMetadata(), is(metadata));
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) HashMap(java.util.HashMap) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Aggregations

DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)13 Test (org.junit.Test)12 ServiceInstance (org.springframework.cloud.client.ServiceInstance)12 Application (de.codecentric.boot.admin.model.Application)7 ArrayList (java.util.ArrayList)2 HeartbeatEvent (org.springframework.cloud.client.discovery.event.HeartbeatEvent)2 ParentHeartbeatEvent (org.springframework.cloud.client.discovery.event.ParentHeartbeatEvent)2 URIEndpointObject (io.servicecomb.foundation.common.net.URIEndpointObject)1 MicroserviceInstance (io.servicecomb.serviceregistry.api.registry.MicroserviceInstance)1 ServiceRegistryClient (io.servicecomb.serviceregistry.client.ServiceRegistryClient)1 HashMap (java.util.HashMap)1 DiscoveryClient (org.springframework.cloud.client.discovery.DiscoveryClient)1 NoopDiscoveryClient (org.springframework.cloud.client.discovery.noop.NoopDiscoveryClient)1 Route (org.springframework.cloud.netflix.zuul.filters.Route)1 ZuulProperties (org.springframework.cloud.netflix.zuul.filters.ZuulProperties)1 ZuulRoute (org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute)1