Search in sources :

Example 86 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.

the class SizeAssertionTest method setUp.

@Before
public void setUp() {
    JMeterContext jmctx = JMeterContextService.getContext();
    assertion = new SizeAssertion();
    assertion.setThreadContext(jmctx);
    assertion.setTestFieldResponseBody();
    JMeterVariables vars = new JMeterVariables();
    jmctx.setVariables(vars);
    sample0 = new SampleResult();
    sample1 = new SampleResult();
    sample1.setResponseData(data1, null);
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) SampleResult(org.apache.jmeter.samplers.SampleResult) Before(org.junit.Before)

Example 87 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.

the class TestRandomVariableConfig method setUp.

@Before
public void setUp() {
    JMeterContext jmcx = JMeterContextService.getContext();
    jmcx.setVariables(new JMeterVariables());
    threadVars = jmcx.getVariables();
    config.setRandomSeed("abcd");
    config.setVariableName("randomVar");
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) Before(org.junit.Before)

Example 88 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.

the class XPathAssertionTest method setUp.

@Before
public void setUp() throws Exception {
    jmctx = JMeterContextService.getContext();
    assertion = new XPathAssertion();
    // This would be done by the run command
    assertion.setThreadContext(jmctx);
    result = new SampleResult();
    result.setResponseData(readFile("testfiles/XPathAssertionTest.xml"));
    vars = new JMeterVariables();
    jmctx.setVariables(vars);
    jmctx.setPreviousResult(result);
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) SampleResult(org.apache.jmeter.samplers.SampleResult) Before(org.junit.Before)

Example 89 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.

the class XPathAssertionTest method testNoTolerance.

@Test
public void testNoTolerance() throws Exception {
    String data = "<html><head><title>testtitle</title></head>" + "<body>" + "<p><i><b>invalid tag nesting</i></b><hr>" + "</body></html>";
    result.setResponseData(data, null);
    vars = new JMeterVariables();
    jmctx.setVariables(vars);
    jmctx.setPreviousResult(result);
    assertion.setXPathString("/html/head/title");
    assertion.setValidating(false);
    assertion.setTolerant(false);
    AssertionResult res = assertion.getResult(result);
    log.debug("failureMessage: {}", res.getFailureMessage());
    assertTrue(res.isError());
    assertFalse(res.isFailure());
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) Test(org.junit.Test)

Example 90 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.

the class CSVDataSet method iterationStart.

@Override
public void iterationStart(LoopIterationEvent iterEvent) {
    FileServer server = FileServer.getFileServer();
    final JMeterContext context = getThreadContext();
    String delim = getDelimiter();
    if ("\\t".equals(delim)) {
        // $NON-NLS-1$
        // Make it easier to enter a Tab // $NON-NLS-1$
        delim = "\t";
    } else if (delim.isEmpty()) {
        log.debug("Empty delimiter, will use ','");
        delim = ",";
    }
    if (vars == null) {
        String fileName = getFilename().trim();
        String mode = getShareMode();
        int modeInt = CSVDataSetBeanInfo.getShareModeAsInt(mode);
        switch(modeInt) {
            case CSVDataSetBeanInfo.SHARE_ALL:
                alias = fileName;
                break;
            case CSVDataSetBeanInfo.SHARE_GROUP:
                alias = fileName + "@" + System.identityHashCode(context.getThreadGroup());
                break;
            case CSVDataSetBeanInfo.SHARE_THREAD:
                alias = fileName + "@" + System.identityHashCode(context.getThread());
                break;
            default:
                // user-specified key
                alias = fileName + "@" + mode;
                break;
        }
        final String names = getVariableNames();
        if (StringUtils.isEmpty(names)) {
            String header = server.reserveFile(fileName, getFileEncoding(), alias, true);
            try {
                vars = CSVSaveService.csvSplitString(header, delim.charAt(0));
                firstLineIsNames = true;
            } catch (IOException e) {
                throw new IllegalArgumentException("Could not split CSV header line from file:" + fileName, e);
            }
        } else {
            server.reserveFile(fileName, getFileEncoding(), alias, ignoreFirstLine);
            // $NON-NLS-1$
            vars = JOrphanUtils.split(names, ",");
        }
        trimVarNames(vars);
    }
    // TODO: fetch this once as per vars above?
    JMeterVariables threadVars = context.getVariables();
    String[] lineValues = {};
    try {
        if (getQuotedData()) {
            lineValues = server.getParsedLine(alias, recycle, firstLineIsNames || ignoreFirstLine, delim.charAt(0));
        } else {
            String line = server.readLine(alias, recycle, firstLineIsNames || ignoreFirstLine);
            lineValues = JOrphanUtils.split(line, delim, false);
        }
        for (int a = 0; a < vars.length && a < lineValues.length; a++) {
            threadVars.put(vars[a], lineValues[a]);
        }
    } catch (IOException e) {
        // treat the same as EOF
        log.error(e.toString());
    }
    if (lineValues.length == 0) {
        // i.e. EOF
        if (getStopThread()) {
            throw new JMeterStopThreadException("End of file:" + getFilename() + " detected for CSV DataSet:" + getName() + " configured with stopThread:" + getStopThread() + ", recycle:" + getRecycle());
        }
        for (String var : vars) {
            threadVars.put(var, EOFVALUE);
        }
    }
}
Also used : JMeterStopThreadException(org.apache.jorphan.util.JMeterStopThreadException) JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) IOException(java.io.IOException) FileServer(org.apache.jmeter.services.FileServer)

Aggregations

JMeterVariables (org.apache.jmeter.threads.JMeterVariables)96 SampleResult (org.apache.jmeter.samplers.SampleResult)35 JMeterContext (org.apache.jmeter.threads.JMeterContext)33 Before (org.junit.Before)33 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)17 Test (org.junit.Test)16 JSONPostProcessor (org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor)8 TestPlan (org.apache.jmeter.testelement.TestPlan)6 HashMap (java.util.HashMap)5 Sampler (org.apache.jmeter.samplers.Sampler)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ValueReplacer (org.apache.jmeter.engine.util.ValueReplacer)4 Properties (java.util.Properties)3 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)3 Logger (org.slf4j.Logger)3 URL (java.net.URL)2 Arguments (org.apache.jmeter.config.Arguments)2 ReplaceStringWithFunctions (org.apache.jmeter.engine.util.ReplaceStringWithFunctions)2 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)2