Commit f8a4df08 authored by Phillip Webb's avatar Phillip Webb

Polish

parent 544bc64d
......@@ -23,7 +23,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
......@@ -33,12 +32,9 @@ import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguratio
* <p>
* Activates when the application is a web application and no
* {@link RepositoryRestMvcConfiguration} is found.
* </p>
* <p>
* Once in effect, the auto-configuration allows to configure any property
* of {@link RepositoryRestConfiguration} using the {@code spring.data.rest}
* prefix.
* </p>
* Once in effect, the auto-configuration allows to configure any property of
* {@link RepositoryRestConfiguration} using the {@code spring.data.rest} prefix.
*
* @author Rob Winch
* @author Stephane Nicoll
......@@ -48,18 +44,17 @@ import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguratio
@ConditionalOnWebApplication
@ConditionalOnMissingBean(RepositoryRestMvcConfiguration.class)
@ConditionalOnClass(RepositoryRestMvcConfiguration.class)
@Import(RepositoryRestMvcAutoConfiguration.RepositoryRestMvcBootConfiguration.class)
public class RepositoryRestMvcAutoConfiguration {
static class RepositoryRestMvcBootConfiguration extends
RepositoryRestMvcConfiguration {
@Configuration
static class RepositoryRestMvcBootConfiguration extends RepositoryRestMvcConfiguration {
@Override
@Bean
@ConfigurationProperties(prefix = "spring.data.rest")
@Override
public RepositoryRestConfiguration config() {
return super.config();
}
}
}
......@@ -20,7 +20,6 @@ import java.net.URI;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
......@@ -36,7 +35,8 @@ import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* Tests for {@link RepositoryRestMvcAutoConfiguration}.
......@@ -64,7 +64,8 @@ public class RepositoryRestMvcAutoConfigurationTests {
public void testWithCustomBaseUri() throws Exception {
load(TestConfiguration.class, "spring.data.rest.baseUri:foo");
assertNotNull(this.context.getBean(RepositoryRestMvcConfiguration.class));
RepositoryRestConfiguration bean = this.context.getBean(RepositoryRestConfiguration.class);
RepositoryRestConfiguration bean = this.context
.getBean(RepositoryRestConfiguration.class);
assertEquals("Custom baseURI not set", URI.create("foo"), bean.getBaseUri());
}
......@@ -72,17 +73,17 @@ public class RepositoryRestMvcAutoConfigurationTests {
public void backOffWithCustomConfiguration() {
load(TestConfigurationWithRestMvcConfig.class, "spring.data.rest.baseUri:foo");
assertNotNull(this.context.getBean(RepositoryRestMvcConfiguration.class));
RepositoryRestConfiguration bean = this.context.getBean(RepositoryRestConfiguration.class);
assertEquals("Custom base URI should not have been set", URI.create(""), bean.getBaseUri());
RepositoryRestConfiguration bean = this.context
.getBean(RepositoryRestConfiguration.class);
assertEquals("Custom base URI should not have been set", URI.create(""),
bean.getBaseUri());
}
private void load(Class<?> config,
String... environment) {
private void load(Class<?> config, String... environment) {
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.setServletContext(new MockServletContext());
applicationContext.register(config,
EmbeddedDataSourceConfiguration.class,
applicationContext.register(config, EmbeddedDataSourceConfiguration.class,
HibernateJpaAutoConfiguration.class,
JpaRepositoriesAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
......@@ -99,7 +100,7 @@ public class RepositoryRestMvcAutoConfigurationTests {
}
@Import({TestConfiguration.class, RepositoryRestMvcConfiguration.class})
@Import({ TestConfiguration.class, RepositoryRestMvcConfiguration.class })
protected static class TestConfigurationWithRestMvcConfig {
}
......
......@@ -28,4 +28,5 @@ class JmsExample implements CommandLineRunner {
log.info "Received ${message}"
latch.countDown()
}
}
\ No newline at end of file
}
......@@ -19,7 +19,6 @@ package org.springframework.boot.cli.compiler.autoconfigure;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.control.CompilationFailedException;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.springframework.boot.cli.compiler.AstUtils;
import org.springframework.boot.cli.compiler.CompilerAutoConfiguration;
import org.springframework.boot.cli.compiler.DependencyCustomizer;
......@@ -30,7 +29,7 @@ import org.springframework.boot.cli.compiler.DependencyCustomizer;
* @author Stephane Nicoll
* @since 1.2.0
*/
public class CachingAutoConfiguration extends CompilerAutoConfiguration {
public class CachingCompilerAutoConfiguration extends CompilerAutoConfiguration {
@Override
public boolean matches(ClassNode classNode) {
......@@ -41,13 +40,13 @@ public class CachingAutoConfiguration extends CompilerAutoConfiguration {
public void applyDependencies(DependencyCustomizer dependencies)
throws CompilationFailedException {
dependencies.add("spring-context-support");
}
@Override
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
imports.addStarImports("org.springframework.cache",
"org.springframework.cache.annotation", "org.springframework.cache.concurrent");
"org.springframework.cache.annotation",
"org.springframework.cache.concurrent");
}
}
......@@ -22,7 +22,6 @@ import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.springframework.boot.cli.compiler.AstUtils;
import org.springframework.boot.cli.compiler.CompilerAutoConfiguration;
import org.springframework.boot.cli.compiler.DependencyCustomizer;
import org.springframework.boot.groovy.EnableJmsMessaging;
/**
* {@link CompilerAutoConfiguration} for Spring JMS.
......@@ -34,26 +33,25 @@ public class JmsCompilerAutoConfiguration extends CompilerAutoConfiguration {
@Override
public boolean matches(ClassNode classNode) {
return AstUtils.hasAtLeastOneAnnotation(classNode, "EnableJms") ||
AstUtils.hasAtLeastOneAnnotation(classNode, "EnableJmsMessaging");
return AstUtils.hasAtLeastOneAnnotation(classNode, "EnableJms")
|| AstUtils.hasAtLeastOneAnnotation(classNode, "EnableJmsMessaging");
}
@Override
public void applyDependencies(DependencyCustomizer dependencies)
throws CompilationFailedException {
dependencies.add("spring-jms", "jms-api");
}
@Override
@SuppressWarnings("deprecation")
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
imports.addStarImports("javax.jms",
"org.springframework.jms.annotation",
"org.springframework.jms.config",
"org.springframework.jms.core",
imports.addStarImports("javax.jms", "org.springframework.jms.annotation",
"org.springframework.jms.config", "org.springframework.jms.core",
"org.springframework.jms.listener",
"org.springframework.jms.listener.adapter")
.addImports(EnableJmsMessaging.class.getCanonicalName());
"org.springframework.jms.listener.adapter").addImports(
org.springframework.boot.groovy.EnableJmsMessaging.class
.getCanonicalName());
}
}
......@@ -4,7 +4,7 @@ org.springframework.boot.cli.compiler.autoconfigure.SpringMvcCompilerAutoConfigu
org.springframework.boot.cli.compiler.autoconfigure.SpringBatchCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.RabbitCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.ReactorCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.CachingAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.CachingCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.JdbcCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.JmsCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.JUnitCompilerAutoConfiguration
......@@ -17,4 +17,4 @@ org.springframework.boot.cli.compiler.autoconfigure.SpringSocialFacebookCompiler
org.springframework.boot.cli.compiler.autoconfigure.SpringSocialLinkedInCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.SpringSocialTwitterCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.SpringTestCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.SpringWebsocketCompilerAutoConfiguration
\ No newline at end of file
org.springframework.boot.cli.compiler.autoconfigure.SpringWebsocketCompilerAutoConfiguration
......@@ -27,6 +27,8 @@ import org.junit.Test;
import org.springframework.boot.cli.command.grab.GrabCommand;
import org.springframework.util.FileSystemUtils;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
......@@ -68,8 +70,9 @@ public class GrabCommandIntegrationTests {
this.cli.grab("duplicateGrabMetadata.groovy");
fail();
}
catch (Exception e) {
assertTrue(e.getMessage().contains("Duplicate @GrabMetadata annotation"));
catch (Exception ex) {
assertThat(ex.getMessage(),
containsString("Duplicate @GrabMetadata annotation"));
}
}
......
......@@ -79,9 +79,4 @@ public class ReproIntegrationTests {
assertThat(this.cli.getOutput(), containsString("Hello World"));
}
@Test
public void caching() throws Exception {
this.cli.run("caching.groovy");
assertThat(this.cli.getOutput(), containsString("Hello World"));
}
}
......@@ -24,7 +24,9 @@ import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
......@@ -156,4 +158,10 @@ public class SampleIntegrationTests {
assertEquals("Hello Normal Device!", this.cli.getHttpOutput());
}
@Test
public void caching() throws Exception {
this.cli.run("caching.groovy");
assertThat(this.cli.getOutput(), containsString("Hello World"));
}
}
......@@ -1847,6 +1847,7 @@ resolved against their provided names.
[[boot-features-using-jms-template]]
[[boot-features-using-jms-sending]]
==== Sending a message
Spring's `JmsTemplate` is auto-configured and you can autowire it directly into your
......@@ -1876,6 +1877,8 @@ own beans:
NOTE: {spring-javadoc}/jms/core/JmsMessagingTemplate.{dc-ext}[`JmsMessagingTemplate`]
(new in Spring 4.1) can be injected in a similar manner.
[[boot-features-using-jms-receiving]]
==== Receiving a message
......
......@@ -80,7 +80,7 @@ public class ConfigurationBeanFactoryMetaData implements BeanFactoryPostProcesso
if (!this.beans.containsKey(beanName)) {
return null;
}
final AtomicReference<Method> found = new AtomicReference<Method>();
final AtomicReference<Method> found = new AtomicReference<Method>(null);
MetaData meta = this.beans.get(beanName);
final String factory = meta.getMethod();
Class<?> type = this.beanFactory.getType(meta.getBean());
......@@ -88,8 +88,8 @@ public class ConfigurationBeanFactoryMetaData implements BeanFactoryPostProcesso
@Override
public void doWith(Method method) throws IllegalArgumentException,
IllegalAccessException {
if (found.get() == null && method.getName().equals(factory)) {
found.set(method);
if (method.getName().equals(factory)) {
found.compareAndSet(null, method);
}
}
});
......
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