Github user ham1 commented on a diff in the pull request:

    https://github.com/apache/jmeter/pull/344#discussion_r154070701
  
    --- Diff: test/src/org/apache/jmeter/assertions/TestJSONPathAssertion.java 
---
    @@ -0,0 +1,383 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + *
    + */
    +package org.apache.jmeter.assertions;
    +
    +import org.apache.jmeter.samplers.SampleResult;
    +import org.junit.Test;
    +
    +import static org.junit.Assert.assertEquals;
    +
    +public class TestJSONPathAssertion {
    +
    +    @Test
    +    public void testGetJsonPath() {
    +        JSONPathAssertion instance = new JSONPathAssertion();
    +        String expResult = "";
    +        String result = instance.getJsonPath();
    +        assertEquals(expResult, result);
    +    }
    +
    +    @Test
    +    public void testSetJsonPath() {
    +        String jsonPath = "";
    +        JSONPathAssertion instance = new JSONPathAssertion();
    +        instance.setJsonPath(jsonPath);
    +    }
    +
    +    @Test
    +    public void testGetExpectedValue() {
    +        JSONPathAssertion instance = new JSONPathAssertion();
    +        String expResult = "";
    +        String result = instance.getExpectedValue();
    +        assertEquals(expResult, result);
    +    }
    +
    +    @Test
    +    public void testSetExpectedValue() {
    +        String expectedValue = "";
    +        JSONPathAssertion instance = new JSONPathAssertion();
    +        instance.setExpectedValue(expectedValue);
    +    }
    +
    +    @Test
    +    public void testSetJsonValidationBool() {
    +        JSONPathAssertion instance = new JSONPathAssertion();
    +        instance.setJsonValidationBool(false);
    +    }
    +
    +    @Test
    +    public void testIsJsonValidationBool() {
    +        JSONPathAssertion instance = new JSONPathAssertion();
    +        boolean result = instance.isJsonValidationBool();
    +        assertEquals(false, result);
    +    }
    +
    +    @Test
    +    public void testGetResult_positive() {
    --- End diff --
    
    These tests would work really well in Spock e.g.:
    
    ```groovy
        def samplerResult = new SampleResult()
        def sut = new JSONPathAssertion()
        
        @Unroll
        def "get #jsonPath expect #expectedValue to fail=#failure"() {
            given:
                samplerResult.setResponseData("{\"myval\": 123}".getBytes())
                sut.setJsonPath("$.myval")
                sut.setJsonValidationBool(true)
                sut.setExpectedValue("123")
            when:
                def result = sut.getResult(samplerResult)
            then:
                result.getName() == new AssertionResult("").getName()
                result.isFailure() == failure
            where:
                jsonPath  || expectedValue | failure
                "$.myval" || "123"         | false
                "$.myval" || "(123|456)"   | false
                "$.myval" || "1234"        | true
        }
    ```


---

Reply via email to