- 
                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 5 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
    
  
  
    
              
        
          
  
    
      
          
            17 changes: 17 additions & 0 deletions
          
          17 
        
  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,17 @@ | ||
| package org.togetherjava.jshellapi.rest; | ||
| 
     | 
||
| /** | ||
| * This class holds endpoints mentioned in controllers. The main objective is to keep endpoints | ||
| * synchronized with testing classes. | ||
                
      
                  Alathreon marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| * | ||
| * @author Firas Regaieg | ||
                
      
                  Alathreon marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| */ | ||
| 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": "jshell-wrapper.image-name", | ||
| "type": "java.lang.String", | ||
| "description": "JShellWrapper image name injected from the top-level gradle build file." | ||
| } | ||
| ] } | ||
                
      
                  Alathreon marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
  
    
      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
    
  
  
    
              
        
          
  
    
      
          
            90 changes: 90 additions & 0 deletions
          
          90 
        
  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,90 @@ | ||
| 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.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; | ||
| 
     | 
||
| /** | ||
| * This class holds integration tests for JShellAPI. It depends on gradle building image task, fore | ||
| * more information check "test" section in gradle.build file. | ||
                
      
                  Alathreon marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| * | ||
| * @author Firas Regaieg | ||
                
      
                  Alathreon marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| */ | ||
| @ContextConfiguration(classes = Main.class) | ||
| @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
| public class JShellApiTests { | ||
| 
     | 
||
| @Autowired | ||
| private WebTestClient webTestClient; | ||
| 
     | 
||
| @Test | ||
| @DisplayName("When posting code snippet, evaluate it then returns successfully result") | ||
| public void evaluateCodeSnippetTest() { | ||
| 
     | 
||
| final String testEvalId = "test"; | ||
| 
     | 
||
| // -- performing a first code snippet execution | ||
| 
     | 
||
| final String firstCodeExpression = "int a = 2+2;"; | ||
| 
     | 
||
| final JShellSnippetResult firstCodeSnippet = new JShellSnippetResult(SnippetStatus.VALID, | ||
| SnippetType.ADDITION, 1, firstCodeExpression, "4"); | ||
| final JShellResult firstCodeExpectedResult = | ||
| getJShellResultDefaultInstance(firstCodeSnippet); | ||
| 
     | 
||
| assertThat(testEval(testEvalId, firstCodeExpression)).isEqualTo(firstCodeExpectedResult); | ||
| 
     | 
||
| // -- performing a second code snippet execution | ||
| 
     | 
||
| final String secondCodeExpression = "a * 2"; | ||
| 
     | 
||
| final JShellSnippetResult secondCodeSnippet = new JShellSnippetResult(SnippetStatus.VALID, | ||
| SnippetType.ADDITION, 2, secondCodeExpression, "8"); | ||
| 
     | 
||
| final JShellResult secondCodeExpectedResult = | ||
| getJShellResultDefaultInstance(secondCodeSnippet); | ||
| 
     | 
||
| assertThat(testEval(testEvalId, secondCodeExpression)).isEqualTo(secondCodeExpectedResult); | ||
| } | ||
                
      
                  Alathreon marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| private JShellResult testEval(String testEvalId, String codeInput) { | ||
| final String endpoint = | ||
| String.join("/", ApiEndpoints.BASE, ApiEndpoints.EVALUATE, testEvalId); | ||
| 
     | 
||
| JShellResult result = this.webTestClient.mutate() | ||
| .responseTimeout(Duration.ofSeconds(6)) | ||
                
      
                  Alathreon marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| .build() | ||
| .post() | ||
| .uri(endpoint) | ||
| .bodyValue(codeInput) | ||
| .exchange() | ||
| .expectStatus() | ||
| .isOk() | ||
| .expectBody(JShellResult.class) | ||
| .value((JShellResult evalResult) -> assertThat(evalResult).isNotNull()) | ||
                
      
                  Alathreon marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| .returnResult() | ||
| .getResponseBody(); | ||
| 
     | 
||
| assertThat(result).isNotNull(); | ||
                
      
                  Alathreon marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| return result; | ||
| } | ||
| 
     | 
||
| private static JShellResult getJShellResultDefaultInstance(JShellSnippetResult snippetResult) { | ||
                
      
                  Alathreon marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| return new JShellResult(List.of(snippetResult), null, false, ""); | ||
| } | ||
| } | ||
      
      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.