@Test public void test() { Application app = Application.create("Hazelcast Test").withHealthUrl("http://127.0.0.1/health").build(); Application app2 = Application.create("Hazelcast Test").withHealthUrl("http://127.0.0.1:2/health").build(); Application app3 = Application.create("Do not find").withHealthUrl("http://127.0.0.1:3/health").build(); // publish app on instance1 ResponseEntity<Application> postResponse = registerApp(app, instance1); app = postResponse.getBody(); assertEquals(HttpStatus.CREATED, postResponse.getStatusCode()); assertNotNull(app.getId()); // publish app2 on instance2 ResponseEntity<Application> postResponse2 = registerApp(app2, instance2); app2 = postResponse2.getBody(); assertEquals(HttpStatus.CREATED, postResponse.getStatusCode()); assertNotNull(app2.getId()); // retrieve app from instance2 ResponseEntity<Application> getResponse = getApp(app.getId(), instance2); assertEquals(HttpStatus.OK, getResponse.getStatusCode()); assertEquals(app, getResponse.getBody()); // retrieve app and app2 from instance1 (but not app3) app3 = registerApp(app3, instance1).getBody(); Collection<Application> apps = getAppByName("Hazelcast Test", instance1).getBody(); assertEquals(2, apps.size()); assertTrue(apps.contains(app)); assertTrue(apps.contains(app2)); assertFalse(apps.contains(app3)); }
@Test public void test_convert_with_defaults() { ServiceInstance service = new DefaultServiceInstance("test", "localhost", 80, false); 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:80")); assertThat(application.getHealthUrl(), is("http://localhost:80/health")); }
@Test public void test_convert_with_metadata() { ServiceInstance service = new DefaultServiceInstance("test", "localhost", 80, false); service.getMetadata().put("health.path", "ping"); service.getMetadata().put("management.context-path", "mgmt"); service.getMetadata().put("management.port", "1234"); 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")); }
@Test public void test_convert_with_custom_defaults() { DefaultServiceInstanceConverter converter = new DefaultServiceInstanceConverter(); converter.setHealthEndpointPath("ping"); converter.setManagementContextPath("mgmt"); ServiceInstance service = new DefaultServiceInstance("test", "localhost", 80, false); Application application = converter.convert(service); assertThat(application.getId(), nullValue()); assertThat(application.getName(), is("test")); assertThat(application.getServiceUrl(), is("http://localhost:80")); assertThat(application.getManagementUrl(), is("http://localhost:80/mgmt")); assertThat(application.getHealthUrl(), is("http://localhost:80/mgmt/ping")); }