-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matias Schilling
committed
Jun 20, 2024
1 parent
4477c2a
commit 9372059
Showing
70 changed files
with
2,777 additions
and
2,295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ out/ | |
hs_err_pid* | ||
|
||
# Gradle | ||
bin/ | ||
.gradle | ||
build/ | ||
gradle-app.setting | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
java=17.0.11-zulu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
interface Version { | ||
public static final String SPRING_BOOT = '2.7.18' | ||
public static final String LOMBOK = '1.18.30' | ||
public static final String JUNIT = '5.10.2' | ||
public static final String REST_ASSURED = '5.4.0' | ||
public static final String SPOTLESS = '7.0.0.BETA1' | ||
public static final String SPRING_BOOT = '2.7.18' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
dependencies { | ||
testImplementation 'commons-logging:commons-logging:1.3.2' | ||
|
||
testImplementation "org.junit.jupiter:junit-jupiter-api:${Version.JUNIT}" | ||
testImplementation "org.junit.jupiter:junit-jupiter:${Version.JUNIT}" | ||
testImplementation("io.rest-assured:json-path:${Version.REST_ASSURED}") { | ||
exclude group: "org.apache.groovy", module: "groovy" | ||
exclude group: "org.apache.groovy", module: "groovy-xml" | ||
} | ||
testImplementation("io.rest-assured:rest-assured:${Version.REST_ASSURED}") { | ||
exclude group: "org.apache.groovy", module: "groovy" | ||
exclude group: "org.apache.groovy", module: "groovy-xml" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...-integration-test/src/test/java/io/chucknorris/integration_test/AbstractEndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.chucknorris.integration_test; | ||
|
||
import io.restassured.RestAssured; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
import java.util.Optional; | ||
|
||
public abstract class AbstractEndpointTest { | ||
|
||
@BeforeAll | ||
public static void beforeAll() { | ||
RestAssured.baseURI = Optional | ||
.ofNullable(System.getenv("TEST_SUBJECT_BASE_URI")) | ||
.orElse("http://localhost"); | ||
|
||
RestAssured.port = Optional | ||
.ofNullable(System.getenv("TEST_SUBJECT_PORT")) | ||
.map(Integer::parseInt) | ||
.orElse(8080); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...gration-test/src/test/java/io/chucknorris/integration_test/health/HealthEndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.chucknorris.integration_test.health; | ||
|
||
import io.chucknorris.integration_test.AbstractEndpointTest; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
class HealthEndpointTest extends AbstractEndpointTest { | ||
|
||
@DisplayName("Should return joke") | ||
@Test | ||
void shouldReturnJoke() { | ||
var specification = given() | ||
.log().all() | ||
.accept("application/json"); | ||
|
||
var response = specification.when().get("/health"); | ||
|
||
response.then() | ||
.log().all() | ||
.statusCode(200) | ||
.assertThat() | ||
.header("Content-Type", Matchers.equalTo("application/json")) | ||
.body("status", Matchers.is("UP")) | ||
.body("start_time", Matchers.isA(String.class)) | ||
.body("uptime", Matchers.isA(String.class)); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...ation-test/src/test/java/io/chucknorris/integration_test/joke/JokeRandomEndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.chucknorris.integration_test.joke; | ||
|
||
import io.chucknorris.integration_test.AbstractEndpointTest; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
class JokeRandomEndpointTest extends AbstractEndpointTest { | ||
|
||
@DisplayName("Should return joke as json") | ||
@Test | ||
void shouldReturnJokeAsJson() { | ||
// given: | ||
var specification = given() | ||
.log().all() | ||
.accept("application/json"); | ||
|
||
// when: | ||
var response = specification.when().get("/jokes/random"); | ||
|
||
// then: | ||
response.then() | ||
.log().all() | ||
.statusCode(200) | ||
.assertThat() | ||
.header("Content-Type", Matchers.equalTo("application/json")) | ||
.body("categories", Matchers.isA(List.class)) | ||
.body("created_at", Matchers.isA(String.class)) | ||
.body("icon_url", Matchers.isA(String.class)) | ||
.body("id", Matchers.isA(String.class)) | ||
.body("updated_at", Matchers.isA(String.class)) | ||
.body("url", Matchers.isA(String.class)) | ||
.body("value", Matchers.isA(String.class)); | ||
} | ||
|
||
@DisplayName("Should include CORS headers") | ||
@Test | ||
void shouldIncludeCORSHeaders() { | ||
// given: | ||
var specification = given() | ||
.log().all() | ||
.accept("application/json") | ||
.header("Origin", "http://localhost:3000"); | ||
|
||
// when: | ||
var response = specification.when().get("/jokes/random"); | ||
|
||
// then: | ||
response.then() | ||
.log().all() | ||
.statusCode(200) | ||
.assertThat() | ||
.header("Access-Control-Allow-Origin", Matchers.equalTo("*")) | ||
.header("Access-Control-Expose-Headers", Matchers.equalTo("Access-Control-Allow-Origin Access-Control-Allow-Credentials")) | ||
.header("Content-Type", Matchers.equalTo("application/json")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.