Skip to content

Commit

Permalink
Merge pull request #401 from Kong/javalin
Browse files Browse the repository at this point in the history
replace Spark with Javalin
  • Loading branch information
ryber authored Apr 3, 2021
2 parents 35d81db + d9003fd commit 5cdc416
Show file tree
Hide file tree
Showing 11 changed files with 314 additions and 293 deletions.
4 changes: 1 addition & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,7 @@
<rules>
<banVulnerable implementation="org.sonatype.ossindex.maven.enforcer.BanVulnerableDependencies">
<excludeVulnerabilityIds>
<!-- Only a test dependency. Waiting on
https://github.com/perwendel/spark/pull/1201 -->
<!-- <exclude>2f9b8690-2b13-48ad-adc9-af1489d0a2f3</exclude>-->

</excludeVulnerabilityIds>
</banVulnerable>
</rules>
Expand Down
21 changes: 8 additions & 13 deletions unirest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,18 @@
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.9.3</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server -->

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.38.v20210224</version>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>3.13.4</version>
<scope>test</scope>
</dependency>

Expand Down
8 changes: 4 additions & 4 deletions unirest/src/test/java/BehaviorTests/AsEmptyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void canDoAEmptyRequestThatDoesNotParseBodyAtAll() {

assertNull(res.getBody());
assertEquals(200, res.getStatus());
assertEquals("json", res.getHeaders().getFirst("Content-Type"));
assertEquals("json;charset=utf-8", res.getHeaders().getFirst("Content-Type"));
}

@Test
Expand All @@ -52,18 +52,18 @@ void canDoEmptyAsync() throws Exception {

assertNull(res.getBody());
assertEquals(200, res.getStatus());
assertEquals("json", res.getHeaders().getFirst("Content-Type"));
assertEquals("json;charset=utf-8", res.getHeaders().getFirst("Content-Type"));
}

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

Unirest.get(MockServer.GET)
.asEmptyAsync(res -> {
assertNull(res.getBody());
assertEquals(200, res.getStatus());
assertEquals("json", res.getHeaders().getFirst("Content-Type"));
assertEquals("json;charset=utf-8", res.getHeaders().getFirst("Content-Type"));
asyncSuccess();
});

Expand Down
9 changes: 9 additions & 0 deletions unirest/src/test/java/BehaviorTests/AsStringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package BehaviorTests;

import io.javalin.core.util.Header;
import org.junit.jupiter.api.Test;
import kong.unirest.HttpResponse;
import kong.unirest.TestUtil;
Expand All @@ -36,6 +37,13 @@

class AsStringTest extends BddTest {

@Test
void simpleExample() {
MockServer.setStringResponse("Hi Mom");
String body = Unirest.get(MockServer.GET).asString().getBody();
assertEquals("Hi Mom", body);
}

@Test
void whenNoBodyIsReturned() {
HttpResponse<String> i = Unirest.get(MockServer.NOBODY).asString();
Expand All @@ -48,6 +56,7 @@ void whenNoBodyIsReturned() {
void canParseGzippedStringResponse() {
HttpResponse<String> i = Unirest.get(MockServer.GZIP)
.queryString("foo", "bar")
.header(Header.ACCEPT_ENCODING, "gzip")
.asString();

RequestCapture cap = TestUtil.readValue(i.getBody(), RequestCapture.class);
Expand Down
7 changes: 3 additions & 4 deletions unirest/src/test/java/BehaviorTests/MetricsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class MetricsTest extends BddTest {
@Test
Expand Down Expand Up @@ -168,8 +167,8 @@ void metricAsALambda() {
}

@Test
void showWhatSparkDoes() {
HashMap map = Unirest.get(SPARKLE)
void showWhatJavalinDoes() {
HashMap map = Unirest.get(JAVALIN)
.routeParam("spark", "joy")
.queryString("food", "hamberders")
.queryString("colour", "red")
Expand All @@ -179,7 +178,7 @@ void showWhatSparkDoes() {
assertEquals("localhost:4567", map.get("host()"));
assertEquals("/sparkle/joy/yippy", map.get("uri()")); // this is different from what the Spark doc says.
assertEquals("http://localhost:4567/sparkle/joy/yippy", map.get("url()"));
assertNull(map.get("contextPath()"));
assertEquals("", map.get("contextPath()"));
assertEquals("/sparkle/joy/yippy", map.get("pathInfo()"));
assertEquals("food=hamberders&colour=red", map.get("queryString()"));
}
Expand Down
Loading

0 comments on commit 5cdc416

Please sign in to comment.