Search in sources :

Example 91 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class TestJSONPathAssertion method testGetResultFloat.

@Test
void testGetResultFloat() {
    Locale prevLocale = Locale.getDefault();
    try {
        // 0.0000123456789 is locale-dependent
        Locale.setDefault(Locale.US);
        SampleResult samplerResult = new SampleResult();
        samplerResult.setResponseData("{\"myval\": [{\"test\":0.0000123456789}]}".getBytes());
        JSONPathAssertion instance = new JSONPathAssertion();
        instance.setJsonPath("$.myval[*].test");
        instance.setJsonValidationBool(true);
        instance.setIsRegex(false);
        instance.setExpectedValue("0.0000123456789");
        AssertionResult expResult = new AssertionResult("");
        AssertionResult result = instance.getResult(samplerResult);
        assertEquals(expResult.getName(), result.getName());
        assertFalse(result.isFailure());
    } finally {
        Locale.setDefault(prevLocale);
    }
}
Also used : Locale(java.util.Locale) SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 92 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class TestJSONPathAssertion method testGetResult_complex_map.

@Test
void testGetResult_complex_map() {
    SampleResult samplerResult = new SampleResult();
    samplerResult.setResponseData("{\"myval\": { \"a\": 23, \"b\": 42, \"c\": \"something\" } }".getBytes());
    JSONPathAssertion instance = new JSONPathAssertion();
    instance.setJsonPath("$.myval");
    instance.setJsonValidationBool(true);
    instance.setIsRegex(false);
    instance.setExpectedValue("{\n\t\"a\": 23,\n\"b\": 42,\n\t\"c\": \"something\"\n}");
    AssertionResult result = instance.getResult(samplerResult);
    assertFalse(result.isFailure());
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 93 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class TestJSONPathAssertion method testGetResult_no_such_path.

@Test
void testGetResult_no_such_path() {
    SampleResult samplerResult = new SampleResult();
    samplerResult.setResponseData("{\"myval\": null}".getBytes());
    JSONPathAssertion instance = new JSONPathAssertion();
    instance.setJsonPath("$.notexist");
    instance.setJsonValidationBool(false);
    AssertionResult expResult = new AssertionResult("");
    AssertionResult result = instance.getResult(samplerResult);
    assertEquals(expResult.getName(), result.getName());
    assertTrue(result.isFailure());
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 94 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class TestJSONPathAssertion method testGetResult_positive_regexp.

@Test
void testGetResult_positive_regexp() {
    SampleResult samplerResult = new SampleResult();
    samplerResult.setResponseData("{\"myval\": 123}".getBytes());
    JSONPathAssertion instance = new JSONPathAssertion();
    instance.setJsonPath("$.myval");
    instance.setJsonValidationBool(true);
    instance.setExpectedValue("(123|456)");
    AssertionResult expResult = new AssertionResult("");
    AssertionResult result = instance.getResult(samplerResult);
    assertEquals(expResult.getName(), result.getName());
    assertFalse(result.isFailure());
    samplerResult.setResponseData("{\"myval\": 456}".getBytes());
    AssertionResult result2 = instance.getResult(samplerResult);
    assertFalse(result2.isFailure());
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 95 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class TestJSONPathAssertion method testGetResult_list_empty_novalidate.

@Test
void testGetResult_list_empty_novalidate() {
    // With bug 65794 the outcome of this test has changed
    // we now consider an indefinite path with no assertion value
    // an error and set the AssertionResult to failure
    SampleResult samplerResult = new SampleResult();
    samplerResult.setResponseData("{\"myval\": []}".getBytes());
    JSONPathAssertion instance = new JSONPathAssertion();
    instance.setJsonPath("$.myval[*]");
    instance.setJsonValidationBool(false);
    AssertionResult expResult = new AssertionResult("");
    AssertionResult result = instance.getResult(samplerResult);
    assertEquals(expResult.getName(), result.getName());
    assertTrue(result.isFailure());
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SampleResult (org.apache.jmeter.samplers.SampleResult)379 Test (org.junit.Test)83 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)71 Test (org.junit.jupiter.api.Test)59 JMeterContext (org.apache.jmeter.threads.JMeterContext)47 BeforeEach (org.junit.jupiter.api.BeforeEach)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 SampleEvent (org.apache.jmeter.samplers.SampleEvent)30 Sampler (org.apache.jmeter.samplers.Sampler)30 AssertionResult (org.apache.jmeter.assertions.AssertionResult)27 ArrayList (java.util.ArrayList)26 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)20 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)20 IOException (java.io.IOException)17 Arguments (org.apache.jmeter.config.Arguments)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)13 CorrectedResultCollector (kg.apc.jmeter.vizualizers.CorrectedResultCollector)12 URL (java.net.URL)9 File (java.io.File)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7