diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJndi.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJndi.java index e8a63967ebd..abad20dccf5 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJndi.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJndi.java @@ -21,6 +21,7 @@ import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; + import javax.naming.InitialContext; import org.springframework.context.annotation.Conditional; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionOnJndiTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionOnJndiTests.java deleted file mode 100644 index 5d0f9aec29b..00000000000 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionOnJndiTests.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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.condition; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -import org.springframework.core.type.AnnotatedTypeMetadata; - -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link OnJndiCondition}. - * - * @author Phillip Webb - */ -public class ConditionOnJndiTests { - - private MockableOnJndi condition = new MockableOnJndi(); - - @Test - public void jndiNotAvailable() { - this.condition.setJndiAvailable(false); - ConditionOutcome outcome = this.condition.getMatchOutcome(null, mockMetaData()); - assertThat(outcome.isMatch(), equalTo(false)); - } - - @Test - public void jndiLocationNotFound() { - ConditionOutcome outcome = this.condition.getMatchOutcome(null, - mockMetaData("java:/a")); - assertThat(outcome.isMatch(), equalTo(false)); - } - - @Test - public void jndiLocationFound() { - this.condition.setFoundLocation("java:/b"); - ConditionOutcome outcome = this.condition.getMatchOutcome(null, - mockMetaData("java:/a", "java:/b")); - assertThat(outcome.isMatch(), equalTo(true)); - } - - private AnnotatedTypeMetadata mockMetaData(String... value) { - AnnotatedTypeMetadata metadata = mock(AnnotatedTypeMetadata.class); - Map attributes = new HashMap(); - attributes.put("value", value); - given(metadata.getAnnotationAttributes(ConditionalOnJndi.class.getName())) - .willReturn(attributes); - return metadata; - } - - private static class MockableOnJndi extends OnJndiCondition { - - private boolean jndiAvailable = true; - - private String foundLocation; - - @Override - protected boolean isJndiAvailable() { - return this.jndiAvailable; - } - - @Override - protected JndiLocator getJndiLocator(String[] locations) { - return new JndiLocator(locations) { - @Override - public String lookupFirstLocation() { - return MockableOnJndi.this.foundLocation; - } - }; - } - - public void setJndiAvailable(boolean jndiAvailable) { - this.jndiAvailable = jndiAvailable; - } - - public void setFoundLocation(String foundLocation) { - this.foundLocation = foundLocation; - } - } - -} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJndiTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJndiTests.java index 91e5822d297..460390e7073 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJndiTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJndiTests.java @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.condition; import java.util.HashMap; import java.util.Hashtable; import java.util.Map; + import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; @@ -27,21 +28,25 @@ import javax.naming.spi.InitialContextFactory; import org.hamcrest.Matcher; import org.junit.After; import org.junit.Test; - import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.type.AnnotatedTypeMetadata; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.iterableWithSize; import static org.junit.Assert.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; /** * Tests for {@link ConditionalOnJndi} * * @author Stephane Nicoll + * @author Phillip Webb */ public class ConditionalOnJndiTests { @@ -49,11 +54,14 @@ public class ConditionalOnJndiTests { private ConfigurableApplicationContext context; + private MockableOnJndi condition = new MockableOnJndi(); + @After public void close() { TestableInitialContextFactory.clearAll(); if (this.initialContextFactory != null) { - System.setProperty(Context.INITIAL_CONTEXT_FACTORY, this.initialContextFactory); + System.setProperty(Context.INITIAL_CONTEXT_FACTORY, + this.initialContextFactory); } else { System.clearProperty(Context.INITIAL_CONTEXT_FACTORY); @@ -91,13 +99,27 @@ public class ConditionalOnJndiTests { assertPresent(true); } + @Test + public void jndiLocationNotFound() { + ConditionOutcome outcome = this.condition.getMatchOutcome(null, + mockMetaData("java:/a")); + assertThat(outcome.isMatch(), equalTo(false)); + } + + @Test + public void jndiLocationFound() { + this.condition.setFoundLocation("java:/b"); + ConditionOutcome outcome = this.condition.getMatchOutcome(null, + mockMetaData("java:/a", "java:/b")); + assertThat(outcome.isMatch(), equalTo(true)); + } + private void setupJndi() { this.initialContextFactory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY); System.setProperty(Context.INITIAL_CONTEXT_FACTORY, TestableInitialContextFactory.class.getName()); } - private void assertPresent(boolean expected) { int expectedNumber = expected ? 1 : 0; Matcher> matcher = iterableWithSize(expectedNumber); @@ -113,6 +135,15 @@ public class ConditionalOnJndiTests { this.context = applicationContext; } + private AnnotatedTypeMetadata mockMetaData(String... value) { + AnnotatedTypeMetadata metadata = mock(AnnotatedTypeMetadata.class); + Map attributes = new HashMap(); + attributes.put("value", value); + given(metadata.getAnnotationAttributes(ConditionalOnJndi.class.getName())) + .willReturn(attributes); + return metadata; + } + @Configuration @ConditionalOnJndi static class JndiAvailableConfiguration { @@ -133,11 +164,37 @@ public class ConditionalOnJndiTests { } } + private static class MockableOnJndi extends OnJndiCondition { + + private boolean jndiAvailable = true; + + private String foundLocation; + + @Override + protected boolean isJndiAvailable() { + return this.jndiAvailable; + } + + @Override + protected JndiLocator getJndiLocator(String[] locations) { + return new JndiLocator(locations) { + @Override + public String lookupFirstLocation() { + return MockableOnJndi.this.foundLocation; + } + }; + } + + public void setFoundLocation(String foundLocation) { + this.foundLocation = foundLocation; + } + } public static class TestableInitialContextFactory implements InitialContextFactory { private static TestableContext context; + @Override public Context getInitialContext(Hashtable environment) throws NamingException { return getContext(); @@ -147,8 +204,8 @@ public class ConditionalOnJndiTests { try { getContext().bind(name, obj); } - catch (NamingException o_O) { - throw new IllegalStateException(o_O); + catch (NamingException ex) { + throw new IllegalStateException(ex); } } @@ -161,14 +218,13 @@ public class ConditionalOnJndiTests { try { context = new TestableContext(); } - catch (NamingException o_O) { - throw new IllegalStateException(o_O); + catch (NamingException ex) { + throw new IllegalStateException(ex); } } return context; } - private static class TestableContext extends InitialContext { private final Map bindings = new HashMap(); @@ -178,8 +234,7 @@ public class ConditionalOnJndiTests { } @Override - public void bind(String name, Object obj) - throws NamingException { + public void bind(String name, Object obj) throws NamingException { this.bindings.put(name, obj); } @@ -190,7 +245,8 @@ public class ConditionalOnJndiTests { @Override public Hashtable getEnvironment() throws NamingException { - return new Hashtable(); // Used to detect if JNDI is available + return new Hashtable(); // Used to detect if JNDI is + // available } public void clearAll() { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jta/JtaAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jta/JtaAutoConfigurationTests.java index c7bf3f71585..2ce09e6f76d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jta/JtaAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jta/JtaAutoConfigurationTests.java @@ -91,13 +91,13 @@ public class JtaAutoConfigurationTests { @Test public void disableJtaSupport() { this.context = new AnnotationConfigApplicationContext(); - EnvironmentTestUtils.addEnvironment(this.context, - "spring.jta.enabled:false"); + EnvironmentTestUtils.addEnvironment(this.context, "spring.jta.enabled:false"); this.context.register(JtaAutoConfiguration.class); this.context.refresh(); assertEquals(0, this.context.getBeansOfType(JtaTransactionManager.class).size()); assertEquals(0, this.context.getBeansOfType(XADataSourceWrapper.class).size()); - assertEquals(0, this.context.getBeansOfType(XAConnectionFactoryWrapper.class).size()); + assertEquals(0, this.context.getBeansOfType(XAConnectionFactoryWrapper.class) + .size()); } @Test diff --git a/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index 7bc77f15426..61eaeda13fe 100644 --- a/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -208,7 +208,7 @@ configuration instead. This is possible in both Maven and Gradle. [[production-ready-application-info-automatic-expansion-maven]] ===== Automatic property expansion using Maven You can automatically expand info properties from the Maven project using resource -filtering. If you use the `spring-boot-starter-parent` you can then refer to your +filtering. If you use the `spring-boot-starter-parent` you can then refer to your Maven '`project properties`' via `@..@` placeholders, e.g. [source,properties,indent=0] @@ -242,16 +242,16 @@ and (inside ``): [source,xml,indent=0] ---- - - org.apache.maven.plugins - maven-resources-plugin - 2.6 - - - @ - - - + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + + @ + + + ---- [[production-ready-application-info-automatic-expansion-gradle]] diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index ca5eb4af856..53af236f843 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -913,6 +913,8 @@ If you need to add or customize converters you can use Spring Boot's Any `HttpMessageConverter` bean that is present in the context will be added to the list of converters. You can also override default converters that way. + + [[boot-features-spring-message-codes]] ==== MessageCodesResolver Spring MVC has a strategy for generating error codes for rendering error messages