Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillip Webb committed Mar 27, 2014
1 parent 71c2c69 commit d117a6b
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,17 @@ public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
String trace = request.getParameter("trace");
Map<String, Object> extracted = extract(attributes,
trace != null && !"false".equals(trace.toLowerCase()), true);
HttpStatus statusCode;
HttpStatus statusCode = getStatus((Integer) extracted.get("status"));
return new ResponseEntity<Map<String, Object>>(extracted, statusCode);
}

private HttpStatus getStatus(Integer value) {
try {
statusCode = HttpStatus.valueOf((Integer) extracted.get("status"));
return HttpStatus.valueOf(value);
}
catch (Exception e) {
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
catch (Exception ex) {
return HttpStatus.INTERNAL_SERVER_ERROR;
}
return new ResponseEntity<Map<String, Object>>(extracted, statusCode);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.client.RestTemplate;

import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -61,8 +60,8 @@ public class ManagementPortSampleActuatorApplicationTests {
@Test
public void testHome() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = getRestTemplate("user", getPassword()).getForEntity(
"http://localhost:" + this.port, Map.class);
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
.getForEntity("http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody();
Expand All @@ -73,14 +72,14 @@ public void testHome() throws Exception {
public void testMetrics() throws Exception {
testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = getRestTemplate().getForEntity(
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
"http://localhost:" + this.managementPort + "/metrics", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
}

@Test
public void testHealth() throws Exception {
ResponseEntity<String> entity = getRestTemplate().getForEntity(
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
"http://localhost:" + this.managementPort + "/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("ok", entity.getBody());
Expand All @@ -89,7 +88,7 @@ public void testHealth() throws Exception {
@Test
public void testErrorPage() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = getRestTemplate().getForEntity(
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
"http://localhost:" + this.managementPort + "/error", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked")
Expand All @@ -101,12 +100,4 @@ private String getPassword() {
return this.security.getUser().getPassword();
}

private RestTemplate getRestTemplate() {
return RestTemplates.get();
}

private RestTemplate getRestTemplate(final String username, final String password) {
return RestTemplates.get(username, password);
}

}
3 changes: 2 additions & 1 deletion spring-boot-starters/spring-boot-starter-actuator/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ public static void write(PrintStream printStream) {
FAINT, version));
printStream.println();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,13 @@ public ClassExcludeFilter(Object... sources) {
protected boolean matchClassName(String className) {
return this.classNames.contains(className);
}

}

protected interface GroovyBeanDefinitionSource {

Closure<?> getBeans();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,31 @@
public interface AnsiElement {

public static final AnsiElement NORMAL = new DefaultAnsiElement("0");

public static final AnsiElement BOLD = new DefaultAnsiElement("1");

public static final AnsiElement FAINT = new DefaultAnsiElement("2");

public static final AnsiElement ITALIC = new DefaultAnsiElement("3");

public static final AnsiElement UNDERLINE = new DefaultAnsiElement("4");

public static final AnsiElement BLACK = new DefaultAnsiElement("30");

public static final AnsiElement RED = new DefaultAnsiElement("31");

public static final AnsiElement GREEN = new DefaultAnsiElement("32");

public static final AnsiElement YELLOW = new DefaultAnsiElement("33");

public static final AnsiElement BLUE = new DefaultAnsiElement("34");

public static final AnsiElement MAGENTA = new DefaultAnsiElement("35");

public static final AnsiElement CYAN = new DefaultAnsiElement("36");

public static final AnsiElement WHITE = new DefaultAnsiElement("37");

public static final AnsiElement DEFAULT = new DefaultAnsiElement("39");

/**
Expand All @@ -60,6 +72,7 @@ public DefaultAnsiElement(String code) {
public String toString() {
return this.code;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public String apply(String value) {
};

public abstract String apply(String value);

}

static enum Manipulation {
Expand Down Expand Up @@ -157,5 +158,7 @@ public String apply(String value) {
};

public abstract String apply(String value);

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-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.
Expand Down Expand Up @@ -89,5 +89,6 @@ protected Property getProperty(Class<?> type, String name)
Property property = (forType == null ? null : forType.get(name));
return (property == null ? super.getProperty(type, name) : property);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void onApplicationEvent(ContextRefreshedEvent event) {
(ConfigurableApplicationContext) context));
}
}

}

public static class ParentContextAvailableEvent extends ApplicationEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
}
}
}

};
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void stop() throws EmbeddedServletContainerException {
public int getPort() {
return 0;
}

};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ public void add(PropertySource<?> source) {
getSource().add(source);
this.names = null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ public PropertySource<?> load(String name, Resource resource, String profile)
}
return null;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-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.
Expand Down Expand Up @@ -640,4 +640,5 @@ class InvalidBase64CharacterException extends IllegalArgumentException {
InvalidBase64CharacterException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,11 @@ public Map<String, Object> getInfo() {
public void setInfo(Map<String, Object> nested) {
this.info = nested;
}

}

public static class TargetWithNestedMap {

private Map<String, Object> nested;

public Map<String, Object> getNested() {
Expand All @@ -499,9 +501,11 @@ public Map<String, Object> getNested() {
public void setNested(Map<String, Object> nested) {
this.nested = nested;
}

}

public static class TargetWithNestedMapOfString {

private Map<String, String> nested;

public Map<String, String> getNested() {
Expand All @@ -511,9 +515,11 @@ public Map<String, String> getNested() {
public void setNested(Map<String, String> nested) {
this.nested = nested;
}

}

public static class TargetWithNestedMapOfListOfString {

private Map<String, List<String>> nested;

public Map<String, List<String>> getNested() {
Expand All @@ -523,9 +529,11 @@ public Map<String, List<String>> getNested() {
public void setNested(Map<String, List<String>> nested) {
this.nested = nested;
}

}

public static class TargetWithNestedMapOfListOfBean {

private Map<String, List<VanillaTarget>> nested;

public Map<String, List<VanillaTarget>> getNested() {
Expand All @@ -535,9 +543,11 @@ public Map<String, List<VanillaTarget>> getNested() {
public void setNested(Map<String, List<VanillaTarget>> nested) {
this.nested = nested;
}

}

public static class TargetWithNestedMapOfBean {

private Map<String, VanillaTarget> nested;

public Map<String, VanillaTarget> getNested() {
Expand All @@ -547,9 +557,11 @@ public Map<String, VanillaTarget> getNested() {
public void setNested(Map<String, VanillaTarget> nested) {
this.nested = nested;
}

}

public static class TargetWithNestedList {

private List<String> nested;

public List<String> getNested() {
Expand All @@ -559,33 +571,41 @@ public List<String> getNested() {
public void setNested(List<String> nested) {
this.nested = nested;
}

}

public static class TargetWithReadOnlyNestedList {

private final List<String> nested = new ArrayList<String>();

public List<String> getNested() {
return this.nested;
}

}

public static class TargetWithReadOnlyDoubleNestedList {

TargetWithReadOnlyNestedList bean = new TargetWithReadOnlyNestedList();

public TargetWithReadOnlyNestedList getBean() {
return this.bean;
}

}

public static class TargetWithReadOnlyNestedCollection {

private final Collection<String> nested = new ArrayList<String>();

public Collection<String> getNested() {
return this.nested;
}

}

public static class TargetWithNestedSet {

private Set<String> nested = new LinkedHashSet<String>();

public Set<String> getNested() {
Expand All @@ -595,6 +615,7 @@ public Set<String> getNested() {
public void setNested(Set<String> nested) {
this.nested = nested;
}

}

public static class TargetWithNestedObject {
Expand Down Expand Up @@ -650,6 +671,7 @@ public String getFooBaz() {
public void setFooBaz(String fooBaz) {
this.fooBaz = fooBaz;
}

}

public static class ValidatedTarget {
Expand Down

0 comments on commit d117a6b

Please sign in to comment.