Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Add repro project for SPR-14397 #133

Merged
merged 1 commit into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions SPR-14397/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Repro project for SPR-14397

## 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`.
103 changes: 103 additions & 0 deletions SPR-14397/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.issues</groupId>
<artifactId>SPR-14397</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.BUILD-SNAPSHOT</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<java.version>1.6</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Tests.java</include>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/*Abstract*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-maven-snapshot</id>
<name>Springframework Maven Snapshot Repository</name>
<url>http://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
<pluginRepository>
<id>spring-maven-snapshot</id>
<name>Springframework Maven Snapshot Repository</name>
<url>http://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.springframework.issues;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
28 changes: 28 additions & 0 deletions SPR-14397/src/main/java/org/springframework/issues/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.springframework.issues;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/test")
public class Controller {
@RequestMapping(value = "",
method = { RequestMethod.POST },
consumes = { MediaType.APPLICATION_JSON_VALUE },
produces = { MediaType.APPLICATION_JSON_VALUE }
)
public String post1() {
return "Accept: JSON";
}

@RequestMapping(value = "",
method = { RequestMethod.POST },
consumes = { MediaType.TEXT_PLAIN_VALUE },
produces = { MediaType.APPLICATION_JSON_VALUE }
)
public String post2() {
return "Accept: TEXT";
}
}
70 changes: 70 additions & 0 deletions SPR-14397/src/test/java/org/springframework/issues/ReproTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.springframework.issues;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

/**
* 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.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
public class ReproTests {
@Autowired
private WebApplicationContext wac;

private MockMvc mockMvc;

@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}

@Test
public void testInputJson() throws Exception {
// Works fine, matches post1()
this.mockMvc.perform(post("/test")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
}

@Test
public void testInputText() throws Exception {
// Works fine, matches post2()
this.mockMvc.perform(post("/test")
.contentType(MediaType.TEXT_PLAIN)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
}

@Test
public void testInputJsonBadAccept() throws Exception {
// Mismatches post1() by specifying an invalid Accept header but a valid Content-Type header
this.mockMvc.perform(post("/test")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_XML))
.andExpect(status().isNotAcceptable());
}

@Test
public void testInputTextBadAccept() throws Exception {
// Mismatches post2() by specifying an invalid Accept header but a valid Content-Type header
this.mockMvc.perform(post("/test")
.contentType(MediaType.TEXT_PLAIN)
.accept(MediaType.APPLICATION_XML))
.andExpect(status().isNotAcceptable());
}
}
7 changes: 7 additions & 0 deletions SPR-14397/src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">

</beans>