pull/8621/head
Phillip Webb 8 years ago
parent bfae0d7739
commit 40b3372884

@ -76,19 +76,14 @@ class OriginTrackedYamlLoader extends YamlProcessor {
public Map<String, Object> load() {
final Map<String, Object> result = new LinkedHashMap<String, Object>();
process(new MatchCallback() {
@Override
public void process(Properties properties, Map<String, Object> map) {
process((properties, map) -> {
result.putAll(getFlattenedMap(map));
}
});
return result;
}
/**
* {@link Constructor}.
* {@link Constructor} that tracks property origins.
*/
private class OriginTrackingConstructor extends StrictMapAppenderConstructor {
@ -100,14 +95,16 @@ class OriginTrackedYamlLoader extends YamlProcessor {
}
}
else if (node instanceof MappingNode) {
List<NodeTuple> value = ((MappingNode) node).getValue();
List<NodeTuple> updatedValues = value.stream().map(nt -> new NodeTuple(KeyScalarNode.get(nt.getKeyNode()),
nt.getValueNode())).collect(Collectors.toList());
((MappingNode) node).setValue(updatedValues);
replaceMappingNodeKeys((MappingNode) node);
}
return super.constructObject(node);
}
private void replaceMappingNodeKeys(MappingNode node) {
node.setValue(node.getValue().stream().map(KeyScalarNode::get)
.collect(Collectors.toList()));
}
private Object constructTrackedObject(Node node, Object value) {
PropertyOrigin origin = getOrigin(node);
return OriginTrackedValue.of(value, origin);
@ -128,7 +125,14 @@ class OriginTrackedYamlLoader extends YamlProcessor {
private static class KeyScalarNode extends ScalarNode {
KeyScalarNode(ScalarNode node) {
super(node.getTag(), node.getValue(), node.getStartMark(), node.getEndMark(), node.getStyle());
super(node.getTag(), node.getValue(), node.getStartMark(), node.getEndMark(),
node.getStyle());
}
public static NodeTuple get(NodeTuple nodeTuple) {
Node keyNode = nodeTuple.getKeyNode();
Node valueNode = nodeTuple.getValueNode();
return new NodeTuple(KeyScalarNode.get(keyNode), valueNode);
}
private static Node get(Node node) {
@ -155,6 +159,10 @@ class OriginTrackedYamlLoader extends YamlProcessor {
}
/**
* {@link SpringProfileDocumentMatcher} that deals with {@link OriginTrackedValue
* OriginTrackedValues}.
*/
private static class OriginTrackedSpringProfileDocumentMatcher
extends SpringProfileDocumentMatcher {

@ -29,7 +29,7 @@ import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.testutil.MockServlet;
import org.springframework.boot.web.servlet.context.config.ExampleEmbeddedWebApplicationConfiguration;
import org.springframework.boot.web.servlet.context.config.ExampleServletWebServerApplicationConfiguration;
import org.springframework.boot.web.servlet.server.MockServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
@ -55,14 +55,15 @@ public class AnnotationConfigServletWebServerApplicationContextTests {
@Test
public void createFromScan() throws Exception {
this.context = new AnnotationConfigServletWebServerApplicationContext(
ExampleEmbeddedWebApplicationConfiguration.class.getPackage().getName());
ExampleServletWebServerApplicationConfiguration.class.getPackage()
.getName());
verifyContext();
}
@Test
public void sessionScopeAvailable() throws Exception {
this.context = new AnnotationConfigServletWebServerApplicationContext(
ExampleEmbeddedWebApplicationConfiguration.class,
ExampleServletWebServerApplicationConfiguration.class,
SessionScopedComponent.class);
verifyContext();
}
@ -70,7 +71,7 @@ public class AnnotationConfigServletWebServerApplicationContextTests {
@Test
public void sessionScopeAvailableToServlet() throws Exception {
this.context = new AnnotationConfigServletWebServerApplicationContext(
ExampleEmbeddedWebApplicationConfiguration.class,
ExampleServletWebServerApplicationConfiguration.class,
ExampleServletWithAutowired.class, SessionScopedComponent.class);
Servlet servlet = this.context.getBean(ExampleServletWithAutowired.class);
assertThat(servlet).isNotNull();
@ -79,14 +80,14 @@ public class AnnotationConfigServletWebServerApplicationContextTests {
@Test
public void createFromConfigClass() throws Exception {
this.context = new AnnotationConfigServletWebServerApplicationContext(
ExampleEmbeddedWebApplicationConfiguration.class);
ExampleServletWebServerApplicationConfiguration.class);
verifyContext();
}
@Test
public void registerAndRefresh() throws Exception {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.register(ExampleEmbeddedWebApplicationConfiguration.class);
this.context.register(ExampleServletWebServerApplicationConfiguration.class);
this.context.refresh();
verifyContext();
}
@ -94,8 +95,8 @@ public class AnnotationConfigServletWebServerApplicationContextTests {
@Test
public void scanAndRefresh() throws Exception {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.scan(
ExampleEmbeddedWebApplicationConfiguration.class.getPackage().getName());
this.context.scan(ExampleServletWebServerApplicationConfiguration.class
.getPackage().getName());
this.context.refresh();
verifyContext();
}

@ -31,7 +31,7 @@ import org.springframework.context.annotation.Configuration;
* @author Phillip Webb
*/
@Configuration
public class ExampleEmbeddedWebApplicationConfiguration {
public class ExampleServletWebServerApplicationConfiguration {
@Bean
public MockServletWebServerFactory webServerFactory() {
Loading…
Cancel
Save