Merge branch '1.1.x'

This commit is contained in:
Phillip Webb
2014-09-25 10:05:35 -07:00
13 changed files with 183 additions and 6 deletions

View File

@@ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@@ -163,6 +164,7 @@ public class ThymeleafAutoConfiguration {
@Configuration
@ConditionalOnClass({ Servlet.class })
@ConditionalOnWebApplication
protected static class ThymeleafViewResolverConfiguration {
@Autowired

View File

@@ -0,0 +1,52 @@
/*
* 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.
* 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 org.springframework.boot.autoconfigure.mongo;
import org.junit.Test;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
/**
* Tests for {@link MongoProperties}.
*
* @author Phillip Webb
*/
public class MongoPropertiesTests {
@Test
public void canBindCharArrayPassword() {
// gh-1572
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, "spring.data.mongodb.password:word");
context.register(Conf.class);
context.refresh();
MongoProperties properties = context.getBean(MongoProperties.class);
assertThat(properties.getPassword(), equalTo("word".toCharArray()));
}
@Configuration
@EnableConfigurationProperties(MongoProperties.class)
static class Conf {
}
}

View File

@@ -30,6 +30,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.support.RequestContext;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
@@ -38,8 +39,10 @@ import org.thymeleaf.spring4.view.ThymeleafViewResolver;
import org.thymeleaf.templateresolver.ITemplateResolver;
import org.thymeleaf.templateresolver.TemplateResolver;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
@@ -49,7 +52,7 @@ import static org.junit.Assert.assertTrue;
*/
public class ThymeleafAutoConfigurationTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
@After
public void close() {
@@ -148,4 +151,33 @@ public class ThymeleafAutoConfigurationTests {
assertEquals("<html><body data-foo=\"bar\"></body></html>", result);
}
@Test
public void renderTemplate() throws Exception {
this.context.register(ThymeleafAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
TemplateEngine engine = this.context.getBean(TemplateEngine.class);
Context attrs = new Context(Locale.UK, Collections.singletonMap("foo", "bar"));
String result = engine.process("home", attrs);
assertEquals("<html><body>bar</body></html>", result);
}
@Test
public void renderNonWebAppTemplate() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
ThymeleafAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
assertEquals(0, context.getBeanNamesForType(ViewResolver.class).length);
try {
TemplateEngine engine = context.getBean(TemplateEngine.class);
Context attrs = new Context(Locale.UK, Collections.singletonMap("greeting",
"Hello World"));
String result = engine.process("message", attrs);
assertThat(result, containsString("Hello World"));
}
finally {
context.close();
}
}
}

View File

@@ -81,7 +81,8 @@ public class BasicErrorControllerIntegrationTest {
"http://localhost:" + this.port + "/bind", Map.class);
String resp = entity.getBody().toString();
assertThat(resp, containsString("Error count: 1"));
assertThat(resp, containsString("errors=[{codes="));
assertThat(resp, containsString("errors=[{"));
assertThat(resp, containsString("codes=["));
assertThat(resp, containsString("org.springframework.validation.BindException"));
}

View File

@@ -0,0 +1 @@
<html><body th:text="${foo}">Home</body></html>

View File

@@ -0,0 +1 @@
<html><body>Message: <span th:text="${greeting}">Hello</span></body></html>