Search in sources :

Example 16 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class JSONPathAssertionTest method testGetResult_match_msg_problem.

@Test
public void testGetResult_match_msg_problem() {
    System.out.println("getResult notexist");
    SampleResult samplerResult = new SampleResult();
    String str = "{\"execution\":[{\"scenario\":{\"requests\":[{\"headers\":{\"headerkey\":\"header value\"}}]}}]}";
    samplerResult.setResponseData(str.getBytes());
    JSONPathAssertion instance = new JSONPathAssertion();
    instance.setJsonPath("$.execution[0].scenario.requests[0].headers");
    instance.setJsonValidationBool(true);
    instance.setExpectNull(false);
    instance.setExpectedValue("{headerkey=header value}");
    instance.setInvert(false);
    AssertionResult expResult = new AssertionResult("");
    AssertionResult result = instance.getResult(samplerResult);
    assertEquals(expResult.getName(), result.getName());
    assertEquals(true, result.isFailure());
    assertEquals("Value expected to match regexp '{headerkey=header value}', but it did not match: '{\"headerkey\":\"header value\"}'", result.getFailureMessage());
}
Also used : AssertionResult(org.apache.jmeter.assertions.AssertionResult) SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.Test)

Example 17 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class JSONPathAssertionTest method testGetResult_list_val.

@Test
public void testGetResult_list_val() {
    System.out.println("getResult 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());
    assertEquals(false, result.isFailure());
}
Also used : AssertionResult(org.apache.jmeter.assertions.AssertionResult) SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.Test)

Example 18 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class JSONPathAssertionTest method testGetResult_inverted_null.

@Test
public void testGetResult_inverted_null() {
    System.out.println("getResult notexist");
    SampleResult samplerResult = new SampleResult();
    samplerResult.setResponseData("{\"myval\": [{\"key\": null}]}".getBytes());
    JSONPathAssertion instance = new JSONPathAssertion();
    instance.setJsonPath("$.myval[*].key");
    instance.setJsonValidationBool(true);
    instance.setExpectNull(true);
    instance.setInvert(true);
    AssertionResult expResult = new AssertionResult("");
    AssertionResult result = instance.getResult(samplerResult);
    assertEquals(expResult.getName(), result.getName());
    assertEquals(true, result.isFailure());
}
Also used : AssertionResult(org.apache.jmeter.assertions.AssertionResult) SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.Test)

Example 19 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class JSONPathAssertionTest method testGetResult_dict.

@Test
public void testGetResult_dict() {
    System.out.println("getResult notexist");
    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());
    assertEquals(false, result.isFailure());
}
Also used : AssertionResult(org.apache.jmeter.assertions.AssertionResult) SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.Test)

Example 20 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class UpperCaseTest method testExecute.

/**
 * Test of execute method, of class UpperCase.
 */
@Test
public void testExecute() throws Exception {
    System.out.println("execute");
    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable("abc"));
    parameters.add(new CompoundVariable("var"));
    SampleResult previousResult = null;
    Sampler currentSampler = null;
    UpperCase instance = new UpperCase();
    instance.setParameters(parameters);
    String expResult = "ABC";
    String result = instance.execute(null, null);
    Assert.assertEquals(expResult, result);
    Assert.assertEquals(expResult, JMeterContextService.getContext().getVariables().get("var"));
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Sampler(org.apache.jmeter.samplers.Sampler) ArrayList(java.util.ArrayList) SampleResult(org.apache.jmeter.samplers.SampleResult)

Aggregations

SampleResult (org.apache.jmeter.samplers.SampleResult)381 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