Skip to content

Commit

Permalink
[Testing][JShellAPI] Synchronizing endpoint paths between controllers…
Browse files Browse the repository at this point in the history
… and test classes
  • Loading branch information
firasrg committed Aug 10, 2024
1 parent c8747e1 commit 6ab35c4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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<String> snippets(@PathVariable String id,
@RequestParam(required = false) boolean includeStartupScript) throws DockerException {
validateId(id);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 6ab35c4

Please sign in to comment.