Commit d0ba735a by Thomas Bosch

Merge remote-tracking branch 'upstream/master'

parents a789ad8a 37fd5316
......@@ -13,6 +13,7 @@
</licenses>
<properties>
<spring-boot.version>1.1.4.RELEASE</spring-boot.version>
<spring.version>4.0.6.RELEASE</spring.version>
<bootstrap.version>2.3.2</bootstrap.version>
<jquery.version>1.11.0</jquery.version>
<angularjs.version>1.2.12</angularjs.version>
......@@ -67,6 +68,12 @@
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
......
......@@ -15,12 +15,14 @@
*/
package de.codecentric.boot.admin.service;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.Validate;
import org.apache.tomcat.util.net.URL;
import org.springframework.stereotype.Service;
import de.codecentric.boot.admin.model.Application;
......@@ -42,12 +44,29 @@ public class ApplicationRegistry {
*/
public Application register(Application app) {
Validate.notNull(app, "Application must not be null");
Validate.notNull(app.getId(), "Application ID must not be null");
Validate.notNull(app.getUrl(), "Application URL must not be null");
Validate.notNull(app.getId(), "ID must not be null");
Validate.notNull(app.getUrl(), "URL must not be null");
Validate.isTrue(checkUrl(app.getUrl()), "URL is not valid");
return registry.put(app.getId(), app);
}
/**
* Checks the syntax of the given URL.
*
* @param url
* The URL.
* @return true, if valid.
*/
private boolean checkUrl(String url) {
try {
new URL(url);
} catch (MalformedURLException e) {
return false;
}
return true;
}
/**
* Checks, if an application is already registerd.
*
* @param id
......
package de.codecentric.boot.admin.service;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import de.codecentric.boot.admin.config.WebappConfig;
import de.codecentric.boot.admin.model.Application;
@ContextConfiguration(classes = { WebappConfig.class })
@RunWith(SpringJUnit4ClassRunner.class)
public class ApplicationRegistryTest {
@Autowired
private ApplicationRegistry registry;
@Test(expected = NullPointerException.class)
public void registerFailed1() throws Exception {
registry.register(new Application());
}
@Test(expected = NullPointerException.class)
public void registerFailed2() throws Exception {
Application app = new Application();
app.setId("abc");
registry.register(app);
}
@Test(expected = IllegalArgumentException.class)
public void registerFailed3() throws Exception {
Application app = new Application();
app.setId("abc");
app.setUrl("not-an-url");
registry.register(app);
}
@Test
public void register() throws Exception {
Application app = new Application();
app.setId("abc");
app.setUrl("http://localhost:8080");
registry.register(app);
}
@Test
public void isRegistered() throws Exception {
Application app = new Application();
app.setId("abc");
app.setUrl("http://localhost:8080");
registry.register(app);
assertFalse(registry.isRegistered("xyz"));
assertTrue(registry.isRegistered("abc"));
}
@Test
public void getApplication() throws Exception {
Application app = new Application();
app.setId("abc");
app.setUrl("http://localhost:8080");
registry.register(app);
assertEquals(app, registry.getApplication("abc"));
}
@Test
public void getApplications() throws Exception {
Application app = new Application();
app.setId("abc");
app.setUrl("http://localhost:8080");
registry.register(app);
assertEquals(1, registry.getApplications().size());
assertEquals(app, registry.getApplications().get(0));
}
}
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