Commit a99a889a by Johannes Edmeier

Detangle server from client

With this commits the server no longer depends on the client. The classes for the clients are moved to de.codecentric.boot.admin.client package. Since the perspective on applications is totally different from client and server the model has been split apart. What means this for users: 1) The client is no longer a transitive dependency for your admin server you may need to add it explicitly to your dependencies, respectively jolokia-core in case you're using discovery and want to use the jmx-bean interface 2)In case you have cutomised parts of the client you need to reflect the package change. fixes #332
parent 98f6bbd1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-samples</artifactId>
<version>1.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>spring-boot-admin-sample-consul</artifactId>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>de.codecentric.boot.admin.SpringBootAdminApplication</mainClass>
<addResources>false</addResources>
</configuration>
</plugin>
</plugins>
</build>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-samples</artifactId>
<version>1.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>spring-boot-admin-sample-consul</artifactId>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>de.codecentric.boot.admin.SpringBootAdminApplication</mainClass>
<addResources>false</addResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
......@@ -35,6 +35,10 @@
<artifactId>spring-boot-admin-server-ui-turbine</artifactId>
</dependency>
<!-- end::dependency-ui-turbine[] -->
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
......
......@@ -17,6 +17,10 @@
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<!-- tag::dependency-hazelcast[] -->
<dependency>
<groupId>com.hazelcast</groupId>
......
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-admin-sample-war</artifactId>
<packaging>war</packaging>
<parent>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-samples</artifactId>
<version>1.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
</execution>
</executions>
<configuration>
<addResources>false</addResources>
</configuration>
</plugin>
</plugins>
</build>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-admin-sample-war</artifactId>
<packaging>war</packaging>
<parent>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-samples</artifactId>
<version>1.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
</execution>
</executions>
<configuration>
<addResources>false</addResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
......@@ -21,6 +21,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
......
......@@ -17,6 +17,10 @@
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
......
......@@ -9,13 +9,13 @@
</parent>
<artifactId>spring-boot-admin-server</artifactId>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
......
......@@ -52,13 +52,9 @@ public class Application implements Serializable {
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) {
@JsonProperty("serviceUrl") String serviceUrl, @JsonProperty("name") String name) {
Builder builder = create(name).withId(id);
if (statusInfo != null) {
builder.withStatusInfo(statusInfo);
}
Builder builder = create(name);
if (StringUtils.hasText(url)) {
// old format
......
......@@ -2,9 +2,6 @@ package de.codecentric.boot.admin.model;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Represents a certain status a certain time.
*
......@@ -25,12 +22,6 @@ public class StatusInfo implements Serializable {
return new StatusInfo(statusCode, System.currentTimeMillis());
}
@JsonCreator
public static StatusInfo valueOf(@JsonProperty("status") String statusCode,
@JsonProperty("timestamp") long timestamp) {
return new StatusInfo(statusCode, timestamp);
}
public static StatusInfo ofUnknown() {
return valueOf("UNKNOWN");
}
......
......@@ -20,9 +20,11 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.After;
import org.junit.Before;
......@@ -42,7 +44,6 @@ import com.hazelcast.config.ListConfig;
import com.hazelcast.config.MapConfig;
import de.codecentric.boot.admin.config.EnableAdminServer;
import de.codecentric.boot.admin.model.Application;
/**
* Integration test to verify the correct functionality of the REST API with Hazelcast
......@@ -73,61 +74,75 @@ public class AdminApplicationHazelcastTest {
@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();
ResponseEntity<Map<String, String>> postResponse = registerApp("Hazelcast Test",
"http://127.0.0.1/health", instance1);
Map<String, String> app = postResponse.getBody();
assertEquals(HttpStatus.CREATED, postResponse.getStatusCode());
assertNotNull(app.getId());
assertNotNull(app.get("id"));
// publish app2 on instance2
ResponseEntity<Application> postResponse2 = registerApp(app2, instance2);
app2 = postResponse2.getBody();
ResponseEntity<Map<String, String>> postResponse2 = registerApp("Hazelcast Test",
"http://127.0.0.2/health", instance2);
Map<String, String> app2 = postResponse2.getBody();
assertEquals(HttpStatus.CREATED, postResponse.getStatusCode());
assertNotNull(app2.getId());
assertNotNull(app2.get("id"));
// retrieve app from instance2
ResponseEntity<Application> getResponse = getApp(app.getId(), instance2);
ResponseEntity<Map<String, String>> getResponse = getApp(app.get("id"), instance2);
assertEquals(HttpStatus.OK, getResponse.getStatusCode());
assertEquals(app, getResponse.getBody());
assertEquals(app.get("id"), getResponse.getBody().get("id"));
// retrieve app and app2 from instance1 (but not app3)
app3 = registerApp(app3, instance1).getBody();
Collection<Application> apps = getAppByName("Hazelcast Test", instance1).getBody();
Map<String, String> app3 = registerApp("Do not find", "http://127.0.0.1:3/health",
instance1).getBody();
Collection<Map<String, String>> apps = getAppByName("Hazelcast Test", instance1).getBody();
assertEquals(2, apps.size());
assertTrue(apps.contains(app));
assertTrue(apps.contains(app2));
assertFalse(apps.contains(app3));
assertTrue(containsApp(apps, app.get("id")));
assertTrue(containsApp(apps, app2.get("id")));
assertFalse(containsApp(apps, app3.get("id")));
}
private boolean containsApp(Collection<Map<String, String>> apps, String id) {
for (Map<String, String> app : apps) {
if (app.get("id").equals(id)) {
return true;
}
}
return false;
}
private ResponseEntity<Application> getApp(String id, EmbeddedWebApplicationContext context) {
private ResponseEntity<Map<String, String>> getApp(String id,
EmbeddedWebApplicationContext context) {
int port = context.getEmbeddedServletContainer().getPort();
ResponseEntity<Application> getResponse = template.getForEntity(
"http://localhost:" + port + "/api/applications/" + id, Application.class);
return getResponse;
@SuppressWarnings("unchecked")
ResponseEntity<Map<String, String>> response = template.getForEntity(
"http://localhost:" + port + "/api/applications/" + id,
(Class<Map<String, String>>) (Class<?>) Map.class);
return response;
}
private ResponseEntity<Application> registerApp(Application app,
private ResponseEntity<Map<String, String>> registerApp(String name, String healthUrl,
EmbeddedWebApplicationContext context) {
Map<String, String> app = new HashMap<>();
app.put("name", name);
app.put("healthUrl", healthUrl);
int port = context.getEmbeddedServletContainer().getPort();
return template.postForEntity("http://localhost:" + port + "/api/applications", app,
Application.class);
@SuppressWarnings("unchecked")
ResponseEntity<Map<String, String>> responseEntity = template.postForEntity(
"http://localhost:" + port + "/api/applications", app,
(Class<Map<String, String>>) (Class<?>) Map.class);
return responseEntity;
}
@SuppressWarnings("unchecked")
private ResponseEntity<Collection<Application>> getAppByName(String name,
private ResponseEntity<Collection<Map<String, String>>> getAppByName(String name,
EmbeddedWebApplicationContext context) {
int port = context.getEmbeddedServletContainer().getPort();
ResponseEntity<?> getResponse = template.getForEntity(
"http://localhost:" + port + "/api/applications?name={name}", ApplicationList.class,
ResponseEntity<?> response = template.getForEntity(
"http://localhost:" + port + "/api/applications?name={name}", List.class,
Collections.singletonMap("name", name));
return (ResponseEntity<Collection<Application>>) getResponse;
return (ResponseEntity<Collection<Map<String, String>>>) response;
}
@Configuration
......@@ -144,9 +159,4 @@ public class AdminApplicationHazelcastTest {
}
}
public static class ApplicationList extends ArrayList<Application> {
private static final long serialVersionUID = 1L;
// needed for JSON deserialization
}
}
......@@ -17,6 +17,7 @@ package de.codecentric.boot.admin;
import static org.junit.Assert.assertEquals;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -34,7 +35,6 @@ import org.springframework.test.context.junit4.SpringRunner;
import de.codecentric.boot.admin.AdminApplicationTest.TestAdminApplication;
import de.codecentric.boot.admin.config.EnableAdminServer;
import de.codecentric.boot.admin.model.Application;
/**
* Integration test to verify the correct functionality of the REST API.
......@@ -61,26 +61,30 @@ public class AdminApplicationTest {
public void testReverseProxy() {
String apiBaseUrl = "http://localhost:" + port + "/api/applications";
Application application = Application.create("TestApp")
.withHealthUrl("http://localhost:" + port + "/health")
.withManagementUrl("http://localhost:" + port).build();
ResponseEntity<Application> entity = new TestRestTemplate().postForEntity(apiBaseUrl,
application, Application.class);
Map<String, String> application = new HashMap<>();
application.put("name", "TestApp");
application.put("managementUrl", "http://localhost:" + port);
application.put("serviceUrl", "http://localhost:" + port);
application.put("healthUrl", "http://localhost:" + port + "/health");
@SuppressWarnings("unchecked")
ResponseEntity<Map<String, String>> entity = new TestRestTemplate().postForEntity(
apiBaseUrl, application, (Class<Map<String, String>>) (Class<?>) Map.class);
@SuppressWarnings("rawtypes")
ResponseEntity<Map> app = new TestRestTemplate()
.getForEntity(apiBaseUrl + "/" + entity.getBody().getId(), Map.class);
.getForEntity(apiBaseUrl + "/" + entity.getBody().get("id"), Map.class);
assertEquals(HttpStatus.OK, app.getStatusCode());
assertEquals("TestApp", app.getBody().get("name"));
@SuppressWarnings("rawtypes")
ResponseEntity<Map> info = new TestRestTemplate()
.getForEntity(apiBaseUrl + "/" + entity.getBody().getId() + "/info", Map.class);
.getForEntity(apiBaseUrl + "/" + entity.getBody().get("id") + "/info", Map.class);
assertEquals(HttpStatus.OK, info.getStatusCode());
@SuppressWarnings("rawtypes")
ResponseEntity<Map> health = new TestRestTemplate()
.getForEntity(apiBaseUrl + "/" + entity.getBody().getId() + "/health", Map.class);
.getForEntity(apiBaseUrl + "/" + entity.getBody().get("id") + "/health", Map.class);
assertEquals(HttpStatus.OK, health.getStatusCode());
}
......
......@@ -23,7 +23,6 @@ public class ApplicationTest {
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"));
......@@ -36,7 +35,6 @@ public class ApplicationTest {
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"));
......@@ -45,12 +43,12 @@ public class ApplicationTest {
@Test(expected = IllegalArgumentException.class)
public void test_name_expected() throws JsonProcessingException, IOException {
Application.fromJson("http://url", "", "", "", "", null, null);
Application.fromJson("http://url", "", "", "", null);
}
@Test(expected = IllegalArgumentException.class)
public void test_healthUrl_expected() throws JsonProcessingException, IOException {
Application.fromJson("", "", "", "", "name", null, null);
Application.fromJson("", "", "", "name", null);
}
@Test
......@@ -78,4 +76,4 @@ public class ApplicationTest {
Application copy = Application.create(app).build();
assertThat(app, is(copy));
}
}
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ public class StatusInfoTest {
@Test
public void test_equals_hashcode() {
StatusInfo up = StatusInfo.ofUp();
StatusInfo up2 = StatusInfo.valueOf("UP", 0L);
StatusInfo up2 = StatusInfo.valueOf("UP");
StatusInfo down = StatusInfo.valueOf("DOWN");
assertThat(up, is(up2));
......@@ -19,4 +19,4 @@ public class StatusInfoTest {
assertThat(up.hashCode(), is(up2.hashCode()));
}
}
}
\ No newline at end of file
......@@ -123,7 +123,7 @@ public class StatusUpdaterTest {
store.save(app1);
Application app2 = Application.create("foo").withId("id-2").withHealthUrl("health-2")
.withStatusInfo(StatusInfo.valueOf("UP", 0L)).build();
.withStatusInfo(StatusInfo.valueOf("UP")).build();
store.save(app2);
when(template.getForEntity("health-2", Map.class))
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.config;
package de.codecentric.boot.admin.client.config;
import static org.springframework.util.StringUtils.trimLeadingCharacter;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.config;
package de.codecentric.boot.admin.client.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.config;
package de.codecentric.boot.admin.client.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
......@@ -28,8 +28,8 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import de.codecentric.boot.admin.services.ApplicationRegistrator;
import de.codecentric.boot.admin.services.RegistrationApplicationListener;
import de.codecentric.boot.admin.client.registration.ApplicationRegistrator;
import de.codecentric.boot.admin.client.registration.RegistrationApplicationListener;
@Configuration
@EnableConfigurationProperties({ AdminProperties.class, AdminClientProperties.class })
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.config;
package de.codecentric.boot.admin.client.config;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
......
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.client.registration;
import java.io.Serializable;
import org.springframework.util.Assert;
/**
* The domain model for all registered application at the spring boot admin application.
*/
public class Application implements Serializable {
private static final long serialVersionUID = 1L;
private final String name;
private final String managementUrl;
private final String healthUrl;
private final String serviceUrl;
protected Application(Builder builder) {
Assert.hasText(builder.name, "name must not be empty!");
Assert.hasText(builder.healthUrl, "healthUrl must not be empty!");
this.healthUrl = builder.healthUrl;
this.managementUrl = builder.managementUrl;
this.serviceUrl = builder.serviceUrl;
this.name = builder.name;
}
public static Builder create(String name) {
return new Builder(name);
}
public static Builder create(Application application) {
return new Builder(application);
}
public static class Builder {
private String name;
private String managementUrl;
private String healthUrl;
private String serviceUrl;
private Builder(String name) {
this.name = name;
}
private Builder(Application application) {
this.healthUrl = application.healthUrl;
this.managementUrl = application.managementUrl;
this.serviceUrl = application.serviceUrl;
this.name = application.name;
}
public Builder withName(String name) {
this.name = name;
return this;
}
public Builder withServiceUrl(String serviceUrl) {
this.serviceUrl = serviceUrl;
return this;
}
public Builder withHealthUrl(String healthUrl) {
this.healthUrl = healthUrl;
return this;
}
public Builder withManagementUrl(String managementUrl) {
this.managementUrl = managementUrl;
return this;
}
public Application build() {
return new Application(this);
}
}
public String getName() {
return name;
}
public String getManagementUrl() {
return managementUrl;
}
public String getHealthUrl() {
return healthUrl;
}
public String getServiceUrl() {
return serviceUrl;
}
@Override
public String toString() {
return "Application [name=" + name + ", managementUrl="
+ managementUrl + ", healthUrl=" + healthUrl + ", serviceUrl=" + serviceUrl + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((healthUrl == null) ? 0 : healthUrl.hashCode());
result = prime * result + ((managementUrl == null) ? 0 : managementUrl.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((serviceUrl == null) ? 0 : serviceUrl.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Application other = (Application) obj;
if (healthUrl == null) {
if (other.healthUrl != null) {
return false;
}
} else if (!healthUrl.equals(other.healthUrl)) {
return false;
}
if (managementUrl == null) {
if (other.managementUrl != null) {
return false;
}
} else if (!managementUrl.equals(other.managementUrl)) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
if (serviceUrl == null) {
if (other.serviceUrl != null) {
return false;
}
} else if (!serviceUrl.equals(other.serviceUrl)) {
return false;
}
return true;
}
}
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.services;
package de.codecentric.boot.admin.client.registration;
import java.util.Collections;
import java.util.Map;
......@@ -28,9 +28,8 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import de.codecentric.boot.admin.config.AdminClientProperties;
import de.codecentric.boot.admin.config.AdminProperties;
import de.codecentric.boot.admin.model.Application;
import de.codecentric.boot.admin.client.config.AdminClientProperties;
import de.codecentric.boot.admin.client.config.AdminProperties;
/**
* Registers the client application at spring-boot-admin-server
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.services;
package de.codecentric.boot.admin.client.registration;
import java.util.concurrent.ScheduledFuture;
......
org.springframework.boot.autoconfigure.EnableAutoConfiguration=de.codecentric.boot.admin.config.SpringBootAdminClientAutoConfiguration
\ No newline at end of file
org.springframework.boot.autoconfigure.EnableAutoConfiguration=de.codecentric.boot.admin.client.config.SpringBootAdminClientAutoConfiguration
\ No newline at end of file
package de.codecentric.boot.admin.config;
package de.codecentric.boot.admin.client.config;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.Matchers.is;
......@@ -24,6 +24,8 @@ import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import de.codecentric.boot.admin.client.config.AdminClientProperties;
public class AdminClientPropertiesTest {
private AnnotationConfigWebApplicationContext context;
......
package de.codecentric.boot.admin.config;
package de.codecentric.boot.admin.client.config;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
......@@ -12,6 +12,8 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import de.codecentric.boot.admin.client.config.AdminProperties;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestClientApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.port=0", "spring.boot.admin.url=http://example.com" })
......
package de.codecentric.boot.admin.config;
package de.codecentric.boot.admin.client.config;
import static org.junit.Assert.assertTrue;
......@@ -12,7 +12,8 @@ import org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration.Res
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import de.codecentric.boot.admin.services.ApplicationRegistrator;
import de.codecentric.boot.admin.client.config.SpringBootAdminClientAutoConfiguration;
import de.codecentric.boot.admin.client.registration.ApplicationRegistrator;
public class SpringBootAdminClientAutoConfigurationTest {
......
package de.codecentric.boot.admin.config;
package de.codecentric.boot.admin.client.config;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
......@@ -11,6 +11,8 @@ import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.mock.env.MockEnvironment;
import de.codecentric.boot.admin.client.config.SpringBootAdminClientEnabledCondition;
public class SpringBootAdminClientEnabledConditionTest {
private SpringBootAdminClientEnabledCondition condition;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.services;
package de.codecentric.boot.admin.registration;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
......@@ -36,9 +36,10 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import de.codecentric.boot.admin.config.AdminClientProperties;
import de.codecentric.boot.admin.config.AdminProperties;
import de.codecentric.boot.admin.model.Application;
import de.codecentric.boot.admin.client.config.AdminClientProperties;
import de.codecentric.boot.admin.client.config.AdminProperties;
import de.codecentric.boot.admin.client.registration.Application;
import de.codecentric.boot.admin.client.registration.ApplicationRegistrator;
public class ApplicationRegistratorTest {
......
package de.codecentric.boot.admin.registration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
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;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import de.codecentric.boot.admin.client.registration.Application;
public class ApplicationTest {
@Test
public void test_json_format() throws JsonProcessingException, IOException {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
Application app = Application.create("test").withHealthUrl("http://health")
.withServiceUrl("http://service").withManagementUrl("http://management").build();
DocumentContext json = JsonPath.parse(objectMapper.writeValueAsString(app));
assertThat(json.read("$.name")).isEqualTo("test");
assertThat(json.read("$.serviceUrl")).isEqualTo("http://service");
assertThat(json.read("$.managementUrl")).isEqualTo("http://management");
assertThat(json.read("$.healthUrl")).isEqualTo("http://health");
}
@Test
public void test_equals_hashCode() {
Application a1 = Application.create("foo").withHealthUrl("healthUrl")
.withManagementUrl("mgmt").withServiceUrl("svc").build();
Application a2 = Application.create("foo").withHealthUrl("healthUrl")
.withManagementUrl("mgmt").withServiceUrl("svc").build();
assertThat(a1, is(a2));
assertThat(a1.hashCode(), is(a2.hashCode()));
Application a3 = Application.create("foo").withHealthUrl("healthUrl2")
.withManagementUrl("mgmt").withServiceUrl("svc").build();
assertThat(a1, not(is(a3)));
assertThat(a2, not(is(a3)));
}
@Test
public void test_builder_copy() {
Application app = Application.create("App").withHealthUrl("http://health")
.withManagementUrl("http://mgmgt").withServiceUrl("http://svc").build();
Application copy = Application.create(app).build();
assertThat(app, is(copy));
}
}
package de.codecentric.boot.admin.services;
package de.codecentric.boot.admin.registration;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isA;
......@@ -17,6 +17,9 @@ import org.springframework.context.event.ContextClosedEvent;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import de.codecentric.boot.admin.client.registration.ApplicationRegistrator;
import de.codecentric.boot.admin.client.registration.RegistrationApplicationListener;
public class RegistrationApplicationListenerTest {
@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