org.apache.jmeter.threads.JMeterContext Java Examples

The following examples show how to use org.apache.jmeter.threads.JMeterContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConversationUpdateSampler.java    From BotServiceStressToolkit with MIT License 6 votes vote down vote up
private String ensureFromUser() {
	JMeterContext context = getThreadContext();
	JMeterVariables vars = context.getVariables();

	String fromUserId = "";
	if (getGenRandomUserIdPerThread()) {
		if (vars.get(Constants.USER) == null) {
			fromUserId = "user-" + RandomStringUtils.randomAlphabetic(3, 7);
			vars.put(Constants.USER, fromUserId);
		} else {
			fromUserId = vars.get(Constants.USER);
		}
	} else {
		fromUserId = getFromMemberId();
	}

	return fromUserId;
}
 
Example #2
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcess() {
    System.out.println("process");
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData(json.getBytes());
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setDefaultValue("DEFAULT");
    instance.setVar("test");
    instance.setJsonPath("$.store.book[*].author");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertEquals("[\"Nigel Rees\",\"Evelyn Waugh\",\"Herman Melville\",\"J. R. R. Tolkien\"]", vars.get("test"));
}
 
Example #3
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcess_chinese() {
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    String chinese = "{\"carBrandName\":\"大众\"}";

    res.setResponseData(chinese.getBytes());
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setDefaultValue("DEFAULT");
    instance.setVar("test");
    instance.setJsonPath("$.carBrandName");
    instance.process();
    JMeterVariables vars = context.getVariables();
    // freaking "static final" DEFAULT_ENCODING field in SampleResult does not allow us to assert this
    // assertEquals("大众", vars.get("test"));
}
 
Example #4
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcess_from_var() {
    System.out.println("process fromvar");
    JMeterContext context = JMeterContextService.getContext();
    JMeterVariables vars = context.getVariables();

    SampleResult res = new SampleResult();
    res.setResponseData("".getBytes());
    context.setPreviousResult(res);

    vars.put("SVAR", json);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setDefaultValue("DEFAULT");
    instance.setVar("test");
    instance.setJsonPath("$.store.book[*].author");
    instance.setSubject(JSONPathExtractor.SUBJECT_VARIABLE);
    instance.setSrcVariableName("SVAR");
    instance.process();
    assertEquals("[\"Nigel Rees\",\"Evelyn Waugh\",\"Herman Melville\",\"J. R. R. Tolkien\"]", vars.get("test"));
}
 
Example #5
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testReported1() {
    System.out.println("process reported");
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData(json2.getBytes());
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setVar("GroupID");
    instance.setJsonPath("$.data.groups[?(@.name=='Zaz')].id");
    instance.setDefaultValue("NOTFOUND");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertNotEquals("NOTFOUND", vars.get("GroupID"));
    assertEquals("378e9b20-99bb-4d1f-bf2c-6a4a6c69a8ed", vars.get("GroupID_1"));
}
 
Example #6
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testReported1_1() {
    System.out.println("process reported");
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData(json2.getBytes());
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setVar("GroupID");
    instance.setJsonPath("$.data.groups[*].id");
    instance.setDefaultValue("NOTFOUND");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertNotEquals("NOTFOUND", vars.get("GroupID"));
    assertEquals("e02991f4-a95d-43dd-8eb0-fbc44349e238", vars.get("GroupID_1"));
}
 
Example #7
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testReported1_3() {
    System.out.println("process reported");
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData(json2.getBytes());
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setVar("GroupID");
    instance.setJsonPath("$.data.groups[?(@.name==Avtovaz)].id");
    instance.setDefaultValue("NOTFOUND");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertEquals("NOTFOUND", vars.get("GroupID"));
}
 
Example #8
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Ignore
@Test // FIXME: we need to solve this one day
public void testReported2() {
    System.out.println("process reported");
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData(json3.getBytes());
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setVar("var");
    instance.setJsonPath("$.data[?(@.attr.value>0)][0].attr");
    instance.setDefaultValue("NOTFOUND");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertNotEquals("NOTFOUND", vars.get("var"));
    assertEquals("{value=1}", vars.get("var"));
}
 
Example #9
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcess_from_var_2() {
    System.out.println("process fromvar");
    JMeterContext context = JMeterContextService.getContext();
    JMeterVariables vars = context.getVariables();

    SampleResult res = new SampleResult();
    res.setResponseData("".getBytes());
    context.setPreviousResult(res);

    vars.put("SVAR", json);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setDefaultValue("DEFAULT");
    instance.setVar("test");
    instance.setJsonPath("$.store.bicycle");
    instance.setSubject(JSONPathExtractor.SUBJECT_VARIABLE);
    instance.setSrcVariableName("SVAR");
    instance.process();
    String test = vars.get("test");
    boolean thiis = "{\"color\":\"red\",\"price\":19.95}".equals(test);
    boolean thaat = "{\"price\":19.95,\"color\":\"red\"}".equals(test);
    assertTrue(thiis || thaat);
}
 
Example #10
Source File: MonitoringResultsCollector.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
   * Update the worker thread jmeter context with the main thread one
   * @param isInit if true the context a full copy is done, if false only update is done
   */
  private void syncContext(boolean isInit)
  {
  	// jmeter context synchronisation
  	JMeterContext current = JMeterContextService.getContext();
JMeterContext ctx = this.getThreadContext();

if (isInit)
{
	current.setCurrentSampler(ctx.getCurrentSampler());
	current.setEngine(ctx.getEngine());
	current.setRestartNextLoop(ctx.isRestartNextLoop());
	current.setSamplingStarted(ctx.isSamplingStarted());
	current.setThread(ctx.getThread());
	current.setThreadGroup(ctx.getThreadGroup());
	current.setThreadNum(ctx.getThreadNum());
}
current.setVariables(ctx.getVariables());
current.setPreviousResult(ctx.getPreviousResult());
//current.getSamplerContext().putAll(ctx.getSamplerContext());
  }
 
Example #11
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testYamlExtractor1() throws IOException {
    File test = new File(getClass().getResource("/test1.yml").getPath());
    String response = FileUtils.readFileToString(test);

    JMeterContext context = JMeterContextService.getContext();
    JMeterVariables vars = context.getVariables();

    SampleResult samplerResult = new SampleResult();
    samplerResult.setResponseData(response.getBytes());
    context.setPreviousResult(samplerResult);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setInputFormat(JSONPathExtractor.INPUT_YAML);
    instance.setDefaultValue("DEFAULT");
    instance.setVar("concurrency");
    instance.setJsonPath("$.execution[*].concurrency");
    instance.process();

    assertEquals("[100]", vars.get("concurrency"));

    instance.setJsonPath("execution[*].concurrency1");
    instance.process();
    assertEquals("DEFAULT", vars.get("concurrency"));
}
 
Example #12
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
@Override
public void statusRefresh(JMeterContext context) {
    try {
        refreshVars(context);
        refreshProperties();
    } catch (Throwable e) {
        log.warn("Problem refreshing status pane", e);
    }
    evaluatePanel.refresh(context, debugger.isContinuing());
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            tree.repaint();
        }
    });
}
 
Example #13
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testYamlExtractor2() throws IOException {
    File test = new File(getClass().getResource("/test.yml").getPath());
    String response = FileUtils.readFileToString(test);

    JMeterContext context = JMeterContextService.getContext();
    JMeterVariables vars = context.getVariables();

    SampleResult samplerResult = new SampleResult();
    samplerResult.setResponseData(response.getBytes());
    context.setPreviousResult(samplerResult);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setInputFormat(JSONPathExtractor.INPUT_YAML);
    instance.setDefaultValue("DEFAULT");
    instance.setVar("architect");
    instance.setJsonPath("$.architect");
    instance.process();

    assertEquals("mihai", vars.get("architect"));
}
 
Example #14
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testYamlExtractor3() throws IOException {
    File test = new File(getClass().getResource("/test.yml").getPath());
    String response = FileUtils.readFileToString(test);

    JMeterContext context = JMeterContextService.getContext();
    JMeterVariables vars = context.getVariables();

    SampleResult samplerResult = new SampleResult();
    samplerResult.setResponseData(response.getBytes());
    context.setPreviousResult(samplerResult);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setInputFormat(JSONPathExtractor.INPUT_YAML);
    instance.setDefaultValue("DEFAULT");
    instance.setVar("developers");
    instance.setJsonPath("$.developers");
    instance.process();

    assertEquals("[\"rultor\",\"salikjan\",\"sherif\"]", vars.get("developers"));
    assertEquals("3", vars.get("developers_matchNr"));
}
 
Example #15
Source File: JMXMonCollector.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
   * Update the worker thread jmeter context with the main thread one
   * @param isInit if true the context a full copy is done, if false only update is done
   */
  private void syncContext(boolean isInit)
  {
  	// jmeter context synchronisation
  	JMeterContext current = JMeterContextService.getContext();
JMeterContext ctx = this.getThreadContext();

if (isInit)
{
	current.setCurrentSampler(ctx.getCurrentSampler());
	current.setEngine(ctx.getEngine());
	current.setRestartNextLoop(ctx.isRestartNextLoop());
	current.setSamplingStarted(ctx.isSamplingStarted());
	current.setThread(ctx.getThread());
	current.setThreadGroup(ctx.getThreadGroup());
	current.setThreadNum(ctx.getThreadNum());
}
current.setVariables(ctx.getVariables());
current.setPreviousResult(ctx.getPreviousResult());
//current.getSamplerContext().putAll(ctx.getSamplerContext());
  }
 
Example #16
Source File: RedisDataSetTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
    // Set up thread variables
    JMeterContext jmcx = JMeterContextService.getContext();
    jmcx.setVariables(new JMeterVariables());
    threadVars = jmcx.getVariables();

    // Create new mock RedisServer
    server = RedisServer.newRedisServer(6370);
    server.start();

    // Setup test data
    JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost", 6370);
    Jedis jedis = pool.getResource();

    jedis.rpush("testRecycleList", "12345678,1234","12345679,1235", "12345680,1236");
    jedis.rpush("testConsumeList", "12345678,1234","12345679,1235", "12345680,1236");
    jedis.sadd("testRecycleSet", "12345678,1234","12345679,1235", "12345680,1236");
    jedis.sadd("testConsumeSet", "12345678,1234","12345679,1235", "12345680,1236");

    jedis.shutdown();

}
 
Example #17
Source File: AbstractSimpleThreadGroup.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
private JMeterThread makeThread(int groupNum,
                                ListenerNotifier notifier, ListedHashTree threadGroupTree,
                                StandardJMeterEngine engine, int threadNum,
                                JMeterContext context) { // N.B. Context needs to be fetched in the correct thread
    boolean onErrorStopTest = getOnErrorStopTest();
    boolean onErrorStopTestNow = getOnErrorStopTestNow();
    boolean onErrorStopThread = getOnErrorStopThread();
    boolean onErrorStartNextLoop = getOnErrorStartNextLoop();

    String groupName = getName();
    String distributedPrefix = JMeterUtils.getPropDefault(THREAD_GROUP_DISTRIBUTED_PREFIX_PROPERTY_NAME, "");
    final String threadName = distributedPrefix + (distributedPrefix.isEmpty() ? "" : "-") + groupName + " " + groupNum + "-" + (threadNum + 1);

    final JMeterThread jmeterThread = new JMeterThread(cloneTree(threadGroupTree), this, notifier);
    jmeterThread.setThreadNum(threadNum);
    jmeterThread.setThreadGroup(this);
    jmeterThread.setInitialContext(context);
    jmeterThread.setThreadName(threadName);
    jmeterThread.setEngine(engine);
    jmeterThread.setOnErrorStopTest(onErrorStopTest);
    jmeterThread.setOnErrorStopTestNow(onErrorStopTestNow);
    jmeterThread.setOnErrorStopThread(onErrorStopThread);
    jmeterThread.setOnErrorStartNextLoop(onErrorStartNextLoop);
    return jmeterThread;
}
 
Example #18
Source File: HttpTestBean.java    From BotServiceStressToolkit with MIT License 6 votes vote down vote up
@Override
public SampleResult sample(Entry entry) {
	SampleResult res = new SampleResult();
	res.setSampleLabel(getName());
	res.sampleStart();
	res.setDataType(SampleResult.TEXT);

	try {
		JMeterContext context = getThreadContext();
		JMeterVariables vars = context.getVariables();

		String body = Unirest.get("http://www.uol.com.br").asString().getBody();

		res.setResponseData(body, null);
		res.sampleEnd();
		res.setSuccessful(true);

	} catch (UnirestException e) {
		res.setResponseData(e.toString(), null);
		res.sampleEnd();
		res.setSuccessful(false);
	} 

	return res;
}
 
Example #19
Source File: WebDriverSampler.java    From jmeter-plugins-webdriver with Apache License 2.0 6 votes vote down vote up
ScriptEngine createScriptEngineWith(SampleResult sampleResult) {
    final ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(this.getScriptLanguage());
    Bindings engineBindings = new SimpleBindings();
    WebDriverScriptable scriptable = new WebDriverScriptable();
    scriptable.setName(getName());
    scriptable.setParameters(getParameters());
    JMeterContext context = JMeterContextService.getContext();
    scriptable.setVars(context.getVariables());
    scriptable.setProps(JMeterUtils.getJMeterProperties());
    scriptable.setCtx(context);
    scriptable.setLog(LOGGER);
    scriptable.setSampleResult(sampleResult);
    scriptable.setBrowser(getWebDriver());
    engineBindings.put("WDS", scriptable);
    scriptEngine.setBindings(engineBindings, ScriptContext.ENGINE_SCOPE);
    return scriptEngine;
}
 
Example #20
Source File: ParallelSampler.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
private void changeVariablesMap() {
    try {
        JMeterContext context = this.getThreadContext();
        if (context != null && context.getVariables() != null) {
            JMeterVariables jMeterVariables = context.getVariables();
            Class<JMeterVariables> cls = JMeterVariables.class;
            Field variablesField = cls.getDeclaredField("variables");
            variablesField.setAccessible(true);
            Object obj = variablesField.get(jMeterVariables);
            synchronized (obj) {
                if (obj instanceof Map) {
                    Map variables = (Map) obj;
                    if (!(variables instanceof ConcurrentHashMap)) {
                        variablesField.set(jMeterVariables, new ConcurrentHashMap(variables));
                    }
                } else {
                    log.warn("Unexpected variables map type " + obj.getClass().getName());
                }
            }
        }
    } catch (Throwable ex) {
        log.warn("Cannot change variables map ", ex);
    }
}
 
Example #21
Source File: PepperBoxSamplerTest.java    From pepper-box with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {

    zkServer = new EmbeddedZookeeper();

    String zkConnect = ZKHOST + ":" + zkServer.port();
    zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = ZkUtils.apply(zkClient, false);

    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST +":" + BROKERPORT);
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);
    //AdminUtils.createTopic(zkUtils, TOPIC, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);

    JMeterContext jmcx = JMeterContextService.getContext();
    jmcx.setVariables(new JMeterVariables());

}
 
Example #22
Source File: PepperBoxLoadGenTest.java    From pepper-box with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {

    zkServer = new EmbeddedZookeeper();

    String zkConnect = ZKHOST + ":" + zkServer.port();
    zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = ZkUtils.apply(zkClient, false);

    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST +":" + BROKERPORT);
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);
    //AdminUtils.createTopic(zkUtils, TOPIC, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);

    JMeterContext jmcx = JMeterContextService.getContext();
    jmcx.setVariables(new JMeterVariables());

}
 
Example #23
Source File: DebuggingThreadGroup.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
private DebuggingThread makeThread(int groupCount, ListenerNotifier notifier, ListedHashTree threadGroupTree, StandardJMeterEngine engine, int i, JMeterContext context) {
    // had to copy whole method because of this line
    DebuggingThread jmeterThread = new DebuggingThread(threadGroupTree, this, notifier, context);

    boolean onErrorStopTest = getOnErrorStopTest();
    boolean onErrorStopTestNow = getOnErrorStopTestNow();
    boolean onErrorStopThread = getOnErrorStopThread();
    boolean onErrorStartNextLoop = getOnErrorStartNextLoop();
    String groupName = getName();

    jmeterThread.setThreadNum(i);
    jmeterThread.setThreadGroup(this);
    jmeterThread.setInitialContext(context);
    String threadName = groupName + " " + (groupCount) + "-" + (i + 1);
    jmeterThread.setThreadName(threadName);
    jmeterThread.setEngine(engine);
    jmeterThread.setOnErrorStopTest(onErrorStopTest);
    jmeterThread.setOnErrorStopTestNow(onErrorStopTestNow);
    jmeterThread.setOnErrorStopThread(onErrorStopThread);
    jmeterThread.setOnErrorStartNextLoop(onErrorStartNextLoop);
    return jmeterThread;
}
 
Example #24
Source File: AbstractSimpleThreadGroup.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void start(int groupNum, ListenerNotifier notifier, ListedHashTree threadGroupTree, StandardJMeterEngine engine) {
    running = true;

    int numThreads = getNumThreads();

    log.info("Starting thread group number " + groupNum + " threads " + numThreads);

    long now = System.currentTimeMillis(); // needs to be same time for all threads in the group
    final JMeterContext context = JMeterContextService.getContext();
    for (int i = 0; running && i < numThreads; i++) {
        JMeterThread jmThread = makeThread(groupNum, notifier, threadGroupTree, engine, i, context);
        scheduleThread(jmThread, now); // set start and end time
        Thread newThread = new Thread(jmThread, jmThread.getThreadName());
        registerStartedThread(jmThread, newThread);
        newThread.start();
    }

    log.info("Started thread group number " + groupNum);
}
 
Example #25
Source File: DummySubPostProcessor.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void process() {
    JMeterContext context = getThreadContext();
    SampleResult res = context.getPreviousResult();
    SampleResult sample = dummy.sample();
    res.addSubResult(sample);
}
 
Example #26
Source File: XMLFormatPostProcessorTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Test of process method, of class XMLFormatPostProcessor.
 */
@Test
public void testProcess() {
    System.out.println("process");
    JMeterContext threadContext = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    threadContext.setPreviousResult(res);
    XMLFormatPostProcessor instance = new XMLFormatPostProcessor();
    instance.process();
    // TODO review the generated test code and remove the default call to fail.

}
 
Example #27
Source File: XMLFormatPostProcessor.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public void process() {
    JMeterContext threadContext = getThreadContext();

    String responseString = threadContext.getPreviousResult().getResponseDataAsString();
    try {
        threadContext.getPreviousResult().setResponseData(serialize2(responseString).getBytes("UTF-8"));
    } catch (Exception e) {
        log.info("Error while formating response xml - " + e.getMessage());
    }
}
 
Example #28
Source File: DummySubPostProcessorTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    JMeterContext threadContext = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.sampleStart();
    res.sampleEnd();
    threadContext.setPreviousResult(res);
}
 
Example #29
Source File: Base64EncodeTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() throws Exception {
    JMeterContext context = JMeterContextService.getContext();
    context.setVariables(new JMeterVariables());

    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable("test string"));
    parameters.add(new CompoundVariable("b64enc_res"));
    Base64Encode instance = new Base64Encode();
    instance.setParameters(parameters);

    String res = instance.execute(null, null);
    Assert.assertEquals("dGVzdCBzdHJpbmc=", res);
    Assert.assertNotNull(context.getVariables().get("b64enc_res"));
}
 
Example #30
Source File: Base64DecodeTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() throws Exception {
    JMeterContext context = JMeterContextService.getContext();
    context.setVariables(new JMeterVariables());

    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable("dGVzdCBzdHJpbmc="));
    parameters.add(new CompoundVariable("b64dec_res"));
    Base64Decode instance = new Base64Decode();
    instance.setParameters(parameters);

    String res = instance.execute(null, null);
    Assert.assertEquals("test string", res);
    Assert.assertNotNull(context.getVariables().get("b64dec_res"));
}