Commit ea5b25de by Johannes Edmeier

Polish Application

parent 272633e1
......@@ -95,7 +95,7 @@ public class ApplicationRegistry implements ApplicationEventPublisherAware {
if (existing != null) {
return existing.getStatusInfo();
}
return null;
return StatusInfo.ofUnknown();
}
/**
......
......@@ -40,7 +40,7 @@ public class JournalControllerTest {
@Test
public void test_getJournal() {
ClientApplicationEvent emittedEvent = new ClientApplicationRegisteredEvent(
Application.create("foo").withId("bar").build());
Application.create("foo").withId("bar").withHealthUrl("http://health").build());
journal.onClientApplicationEvent(emittedEvent);
Collection<ClientApplicationEvent> history = controller.getJournal();
......@@ -54,7 +54,7 @@ public class JournalControllerTest {
@Test
public void test_getJournal_sse() {
ClientApplicationEvent emittedEvent = new ClientApplicationRegisteredEvent(
Application.create("foo").withId("bar").build());
Application.create("foo").withId("bar").withHealthUrl("http://health").build());
SseEmitter emitter = controller.getJournalEvents();
journal.onClientApplicationEvent(emittedEvent);
......
......@@ -35,7 +35,7 @@ public class ClientApplicationEventTest {
@Test
public void hashCode_equals() throws Exception {
ClientApplicationEvent event1 = new ClientApplicationRegisteredEvent(
Application.create("test").build());
Application.create("test").withHealthUrl("http://health").build());
ClientApplicationEvent event2 = cloneBySerialization(event1);
assertThat(event1.hashCode(), is(event2.hashCode()));
......@@ -45,9 +45,9 @@ public class ClientApplicationEventTest {
@Test
public void equals() throws Exception {
ClientApplicationEvent event1 = new ClientApplicationRegisteredEvent(
Application.create("test").build());
Application.create("test").withHealthUrl("http://health").build());
ClientApplicationEvent event2 = new ClientApplicationDeregisteredEvent(
Application.create("test").build());
Application.create("test").withHealthUrl("http://health").build());
assertThat(event1, not(is(event2)));
}
......
......@@ -35,7 +35,7 @@ public class ApplicationEventJournalTest {
@Test
public void test_registration() {
ClientApplicationEvent emittedEvent = new ClientApplicationRegisteredEvent(Application
.create("foo").withId("bar").build());
.create("foo").withId("bar").withHealthUrl("http://health").build());
journal.onClientApplicationEvent(emittedEvent);
Collection<ClientApplicationEvent> events = journal.getEvents();
......
......@@ -49,7 +49,8 @@ public class HazelcastJournaledEventStoreTest {
@Test
public void test_store() {
Application application = Application.create("foo").withId("bar").build();
Application application = Application.create("foo").withId("bar")
.withHealthUrl("http://health").build();
List<ClientApplicationEvent> events = Arrays.asList(
new ClientApplicationRegisteredEvent(application),
new ClientApplicationDeregisteredEvent(application));
......
......@@ -34,7 +34,8 @@ public class SimpleJournaledEventStoreTest {
@Test
public void test_store() {
SimpleJournaledEventStore store = new SimpleJournaledEventStore();
Application application = Application.create("foo").withId("bar").build();
Application application = Application.create("foo").withId("bar")
.withHealthUrl("http://health").build();
List<ClientApplicationEvent> events = Arrays.asList(
new ClientApplicationRegisteredEvent(application),
new ClientApplicationDeregisteredEvent(application));
......@@ -52,7 +53,8 @@ public class SimpleJournaledEventStoreTest {
SimpleJournaledEventStore store = new SimpleJournaledEventStore();
store.setCapacity(2);
Application application = Application.create("foo").withId("bar").build();
Application application = Application.create("foo").withId("bar")
.withHealthUrl("http://health").build();
List<ClientApplicationEvent> events = Arrays.asList(
new ClientApplicationRegisteredEvent(application),
new ClientApplicationDeregisteredEvent(application),
......
......@@ -36,32 +36,38 @@ public class Application implements Serializable {
private final String serviceUrl;
private final StatusInfo statusInfo;
protected Application(String healthUrl, String managementUrl, String serviceUrl, String name,
String id, StatusInfo statusInfo) {
this.healthUrl = healthUrl;
this.managementUrl = managementUrl;
this.serviceUrl = serviceUrl;
this.name = name;
this.id = id;
this.statusInfo = statusInfo != null ? statusInfo : StatusInfo.ofUnknown();
protected Application(Builder builder) {
Assert.hasText(builder.name, "name must not be empty!");
Assert.hasText(builder.healthUrl, "healthUrl must not be empty!");
Assert.notNull(builder.statusInfo, "statusInfo must not be null!");
this.healthUrl = builder.healthUrl;
this.managementUrl = builder.managementUrl;
this.serviceUrl = builder.serviceUrl;
this.name = builder.name;
this.id = builder.id;
this.statusInfo = builder.statusInfo;
}
@JsonCreator
public static Application create(@JsonProperty("url") String url,
public static Application fromJson(@JsonProperty("url") String url,
@JsonProperty("managementUrl") String managementUrl,
@JsonProperty("healthUrl") String healthUrl,
@JsonProperty("serviceUrl") String serviceUrl, @JsonProperty("name") String name,
@JsonProperty("id") String id, @JsonProperty("statusInfo") StatusInfo statusInfo) {
Assert.hasText(name, "name must not be empty!");
Builder builder = create(name).withId(id);
if (statusInfo != null) {
builder.withStatusInfo(statusInfo);
}
if (StringUtils.hasText(url)) {
// old format
return new Application(url.replaceFirst("/+$", "") + "/health", url, null, name, id,
statusInfo);
builder.withHealthUrl(url.replaceFirst("/+$", "") + "/health").withManagementUrl(url);
} else {
Assert.hasText(healthUrl, "healthUrl must not be empty!");
return new Application(healthUrl, managementUrl, serviceUrl, name, id, statusInfo);
builder.withHealthUrl(healthUrl).withManagementUrl(managementUrl)
.withServiceUrl(serviceUrl);
}
return builder.build();
}
public static Builder create(String name) {
......@@ -78,7 +84,7 @@ public class Application implements Serializable {
private String managementUrl;
private String healthUrl;
private String serviceUrl;
private StatusInfo statusInfo;
private StatusInfo statusInfo = StatusInfo.ofUnknown();
private Builder(String name) {
this.name = name;
......@@ -124,7 +130,7 @@ public class Application implements Serializable {
}
public Application build() {
return new Application(healthUrl, managementUrl, serviceUrl, name, id, statusInfo);
return new Application(this);
}
}
......@@ -154,8 +160,8 @@ public class Application implements Serializable {
@Override
public String toString() {
return "Application [id=" + id + ", name=" + name + ", managementUrl=" + managementUrl
+ ", healthUrl=" + healthUrl + ", serviceUrl=" + serviceUrl + "]";
return "Application [id=" + id + ", name=" + name + ", managementUrl="
+ managementUrl + ", healthUrl=" + healthUrl + ", serviceUrl=" + serviceUrl + "]";
}
@Override
......
......@@ -45,12 +45,12 @@ public class ApplicationTest {
@Test(expected = IllegalArgumentException.class)
public void test_name_expected() throws JsonProcessingException, IOException {
Application.create("http://url", "", "", "", "", null, null);
Application.fromJson("http://url", "", "", "", "", null, null);
}
@Test(expected = IllegalArgumentException.class)
public void test_healthUrl_expected() throws JsonProcessingException, IOException {
Application.create("", "", "", "", "name", null, null);
Application.fromJson("", "", "", "", "name", null, null);
}
@Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment