Пример #1
0
  @Test
  public void testScheme() {
    UriSpec spec = new UriSpec("{scheme}://foo.com");

    ServiceInstanceBuilder<Void> builder = new ServiceInstanceBuilder<Void>();
    builder.id("x");
    builder.name("foo");
    builder.port(5);
    ServiceInstance<Void> instance = builder.build();
    Assert.assertEquals(spec.build(instance), "http://foo.com");

    builder.sslPort(5);
    instance = builder.build();
    Assert.assertEquals(spec.build(instance), "https://foo.com");
  }
Пример #2
0
  @Test
  public void testFromInstance() {
    ServiceInstanceBuilder<Void> builder = new ServiceInstanceBuilder<Void>();
    builder.address("1.2.3.4");
    builder.name("foo");
    builder.id("bar");
    builder.port(5);
    builder.sslPort(6);
    builder.registrationTimeUTC(789);
    builder.serviceType(ServiceType.PERMANENT);
    ServiceInstance<Void> instance = builder.build();

    UriSpec spec =
        new UriSpec(
            "{scheme}://{address}:{port}:{ssl-port}/{name}/{id}/{registration-time-utc}/{service-type}");

    Map<String, Object> m = Maps.newHashMap();
    m.put("scheme", "test");
    Assert.assertEquals(spec.build(instance, m), "test://1.2.3.4:5:6/foo/bar/789/permanent");
  }