jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject [jmeter] branch master updated: Clean up of tests
Date Sat, 11 Sep 2021 11:16:55 GMT
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new a6ad60a  Clean up of tests
a6ad60a is described below

commit a6ad60a1d68df22999050a568fecb1730abec303
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Sat Sep 11 13:15:48 2021 +0200

    Clean up of tests
    
    * deduplicate code by using ParameterizedTest
    * add assertions to simple tests, that check the getters and setters
    * make sonarqube happy :)
---
 .../jmeter/assertions/TestJSONPathAssertion.java   | 70 ++++++----------------
 1 file changed, 18 insertions(+), 52 deletions(-)

diff --git a/src/components/src/test/java/org/apache/jmeter/assertions/TestJSONPathAssertion.java
b/src/components/src/test/java/org/apache/jmeter/assertions/TestJSONPathAssertion.java
index 636a139..f4245f2 100644
--- a/src/components/src/test/java/org/apache/jmeter/assertions/TestJSONPathAssertion.java
+++ b/src/components/src/test/java/org/apache/jmeter/assertions/TestJSONPathAssertion.java
@@ -26,6 +26,8 @@ import java.util.Locale;
 
 import org.apache.jmeter.samplers.SampleResult;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
 
 class TestJSONPathAssertion {
 
@@ -39,9 +41,10 @@ class TestJSONPathAssertion {
 
     @Test
     void testSetJsonPath() {
-        String jsonPath = "";
+        String jsonPath = "$.someVar";
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonPath(jsonPath);
+        assertEquals(jsonPath, instance.getJsonPath());
     }
 
     @Test
@@ -54,15 +57,17 @@ class TestJSONPathAssertion {
 
     @Test
     void testSetExpectedValue() {
-        String expectedValue = "";
+        String expectedValue = "some value";
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setExpectedValue(expectedValue);
+        assertEquals(expectedValue, instance.getExpectedValue());
     }
 
     @Test
     void testSetJsonValidationBool() {
         JSONPathAssertion instance = new JSONPathAssertion();
         instance.setJsonValidationBool(false);
+        assertFalse(instance.isJsonValidationBool());
     }
 
     @Test
@@ -72,15 +77,21 @@ class TestJSONPathAssertion {
         assertFalse(result);
     }
 
-    @Test
-    void testGetResult_positive() {
+    @ParameterizedTest
+    @CsvSource(value={
+        "{\"myval\": 123}; $.myval; 123",
+        "{\"myval\": [{\"test\":1},{\"test\":2},{\"test\":3}]}; $.myval[*].test; 2",
+        "{\"myval\": []}; $.myval; []",
+        "{\"myval\": {\"key\": \"val\"}}; $.myval; {\"key\":\"val\"}"
+    }, delimiterString=";")
+    void testGetResult_pathsWithOneResult(String data, String jsonPath, String expectedResult)
{
         SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": 123}".getBytes());
+        samplerResult.setResponseData(data.getBytes());
 
         JSONPathAssertion instance = new JSONPathAssertion();
-        instance.setJsonPath("$.myval");
+        instance.setJsonPath(jsonPath);
         instance.setJsonValidationBool(true);
-        instance.setExpectedValue("123");
+        instance.setExpectedValue(expectedResult);
         AssertionResult expResult = new AssertionResult("");
         AssertionResult result = instance.getResult(samplerResult);
         assertEquals(expResult.getName(), result.getName());
@@ -243,21 +254,6 @@ class TestJSONPathAssertion {
     }
 
     @Test
-    void testGetResult_list_val() {
-        SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": [{\"test\":1},{\"test\":2},{\"test\":3}]}".getBytes());
-
-        JSONPathAssertion instance = new JSONPathAssertion();
-        instance.setJsonPath("$.myval[*].test");
-        instance.setJsonValidationBool(true);
-        instance.setExpectedValue("2");
-        AssertionResult expResult = new AssertionResult("");
-        AssertionResult result = instance.getResult(samplerResult);
-        assertEquals(expResult.getName(), result.getName());
-        assertFalse(result.isFailure());
-    }
-
-    @Test
     void testGetResult_list_negative() {
         SampleResult samplerResult = new SampleResult();
         samplerResult.setResponseData("{\"myval\": [{\"test\":1},{\"test\":2},{\"test\":3}]}".getBytes());
@@ -287,36 +283,6 @@ class TestJSONPathAssertion {
     }
 
     @Test
-    void testGetResult_list_empty_validate() {
-        SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": []}".getBytes());
-
-        JSONPathAssertion instance = new JSONPathAssertion();
-        instance.setJsonPath("$.myval");
-        instance.setJsonValidationBool(true);
-        instance.setExpectedValue("[]");
-        AssertionResult expResult = new AssertionResult("");
-        AssertionResult result = instance.getResult(samplerResult);
-        assertEquals(expResult.getName(), result.getName());
-        assertFalse(result.isFailure());
-    }
-
-    @Test
-    void testGetResult_dict() {
-        SampleResult samplerResult = new SampleResult();
-        samplerResult.setResponseData("{\"myval\": {\"key\": \"val\"}}".getBytes());
-
-        JSONPathAssertion instance = new JSONPathAssertion();
-        instance.setJsonPath("$.myval");
-        instance.setJsonValidationBool(true);
-        instance.setExpectedValue("{\"key\":\"val\"}");
-        AssertionResult expResult = new AssertionResult("");
-        AssertionResult result = instance.getResult(samplerResult);
-        assertEquals(expResult.getName(), result.getName());
-        assertFalse(result.isFailure());
-    }
-
-    @Test
     void testGetResult_inverted_null() {
         SampleResult samplerResult = new SampleResult();
         samplerResult.setResponseData("{\"myval\": [{\"key\": null}]}".getBytes());

Mime
View raw message