From 041081078c492a3ed5641bc1bc88be0d8c8777b5 Mon Sep 17 00:00:00 2001 From: Alessio Coser Date: Fri, 13 Mar 2020 13:11:26 +0100 Subject: [PATCH] extracted routing in an external library: daikon-core --- build.gradle | 1 + src/main/kotlin/daikon/BasicAuthentication.kt | 4 +- src/main/kotlin/daikon/Context.kt | 7 -- src/main/kotlin/daikon/DefaultRouteAction.kt | 77 ---------------- src/main/kotlin/daikon/DummyRouteAction.kt | 13 --- src/main/kotlin/daikon/HaltException.kt | 3 - src/main/kotlin/daikon/HttpRequest.kt | 3 + src/main/kotlin/daikon/HttpResponse.kt | 1 + src/main/kotlin/daikon/HttpServer.kt | 5 +- src/main/kotlin/daikon/HttpStatus.kt | 89 ------------------- src/main/kotlin/daikon/Method.kt | 11 --- src/main/kotlin/daikon/PathParams.kt | 14 --- src/main/kotlin/daikon/Request.kt | 14 --- src/main/kotlin/daikon/RequestFlow.kt | 11 --- src/main/kotlin/daikon/Response.kt | 12 --- src/main/kotlin/daikon/Route.kt | 18 ---- src/main/kotlin/daikon/RouteAction.kt | 5 -- src/main/kotlin/daikon/Routing.kt | 46 ---------- src/main/kotlin/daikon/RoutingHandler.kt | 32 ------- src/main/kotlin/daikon/RoutingServlet.kt | 3 + src/main/kotlin/daikon/ServerContext.kt | 2 + .../daikon/BasicAuthenticationHttpTest.kt | 4 +- .../kotlin/daikon/DefaultRouteActionTest.kt | 10 ++- src/test/kotlin/daikon/HooksTest.kt | 2 +- src/test/kotlin/daikon/HttpMethodsTest.kt | 8 +- src/test/kotlin/daikon/HttpRoutingTest.kt | 14 +-- src/test/kotlin/daikon/HttpServerTest.kt | 2 +- src/test/kotlin/daikon/NopAction.kt | 5 ++ src/test/kotlin/daikon/PathParamsTest.kt | 1 + src/test/kotlin/daikon/PerformanceTest.kt | 2 +- src/test/kotlin/daikon/RequestTest.kt | 2 +- src/test/kotlin/daikon/ResponseTest.kt | 4 +- src/test/kotlin/daikon/RoutingTest.kt | 5 +- src/test/kotlin/daikon/WelcomePageTest.kt | 4 +- 34 files changed, 56 insertions(+), 378 deletions(-) delete mode 100644 src/main/kotlin/daikon/Context.kt delete mode 100644 src/main/kotlin/daikon/DefaultRouteAction.kt delete mode 100644 src/main/kotlin/daikon/DummyRouteAction.kt delete mode 100644 src/main/kotlin/daikon/HaltException.kt delete mode 100644 src/main/kotlin/daikon/HttpStatus.kt delete mode 100644 src/main/kotlin/daikon/Method.kt delete mode 100644 src/main/kotlin/daikon/PathParams.kt delete mode 100644 src/main/kotlin/daikon/Request.kt delete mode 100644 src/main/kotlin/daikon/RequestFlow.kt delete mode 100644 src/main/kotlin/daikon/Response.kt delete mode 100644 src/main/kotlin/daikon/Route.kt delete mode 100644 src/main/kotlin/daikon/RouteAction.kt delete mode 100644 src/main/kotlin/daikon/Routing.kt delete mode 100644 src/main/kotlin/daikon/RoutingHandler.kt diff --git a/build.gradle b/build.gradle index 1ed62e6..5aaccc6 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,7 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") compile("org.eclipse.jetty:jetty-server:9.4.26.v20200117") compile("org.eclipse.jetty:jetty-servlet:9.4.26.v20200117") + compile("com.github.DaikonWeb:daikon-core:0.0.1") testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2") testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0") testImplementation("org.junit.jupiter:junit-jupiter-api:5.5.1") diff --git a/src/main/kotlin/daikon/BasicAuthentication.kt b/src/main/kotlin/daikon/BasicAuthentication.kt index fb218f0..6cf9ab5 100644 --- a/src/main/kotlin/daikon/BasicAuthentication.kt +++ b/src/main/kotlin/daikon/BasicAuthentication.kt @@ -1,6 +1,8 @@ package daikon -import daikon.RequestFlow.halt +import daikon.core.Request +import daikon.core.RequestFlow.halt +import daikon.core.Response import org.eclipse.jetty.http.HttpHeader.AUTHORIZATION import org.eclipse.jetty.http.HttpHeader.WWW_AUTHENTICATE import java.nio.charset.StandardCharsets.UTF_8 diff --git a/src/main/kotlin/daikon/Context.kt b/src/main/kotlin/daikon/Context.kt deleted file mode 100644 index 407498f..0000000 --- a/src/main/kotlin/daikon/Context.kt +++ /dev/null @@ -1,7 +0,0 @@ -package daikon - -interface Context { - fun addAttribute(key: String, value: Any) - fun getAttribute(key: String) : T - fun port(): Int -} \ No newline at end of file diff --git a/src/main/kotlin/daikon/DefaultRouteAction.kt b/src/main/kotlin/daikon/DefaultRouteAction.kt deleted file mode 100644 index 2c9618c..0000000 --- a/src/main/kotlin/daikon/DefaultRouteAction.kt +++ /dev/null @@ -1,77 +0,0 @@ -package daikon - -import daikon.Method.GET -import daikon.HttpStatus.NOT_FOUND_404 -import daikon.HttpStatus.OK_200 - -class DefaultRouteAction : RouteAction { - override fun handle(request: Request, response: Response, context: Context) { - if (request.method() == GET && request.path() == "/") { - response.status(OK_200) - response.type("text/html") - response.write(html()) - } else { - response.status(NOT_FOUND_404) - } - } - - private fun html() = """ - - - Welcome to Daikon! - -
-

You are eating a Daikon!!

- - - - - - - - - - - - -
- - -""" - -} diff --git a/src/main/kotlin/daikon/DummyRouteAction.kt b/src/main/kotlin/daikon/DummyRouteAction.kt deleted file mode 100644 index 1fb09fc..0000000 --- a/src/main/kotlin/daikon/DummyRouteAction.kt +++ /dev/null @@ -1,13 +0,0 @@ -package daikon - -class DummyRouteAction(private val action: (Request, Response) -> Unit) : RouteAction { - override fun handle(request: Request, response: Response, context: Context) { - action.invoke(request, response) - } -} - -class ContextRouteAction(private val action: (Request, Response, Context) -> Unit) : RouteAction { - override fun handle(request: Request, response: Response, context: Context) { - action.invoke(request, response, context) - } -} \ No newline at end of file diff --git a/src/main/kotlin/daikon/HaltException.kt b/src/main/kotlin/daikon/HaltException.kt deleted file mode 100644 index 5cf0ed7..0000000 --- a/src/main/kotlin/daikon/HaltException.kt +++ /dev/null @@ -1,3 +0,0 @@ -package daikon - -class HaltException : Throwable() diff --git a/src/main/kotlin/daikon/HttpRequest.kt b/src/main/kotlin/daikon/HttpRequest.kt index a1e0f74..ffb43a8 100644 --- a/src/main/kotlin/daikon/HttpRequest.kt +++ b/src/main/kotlin/daikon/HttpRequest.kt @@ -1,5 +1,8 @@ package daikon +import daikon.core.Method +import daikon.core.PathParams +import daikon.core.Request import javax.servlet.http.HttpServletRequest class HttpRequest(private val request: HttpServletRequest) : Request { diff --git a/src/main/kotlin/daikon/HttpResponse.kt b/src/main/kotlin/daikon/HttpResponse.kt index 02a2a6e..704726f 100644 --- a/src/main/kotlin/daikon/HttpResponse.kt +++ b/src/main/kotlin/daikon/HttpResponse.kt @@ -1,5 +1,6 @@ package daikon +import daikon.core.Response import java.io.StringWriter import java.nio.charset.StandardCharsets.UTF_8 import javax.servlet.http.HttpServletResponse diff --git a/src/main/kotlin/daikon/HttpServer.kt b/src/main/kotlin/daikon/HttpServer.kt index 8f05919..b89d1a1 100644 --- a/src/main/kotlin/daikon/HttpServer.kt +++ b/src/main/kotlin/daikon/HttpServer.kt @@ -1,6 +1,7 @@ package daikon -import daikon.Method.* +import daikon.core.Method.* +import daikon.core.* import org.eclipse.jetty.server.Server import org.eclipse.jetty.servlet.DefaultServlet import org.eclipse.jetty.servlet.ServletContextHandler @@ -163,7 +164,7 @@ class HttpServer(private val port: Int = 4545, initializeActions: HttpServer.() } fun after(path: String = "/*", action: (Request, Response) -> Unit): HttpServer { - afterActions.add(Route(ANY, joinPaths(path), DummyRouteAction(action))) + afterActions.add(Route(Method.ANY, joinPaths(path), DummyRouteAction(action))) return this } diff --git a/src/main/kotlin/daikon/HttpStatus.kt b/src/main/kotlin/daikon/HttpStatus.kt deleted file mode 100644 index 4430291..0000000 --- a/src/main/kotlin/daikon/HttpStatus.kt +++ /dev/null @@ -1,89 +0,0 @@ -package daikon - -object HttpStatus { - const val CONTINUE_100 = 100 - const val SWITCHING_PROTOCOLS_101 = 101 - const val PROCESSING_102 = 102 - const val OK_200 = 200 - const val CREATED_201 = 201 - const val ACCEPTED_202 = 202 - const val NON_AUTHORITATIVE_INFORMATION_203 = 203 - const val NO_CONTENT_204 = 204 - const val RESET_CONTENT_205 = 205 - const val PARTIAL_CONTENT_206 = 206 - const val MULTI_STATUS_207 = 207 - const val MULTIPLE_CHOICES_300 = 300 - const val MOVED_PERMANENTLY_301 = 301 - const val MOVED_TEMPORARILY_302 = 302 - const val SEE_OTHER_303 = 303 - const val NOT_MODIFIED_304 = 304 - const val USE_PROXY_305 = 305 - const val TEMPORARY_REDIRECT_307 = 307 - const val PERMANENT_REDIRECT_308 = 308 - const val BAD_REQUEST_400 = 400 - const val UNAUTHORIZED_401 = 401 - const val PAYMENT_REQUIRED_402 = 402 - const val FORBIDDEN_403 = 403 - const val NOT_FOUND_404 = 404 - const val METHOD_NOT_ALLOWED_405 = 405 - const val NOT_ACCEPTABLE_406 = 406 - const val PROXY_AUTHENTICATION_REQUIRED_407 = 407 - const val REQUEST_TIMEOUT_408 = 408 - const val CONFLICT_409 = 409 - const val GONE_410 = 410 - const val LENGTH_REQUIRED_411 = 411 - const val PRECONDITION_FAILED_412 = 412 - const val PAYLOAD_TOO_LARGE_413 = 413 - const val URI_TOO_LONG_414 = 414 - const val UNSUPPORTED_MEDIA_TYPE_415 = 415 - const val RANGE_NOT_SATISFIABLE_416 = 416 - const val EXPECTATION_FAILED_417 = 417 - const val IM_A_TEAPOT_418 = 418 - const val ENHANCE_YOUR_CALM_420 = 420 - const val MISDIRECTED_REQUEST_421 = 421 - const val UNPROCESSABLE_ENTITY_422 = 422 - const val LOCKED_423 = 423 - const val FAILED_DEPENDENCY_424 = 424 - const val UPGRADE_REQUIRED_426 = 426 - const val PRECONDITION_REQUIRED_428 = 428 - const val TOO_MANY_REQUESTS_429 = 429 - const val REQUEST_HEADER_FIELDS_TOO_LARGE_431 = 431 - const val UNAVAILABLE_FOR_LEGAL_REASONS_451 = 451 - const val INTERNAL_SERVER_ERROR_500 = 500 - const val NOT_IMPLEMENTED_501 = 501 - const val BAD_GATEWAY_502 = 502 - const val SERVICE_UNAVAILABLE_503 = 503 - const val GATEWAY_TIMEOUT_504 = 504 - const val HTTP_VERSION_NOT_SUPPORTED_505 = 505 - const val INSUFFICIENT_STORAGE_507 = 507 - const val LOOP_DETECTED_508 = 508 - const val NOT_EXTENDED_510 = 510 - const val NETWORK_AUTHENTICATION_REQUIRED_511 = 511 - - fun hasNoBody(code: Int): Boolean { - return when (code) { - NO_CONTENT_204, NOT_MODIFIED_304, PARTIAL_CONTENT_206 -> true - else -> code < OK_200 - } - } - - fun isInformational(code: Int): Boolean { - return code in 100..199 - } - - fun isSuccess(code: Int): Boolean { - return code in 200..299 - } - - fun isRedirection(code: Int): Boolean { - return code in 300..399 - } - - fun isClientError(code: Int): Boolean { - return code in 400..499 - } - - fun isServerError(code: Int): Boolean { - return code in 500..599 - } -} \ No newline at end of file diff --git a/src/main/kotlin/daikon/Method.kt b/src/main/kotlin/daikon/Method.kt deleted file mode 100644 index ca89050..0000000 --- a/src/main/kotlin/daikon/Method.kt +++ /dev/null @@ -1,11 +0,0 @@ -package daikon - -enum class Method { - GET, - POST, - PUT, - DELETE, - OPTIONS, - HEAD, - ANY -} \ No newline at end of file diff --git a/src/main/kotlin/daikon/PathParams.kt b/src/main/kotlin/daikon/PathParams.kt deleted file mode 100644 index 2d17631..0000000 --- a/src/main/kotlin/daikon/PathParams.kt +++ /dev/null @@ -1,14 +0,0 @@ -package daikon - -class PathParams(private val path: String) { - - fun path(): String { - return path.split("/").joinToString(separator = "/") { if (it.startsWith(":")) "[^/]+" else it } - } - - fun valueOf(ulrPath: String): Map { - val parts = ulrPath.split("/") - val placeholders = path.split("/").mapIndexed { index, part -> index to part }.toMap() - return placeholders.map { entry -> entry.value to parts[entry.key] }.toMap() - } -} diff --git a/src/main/kotlin/daikon/Request.kt b/src/main/kotlin/daikon/Request.kt deleted file mode 100644 index e0d7c59..0000000 --- a/src/main/kotlin/daikon/Request.kt +++ /dev/null @@ -1,14 +0,0 @@ -package daikon - -interface Request { - fun param(name: String): String - fun header(name: String): String - fun hasHeader(name: String): Boolean - fun body(): String - fun url(): String - fun path(): String - fun attribute(key: String, value: T) - fun attribute(key: String) : T - fun method(): Method - fun withPathParams(value: String): Request -} \ No newline at end of file diff --git a/src/main/kotlin/daikon/RequestFlow.kt b/src/main/kotlin/daikon/RequestFlow.kt deleted file mode 100644 index 647a566..0000000 --- a/src/main/kotlin/daikon/RequestFlow.kt +++ /dev/null @@ -1,11 +0,0 @@ -package daikon - -import daikon.HttpStatus.INTERNAL_SERVER_ERROR_500 - -object RequestFlow { - fun halt(response: Response, statusCode: Int = INTERNAL_SERVER_ERROR_500, message: String = "") { - response.status(statusCode) - response.write(message) - throw HaltException() - } -} diff --git a/src/main/kotlin/daikon/Response.kt b/src/main/kotlin/daikon/Response.kt deleted file mode 100644 index a1fe187..0000000 --- a/src/main/kotlin/daikon/Response.kt +++ /dev/null @@ -1,12 +0,0 @@ -package daikon - -import daikon.HttpStatus.MOVED_TEMPORARILY_302 - -interface Response { - fun write(text: String) - fun status(code: Int) - fun type(contentType: String) - fun header(name: String, value: String) - fun body(): String - fun redirect(path: String, status: Int = MOVED_TEMPORARILY_302) -} \ No newline at end of file diff --git a/src/main/kotlin/daikon/Route.kt b/src/main/kotlin/daikon/Route.kt deleted file mode 100644 index a333caf..0000000 --- a/src/main/kotlin/daikon/Route.kt +++ /dev/null @@ -1,18 +0,0 @@ -package daikon - -data class Route(val method: Method, val path: String, val action: RouteAction) { - - private fun pathPattern() : Regex { - if(path.contains(":")) { - return asRegex(PathParams(path).path()) - } - - return asRegex(path) - } - - fun matches(actualPath: String) : Boolean { - return actualPath.matches(pathPattern()) - } - - private fun asRegex(rawPath: String) = rawPath.replace("*", ".*").toRegex() -} diff --git a/src/main/kotlin/daikon/RouteAction.kt b/src/main/kotlin/daikon/RouteAction.kt deleted file mode 100644 index d0e8fb8..0000000 --- a/src/main/kotlin/daikon/RouteAction.kt +++ /dev/null @@ -1,5 +0,0 @@ -package daikon - -interface RouteAction { - fun handle(request: Request, response: Response, context: Context) -} diff --git a/src/main/kotlin/daikon/Routing.kt b/src/main/kotlin/daikon/Routing.kt deleted file mode 100644 index 435a108..0000000 --- a/src/main/kotlin/daikon/Routing.kt +++ /dev/null @@ -1,46 +0,0 @@ -package daikon - -import daikon.Method.ANY - -class Routing { - private var defaultRoute = Route(ANY, "/*", DummyRouteAction { _, _ -> }) - private val routes = mutableListOf() - - fun default(route: Route): Routing { - defaultRoute = route - return this - } - - fun bestFor(method: Method, path: String): Route { - return filterBy(method) - .filter { match(it, path) } - .asReversed() - .chooseFrom(path) - ?: defaultRoute - } - - private fun List.chooseFrom(path: String) = maxBy { route -> route.path.length * matchFactor(route, path) } - - private fun matchFactor(route: Route, path: String) = if (exact(route, path)) 1000 else 1 - - private fun match(it: Route, path: String) = exact(it, path) || approximate(it, path) - - fun allFor(method: Method, path: String): List { - return filterBy(method).filter { match(it, path) } - } - - private fun filterBy(method: Method) = routes.filter { it.method == method || it.method == ANY } - - private fun approximate(route: Route, path: String): Boolean { - return route.matches(path) - } - - private fun exact(route: Route, path: String): Boolean { - return route.path == path - } - - fun add(route: Route): Routing { - routes.add(route) - return this - } -} diff --git a/src/main/kotlin/daikon/RoutingHandler.kt b/src/main/kotlin/daikon/RoutingHandler.kt deleted file mode 100644 index 2ac6b1e..0000000 --- a/src/main/kotlin/daikon/RoutingHandler.kt +++ /dev/null @@ -1,32 +0,0 @@ -package daikon - -import daikon.Method.ANY - -class RoutingHandler( - private val befores: Routing, - private val routes: Routing, - private val afters: Routing, - private val context: Context -) { - fun execute(request: Request, response: Response) { - try { - befores - .allFor(request.method(), request.path()) - .forEach { invoke(it, request, response) } - - routes - .default(Route(ANY, "ignore", DefaultRouteAction())) - .bestFor(request.method(), request.path()) - .also { invoke(it, request, response) } - - afters - .allFor(request.method(), request.path()) - .forEach { invoke(it, request, response) } - } catch (e: HaltException) { - } - } - - private fun invoke(route: Route, req: Request, res: Response) { - route.action.handle(req.withPathParams(route.path), res, context) - } -} \ No newline at end of file diff --git a/src/main/kotlin/daikon/RoutingServlet.kt b/src/main/kotlin/daikon/RoutingServlet.kt index b25d75d..4d20ebd 100644 --- a/src/main/kotlin/daikon/RoutingServlet.kt +++ b/src/main/kotlin/daikon/RoutingServlet.kt @@ -1,5 +1,8 @@ package daikon +import daikon.core.Context +import daikon.core.Routing +import daikon.core.RoutingHandler import javax.servlet.GenericServlet import javax.servlet.ServletRequest import javax.servlet.ServletResponse diff --git a/src/main/kotlin/daikon/ServerContext.kt b/src/main/kotlin/daikon/ServerContext.kt index 95669ce..adb3f2f 100644 --- a/src/main/kotlin/daikon/ServerContext.kt +++ b/src/main/kotlin/daikon/ServerContext.kt @@ -1,5 +1,7 @@ package daikon +import daikon.core.Context + class ServerContext(private val port: Int) : Context { private val attributes = mutableMapOf() diff --git a/src/test/kotlin/daikon/BasicAuthenticationHttpTest.kt b/src/test/kotlin/daikon/BasicAuthenticationHttpTest.kt index e8a18c2..27f8d1f 100644 --- a/src/test/kotlin/daikon/BasicAuthenticationHttpTest.kt +++ b/src/test/kotlin/daikon/BasicAuthenticationHttpTest.kt @@ -3,8 +3,8 @@ package daikon import daikon.Localhost.get import khttp.structures.authorization.BasicAuthorization import org.assertj.core.api.Assertions.assertThat -import daikon.HttpStatus.OK_200 -import daikon.HttpStatus.UNAUTHORIZED_401 +import daikon.core.HttpStatus.OK_200 +import daikon.core.HttpStatus.UNAUTHORIZED_401 import org.junit.jupiter.api.Test class BasicAuthenticationHttpTest { diff --git a/src/test/kotlin/daikon/DefaultRouteActionTest.kt b/src/test/kotlin/daikon/DefaultRouteActionTest.kt index cf8b375..d47e732 100644 --- a/src/test/kotlin/daikon/DefaultRouteActionTest.kt +++ b/src/test/kotlin/daikon/DefaultRouteActionTest.kt @@ -3,9 +3,13 @@ package daikon import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever -import daikon.Method.GET -import daikon.HttpStatus.NOT_FOUND_404 -import daikon.HttpStatus.OK_200 +import daikon.core.Context +import daikon.core.DefaultRouteAction +import daikon.core.Method.GET +import daikon.core.HttpStatus.NOT_FOUND_404 +import daikon.core.HttpStatus.OK_200 +import daikon.core.Request +import daikon.core.Response import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers.contains diff --git a/src/test/kotlin/daikon/HooksTest.kt b/src/test/kotlin/daikon/HooksTest.kt index 1f84960..445d906 100644 --- a/src/test/kotlin/daikon/HooksTest.kt +++ b/src/test/kotlin/daikon/HooksTest.kt @@ -2,7 +2,7 @@ package daikon import daikon.Localhost.get import org.assertj.core.api.Assertions.assertThat -import daikon.HttpStatus.ACCEPTED_202 +import daikon.core.HttpStatus.ACCEPTED_202 import org.junit.jupiter.api.Test class HooksTest { diff --git a/src/test/kotlin/daikon/HttpMethodsTest.kt b/src/test/kotlin/daikon/HttpMethodsTest.kt index 04a2ffd..6655567 100644 --- a/src/test/kotlin/daikon/HttpMethodsTest.kt +++ b/src/test/kotlin/daikon/HttpMethodsTest.kt @@ -1,9 +1,9 @@ package daikon -import daikon.HttpStatus.ACCEPTED_202 -import daikon.HttpStatus.NOT_FOUND_404 -import daikon.HttpStatus.NO_CONTENT_204 -import daikon.HttpStatus.OK_200 +import daikon.core.HttpStatus.ACCEPTED_202 +import daikon.core.HttpStatus.NOT_FOUND_404 +import daikon.core.HttpStatus.NO_CONTENT_204 +import daikon.core.HttpStatus.OK_200 import daikon.Localhost.delete import daikon.Localhost.get import daikon.Localhost.head diff --git a/src/test/kotlin/daikon/HttpRoutingTest.kt b/src/test/kotlin/daikon/HttpRoutingTest.kt index 98d16a7..c66b259 100644 --- a/src/test/kotlin/daikon/HttpRoutingTest.kt +++ b/src/test/kotlin/daikon/HttpRoutingTest.kt @@ -1,12 +1,16 @@ package daikon -import daikon.HttpStatus.INTERNAL_SERVER_ERROR_500 -import daikon.HttpStatus.NOT_FOUND_404 -import daikon.HttpStatus.OK_200 -import daikon.HttpStatus.UNAUTHORIZED_401 +import daikon.core.HttpStatus.INTERNAL_SERVER_ERROR_500 +import daikon.core.HttpStatus.NOT_FOUND_404 +import daikon.core.HttpStatus.OK_200 +import daikon.core.HttpStatus.UNAUTHORIZED_401 import daikon.Localhost.get -import daikon.RequestFlow.halt +import daikon.core.Context +import daikon.core.Request +import daikon.core.RequestFlow.halt +import daikon.core.Response +import daikon.core.RouteAction import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test diff --git a/src/test/kotlin/daikon/HttpServerTest.kt b/src/test/kotlin/daikon/HttpServerTest.kt index d1aaaf0..3c064bd 100644 --- a/src/test/kotlin/daikon/HttpServerTest.kt +++ b/src/test/kotlin/daikon/HttpServerTest.kt @@ -3,7 +3,7 @@ package daikon import daikon.Localhost.get import org.junit.jupiter.api.Test import org.assertj.core.api.Assertions.assertThat -import daikon.HttpStatus.OK_200 +import daikon.core.HttpStatus.OK_200 class HttpServerTest { diff --git a/src/test/kotlin/daikon/NopAction.kt b/src/test/kotlin/daikon/NopAction.kt index 566b072..0ca5060 100644 --- a/src/test/kotlin/daikon/NopAction.kt +++ b/src/test/kotlin/daikon/NopAction.kt @@ -1,5 +1,10 @@ package daikon +import daikon.core.Context +import daikon.core.Request +import daikon.core.Response +import daikon.core.RouteAction + class NopAction : RouteAction { override fun handle(request: Request, response: Response, context: Context) { } diff --git a/src/test/kotlin/daikon/PathParamsTest.kt b/src/test/kotlin/daikon/PathParamsTest.kt index df77cc7..b9fc7f6 100644 --- a/src/test/kotlin/daikon/PathParamsTest.kt +++ b/src/test/kotlin/daikon/PathParamsTest.kt @@ -1,5 +1,6 @@ package daikon +import daikon.core.PathParams import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test diff --git a/src/test/kotlin/daikon/PerformanceTest.kt b/src/test/kotlin/daikon/PerformanceTest.kt index c057b32..71cffb5 100644 --- a/src/test/kotlin/daikon/PerformanceTest.kt +++ b/src/test/kotlin/daikon/PerformanceTest.kt @@ -1,6 +1,6 @@ package daikon -import daikon.HttpStatus.OK_200 +import daikon.core.HttpStatus.OK_200 import daikon.Localhost.get import kotlinx.coroutines.* import org.assertj.core.api.AbstractIntegerAssert diff --git a/src/test/kotlin/daikon/RequestTest.kt b/src/test/kotlin/daikon/RequestTest.kt index 6be3ce8..ca3e32b 100644 --- a/src/test/kotlin/daikon/RequestTest.kt +++ b/src/test/kotlin/daikon/RequestTest.kt @@ -1,6 +1,6 @@ package daikon -import daikon.HttpStatus.INTERNAL_SERVER_ERROR_500 +import daikon.core.HttpStatus.INTERNAL_SERVER_ERROR_500 import daikon.Localhost.get import daikon.Localhost.post import org.assertj.core.api.Assertions.assertThat diff --git a/src/test/kotlin/daikon/ResponseTest.kt b/src/test/kotlin/daikon/ResponseTest.kt index 21e0de2..df311b4 100644 --- a/src/test/kotlin/daikon/ResponseTest.kt +++ b/src/test/kotlin/daikon/ResponseTest.kt @@ -2,8 +2,8 @@ package daikon import daikon.Localhost.get import org.assertj.core.api.Assertions.assertThat -import daikon.HttpStatus.CREATED_201 -import daikon.HttpStatus.MOVED_PERMANENTLY_301 +import daikon.core.HttpStatus.CREATED_201 +import daikon.core.HttpStatus.MOVED_PERMANENTLY_301 import org.junit.jupiter.api.Test class ResponseTest { diff --git a/src/test/kotlin/daikon/RoutingTest.kt b/src/test/kotlin/daikon/RoutingTest.kt index 5bc5237..5dd1fac 100644 --- a/src/test/kotlin/daikon/RoutingTest.kt +++ b/src/test/kotlin/daikon/RoutingTest.kt @@ -1,7 +1,10 @@ package daikon import com.nhaarman.mockitokotlin2.mock -import daikon.Method.* +import daikon.core.Method.* +import daikon.core.Route +import daikon.core.RouteAction +import daikon.core.Routing import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test diff --git a/src/test/kotlin/daikon/WelcomePageTest.kt b/src/test/kotlin/daikon/WelcomePageTest.kt index 119ac9b..cc87e4c 100644 --- a/src/test/kotlin/daikon/WelcomePageTest.kt +++ b/src/test/kotlin/daikon/WelcomePageTest.kt @@ -1,8 +1,8 @@ package daikon import org.assertj.core.api.Assertions.assertThat -import daikon.HttpStatus.INTERNAL_SERVER_ERROR_500 -import daikon.HttpStatus.OK_200 +import daikon.core.HttpStatus.INTERNAL_SERVER_ERROR_500 +import daikon.core.HttpStatus.OK_200 import org.junit.jupiter.api.Test class WelcomePageTest {