Search in sources :

Example 16 with TestSampler

use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.

the class TestOnceOnlyController method testProcessing.

@Test
public void testProcessing() throws Exception {
    GenericController controller = new GenericController();
    GenericController sub_1 = new OnceOnlyController();
    sub_1.addTestElement(new TestSampler("one"));
    sub_1.addTestElement(new TestSampler("two"));
    controller.addTestElement(sub_1);
    controller.addTestElement(new TestSampler("three"));
    LoopController sub_2 = new LoopController();
    sub_2.setLoops(3);
    GenericController sub_3 = new GenericController();
    sub_2.addTestElement(new TestSampler("four"));
    sub_3.addTestElement(new TestSampler("five"));
    sub_3.addTestElement(new TestSampler("six"));
    sub_2.addTestElement(sub_3);
    sub_2.addTestElement(new TestSampler("seven"));
    controller.addTestElement(sub_2);
    String[] interleaveOrder = new String[] { "one", "two" };
    String[] order = new String[] { "", "", "three", "four", "five", "six", "seven", "four", "five", "six", "seven", "four", "five", "six", "seven" };
    int counter = 15;
    controller.setRunningVersion(true);
    sub_1.setRunningVersion(true);
    sub_2.setRunningVersion(true);
    sub_3.setRunningVersion(true);
    controller.initialize();
    for (int i = 0; i < 4; i++) {
        assertEquals(15, counter);
        counter = 0;
        if (i > 0) {
            counter = 2;
        }
        TestElement sampler = null;
        while ((sampler = controller.next()) != null) {
            if (i == 0 && counter < 2) {
                assertEquals(interleaveOrder[counter], sampler.getName());
            } else {
                assertEquals(order[counter], sampler.getName());
            }
            counter++;
        }
    }
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

Example 17 with TestSampler

use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.

the class TestSamplerNameFunction method testSamplerNameWithVar.

@Test
public void testSamplerNameWithVar() throws Exception {
    variable.setParameters(params);
    TestSampler sampler = new TestSampler("UnitTestSampler");
    variable.setParameters(FunctionTestHelper.makeParams("var1", null, null));
    value = variable.execute(result, sampler);
    assertEquals("UnitTestSampler", value);
    assertEquals("UnitTestSampler", vars.get("var1"));
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) Test(org.junit.Test)

Example 18 with TestSampler

use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.

the class TestSamplerNameFunction method testSamplerName.

@Test
public void testSamplerName() throws Exception {
    variable.setParameters(params);
    TestSampler sampler = new TestSampler("UnitTestSampler");
    value = variable.execute(result, sampler);
    assertEquals("UnitTestSampler", value);
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) Test(org.junit.Test)

Example 19 with TestSampler

use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.

the class TestLoopController method testBug54467.

@Test
public void testBug54467() throws Exception {
    JMeterContext jmctx = JMeterContextService.getContext();
    LoopController loop = new LoopController();
    Map<String, String> variables = new HashMap<>();
    ReplaceStringWithFunctions transformer = new ReplaceStringWithFunctions(new CompoundVariable(), variables);
    jmctx.setVariables(new JMeterVariables());
    StringProperty prop = new StringProperty(LoopController.LOOPS, "${__Random(1,12,)}");
    JMeterProperty newProp = transformer.transformValue(prop);
    newProp.setRunningVersion(true);
    loop.setProperty(newProp);
    loop.addTestElement(new TestSampler("random run"));
    loop.setRunningVersion(true);
    loop.initialize();
    int loops = loop.getLoops();
    for (int i = 0; i < loops; i++) {
        Sampler s = loop.next();
        assertNotNull(s);
    }
    assertNull(loop.next());
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) ReplaceStringWithFunctions(org.apache.jmeter.engine.util.ReplaceStringWithFunctions) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) HashMap(java.util.HashMap) StringProperty(org.apache.jmeter.testelement.property.StringProperty) JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) TestSampler(org.apache.jmeter.junit.stubs.TestSampler) Sampler(org.apache.jmeter.samplers.Sampler) TestSampler(org.apache.jmeter.junit.stubs.TestSampler) Test(org.junit.Test)

Example 20 with TestSampler

use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.

the class TestLoopController method testProcessing.

@Test
public void testProcessing() throws Exception {
    GenericController controller = new GenericController();
    GenericController sub_1 = new GenericController();
    sub_1.addTestElement(new TestSampler("one"));
    sub_1.addTestElement(new TestSampler("two"));
    controller.addTestElement(sub_1);
    controller.addTestElement(new TestSampler("three"));
    LoopController sub_2 = new LoopController();
    sub_2.setLoops(3);
    GenericController sub_3 = new GenericController();
    sub_2.addTestElement(new TestSampler("four"));
    sub_3.addTestElement(new TestSampler("five"));
    sub_3.addTestElement(new TestSampler("six"));
    sub_2.addTestElement(sub_3);
    sub_2.addTestElement(new TestSampler("seven"));
    controller.addTestElement(sub_2);
    String[] order = new String[] { "one", "two", "three", "four", "five", "six", "seven", "four", "five", "six", "seven", "four", "five", "six", "seven" };
    int counter = 15;
    controller.setRunningVersion(true);
    sub_1.setRunningVersion(true);
    sub_2.setRunningVersion(true);
    sub_3.setRunningVersion(true);
    controller.initialize();
    for (int i = 0; i < 2; i++) {
        assertEquals(15, counter);
        counter = 0;
        TestElement sampler = null;
        while ((sampler = controller.next()) != null) {
            assertEquals(order[counter++], sampler.getName());
        }
    }
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

Aggregations

TestSampler (org.apache.jmeter.junit.stubs.TestSampler)43 Test (org.junit.Test)36 TestElement (org.apache.jmeter.testelement.TestElement)21 Sampler (org.apache.jmeter.samplers.Sampler)7 DebugSampler (org.apache.jmeter.sampler.DebugSampler)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)2 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)2 ReplaceStringWithFunctions (org.apache.jmeter.engine.util.ReplaceStringWithFunctions)2 ValueReplacer (org.apache.jmeter.engine.util.ValueReplacer)2 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)2 StringProperty (org.apache.jmeter.testelement.property.StringProperty)2 JMeterContext (org.apache.jmeter.threads.JMeterContext)2 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)2