Skip to content

Commit 5cdc416

Browse files
authored
Merge pull request #401 from Kong/javalin
replace Spark with Javalin
2 parents 35d81db + d9003fd commit 5cdc416

File tree

11 files changed

+314
-293
lines changed

11 files changed

+314
-293
lines changed

pom.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,7 @@
312312
<rules>
313313
<banVulnerable implementation="org.sonatype.ossindex.maven.enforcer.BanVulnerableDependencies">
314314
<excludeVulnerabilityIds>
315-
<!-- Only a test dependency. Waiting on
316-
https://github.com/perwendel/spark/pull/1201 -->
317-
<!-- <exclude>2f9b8690-2b13-48ad-adc9-af1489d0a2f3</exclude>-->
315+
318316
</excludeVulnerabilityIds>
319317
</banVulnerable>
320318
</rules>

unirest/pom.xml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,18 @@
6868
<version>${jackson.version}</version>
6969
<scope>test</scope>
7070
</dependency>
71+
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
7172
<dependency>
72-
<groupId>com.sparkjava</groupId>
73-
<artifactId>spark-core</artifactId>
74-
<version>2.9.3</version>
73+
<groupId>org.apache.commons</groupId>
74+
<artifactId>commons-io</artifactId>
75+
<version>1.3.2</version>
7576
<scope>test</scope>
76-
<exclusions>
77-
<exclusion>
78-
<groupId>org.eclipse.jetty.websocket</groupId>
79-
<artifactId>websocket-server</artifactId>
80-
</exclusion>
81-
</exclusions>
8277
</dependency>
83-
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server -->
78+
8479
<dependency>
85-
<groupId>org.eclipse.jetty</groupId>
86-
<artifactId>jetty-server</artifactId>
87-
<version>9.4.38.v20210224</version>
80+
<groupId>io.javalin</groupId>
81+
<artifactId>javalin</artifactId>
82+
<version>3.13.4</version>
8883
<scope>test</scope>
8984
</dependency>
9085

unirest/src/test/java/BehaviorTests/AsEmptyTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void canDoAEmptyRequestThatDoesNotParseBodyAtAll() {
4242

4343
assertNull(res.getBody());
4444
assertEquals(200, res.getStatus());
45-
assertEquals("json", res.getHeaders().getFirst("Content-Type"));
45+
assertEquals("json;charset=utf-8", res.getHeaders().getFirst("Content-Type"));
4646
}
4747

4848
@Test
@@ -52,18 +52,18 @@ void canDoEmptyAsync() throws Exception {
5252

5353
assertNull(res.getBody());
5454
assertEquals(200, res.getStatus());
55-
assertEquals("json", res.getHeaders().getFirst("Content-Type"));
55+
assertEquals("json;charset=utf-8", res.getHeaders().getFirst("Content-Type"));
5656
}
5757

5858
@Test
5959
void canDoEmptyAsyncWithCallback() {
60-
MockServer.addResponseHeader("Content-Type", "json");
60+
MockServer.addResponseHeader("Content-Type", "json;charset=utf-8");
6161

6262
Unirest.get(MockServer.GET)
6363
.asEmptyAsync(res -> {
6464
assertNull(res.getBody());
6565
assertEquals(200, res.getStatus());
66-
assertEquals("json", res.getHeaders().getFirst("Content-Type"));
66+
assertEquals("json;charset=utf-8", res.getHeaders().getFirst("Content-Type"));
6767
asyncSuccess();
6868
});
6969

unirest/src/test/java/BehaviorTests/AsStringTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package BehaviorTests;
2727

28+
import io.javalin.core.util.Header;
2829
import org.junit.jupiter.api.Test;
2930
import kong.unirest.HttpResponse;
3031
import kong.unirest.TestUtil;
@@ -36,6 +37,13 @@
3637

3738
class AsStringTest extends BddTest {
3839

40+
@Test
41+
void simpleExample() {
42+
MockServer.setStringResponse("Hi Mom");
43+
String body = Unirest.get(MockServer.GET).asString().getBody();
44+
assertEquals("Hi Mom", body);
45+
}
46+
3947
@Test
4048
void whenNoBodyIsReturned() {
4149
HttpResponse<String> i = Unirest.get(MockServer.NOBODY).asString();
@@ -48,6 +56,7 @@ void whenNoBodyIsReturned() {
4856
void canParseGzippedStringResponse() {
4957
HttpResponse<String> i = Unirest.get(MockServer.GZIP)
5058
.queryString("foo", "bar")
59+
.header(Header.ACCEPT_ENCODING, "gzip")
5160
.asString();
5261

5362
RequestCapture cap = TestUtil.readValue(i.getBody(), RequestCapture.class);

unirest/src/test/java/BehaviorTests/MetricsTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import static org.junit.jupiter.api.Assertions.*;
3939
import static org.mockito.ArgumentMatchers.any;
4040
import static org.mockito.Mockito.mock;
41-
import static org.mockito.Mockito.when;
4241

4342
class MetricsTest extends BddTest {
4443
@Test
@@ -168,8 +167,8 @@ void metricAsALambda() {
168167
}
169168

170169
@Test
171-
void showWhatSparkDoes() {
172-
HashMap map = Unirest.get(SPARKLE)
170+
void showWhatJavalinDoes() {
171+
HashMap map = Unirest.get(JAVALIN)
173172
.routeParam("spark", "joy")
174173
.queryString("food", "hamberders")
175174
.queryString("colour", "red")
@@ -179,7 +178,7 @@ void showWhatSparkDoes() {
179178
assertEquals("localhost:4567", map.get("host()"));
180179
assertEquals("/sparkle/joy/yippy", map.get("uri()")); // this is different from what the Spark doc says.
181180
assertEquals("http://localhost:4567/sparkle/joy/yippy", map.get("url()"));
182-
assertNull(map.get("contextPath()"));
181+
assertEquals("", map.get("contextPath()"));
183182
assertEquals("/sparkle/joy/yippy", map.get("pathInfo()"));
184183
assertEquals("food=hamberders&colour=red", map.get("queryString()"));
185184
}

0 commit comments

Comments
 (0)