diff --git a/JShellAPI/src/main/java/org/togetherjava/jshellapi/rest/ApiEndpoints.java b/JShellAPI/src/main/java/org/togetherjava/jshellapi/rest/ApiEndpoints.java index a0b4bea..889014f 100644 --- a/JShellAPI/src/main/java/org/togetherjava/jshellapi/rest/ApiEndpoints.java +++ b/JShellAPI/src/main/java/org/togetherjava/jshellapi/rest/ApiEndpoints.java @@ -1,7 +1,17 @@ package org.togetherjava.jshellapi.rest; +/** + * This class holds endpoints mentioned in controllers. The main objective is to keep endpoints + * synchronized with testing classes. + * + * @author Firas Regaieg + */ public final class ApiEndpoints { private ApiEndpoints() {} - public static final String EVALUATE_CODE_SNIPPET = "/jshell/eval"; + 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"; } diff --git a/JShellAPI/src/main/java/org/togetherjava/jshellapi/rest/JShellController.java b/JShellAPI/src/main/java/org/togetherjava/jshellapi/rest/JShellController.java index 2c60570..d605bc2 100644 --- a/JShellAPI/src/main/java/org/togetherjava/jshellapi/rest/JShellController.java +++ b/JShellAPI/src/main/java/org/togetherjava/jshellapi/rest/JShellController.java @@ -15,13 +15,13 @@ import java.util.List; -@RequestMapping("jshell") +@RequestMapping(ApiEndpoints.BASE) @RestController public class JShellController { private JShellSessionService service; private StartupScriptsService startupScriptsService; - @PostMapping("/eval/{id}") + @PostMapping(ApiEndpoints.EVALUATE + "/{id}") public JShellResult eval(@PathVariable String id, @RequestParam(required = false) StartupScriptId startupScriptId, @RequestBody String code) throws DockerException { @@ -32,7 +32,7 @@ public JShellResult eval(@PathVariable String id, "An operation is already running")); } - @PostMapping("/eval") + @PostMapping(ApiEndpoints.EVALUATE) public JShellResultWithId eval(@RequestParam(required = false) StartupScriptId startupScriptId, @RequestBody String code) throws DockerException { JShellService jShellService = service.session(startupScriptId); @@ -42,7 +42,7 @@ public JShellResultWithId eval(@RequestParam(required = false) StartupScriptId s "An operation is already running"))); } - @PostMapping("/single-eval") + @PostMapping(ApiEndpoints.SINGLE_EVALUATE) public JShellResult singleEval(@RequestParam(required = false) StartupScriptId startupScriptId, @RequestBody String code) throws DockerException { JShellService jShellService = service.oneTimeSession(startupScriptId); @@ -51,7 +51,7 @@ public JShellResult singleEval(@RequestParam(required = false) StartupScriptId s "An operation is already running")); } - @GetMapping("/snippets/{id}") + @GetMapping(ApiEndpoints.SNIPPETS + "/{id}") public List snippets(@PathVariable String id, @RequestParam(required = false) boolean includeStartupScript) throws DockerException { validateId(id); @@ -71,7 +71,7 @@ public void delete(@PathVariable String id) throws DockerException { service.deleteSession(id); } - @GetMapping("/startup_script/{id}") + @GetMapping(ApiEndpoints.STARTING_SCRIPT + "/{id}") public String startupScript(@PathVariable StartupScriptId id) { return startupScriptsService.get(id); } diff --git a/JShellAPI/src/test/java/org/togetherjava/jshellapi/JShellApiTests.java b/JShellAPI/src/test/java/org/togetherjava/jshellapi/JShellApiTests.java index 434f0e2..e0809a4 100644 --- a/JShellAPI/src/test/java/org/togetherjava/jshellapi/JShellApiTests.java +++ b/JShellAPI/src/test/java/org/togetherjava/jshellapi/JShellApiTests.java @@ -35,11 +35,14 @@ public class JShellApiTests { @DisplayName("When posting code snippet, evaluate it then returns successfully result") public void evaluateCodeSnippetTest() { + final String endpoint = + String.join("/", ApiEndpoints.BASE, ApiEndpoints.EVALUATE, TEST_EVALUATION_ID); + JShellResult result = this.webTestClient.mutate() .responseTimeout(Duration.ofSeconds(6)) .build() .post() - .uri(ApiEndpoints.EVALUATE_CODE_SNIPPET + "/" + TEST_EVALUATION_ID) + .uri(endpoint) .bodyValue(TEST_CODE_INPUT) .exchange() .expectStatus()