-
Notifications
You must be signed in to change notification settings - Fork 2
[JShellAPI][Testing] Setting up First Integration Test - Simple code snippet evaluation scenario #50
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
Merged
Alathreon
merged 6 commits into
Together-Java:develop
from
firasrg:testing/30-add-integration-tests
Oct 4, 2024
Merged
[JShellAPI][Testing] Setting up First Integration Test - Simple code snippet evaluation scenario #50
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9dc586e
[Testing][JShellAPI] Settings up gradle tasks for testing; ;
firasrg c8747e1
[Testing][JShellAPI] Setting first integration test for /eval endpoint;
firasrg 6ab35c4
[Testing][JShellAPI] Synchronizing endpoint paths between controllers…
firasrg cccd5f1
[Testing][JShellAPI] adding a second subtest for same endpoint with a…
firasrg 3de55c6
[Testing][JShellAPI] write documentation about testing approach
firasrg 8cc1485
[Testing][JShellAPI] apply pr review fixes
firasrg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
14 changes: 14 additions & 0 deletions
14
JShellAPI/src/main/java/org/togetherjava/jshellapi/rest/ApiEndpoints.java
This file contains hidden or 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,14 @@ | ||
package org.togetherjava.jshellapi.rest; | ||
|
||
/** | ||
* Holds endpoints mentioned in controllers. | ||
*/ | ||
public final class ApiEndpoints { | ||
private ApiEndpoints() {} | ||
|
||
public static final String BASE = "/jshell"; | ||
public static final String EVALUATE = "/eval"; | ||
public static final String SINGLE_EVALUATE = "/single-eval"; | ||
public static final String SNIPPETS = "/snippets"; | ||
public static final String STARTING_SCRIPT = "/startup_script"; | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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": "jshellapi.jshellwrapper-imageName", | ||
"type": "java.lang.String", | ||
"description": "JShellWrapper image name injected from the top-level gradle build file." | ||
} | ||
] } |
This file contains hidden or 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
76 changes: 76 additions & 0 deletions
76
JShellAPI/src/test/java/org/togetherjava/jshellapi/JShellApiTests.java
This file contains hidden or 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,76 @@ | ||
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.ActiveProfiles; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
|
||
import org.togetherjava.jshellapi.dto.JShellResult; | ||
import org.togetherjava.jshellapi.dto.JShellSnippetResult; | ||
import org.togetherjava.jshellapi.dto.SnippetStatus; | ||
import org.togetherjava.jshellapi.dto.SnippetType; | ||
import org.togetherjava.jshellapi.rest.ApiEndpoints; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Integrates tests for JShellAPI. | ||
*/ | ||
@ActiveProfiles("testing") | ||
@ContextConfiguration(classes = Main.class) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class JShellApiTests { | ||
|
||
@Autowired | ||
private WebTestClient webTestClient; | ||
|
||
@Autowired | ||
private Config testsConfig; | ||
|
||
@Test | ||
@DisplayName("When posting code snippet, evaluate it then return successfully result") | ||
public void evaluateCodeSnippetTest() { | ||
|
||
final String testEvalId = "test"; | ||
|
||
// -- first code snippet eval | ||
executeCodeEvalTest(testEvalId, "int a = 2+2;", 1, "4"); | ||
|
||
// -- second code snippet eval | ||
executeCodeEvalTest(testEvalId, "a * 2", 2, "8"); | ||
} | ||
|
||
private void executeCodeEvalTest(String evalId, String codeSnippet, int expectedId, | ||
String expectedResult) { | ||
final JShellSnippetResult jshellCodeSnippet = new JShellSnippetResult(SnippetStatus.VALID, | ||
SnippetType.ADDITION, expectedId, codeSnippet, expectedResult); | ||
|
||
assertThat(testEval(evalId, codeSnippet)) | ||
.isEqualTo(new JShellResult(List.of(jshellCodeSnippet), null, false, "")); | ||
} | ||
|
||
private JShellResult testEval(String testEvalId, String codeInput) { | ||
final String endpoint = | ||
String.join("/", ApiEndpoints.BASE, ApiEndpoints.EVALUATE, testEvalId); | ||
|
||
return this.webTestClient.mutate() | ||
.responseTimeout(Duration.ofSeconds(testsConfig.evalTimeoutSeconds())) | ||
.build() | ||
.post() | ||
.uri(endpoint) | ||
.bodyValue(codeInput) | ||
.exchange() | ||
.expectStatus() | ||
.isOk() | ||
.expectBody(JShellResult.class) | ||
.value((JShellResult evalResult) -> assertThat(evalResult).isNotNull()) | ||
.returnResult() | ||
.getResponseBody(); | ||
} | ||
} |
This file contains hidden or 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,11 @@ | ||
jshellapi: | ||
|
||
# Public API Config | ||
regularSessionTimeoutSeconds: 10 | ||
|
||
# Internal config | ||
schedulerSessionKillScanRateSeconds: 6 | ||
|
||
# Docker service config | ||
dockerResponseTimeout: 6 | ||
dockerConnectionTimeout: 6 |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.