Use Spotless for formatting (DataDog/dd-trace-java#1619)

This commit is contained in:
Tyler Benson 2020-06-19 15:17:38 -04:00 committed by Trask Stalnaker
parent b558c50229
commit 4a943c8411
26 changed files with 356 additions and 201 deletions

View File

@ -663,10 +663,8 @@ ij_groovy_while_brace_force = never
ij_groovy_while_on_new_line = false
ij_groovy_wrap_long_lines = false
[{*.gradle.kts,*.kt,*.kts,*.main.kts}]
indent_size = 4
tab_width = 4
ij_continuation_indent_size = 8
[{*.kt,*.kts}]
ij_continuation_indent_size = 2
ij_kotlin_align_in_columns_case_branch = false
ij_kotlin_align_multiline_binary_operation = false
ij_kotlin_align_multiline_extends_list = false

14
.githooks/pre-commit Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
if ! ./gradlew spotlessCheck; then
./gradlew spotlessApply
echo ""
echo ""
echo -e "\033[0;33mCode has been formatted; please git diff/add and recommit."
echo ""
echo ""
exit 1
fi

View File

@ -145,31 +145,34 @@ We follow the [Google Java Style
Guide](https://google.github.io/styleguide/javaguide.html). Our build will
fail if source code is not formatted according to that style.
To verify code style manually run the following command, which uses
[google-java-format](https://github.com/google/google-java-format) library:
The main goal is to avoid extensive reformatting caused by different IDEs having different opinion
about how things should be formatted by establishing.
`./gradlew verifyGoogleJavaFormat`
Running
or on Windows
```bash
./gradlew spotlessApply
```
`gradlew.bat verifyGoogleJavaFormat`
reformats all the files that need reformatting.
Instead of fixing style inconsistencies by hand, you can run gradle task
`googleJavaFormat` to automatically fix all found issues:
Running
`./gradlew googleJavaFormat`
```bash
./gradlew spotlessCheck
```
or on Windows
`gradlew.bat googleJavaFormat`
runs formatting verify task only.
#### Pre-commit hook
To completely delegate code style formatting to the machine, you can add [git
pre-commit hook](https://git-scm.com/docs/githooks). We provide an example
script in `buildscripts/pre-commit` file. Just copy or symlink it into
`.git/hooks` folder.
To completely delegate code style formatting to the machine,
there is a pre-commit hook setup to verify formatting before committing.
It can be activated with this command:
```bash
git config core.hooksPath .githooks
```
#### Editorconfig

View File

@ -8,14 +8,11 @@ plugins {
id 'org.unbroken-dome.test-sets' version '2.2.1'
id 'com.github.ben-manes.versions' version '0.27.0'
// Not applying google java format by default because it gets confused by stray java build
// files in 'workspace' build directory in CI
id 'com.github.sherter.google-java-format' version '0.8' apply false
id 'com.dorongold.task-tree' version '1.5'
id "com.github.johnrengelman.shadow" version "5.2.0"
id "com.diffplug.gradle.spotless" version "3.28.1"
id "com.diffplug.gradle.spotless" version "4.3.0"
id "com.github.spotbugs" version "4.0.1"
}
@ -67,3 +64,19 @@ task writeMuzzleTasksToFile {
.join('\n')
}
}
apply plugin: 'com.diffplug.gradle.spotless'
spotless {
// this formatting is applied at the root level, as some of these files are not in a submodules
// and would be missed otherwise
format 'misc', {
target '**/.gitignore', '**/*.md', '**/*.sh'
indentWithSpaces()
trimTrailingWhitespace()
endWithNewline()
}
}
task formatCode(dependsOn: ['spotlessApply'])
check.dependsOn 'spotlessCheck'

View File

@ -1,6 +1,7 @@
plugins {
groovy
`java-gradle-plugin`
id("com.diffplug.gradle.spotless") version "4.3.0"
}
gradlePlugin {

View File

@ -1,3 +0,0 @@
#!/usr/bin/env sh
./gradlew googleJavaFormat

View File

@ -34,15 +34,3 @@ check.dependsOn checkstyleTasks
tasks.withType(Test).configureEach {
mustRunAfter checkstyleTasks
}
// Verification seems broken on Java 9.
apply plugin: 'com.github.sherter.google-java-format'
googleJavaFormat {
source = sourceSets*.allJava
exclude '**/build/**/*.java'
}
tasks.withType(Checkstyle).configureEach {
mustRunAfter verifyGoogleJavaFormat
}

View File

@ -0,0 +1,12 @@
# Disable formatting errors
ignoreFormatterProblems=true
org.eclipse.jdt.core.formatter.tabulation.char=space
org.eclipse.jdt.core.formatter.tabulation.size=2
org.eclipse.jdt.core.formatter.indentation.size=1
org.eclipse.jdt.core.formatter.indentation.text_block_indentation=indent by one
org.eclipse.jdt.core.formatter.indent_empty_lines=false
org.eclipse.jdt.core.formatter.continuation_indentation=1
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=1
groovy.formatter.longListLength=50
groovy.formatter.multiline.indentation=1
groovy.formatter.remove.unnecessary.semicolons=true

View File

@ -2,6 +2,7 @@ apply plugin: 'com.diffplug.gradle.spotless'
spotless {
java {
googleJavaFormat()
licenseHeaderFile rootProject.file('gradle/enforcement/spotless.license.java'), '(package|import|public)'
target 'src/**/*.java'
}
@ -9,9 +10,15 @@ spotless {
licenseHeaderFile rootProject.file('gradle/enforcement/spotless.license.java'), '(package|import|class)'
}
scala {
scalafmt()
licenseHeaderFile rootProject.file('gradle/enforcement/spotless.license.java'), '(package|import|public)'
}
kotlin {
// ktfmt() // only supports 4 space indentation
ktlint().userData(['indent_size': '2', 'continuation_indent_size': '2'])
licenseHeaderFile rootProject.file('gradle/enforcement/spotless.license.java'), '(package|import|public)'
}
}
task formatCode(dependsOn: ['spotlessApply'])
check.dependsOn 'spotlessApply'

View File

@ -34,20 +34,27 @@ object AkkaHttpTestAsyncWebServer {
val asyncHandler: HttpRequest => Future[HttpResponse] = {
case HttpRequest(GET, uri: Uri, _, _, _) =>
Future {
val endpoint = HttpServerTest.ServerEndpoint.forPath(uri.path.toString())
HttpServerTest.controller(endpoint, new Closure[HttpResponse](()) {
def doCall(): HttpResponse = {
val resp = HttpResponse(status = endpoint.getStatus) //.withHeaders(headers.Type)resp.contentType = "text/plain"
endpoint match {
case SUCCESS => resp.withEntity(endpoint.getBody)
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
case REDIRECT => resp.withHeaders(headers.Location(endpoint.getBody))
case ERROR => resp.withEntity(endpoint.getBody)
case EXCEPTION => throw new Exception(endpoint.getBody)
case _ => HttpResponse(status = NOT_FOUND.getStatus).withEntity(NOT_FOUND.getBody)
val endpoint =
HttpServerTest.ServerEndpoint.forPath(uri.path.toString())
HttpServerTest.controller(
endpoint,
new Closure[HttpResponse](()) {
def doCall(): HttpResponse = {
val resp = HttpResponse(status = endpoint.getStatus) //.withHeaders(headers.Type)resp.contentType = "text/plain"
endpoint match {
case SUCCESS => resp.withEntity(endpoint.getBody)
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
case REDIRECT =>
resp.withHeaders(headers.Location(endpoint.getBody))
case ERROR => resp.withEntity(endpoint.getBody)
case EXCEPTION => throw new Exception(endpoint.getBody)
case _ =>
HttpResponse(status = NOT_FOUND.getStatus)
.withEntity(NOT_FOUND.getBody)
}
}
}
})
)
}
}
@ -56,7 +63,10 @@ object AkkaHttpTestAsyncWebServer {
def start(port: Int): Unit = synchronized {
if (null == binding) {
import scala.concurrent.duration._
binding = Await.result(Http().bindAndHandleAsync(asyncHandler, "localhost", port), 10 seconds)
binding = Await.result(
Http().bindAndHandleAsync(asyncHandler, "localhost", port),
10 seconds
)
}
}

View File

@ -34,19 +34,25 @@ object AkkaHttpTestSyncWebServer {
val syncHandler: HttpRequest => HttpResponse = {
case HttpRequest(GET, uri: Uri, _, _, _) => {
val endpoint = HttpServerTest.ServerEndpoint.forPath(uri.path.toString())
HttpServerTest.controller(endpoint, new Closure[HttpResponse](()) {
def doCall(): HttpResponse = {
val resp = HttpResponse(status = endpoint.getStatus)
endpoint match {
case SUCCESS => resp.withEntity(endpoint.getBody)
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
case REDIRECT => resp.withHeaders(headers.Location(endpoint.getBody))
case ERROR => resp.withEntity(endpoint.getBody)
case EXCEPTION => throw new Exception(endpoint.getBody)
case _ => HttpResponse(status = NOT_FOUND.getStatus).withEntity(NOT_FOUND.getBody)
HttpServerTest.controller(
endpoint,
new Closure[HttpResponse](()) {
def doCall(): HttpResponse = {
val resp = HttpResponse(status = endpoint.getStatus)
endpoint match {
case SUCCESS => resp.withEntity(endpoint.getBody)
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
case REDIRECT =>
resp.withHeaders(headers.Location(endpoint.getBody))
case ERROR => resp.withEntity(endpoint.getBody)
case EXCEPTION => throw new Exception(endpoint.getBody)
case _ =>
HttpResponse(status = NOT_FOUND.getStatus)
.withEntity(NOT_FOUND.getBody)
}
}
}
})
)
}
}
@ -55,7 +61,10 @@ object AkkaHttpTestSyncWebServer {
def start(port: Int): Unit = synchronized {
if (null == binding) {
import scala.concurrent.duration._
binding = Await.result(Http().bindAndHandleSync(syncHandler, "localhost", port), 10 seconds)
binding = Await.result(
Http().bindAndHandleSync(syncHandler, "localhost", port),
10 seconds
)
}
}

View File

@ -33,14 +33,21 @@ object AkkaHttpTestWebServer {
implicit val executionContext = system.dispatcher
val exceptionHandler = ExceptionHandler {
case ex: Exception => complete(HttpResponse(status = EXCEPTION.getStatus).withEntity(ex.getMessage))
case ex: Exception =>
complete(
HttpResponse(status = EXCEPTION.getStatus).withEntity(ex.getMessage)
)
}
val route = { //handleExceptions(exceptionHandler) {
path(SUCCESS.rawPath) {
complete(HttpResponse(status = SUCCESS.getStatus).withEntity(SUCCESS.getBody))
complete(
HttpResponse(status = SUCCESS.getStatus).withEntity(SUCCESS.getBody)
)
} ~ path(QUERY_PARAM.rawPath) {
complete(HttpResponse(status = QUERY_PARAM.getStatus).withEntity(SUCCESS.getBody))
complete(
HttpResponse(status = QUERY_PARAM.getStatus).withEntity(SUCCESS.getBody)
)
} ~ path(REDIRECT.rawPath) {
redirect(Uri(REDIRECT.getBody), StatusCodes.Found)
} ~ path(ERROR.rawPath) {
@ -55,7 +62,8 @@ object AkkaHttpTestWebServer {
def start(port: Int): Unit = synchronized {
if (null == binding) {
import scala.concurrent.duration._
binding = Await.result(Http().bindAndHandle(route, "localhost", port), 10 seconds)
binding =
Await.result(Http().bindAndHandle(route, "localhost", port), 10 seconds)
}
}

View File

@ -21,7 +21,7 @@ import javax.inject.{Inject, Singleton}
@Singleton
class ResponseSettingExceptionMapper @Inject()(response: ResponseBuilder)
extends ExceptionMapper[Exception] {
extends ExceptionMapper[Exception] {
override def toResponse(request: Request, exception: Exception): Response = {
response.internalServerError(exception.getMessage)

View File

@ -24,7 +24,8 @@ import scala.concurrent.duration._
// ! == send-message
object AkkaActors {
val TRACER: Tracer = OpenTelemetry.getTracerProvider.get("io.opentelemetry.auto")
val TRACER: Tracer =
OpenTelemetry.getTracerProvider.get("io.opentelemetry.auto")
val system: ActorSystem = ActorSystem("helloAkka")
@ -33,8 +34,10 @@ object AkkaActors {
val howdyGreeter: ActorRef =
system.actorOf(Greeter.props("Howdy", printer), "howdyGreeter")
val forwarder: ActorRef = system.actorOf(Forwarder.props(printer), "forwarderActor")
val helloGreeter: ActorRef = system.actorOf(Greeter.props("Hello", forwarder), "helloGreeter")
val forwarder: ActorRef =
system.actorOf(Forwarder.props(printer), "forwarderActor")
val helloGreeter: ActorRef =
system.actorOf(Greeter.props("Hello", forwarder), "helloGreeter")
def tracedChild(opName: String): Unit = {
TRACER.spanBuilder(opName).startSpan().end()
@ -86,7 +89,8 @@ class AkkaActors {
}
object Greeter {
def props(message: String, receiverActor: ActorRef): Props = Props(new Greeter(message, receiverActor))
def props(message: String, receiverActor: ActorRef): Props =
Props(new Greeter(message, receiverActor))
final case class WhoToGreet(who: String)
@ -129,7 +133,8 @@ class Receiver extends Actor with ActorLogging {
}
object Forwarder {
def props(receiverActor: ActorRef): Props = Props(new Forwarder(receiverActor))
def props(receiverActor: ActorRef): Props =
Props(new Forwarder(receiverActor))
}
class Forwarder(receiverActor: ActorRef) extends Actor with ActorLogging {

View File

@ -17,13 +17,22 @@
import io.opentelemetry.OpenTelemetry
import io.opentelemetry.trace.Tracer
import io.opentelemetry.trace.TracingContextUtils.currentContextWith
import kotlinx.coroutines.*
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.channels.consumeEach
import kotlinx.coroutines.channels.produce
import kotlinx.coroutines.channels.toChannel
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.selects.select
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.withTimeout
import kotlinx.coroutines.yield
class KotlinCoroutineTests(private val dispatcher: CoroutineDispatcher) {
val tracer: Tracer = OpenTelemetry.getTracerProvider().get("io.opentelemetry.auto")
@ -144,4 +153,3 @@ class KotlinCoroutineTests(private val dispatcher: CoroutineDispatcher) {
}
}
}

View File

@ -24,11 +24,12 @@ import scala.concurrent.duration._
import scala.concurrent.{Await, Future, Promise}
class ScalaConcurrentTests {
val TRACER: Tracer = OpenTelemetry.getTracerProvider.get("io.opentelemetry.auto")
val TRACER: Tracer =
OpenTelemetry.getTracerProvider.get("io.opentelemetry.auto")
/**
* @return Number of expected spans in the trace
*/
* @return Number of expected spans in the trace
*/
def traceWithFutureAndCallbacks() {
val parentSpan = TRACER.spanBuilder("parent").startSpan()
val parentScope = TRACER.withSpan(parentSpan)
@ -71,14 +72,15 @@ class ScalaConcurrentTests {
1
}
goodFuture onSuccess {
case _ => Future {
2
} onSuccess {
case _ => {
tracedChild("callback")
latch.countDown()
case _ =>
Future {
2
} onSuccess {
case _ => {
tracedChild("callback")
latch.countDown()
}
}
}
}
latch.await()
@ -89,8 +91,8 @@ class ScalaConcurrentTests {
}
/**
* @return Number of expected spans in the trace
*/
* @return Number of expected spans in the trace
*/
def traceWithPromises() {
val parentSpan = TRACER.spanBuilder("parent").startSpan()
val parentScope = TRACER.withSpan(parentSpan)
@ -137,26 +139,22 @@ class ScalaConcurrentTests {
}
/**
* @return Number of expected spans in the trace
*/
* @return Number of expected spans in the trace
*/
def tracedWithFutureFirstCompletions() {
val parentSpan = TRACER.spanBuilder("parent").startSpan()
val parentScope = TRACER.withSpan(parentSpan)
try {
val completedVal = Future.firstCompletedOf(
List(
Future {
tracedChild("timeout1")
false
},
Future {
tracedChild("timeout2")
false
},
Future {
tracedChild("timeout3")
true
}))
val completedVal = Future.firstCompletedOf(List(Future {
tracedChild("timeout1")
false
}, Future {
tracedChild("timeout2")
false
}, Future {
tracedChild("timeout3")
true
}))
Await.result(completedVal, 30 seconds)
} finally {
parentSpan.end()
@ -165,8 +163,8 @@ class ScalaConcurrentTests {
}
/**
* @return Number of expected spans in the trace
*/
* @return Number of expected spans in the trace
*/
def tracedTimeout(): Integer = {
val parentSpan = TRACER.spanBuilder("parent").startSpan()
val parentScope = TRACER.withSpan(parentSpan)

View File

@ -22,11 +22,13 @@ import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
class SlickUtils {
val TRACER: Tracer = OpenTelemetry.getTracerProvider.get("io.opentelemetry.auto")
val TRACER: Tracer =
OpenTelemetry.getTracerProvider.get("io.opentelemetry.auto")
import SlickUtils._
val database = Database.forURL(Url,
val database = Database.forURL(
Url,
user = Username,
driver = "org.h2.Driver",
keepAliveConnection = true,
@ -34,7 +36,12 @@ class SlickUtils {
// wrapped runnables.
executor = AsyncExecutor("test", numThreads = 1, queueSize = 1000)
)
Await.result(database.run(sqlu"""CREATE ALIAS IF NOT EXISTS SLEEP FOR "java.lang.Thread.sleep(long)""""), Duration.Inf)
Await.result(
database.run(
sqlu"""CREATE ALIAS IF NOT EXISTS SLEEP FOR "java.lang.Thread.sleep(long)""""
),
Duration.Inf
)
def startQuery(query: String): Future[Vector[Int]] = {
val span = TRACER.spanBuilder("run query").startSpan()

View File

@ -1,5 +1,5 @@
plugins {
id 'com.intershop.gradle.javacc' version '4.0.0'
id 'com.intershop.gradle.javacc' version '4.0.0'
}
apply from: "$rootDir/gradle/instrumentation.gradle"
@ -21,9 +21,6 @@ javacc {
}
}
tasks.withType(com.github.sherter.googlejavaformatgradleplugin.VerifyGoogleJavaFormat).configureEach {
exclude '**/jdbc/normalizer/*.java'
}
tasks.withType(Checkstyle).configureEach {
exclude '**/jdbc/normalizer/*.java'
}
@ -36,7 +33,8 @@ testSets {
dependencies {
// jdbc unit testing
testCompile group: 'com.h2database', name: 'h2', version: '1.3.169' // first version jdk 1.6 compatible
testCompile group: 'com.h2database', name: 'h2', version: '1.3.169'
// first version jdk 1.6 compatible
testCompile group: 'org.apache.derby', name: 'derby', version: '10.6.1.0'
testCompile group: 'org.hsqldb', name: 'hsqldb', version: '2.0.0'

View File

@ -25,18 +25,64 @@ import scala.concurrent.Future
object AsyncServer {
val routes: PartialFunction[(String, String), Handler] = {
case ("GET", "/success") => Action.async { request => HttpServerTest.controller(SUCCESS, new AsyncControllerClosureAdapter(Future.successful(Results.Status(SUCCESS.getStatus).apply(SUCCESS.getBody)))) }
case ("GET", "/redirect") => Action.async { request => HttpServerTest.controller(REDIRECT, new AsyncControllerClosureAdapter(Future.successful(Results.Redirect(REDIRECT.getBody, REDIRECT.getStatus)))) }
case ("GET", "/query") => Action.async { result => HttpServerTest.controller(QUERY_PARAM, new AsyncControllerClosureAdapter(Future.successful(Results.Status(QUERY_PARAM.getStatus).apply(QUERY_PARAM.getBody)))) }
case ("GET", "/error-status") => Action.async { result => HttpServerTest.controller(ERROR, new AsyncControllerClosureAdapter(Future.successful(Results.Status(ERROR.getStatus).apply(ERROR.getBody)))) }
case ("GET", "/exception") => Action.async { result =>
HttpServerTest.controller(EXCEPTION, new AsyncBlockClosureAdapter(() => {
throw new Exception(EXCEPTION.getBody)
}))
}
case ("GET", "/success") =>
Action.async { request =>
HttpServerTest.controller(
SUCCESS,
new AsyncControllerClosureAdapter(
Future.successful(
Results.Status(SUCCESS.getStatus).apply(SUCCESS.getBody)
)
)
)
}
case ("GET", "/redirect") =>
Action.async { request =>
HttpServerTest.controller(
REDIRECT,
new AsyncControllerClosureAdapter(
Future.successful(
Results.Redirect(REDIRECT.getBody, REDIRECT.getStatus)
)
)
)
}
case ("GET", "/query") =>
Action.async { result =>
HttpServerTest.controller(
QUERY_PARAM,
new AsyncControllerClosureAdapter(
Future.successful(
Results.Status(QUERY_PARAM.getStatus).apply(QUERY_PARAM.getBody)
)
)
)
}
case ("GET", "/error-status") =>
Action.async { result =>
HttpServerTest.controller(
ERROR,
new AsyncControllerClosureAdapter(
Future
.successful(Results.Status(ERROR.getStatus).apply(ERROR.getBody))
)
)
}
case ("GET", "/exception") =>
Action.async { result =>
HttpServerTest.controller(
EXCEPTION,
new AsyncBlockClosureAdapter(() => {
throw new Exception(EXCEPTION.getBody)
})
)
}
}
def server(port: Int): TestServer = {
TestServer(port, FakeApplication(withGlobal = Some(new Settings()), withRoutes = routes))
TestServer(
port,
FakeApplication(withGlobal = Some(new Settings()), withRoutes = routes)
)
}
}

View File

@ -29,10 +29,12 @@ class BlockClosureAdapter(block: () => Result) extends Closure[Result] {
override def call(): Result = block()
}
class AsyncControllerClosureAdapter(response: Future[Result]) extends Closure[Future[Result]] {
class AsyncControllerClosureAdapter(response: Future[Result])
extends Closure[Future[Result]] {
override def call(): Future[Result] = response
}
class AsyncBlockClosureAdapter(block: () => Future[Result]) extends Closure[Future[Result]] {
class AsyncBlockClosureAdapter(block: () => Future[Result])
extends Closure[Future[Result]] {
override def call(): Future[Result] = block()
}

View File

@ -22,7 +22,10 @@ import play.api.mvc.{RequestHeader, Result, Results}
import scala.concurrent.Future
class Settings extends GlobalSettings {
override def onError(request: RequestHeader, ex: Throwable): Future[Result] = {
override def onError(
request: RequestHeader,
ex: Throwable
): Future[Result] = {
Future.successful(Results.InternalServerError(ex.getCause.getMessage))
}
}

View File

@ -23,26 +23,54 @@ import play.api.test.{FakeApplication, TestServer}
object SyncServer {
val routes: PartialFunction[(String, String), Handler] = {
case ("GET", "/success") => Action { request =>
HttpServerTest.controller(SUCCESS, new ControllerClosureAdapter(Results.Status(SUCCESS.getStatus).apply(SUCCESS.getBody)))
}
case ("GET", "/redirect") => Action { request =>
HttpServerTest.controller(REDIRECT, new ControllerClosureAdapter(Results.Redirect(REDIRECT.getBody, REDIRECT.getStatus)))
}
case ("GET", "/query") => Action { request =>
HttpServerTest.controller(QUERY_PARAM, new ControllerClosureAdapter(Results.Status(QUERY_PARAM.getStatus).apply(QUERY_PARAM.getBody)))
}
case ("GET", "/error-status") => Action { request =>
HttpServerTest.controller(ERROR, new ControllerClosureAdapter(Results.Status(ERROR.getStatus).apply(ERROR.getBody)))
}
case ("GET", "/exception") => Action { request =>
HttpServerTest.controller(EXCEPTION, new BlockClosureAdapter(() => {
throw new Exception(EXCEPTION.getBody)
}))
}
case ("GET", "/success") =>
Action { request =>
HttpServerTest.controller(
SUCCESS,
new ControllerClosureAdapter(
Results.Status(SUCCESS.getStatus).apply(SUCCESS.getBody)
)
)
}
case ("GET", "/redirect") =>
Action { request =>
HttpServerTest.controller(
REDIRECT,
new ControllerClosureAdapter(
Results.Redirect(REDIRECT.getBody, REDIRECT.getStatus)
)
)
}
case ("GET", "/query") =>
Action { request =>
HttpServerTest.controller(
QUERY_PARAM,
new ControllerClosureAdapter(
Results.Status(QUERY_PARAM.getStatus).apply(QUERY_PARAM.getBody)
)
)
}
case ("GET", "/error-status") =>
Action { request =>
HttpServerTest.controller(
ERROR,
new ControllerClosureAdapter(
Results.Status(ERROR.getStatus).apply(ERROR.getBody)
)
)
}
case ("GET", "/exception") =>
Action { request =>
HttpServerTest.controller(EXCEPTION, new BlockClosureAdapter(() => {
throw new Exception(EXCEPTION.getBody)
}))
}
}
def server(port: Int): TestServer = {
TestServer(port, FakeApplication(withGlobal = Some(new Settings()), withRoutes = routes))
TestServer(
port,
FakeApplication(withGlobal = Some(new Settings()), withRoutes = routes)
)
}
}