Skip to content

Commit 6ab35c4

Browse files
committed
[Testing][JShellAPI] Synchronizing endpoint paths between controllers and test classes
1 parent c8747e1 commit 6ab35c4

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
package org.togetherjava.jshellapi.rest;
22

3+
/**
4+
* This class holds endpoints mentioned in controllers. The main objective is to keep endpoints
5+
* synchronized with testing classes.
6+
*
7+
* @author Firas Regaieg
8+
*/
39
public final class ApiEndpoints {
410
private ApiEndpoints() {}
511

6-
public static final String EVALUATE_CODE_SNIPPET = "/jshell/eval";
12+
public static final String BASE = "/jshell";
13+
public static final String EVALUATE = "/eval";
14+
public static final String SINGLE_EVALUATE = "/single-eval";
15+
public static final String SNIPPETS = "/snippets";
16+
public static final String STARTING_SCRIPT = "/startup_script";
717
}

JShellAPI/src/main/java/org/togetherjava/jshellapi/rest/JShellController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515

1616
import java.util.List;
1717

18-
@RequestMapping("jshell")
18+
@RequestMapping(ApiEndpoints.BASE)
1919
@RestController
2020
public class JShellController {
2121
private JShellSessionService service;
2222
private StartupScriptsService startupScriptsService;
2323

24-
@PostMapping("/eval/{id}")
24+
@PostMapping(ApiEndpoints.EVALUATE + "/{id}")
2525
public JShellResult eval(@PathVariable String id,
2626
@RequestParam(required = false) StartupScriptId startupScriptId,
2727
@RequestBody String code) throws DockerException {
@@ -32,7 +32,7 @@ public JShellResult eval(@PathVariable String id,
3232
"An operation is already running"));
3333
}
3434

35-
@PostMapping("/eval")
35+
@PostMapping(ApiEndpoints.EVALUATE)
3636
public JShellResultWithId eval(@RequestParam(required = false) StartupScriptId startupScriptId,
3737
@RequestBody String code) throws DockerException {
3838
JShellService jShellService = service.session(startupScriptId);
@@ -42,7 +42,7 @@ public JShellResultWithId eval(@RequestParam(required = false) StartupScriptId s
4242
"An operation is already running")));
4343
}
4444

45-
@PostMapping("/single-eval")
45+
@PostMapping(ApiEndpoints.SINGLE_EVALUATE)
4646
public JShellResult singleEval(@RequestParam(required = false) StartupScriptId startupScriptId,
4747
@RequestBody String code) throws DockerException {
4848
JShellService jShellService = service.oneTimeSession(startupScriptId);
@@ -51,7 +51,7 @@ public JShellResult singleEval(@RequestParam(required = false) StartupScriptId s
5151
"An operation is already running"));
5252
}
5353

54-
@GetMapping("/snippets/{id}")
54+
@GetMapping(ApiEndpoints.SNIPPETS + "/{id}")
5555
public List<String> snippets(@PathVariable String id,
5656
@RequestParam(required = false) boolean includeStartupScript) throws DockerException {
5757
validateId(id);
@@ -71,7 +71,7 @@ public void delete(@PathVariable String id) throws DockerException {
7171
service.deleteSession(id);
7272
}
7373

74-
@GetMapping("/startup_script/{id}")
74+
@GetMapping(ApiEndpoints.STARTING_SCRIPT + "/{id}")
7575
public String startupScript(@PathVariable StartupScriptId id) {
7676
return startupScriptsService.get(id);
7777
}

JShellAPI/src/test/java/org/togetherjava/jshellapi/JShellApiTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ public class JShellApiTests {
3535
@DisplayName("When posting code snippet, evaluate it then returns successfully result")
3636
public void evaluateCodeSnippetTest() {
3737

38+
final String endpoint =
39+
String.join("/", ApiEndpoints.BASE, ApiEndpoints.EVALUATE, TEST_EVALUATION_ID);
40+
3841
JShellResult result = this.webTestClient.mutate()
3942
.responseTimeout(Duration.ofSeconds(6))
4043
.build()
4144
.post()
42-
.uri(ApiEndpoints.EVALUATE_CODE_SNIPPET + "/" + TEST_EVALUATION_ID)
45+
.uri(endpoint)
4346
.bodyValue(TEST_CODE_INPUT)
4447
.exchange()
4548
.expectStatus()

0 commit comments

Comments
 (0)