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

Commit

Permalink
Add repro project for SPR-15701
Browse files Browse the repository at this point in the history
  • Loading branch information
dorongold committed Jun 24, 2017
1 parent 8a349c2 commit 307a7c0
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 0 deletions.
39 changes: 39 additions & 0 deletions SPR-15701/build.gradle
@@ -0,0 +1,39 @@
group = 'org.springframework.issues'
version = '1.0.0.SNAPSHOT'

buildscript {
ext {
springBootVersion = '2.0.0.M2'
}
repositories {
maven {
url "http://repo.spring.io/libs-milestone"
}
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

repositories {
maven {
url "http://repo.spring.io/libs-milestone"
}
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile("org.springframework.boot:spring-boot-starter-webflux")
testCompile('org.springframework.boot:spring-boot-starter-test')
}


@@ -0,0 +1,12 @@
package org.springframework.issues.errorhandling;

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

@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@@ -0,0 +1,11 @@
package org.springframework.issues.errorhandling;

/**
* Created by dorongold on 6/23/17.
*/
public class CustomException extends RuntimeException {

public CustomException(final String message, final Throwable cause) {
super(message, cause);
}
}
@@ -0,0 +1,22 @@
package org.springframework.issues.errorhandling;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

public static final String ERROR_MSG = "An error occurred!";

@RequestMapping("/hello")
public String hello() {
final NestedException nested = new NestedException("nested");
throw new CustomException("outer", nested);
}

@ExceptionHandler()
public String handleCustomException(final CustomException e) {
return ERROR_MSG;
}
}
@@ -0,0 +1,11 @@
package org.springframework.issues.errorhandling;

/**
* Created by dorongold on 6/23/17.
*/
public class NestedException extends Exception {

public NestedException(final String message) {
super(message);
}
}
@@ -0,0 +1,36 @@
package org.springframework.issues.errorhandling;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;

/**
* Created by dorongold on 6/24/17.
*/

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureWebTestClient
public class HelloControllerTest {

@Autowired
private WebTestClient client;

/*
* fails because exception handler invocation fails with "java.lang.IllegalStateException: No suitable resolver
* for argument 0 of type..."
*/
@Test
public void testHello() {

final String response = client.get().uri("hello").exchange().expectBody(String.class).returnResult().getResponseBody();
assertEquals(HelloController.ERROR_MSG, response);
}

}

0 comments on commit 307a7c0

Please sign in to comment.