-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Testing][JShellAPI] Setting first integration test for /eval endpoint;
Note: this includes changes and improvements in gradle.build files;
- Loading branch information
Showing
9 changed files
with
122 additions
and
63 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
7 changes: 7 additions & 0 deletions
7
JShellAPI/src/main/java/org/togetherjava/jshellapi/rest/ApiEndpoints.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,7 @@ | ||
package org.togetherjava.jshellapi.rest; | ||
|
||
public final class ApiEndpoints { | ||
private ApiEndpoints() {} | ||
|
||
public static final String EVALUATE_CODE_SNIPPET = "/jshell/eval"; | ||
} |
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
8 changes: 8 additions & 0 deletions
8
JShellAPI/src/main/resources/META-INF/additional-spring-configuration-metadata.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"properties": [ | ||
{ | ||
"name": "jshell-wrapper.image-name", | ||
"type": "java.lang.String", | ||
"description": "JShellWrapper image name injected from the top-level gradle build file." | ||
} | ||
] } |
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
52 changes: 49 additions & 3 deletions
52
JShellAPI/src/test/java/org/togetherjava/jshellapi/JShellApiTests.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 |
---|---|---|
@@ -1,16 +1,62 @@ | ||
package org.togetherjava.jshellapi; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
|
||
import org.togetherjava.jshellapi.dto.JShellResult; | ||
import org.togetherjava.jshellapi.rest.ApiEndpoints; | ||
|
||
import java.time.Duration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
// TODO - write some integrations | ||
/** | ||
* This class holds integration tests for JShellAPI. It depends on gradle building image task, fore | ||
* more information check "test" section in gradle.build file. | ||
* | ||
* @author Firas Regaieg | ||
*/ | ||
@ContextConfiguration | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class JShellApiTests { | ||
|
||
@Autowired | ||
private WebTestClient webTestClient; | ||
|
||
private static final String TEST_EVALUATION_ID = "test"; | ||
private static final String TEST_CODE_INPUT = "2+2"; | ||
private static final String TEST_CODE_EXPECTED_OUTPUT = "4"; | ||
|
||
@Test | ||
public void test() { | ||
assertThat(true).isTrue(); | ||
@DisplayName("When posting code snippet, evaluate it then returns successfully result") | ||
public void evaluateCodeSnippetTest() { | ||
|
||
JShellResult result = this.webTestClient.mutate() | ||
.responseTimeout(Duration.ofSeconds(6)) | ||
.build() | ||
.post() | ||
.uri(ApiEndpoints.EVALUATE_CODE_SNIPPET + "/" + TEST_EVALUATION_ID) | ||
.bodyValue(TEST_CODE_INPUT) | ||
.exchange() | ||
.expectStatus() | ||
.isOk() | ||
.expectBody(JShellResult.class) | ||
.value(task -> assertThat(task).isNotNull()) | ||
.returnResult() | ||
.getResponseBody(); | ||
|
||
assertThat(result).isNotNull(); | ||
|
||
boolean isValidResult = result.snippetsResults() | ||
.stream() | ||
.filter(res -> res.result() != null) | ||
.anyMatch(res -> res.result().equals(TEST_CODE_EXPECTED_OUTPUT)); | ||
|
||
assertThat(isValidResult).isTrue(); | ||
|
||
} | ||
} |
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
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