From d2cd719b2d6be41d2a004d191ab0319e04823126 Mon Sep 17 00:00:00 2001 From: Alessandro Polverini Date: Mon, 10 Feb 2014 22:37:34 +0100 Subject: [PATCH] SPR-11281 test case --- SPR-11281/nb-configuration.xml | 18 ++ SPR-11281/pom.xml | 253 ++++++++++++++++++ .../org/springframework/issues/.gitignore | 0 .../springframework/issues/Controller1.java | 35 +++ .../springframework/issues/Controller2.java | 39 +++ .../org/springframework/issues/MyEvent.java | 15 ++ .../issues/WebAppInitializer.java | 24 ++ SPR-11281/src/main/resources/log4j.properties | 8 + .../src/main/webapp/META-INF/context.xml | 2 + .../webapp/WEB-INF/applicationContext.xml | 35 +++ .../src/main/webapp/WEB-INF/views/home.jsp | 11 + SPR-11281/src/main/webapp/WEB-INF/web.xml | 6 + .../org/springframework/issues/.gitignore | 0 SPR-11281/src/test/resources/log4j.properties | 7 + 14 files changed, 453 insertions(+) create mode 100644 SPR-11281/nb-configuration.xml create mode 100644 SPR-11281/pom.xml create mode 100644 SPR-11281/src/main/java/org/springframework/issues/.gitignore create mode 100644 SPR-11281/src/main/java/org/springframework/issues/Controller1.java create mode 100644 SPR-11281/src/main/java/org/springframework/issues/Controller2.java create mode 100644 SPR-11281/src/main/java/org/springframework/issues/MyEvent.java create mode 100644 SPR-11281/src/main/java/org/springframework/issues/WebAppInitializer.java create mode 100644 SPR-11281/src/main/resources/log4j.properties create mode 100644 SPR-11281/src/main/webapp/META-INF/context.xml create mode 100644 SPR-11281/src/main/webapp/WEB-INF/applicationContext.xml create mode 100644 SPR-11281/src/main/webapp/WEB-INF/views/home.jsp create mode 100644 SPR-11281/src/main/webapp/WEB-INF/web.xml create mode 100644 SPR-11281/src/test/java/org/springframework/issues/.gitignore create mode 100644 SPR-11281/src/test/resources/log4j.properties diff --git a/SPR-11281/nb-configuration.xml b/SPR-11281/nb-configuration.xml new file mode 100644 index 00000000..4735c891 --- /dev/null +++ b/SPR-11281/nb-configuration.xml @@ -0,0 +1,18 @@ + + + + + + Tomcat + + diff --git a/SPR-11281/pom.xml b/SPR-11281/pom.xml new file mode 100644 index 00000000..64b0ffca --- /dev/null +++ b/SPR-11281/pom.xml @@ -0,0 +1,253 @@ + + 4.0.0 + org.springframework.issues + SPR-11281 + 1.0-SNAPSHOT + SPR-11281 + war + + + 1.7 + 4.0.1.RELEASE + 1.6.1 + + + + + + org.springframework + spring-context + ${org.springframework-version} + + + + commons-logging + commons-logging + + + + + org.springframework + spring-webmvc + ${org.springframework-version} + + + + + org.slf4j + slf4j-api + ${org.slf4j-version} + + + org.slf4j + jcl-over-slf4j + ${org.slf4j-version} + runtime + + + org.slf4j + slf4j-log4j12 + ${org.slf4j-version} + runtime + + + log4j + log4j + 1.2.16 + runtime + + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + + + + + + + + + + + + + + + + org.springframework + spring-orm + ${org.springframework-version} + + + + org.springframework + spring-tx + ${org.springframework-version} + + + + org.springframework + spring-jdbc + ${org.springframework-version} + + + + org.hsqldb + hsqldb + 2.3.1 + + + + org.hibernate + hibernate-entitymanager + 4.3.0.Final + + + + + junit + junit + 4.8 + test + + + + + + spring-maven-snapshot + Springframework Maven Snapshot Repository + http://repo.spring.io/snapshot + + true + + + + + + + + maven-compiler-plugin + 3.1 + + ${java-version} + ${java-version} + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.8 + + + install + install + + sources + + + + + + org.apache.maven.plugins + maven-eclipse-plugin + 2.8 + + true + false + 2.0 + + + + maven-surefire-plugin + 2.16 + + + **/*Tests.java + + + **/*Abstract*.java + + + + + + + + diff --git a/SPR-11281/src/main/java/org/springframework/issues/.gitignore b/SPR-11281/src/main/java/org/springframework/issues/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/SPR-11281/src/main/java/org/springframework/issues/Controller1.java b/SPR-11281/src/main/java/org/springframework/issues/Controller1.java new file mode 100644 index 00000000..43f7ab30 --- /dev/null +++ b/SPR-11281/src/main/java/org/springframework/issues/Controller1.java @@ -0,0 +1,35 @@ +package org.springframework.issues; + +import javax.transaction.Transactional; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationListener; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * + * @author Alessandro Polverini + */ +@RestController +@Transactional +public class Controller1 implements ApplicationListener { + + private static final Logger logger = LoggerFactory.getLogger(Controller1.class); + + public Controller1() { + logger.info("Controller1 init"); + } + + @Override + public void onApplicationEvent(MyEvent e) { + logger.info("Received MyEvent"); + } + + @RequestMapping("/test") + public Object test(String msg) { + logger.info("Test method called"); + return "test: " + msg; + } + +} diff --git a/SPR-11281/src/main/java/org/springframework/issues/Controller2.java b/SPR-11281/src/main/java/org/springframework/issues/Controller2.java new file mode 100644 index 00000000..4e2fb459 --- /dev/null +++ b/SPR-11281/src/main/java/org/springframework/issues/Controller2.java @@ -0,0 +1,39 @@ +package org.springframework.issues; + +import javax.transaction.Transactional; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.ApplicationEventPublisherAware; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * + * @author Alessandro Polverini + */ +@RestController +@Transactional +public class Controller2 implements ApplicationEventPublisherAware { + + private static final Logger logger = LoggerFactory.getLogger(Controller2.class); + private ApplicationEventPublisher publisher; + + public Controller2() { + logger.info("Controller2 init"); + } + + @Override + public void setApplicationEventPublisher(ApplicationEventPublisher publisher) { + logger.info("ApplicationContextPublisher publisher: " + publisher); + this.publisher = publisher; + } + + @RequestMapping("/x1") + public Object publishClearCacheEvent() { + publisher.publishEvent(new MyEvent(this)); + logger.info("MyEvent published"); + return "Event published"; + } + +} diff --git a/SPR-11281/src/main/java/org/springframework/issues/MyEvent.java b/SPR-11281/src/main/java/org/springframework/issues/MyEvent.java new file mode 100644 index 00000000..d4217216 --- /dev/null +++ b/SPR-11281/src/main/java/org/springframework/issues/MyEvent.java @@ -0,0 +1,15 @@ +package org.springframework.issues; + +import org.springframework.context.ApplicationEvent; + +/** + * + * @author Alessandro Polverini + */ +class MyEvent extends ApplicationEvent { + + public MyEvent(Object source) { + super(source); + } + +} diff --git a/SPR-11281/src/main/java/org/springframework/issues/WebAppInitializer.java b/SPR-11281/src/main/java/org/springframework/issues/WebAppInitializer.java new file mode 100644 index 00000000..ed963694 --- /dev/null +++ b/SPR-11281/src/main/java/org/springframework/issues/WebAppInitializer.java @@ -0,0 +1,24 @@ +package org.springframework.issues; + +import javax.servlet.ServletContext; +import javax.servlet.ServletRegistration; +import org.springframework.web.WebApplicationInitializer; +import org.springframework.web.context.support.XmlWebApplicationContext; +import org.springframework.web.servlet.DispatcherServlet; + +/** + * + * @author Alessandro Polverini + */ +public class WebAppInitializer implements WebApplicationInitializer { + + @Override + public void onStartup(ServletContext container) { + XmlWebApplicationContext appContext = new XmlWebApplicationContext(); + appContext.setConfigLocation("/WEB-INF/applicationContext.xml"); + + ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(appContext)); + dispatcher.setLoadOnStartup(1); + dispatcher.addMapping("/"); + } +} diff --git a/SPR-11281/src/main/resources/log4j.properties b/SPR-11281/src/main/resources/log4j.properties new file mode 100644 index 00000000..dca18205 --- /dev/null +++ b/SPR-11281/src/main/resources/log4j.properties @@ -0,0 +1,8 @@ +log4j.rootCategory=INFO, 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.web=DEBUG +log4j.category.org.springframework.issues=DEBUG diff --git a/SPR-11281/src/main/webapp/META-INF/context.xml b/SPR-11281/src/main/webapp/META-INF/context.xml new file mode 100644 index 00000000..84efc92d --- /dev/null +++ b/SPR-11281/src/main/webapp/META-INF/context.xml @@ -0,0 +1,2 @@ + + diff --git a/SPR-11281/src/main/webapp/WEB-INF/applicationContext.xml b/SPR-11281/src/main/webapp/WEB-INF/applicationContext.xml new file mode 100644 index 00000000..3626f2d9 --- /dev/null +++ b/SPR-11281/src/main/webapp/WEB-INF/applicationContext.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + diff --git a/SPR-11281/src/main/webapp/WEB-INF/views/home.jsp b/SPR-11281/src/main/webapp/WEB-INF/views/home.jsp new file mode 100644 index 00000000..1696c2dd --- /dev/null +++ b/SPR-11281/src/main/webapp/WEB-INF/views/home.jsp @@ -0,0 +1,11 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> + + + + +Home + + +

Home

+ + diff --git a/SPR-11281/src/main/webapp/WEB-INF/web.xml b/SPR-11281/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..25c7ba93 --- /dev/null +++ b/SPR-11281/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,6 @@ + + + + diff --git a/SPR-11281/src/test/java/org/springframework/issues/.gitignore b/SPR-11281/src/test/java/org/springframework/issues/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/SPR-11281/src/test/resources/log4j.properties b/SPR-11281/src/test/resources/log4j.properties new file mode 100644 index 00000000..17a835fa --- /dev/null +++ b/SPR-11281/src/test/resources/log4j.properties @@ -0,0 +1,7 @@ +log4j.rootCategory=INFO, 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.web=DEBUG