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);
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations