org.apache.jmeter.protocol.http.control.CookieManager Java Examples

The following examples show how to use org.apache.jmeter.protocol.http.control.CookieManager. 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: CustomTreeClonerTest.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testFlow() throws Exception {
    final CookieManager manager = new CookieManager();
    final ThroughputController controller = new ThroughputController();

    CustomTreeCloner cloner = new CustomTreeCloner();
    HashTree tree = createTestTree(controller, manager);
    tree.traverse(cloner);

    ListedHashTree clonedTree = cloner.getClonedTree();
    ListedHashTree loop = (ListedHashTree) clonedTree.values().toArray()[0];

    Object actualController = loop.keySet().toArray()[0];
    assertTrue("This links should be to the same instance", controller == actualController);

    Object actualManager = loop.get(actualController).keySet().toArray()[0];
    assertTrue("Cookie manager should be changed to ThreadSafe instance", actualManager instanceof ThreadSafeCookieManager);
}
 
Example #2
Source File: CustomTreeCloner.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final void addNode(Object node, HashTree subTree) {
    if (node instanceof CookieManager) {
        node = new ThreadSafeCookieManager((CookieManager) node);
    }
    newTree.add(objects, node);
    addLast(node);
}
 
Example #3
Source File: WebSocketAbstractSampler.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void addTestElement(TestElement el) {
	if (el instanceof HeaderManager) {
		setHeaderManager((HeaderManager) el);
	} else if (el instanceof CookieManager) {
		setCookieManager((CookieManager) el);
	} else {
		super.addTestElement(el);
	}
}
 
Example #4
Source File: WebSocketAbstractSampler.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
public void setCookieManager(CookieManager value) {
    CookieManager mgr = getCookieManager();
    if (mgr != null) {
        log.warn("Existing CookieManager " + mgr.getName() + " superseded by " + value.getName());
    }
    setCookieManagerProperty(value);
}
 
Example #5
Source File: ParallelSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testThreadSafeCookieManager() throws Exception {
    CookieManager cookieManager = new CookieManager();
    Cookie c = new Cookie();
    c.setName("name");
    c.setValue("value");
    c.setDomain("blazedemo.com");
    c.setPath("");
    cookieManager.add(c);
    HashTree hashtree = createTestTree(cookieManager);

    TestPlan testPlan = new TestPlan();
    HashTree testPlanHashTree = new HashTree();
    testPlanHashTree.put(testPlan, hashtree);

    StandardJMeterEngine engine = new StandardJMeterEngine();
    engine.configure(testPlanHashTree);

    EmulatorThreadMonitor monitor = new EmulatorThreadMonitor();
    JMeterThread thread = new JMeterThread(hashtree, monitor, null);
    thread.setThreadName("test thread");
    JMeterContextService.getContext().setThread(thread);

    ParallelSampler parallel = new ParallelSampler();
    parallel.testStarted();

    Field field = StandardJMeterEngine.class.getDeclaredField("test");
    field.setAccessible(true);
    HashTree testTree = (HashTree) field.get(engine);

    assertTrue("CookieManager should be changed to ThreadSafeCookieManager", testTree.toString().contains("ThreadSafeCookieManager"));
    ListedHashTree loop = (ListedHashTree) (testTree.values().toArray()[0]);
    ListedHashTree threadSafeManager = ((ListedHashTree) (loop.values().toArray()[0]));

    CookieManager mgr = (CookieManager) threadSafeManager.getArray()[0];
    assertTrue(mgr instanceof ThreadSafeCookieManager);
    assertEquals(1, mgr.getCookieCount());
    JMeterProperty property = mgr.getCookies().get(0);
    assertEquals("name", property.getName());
    assertEquals("blazedemo.com\tTRUE\t\tFALSE\t0\tname\tvalue", property.getStringValue());
}
 
Example #6
Source File: WebSocketAbstractSampler.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
public CookieManager getCookieManager() {
    return (CookieManager) getProperty(this.COOKIE_MANAGER).getObjectValue();
}
 
Example #7
Source File: WebSocketAbstractSampler.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
private void setCookieManagerProperty(CookieManager value) {
	setProperty(new TestElementProperty(COOKIE_MANAGER, value));
}