From 4c987fd077192c06ecf2655684e52c138221dad6 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Tue, 17 May 2016 12:06:06 -0500 Subject: [PATCH] Add test for SPR-14282 --- SPR-14282/README-template.md | 37 ++++++++ SPR-14282/README.md | 20 +++++ SPR-14282/pom.xml | 84 +++++++++++++++++++ .../java/org/springframework/issues/Bar.java | 5 ++ .../java/org/springframework/issues/Foo.java | 9 ++ SPR-14282/src/main/resources/.gitignore | 0 .../issues/JavaConfigTests.java | 44 ++++++++++ .../issues/XmlConfigTests.java | 28 +++++++ SPR-14282/src/test/resources/log4j.properties | 7 ++ .../issues/XmlConfigTests-context.xml | 12 +++ 10 files changed, 246 insertions(+) create mode 100644 SPR-14282/README-template.md create mode 100644 SPR-14282/README.md create mode 100644 SPR-14282/pom.xml create mode 100644 SPR-14282/src/main/java/org/springframework/issues/Bar.java create mode 100644 SPR-14282/src/main/java/org/springframework/issues/Foo.java create mode 100644 SPR-14282/src/main/resources/.gitignore create mode 100644 SPR-14282/src/test/java/org/springframework/issues/JavaConfigTests.java create mode 100644 SPR-14282/src/test/java/org/springframework/issues/XmlConfigTests.java create mode 100644 SPR-14282/src/test/resources/log4j.properties create mode 100644 SPR-14282/src/test/resources/org/springframework/issues/XmlConfigTests-context.xml diff --git a/SPR-14282/README-template.md b/SPR-14282/README-template.md new file mode 100644 index 00000000..b9cc4f96 --- /dev/null +++ b/SPR-14282/README-template.md @@ -0,0 +1,37 @@ +# Repro project for SPR-0000 + +## Deploying + +It is possible to deploy your application directly from the command-line +using maven. You can use either [cargo](http://cargo.codehaus.org/) or +the [jetty plugin](http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html) +to run on a wide range of containers. + +### Cargo + +By default Cargo is configured to start `Tomcat7` and can be invoked by +running `mvn package cargo:run`. Cargo can also run a [wide range of other +containers](http://cargo.codehaus.org/Containers) and you can easily add +yours by editing the `pom.xml`. For instance, a `tomcat8` profile +has been added and can be invoked via `mvn package cargo:run -Ptomcat8`. + +You can remote debug the application, in your IDE, by using the following command: + `mvn package cargo:run -Ptomcat8 -Pdebug`. Note that you can customize the debug + port used with the `cargo.jvm.debug.port` maven property. + +### Jetty + +To deploy your application to jetty9, simply invoke `mvn jetty:run`. It +is possible to tune the exact jetty9 version you want to use by specifying +the version of the command line, e.g. `mvn jetty:run -Djetty.version=9.0.6.v20130930` + +To run a different version of jetty, please fallback to cargo as the +coordinates of the maven plugin have changed. A sample `jetty8` profile is +created for reference and can be tuned to suit your needs. To deploy your +sample application to jetty8 run `mvn cargo:run -Pjetty8` + +## Logging + +This project contains a `log4j.properties` file in `src/main/resources` that you +may wish to configure to emit more detailed logging. The root logger is set to +`INFO` and a custom `org.springframework.web` logger is set to `DEBUG`. diff --git a/SPR-14282/README.md b/SPR-14282/README.md new file mode 100644 index 00000000..126124ec --- /dev/null +++ b/SPR-14282/README.md @@ -0,0 +1,20 @@ +## Simple Spring application template + +This is a simple template for creating issue reproduction projects per +the [README in the root of this repository](https://github.com/spring-projects/spring-framework-issues#readme). +Please read that document completely before starting. + +As described at the link above, do not edit this project directly! Rather +use the `./create-repro-project.sh` script to create a fresh copy to +a new directory having the same name as the JIRA issue you're trying +to reproduce and edit from there. + +Both Gradle (`build.gradle`) and Maven (`pom.xml`) build scripts are +included for your convenience and choice. Once you've created your +copy of this directory, delete whichever build script you don't wish +to use, and then edit the remaining one to suit your needs. + +Note that this project contains a `log4j.properties` file in +`src/test/resources` that you may wish to configure to emit more +detailed logging. The log level for `org.springframework` is set +to `WARN` by default. diff --git a/SPR-14282/pom.xml b/SPR-14282/pom.xml new file mode 100644 index 00000000..c90df200 --- /dev/null +++ b/SPR-14282/pom.xml @@ -0,0 +1,84 @@ + + 4.0.0 + org.springframework.issues + SPR-14282 + 1.0-SNAPSHOT + jar + + + UTF-8 + + 1.8 + 4.3.0.RC2 + 1.7.18 + + + + + org.springframework + spring-context + ${spring.version} + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + slf4j-log4j12 + ${slf4j.version} + runtime + + + + junit + junit + 4.12 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + + **/*Tests.java + **/*Test.java + + + **/*Abstract*.java + + + + + + + + + spring-maven-snapshot + Springframework Maven Snapshot Repository + http://repo.spring.io/libs-snapshot + + true + + + + + + diff --git a/SPR-14282/src/main/java/org/springframework/issues/Bar.java b/SPR-14282/src/main/java/org/springframework/issues/Bar.java new file mode 100644 index 00000000..2180bac3 --- /dev/null +++ b/SPR-14282/src/main/java/org/springframework/issues/Bar.java @@ -0,0 +1,5 @@ +package org.springframework.issues; + +public class Bar { + +} diff --git a/SPR-14282/src/main/java/org/springframework/issues/Foo.java b/SPR-14282/src/main/java/org/springframework/issues/Foo.java new file mode 100644 index 00000000..5574dc39 --- /dev/null +++ b/SPR-14282/src/main/java/org/springframework/issues/Foo.java @@ -0,0 +1,9 @@ +package org.springframework.issues; + +import org.springframework.beans.factory.annotation.Autowired; + +public class Foo { + + @Autowired + Bar bar; +} diff --git a/SPR-14282/src/main/resources/.gitignore b/SPR-14282/src/main/resources/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/SPR-14282/src/test/java/org/springframework/issues/JavaConfigTests.java b/SPR-14282/src/test/java/org/springframework/issues/JavaConfigTests.java new file mode 100644 index 00000000..2b93570a --- /dev/null +++ b/SPR-14282/src/test/java/org/springframework/issues/JavaConfigTests.java @@ -0,0 +1,44 @@ +package org.springframework.issues; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + +import org.junit.Test; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Unit test that reproduces an issue reported against SPR JIRA. @Test methods + * within need not pass with the green bar! Rather they should fail in such a + * way that demonstrates the reported issue. + */ +public class JavaConfigTests { + + @Test + public void repro() { + try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext()) { + ctx.register(Config.class); + ctx.refresh(); + + Foo foo = ctx.getBean(Foo.class); + + assertThat(foo.bar, nullValue()); + } + } + + @Configuration + static class Config { + + @Bean + public Foo foo() { + return new Foo(); + } + + @Bean + public Bar bar() { + return new Bar(); + } + + } +} diff --git a/SPR-14282/src/test/java/org/springframework/issues/XmlConfigTests.java b/SPR-14282/src/test/java/org/springframework/issues/XmlConfigTests.java new file mode 100644 index 00000000..3012e656 --- /dev/null +++ b/SPR-14282/src/test/java/org/springframework/issues/XmlConfigTests.java @@ -0,0 +1,28 @@ +package org.springframework.issues; + +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; + +import org.junit.Test; +import org.springframework.context.support.GenericXmlApplicationContext; + +/** + * Unit test that reproduces an issue reported against SPR JIRA. @Test methods within + * need not pass with the green bar! Rather they should fail in such a way that + * demonstrates the reported issue. + */ +public class XmlConfigTests { + + @Test + public void repro() { + try(GenericXmlApplicationContext ctx = new GenericXmlApplicationContext()) { + ctx.load("classpath:org/springframework/issues/XmlConfigTests-context.xml"); + ctx.refresh(); + + Foo foo = ctx.getBean(Foo.class); + + assertThat(foo.bar, nullValue()); + } + } + +} diff --git a/SPR-14282/src/test/resources/log4j.properties b/SPR-14282/src/test/resources/log4j.properties new file mode 100644 index 00000000..82776b7b --- /dev/null +++ b/SPR-14282/src/test/resources/log4j.properties @@ -0,0 +1,7 @@ +log4j.rootCategory=ERROR, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n + +log4j.category.org.springframework=WARN \ No newline at end of file diff --git a/SPR-14282/src/test/resources/org/springframework/issues/XmlConfigTests-context.xml b/SPR-14282/src/test/resources/org/springframework/issues/XmlConfigTests-context.xml new file mode 100644 index 00000000..0c2cdf82 --- /dev/null +++ b/SPR-14282/src/test/resources/org/springframework/issues/XmlConfigTests-context.xml @@ -0,0 +1,12 @@ + + + + + + + +