Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to unirest 4.x #2088

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion javalin-utils/javalin-context-mock/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
</dependency>
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<artifactId>unirest-java-core</artifactId>
<version>${unirest.version}</version>
<scope>test</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion javalin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
</dependency>
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<artifactId>unirest-java-core</artifactId>
<version>${unirest.version}</version>
<scope>test</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion javalin/src/test/java/io/javalin/TestAccessManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import io.javalin.http.HttpStatus.UNAUTHORIZED
import io.javalin.http.UnauthorizedResponse
import io.javalin.security.RouteRole
import io.javalin.testing.TestUtil
import kong.unirest.Unirest
import kong.unirest.core.Unirest
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

Expand Down
4 changes: 2 additions & 2 deletions javalin/src/test/java/io/javalin/TestApiBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import io.javalin.http.HttpStatus.OK
import io.javalin.testing.TestUtil
import io.javalin.testing.TestUtil.okHandler
import io.javalin.testing.httpCode
import kong.unirest.HttpMethod
import kong.unirest.Unirest
import kong.unirest.core.HttpMethod
import kong.unirest.core.Unirest
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.jupiter.api.Test
Expand Down
4 changes: 2 additions & 2 deletions javalin/src/test/java/io/javalin/TestBeforeAfterMatched.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.javalin.http.servlet.DefaultTasks.ERROR
import io.javalin.http.servlet.DefaultTasks.HTTP
import io.javalin.http.staticfiles.Location
import io.javalin.testing.TestUtil
import kong.unirest.HttpResponse
import kong.unirest.core.HttpResponse
import org.assertj.core.api.Assertions.assertThat
import org.eclipse.jetty.server.handler.ContextHandler
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -200,7 +200,7 @@ class TestBeforeAfterMatched {
app.get("/hello") { it.result("hello") }
app.afterMatched { it.result(it.result() + "!") }

assertThat(http.call(kong.unirest.HttpMethod.HEAD, "/hello").status).isEqualTo(418)
assertThat(http.call(kong.unirest.core.HttpMethod.HEAD, "/hello").status).isEqualTo(418)
assertThat(http.getStatus("/hello")).isEqualTo(HttpStatus.IM_A_TEAPOT)
assertThat(http.getBody("/hello")).isEqualTo("hello!")
assertThat(http.getStatus("/other")).isEqualTo(HttpStatus.NOT_FOUND)
Expand Down
2 changes: 1 addition & 1 deletion javalin/src/test/java/io/javalin/TestCompression.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import io.javalin.http.staticfiles.Location
import io.javalin.testing.TestDependency
import io.javalin.testing.TestUtil
import io.javalin.util.FileUtil
import kong.unirest.Unirest
import kong.unirest.core.Unirest
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
Expand Down
2 changes: 1 addition & 1 deletion javalin/src/test/java/io/javalin/TestCookie.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.javalin.http.Cookie
import io.javalin.http.Header
import io.javalin.http.SameSite
import io.javalin.testing.TestUtil
import kong.unirest.Unirest
import kong.unirest.core.Unirest
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

Expand Down
6 changes: 3 additions & 3 deletions javalin/src/test/java/io/javalin/TestCors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import io.javalin.http.HttpStatus.UNAUTHORIZED
import io.javalin.plugin.bundled.CorsPlugin
import io.javalin.testing.HttpUtil
import io.javalin.testing.TestUtil
import kong.unirest.HttpResponse
import kong.unirest.HttpStatus
import kong.unirest.Unirest
import kong.unirest.core.HttpResponse
import kong.unirest.core.HttpStatus
import kong.unirest.core.Unirest
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.jupiter.api.Nested
Expand Down
2 changes: 1 addition & 1 deletion javalin/src/test/java/io/javalin/TestCustomJetty.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import jakarta.servlet.DispatcherType
import jakarta.servlet.http.HttpServlet
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import kong.unirest.Unirest
import kong.unirest.core.Unirest
import org.assertj.core.api.Assertions.assertThat
import org.eclipse.jetty.server.ForwardedRequestCustomizer
import org.eclipse.jetty.server.Handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
package io.javalin

import io.javalin.testing.TestUtil
import kong.unirest.Unirest
import kong.unirest.core.Unirest
import org.assertj.core.api.Assertions.assertThat
import org.eclipse.jetty.server.ForwardedRequestCustomizer
import org.eclipse.jetty.server.HttpConnectionFactory
Expand Down
2 changes: 1 addition & 1 deletion javalin/src/test/java/io/javalin/TestEncoding.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package io.javalin
import io.javalin.http.ContentType
import io.javalin.http.Header
import io.javalin.testing.TestUtil
import kong.unirest.Unirest
import kong.unirest.core.Unirest
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import java.net.URLEncoder
Expand Down
2 changes: 1 addition & 1 deletion javalin/src/test/java/io/javalin/TestEtags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import io.javalin.http.HttpStatus.NOT_MODIFIED
import io.javalin.http.HttpStatus.OK
import io.javalin.testing.TestUtil
import io.javalin.testing.httpCode
import kong.unirest.Unirest
import kong.unirest.core.Unirest
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

Expand Down
2 changes: 1 addition & 1 deletion javalin/src/test/java/io/javalin/TestFilters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package io.javalin
import io.javalin.http.HttpStatus.NOT_FOUND
import io.javalin.testing.TestUtil
import io.javalin.testing.httpCode
import kong.unirest.HttpMethod
import kong.unirest.core.HttpMethod
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

Expand Down
4 changes: 2 additions & 2 deletions javalin/src/test/java/io/javalin/TestGracefulShutdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import kong.unirest.HttpResponse;
import kong.unirest.Unirest;
import kong.unirest.core.HttpResponse;
import kong.unirest.core.Unirest;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.StatisticsHandler;
import org.junit.jupiter.api.Disabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import io.javalin.http.HttpStatus.NOT_MODIFIED
import io.javalin.http.HttpStatus.OK
import io.javalin.plugin.bundled.HttpAllowedMethodsPlugin
import io.javalin.testing.TestUtil
import kong.unirest.Unirest
import kong.unirest.core.Unirest
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import io.javalin.http.HttpStatus.MOVED_PERMANENTLY
import io.javalin.plugin.bundled.RedirectToLowercasePathPlugin
import io.javalin.testing.TestUtil
import io.javalin.testing.httpCode
import kong.unirest.HttpResponse
import kong.unirest.core.HttpResponse
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatIllegalArgumentException
import org.junit.jupiter.api.Test
Expand Down
4 changes: 2 additions & 2 deletions javalin/src/test/java/io/javalin/TestRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import io.javalin.http.servlet.SESSION_CACHE_KEY_PREFIX
import io.javalin.http.staticfiles.Location
import io.javalin.plugin.bundled.BasicAuthPlugin
import io.javalin.testing.TestUtil
import kong.unirest.Unirest
import kong.unirest.core.Unirest
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

Expand Down Expand Up @@ -379,7 +379,7 @@ class TestRequest {
@Test
fun `userAgent works`() = TestUtil.test { app, http ->
app.get("/") { it.result(it.userAgent()!!) }
assertThat(http.getBody("/")).isEqualTo("unirest-java/3.1.00")
assertThat(http.getBody("/")).contains("Java-http-client")
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions javalin/src/test/java/io/javalin/TestResponse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import io.javalin.http.util.SeekableWriter
import io.javalin.plugin.bundled.CorsPlugin
import io.javalin.testing.TestUtil
import io.javalin.testing.httpCode
import kong.unirest.HttpMethod
import kong.unirest.Unirest
import kong.unirest.core.HttpMethod
import kong.unirest.core.Unirest
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatIOException
import org.junit.jupiter.api.Disabled
Expand Down
11 changes: 7 additions & 4 deletions javalin/src/test/java/io/javalin/TestRouting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import io.javalin.router.matcher.WildcardBracketAdjacentException
import io.javalin.testing.TestUtil
import io.javalin.testing.httpCode
import io.javalin.websocket.WsHandlerType
import kong.unirest.HttpMethod
import kong.unirest.core.HttpMethod
import okhttp3.OkHttpClient
import okhttp3.Request
import org.assertj.core.api.Assertions.assertThat
Expand All @@ -39,6 +39,10 @@ class TestRouting {
private val okHttp = OkHttpClient().newBuilder().build()
fun OkHttpClient.getBody(path: String) = this.newCall(Request.Builder().url(path).get().build()).execute().body!!.string()

val httpMethods = listOf(
HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.PATCH, HttpMethod.HEAD, HttpMethod.OPTIONS, HttpMethod.TRACE
)

@Test
fun `basic hello world works`() = TestUtil.test { app, http ->
app.get("/hello") { it.result("Hello World") }
Expand Down Expand Up @@ -95,15 +99,14 @@ class TestRouting {
app.head("/mapped", TestUtil.okHandler)
app.options("/mapped", TestUtil.okHandler)
app.addHttpHandler(TRACE, "/mapped", TestUtil.okHandler)

for (httpMethod in HttpMethod.all()) {
for (httpMethod in httpMethods) {
assertThat(http.call(httpMethod, "/mapped").httpCode()).isEqualTo(OK)
}
}

@Test
fun `all unmapped verbs return 404`() = TestUtil.test { _, http ->
for (httpMethod in HttpMethod.all()) {
for (httpMethod in httpMethods) {
val response = http.call(httpMethod, "/unmapped")
assertThat(response.httpCode()).isEqualTo(NOT_FOUND)

Expand Down
2 changes: 1 addition & 1 deletion javalin/src/test/java/io/javalin/TestServerHeader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.javalin

import io.javalin.http.HttpStatus.OK
import io.javalin.testing.TestUtil
import kong.unirest.HttpMethod
import kong.unirest.core.HttpMethod
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

Expand Down
2 changes: 1 addition & 1 deletion javalin/src/test/java/io/javalin/TestSslRedirectPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.javalin
import io.javalin.http.Header
import io.javalin.plugin.bundled.SslRedirectPlugin
import io.javalin.testing.TestUtil
import kong.unirest.Unirest
import kong.unirest.core.Unirest
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

Expand Down
2 changes: 1 addition & 1 deletion javalin/src/test/java/io/javalin/TestWebSocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import io.javalin.testing.fasterJacksonMapper
import io.javalin.websocket.WsCloseStatus
import io.javalin.websocket.WsContext
import io.javalin.websocket.pingFutures
import kong.unirest.Unirest
import kong.unirest.core.Unirest
import org.assertj.core.api.Assertions.assertThat
import org.eclipse.jetty.websocket.api.CloseStatus
import org.eclipse.jetty.websocket.api.StatusCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import io.javalin.http.staticfiles.Location
import io.javalin.testing.TestDependency
import io.javalin.testing.TestUtil
import io.javalin.testing.httpCode
import kong.unirest.Unirest
import kong.unirest.core.Unirest
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.jupiter.api.Test
Expand Down
6 changes: 3 additions & 3 deletions javalin/src/test/java/io/javalin/testing/HttpUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ package io.javalin.testing

import io.javalin.http.ContentType
import io.javalin.http.HttpStatus
import kong.unirest.HttpMethod
import kong.unirest.HttpResponse
import kong.unirest.Unirest
import kong.unirest.core.HttpMethod
import kong.unirest.core.HttpResponse
import kong.unirest.core.Unirest

class HttpUtil(port: Int) {

Expand Down
2 changes: 1 addition & 1 deletion javalin/src/test/java/io/javalin/testing/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import io.javalin.util.JavalinLogger;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import kong.unirest.HttpMethod;
import kong.unirest.core.HttpMethod;

public class TestUtil {

Expand Down
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<jmh.version>1.37</jmh.version>
<mockito.version>5.8.0</mockito.version>
<mockk.version>1.13.8</mockk.version>
<unirest.version>3.14.5</unirest.version>
<unirest.version>4.2.7</unirest.version>
<selenium.chrome.driver.version>4.16.1</selenium.chrome.driver.version>
<webdrivermanager.version>5.6.3</webdrivermanager.version>
<swagger.ui.version>4.10.3</swagger.ui.version> <!-- used for testing webjars -->
Expand Down Expand Up @@ -488,6 +488,9 @@
<exclude />
</excludes>
<useModulePath>false</useModulePath>
<systemPropertyVariables>
<jdk.httpclient.allowRestrictedHeaders>Connection,Upgrade,Host</jdk.httpclient.allowRestrictedHeaders>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
Expand Down