1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package de.codecentric.boot.admin.model;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import java.io.IOException;
import org.junit.Test;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class ApplicationTest {
private ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
@Test
public void test_old_json_format() throws JsonProcessingException, IOException {
String json = "{ \"name\" : \"test\", \"url\" : \"http://test\" }";
Application value = objectMapper.readValue(json, Application.class);
assertThat(value.getId(), nullValue());
assertThat(value.getName(), is("test"));
assertThat(value.getManagementUrl(), is("http://test"));
assertThat(value.getHealthUrl(), is("http://test/health"));
assertThat(value.getServiceUrl(), nullValue());
}
@Test
public void test_new_json_format() throws JsonProcessingException, IOException {
String json = "{ \"name\" : \"test\", \"managementUrl\" : \"http://test\" , \"healthUrl\" : \"http://health\" , \"serviceUrl\" : \"http://service\"}";
Application value = objectMapper.readValue(json, Application.class);
assertThat(value.getId(), nullValue());
assertThat(value.getName(), is("test"));
assertThat(value.getManagementUrl(), is("http://test"));
assertThat(value.getHealthUrl(), is("http://health"));
assertThat(value.getServiceUrl(), is("http://service"));
}
@Test(expected = IllegalArgumentException.class)
public void test_name_expected() throws JsonProcessingException, IOException {
Application.create("http://url", "", "", "", "", null, null);
}
@Test(expected = IllegalArgumentException.class)
public void test_healthUrl_expected() throws JsonProcessingException, IOException {
Application.create("", "", "", "", "name", null, null);
}
@Test
public void test_equals_hashCode() {
Application a1 = Application.create("foo").withHealthUrl("healthUrl")
.withManagementUrl("mgmt").withServiceUrl("svc").withId("id").build();
Application a2 = Application.create("foo").withHealthUrl("healthUrl")
.withManagementUrl("mgmt").withServiceUrl("svc").withId("id").build();
assertThat(a1, is(a2));
assertThat(a1.hashCode(), is(a2.hashCode()));
Application a3 = Application.create("foo").withHealthUrl("healthUrl2")
.withManagementUrl("mgmt").withServiceUrl("svc").withId("other").build();
assertThat(a1, not(is(a3)));
assertThat(a2, not(is(a3)));
}
@Test
public void test_builder_copy() {
Application app = Application.create("App").withId("-id-").withHealthUrl("http://health")
.withManagementUrl("http://mgmgt").withServiceUrl("http://svc")
.withStatusInfo(StatusInfo.ofUp()).build();
Application copy = Application.create(app).build();
assertThat(app, is(copy));
}
}