Search in sources :

Example 1 with HttpTestSampleGui

use of org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui in project jmeter by apache.

the class TestCookieManagerThreadIteration method testJmeterVariableCookieWhenThreadIterationIsANewUser.

@Test
public void testJmeterVariableCookieWhenThreadIterationIsANewUser() {
    jmvars.putObject(SAME_USER, true);
    jmctx.setVariables(jmvars);
    HTTPSamplerBase sampler = (HTTPSamplerBase) new HttpTestSampleGui().createTestElement();
    CookieManager cookieManager = new CookieManager();
    cookieManager.setControlledByThread(true);
    sampler.setCookieManager(cookieManager);
    sampler.setThreadContext(jmctx);
    boolean res = (boolean) cookieManager.getThreadContext().getVariables().getObject(SAME_USER);
    assertTrue("When test different users on the different iternations, the cookie should be cleared", res);
}
Also used : HttpTestSampleGui(org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.jupiter.api.Test)

Example 2 with HttpTestSampleGui

use of org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui in project jmeter by apache.

the class TestCookieManagerThreadIteration method testJmeterVariableCookieWhenThreadIterationIsSameUser.

@Test
public void testJmeterVariableCookieWhenThreadIterationIsSameUser() {
    jmvars.putObject(SAME_USER, false);
    jmctx.setVariables(jmvars);
    HTTPSamplerBase sampler = (HTTPSamplerBase) new HttpTestSampleGui().createTestElement();
    CookieManager cookieManager = new CookieManager();
    cookieManager.setControlledByThread(true);
    sampler.setCookieManager(cookieManager);
    sampler.setThreadContext(jmctx);
    boolean res = (boolean) cookieManager.getThreadContext().getVariables().getObject(SAME_USER);
    assertFalse("When test same user on the different iternations, the cookie shouldn't be cleared", res);
}
Also used : HttpTestSampleGui(org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.jupiter.api.Test)

Example 3 with HttpTestSampleGui

use of org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui in project jmeter by apache.

the class TestCacheManagerThreadIteration method testJmeterVariableWhenThreadIterationIsSameUser.

@Test
public void testJmeterVariableWhenThreadIterationIsSameUser() {
    jmvars.putObject(SAME_USER, false);
    jmctx.setVariables(jmvars);
    HTTPSamplerBase sampler = (HTTPSamplerBase) new HttpTestSampleGui().createTestElement();
    cacheManager.setControlledByThread(true);
    sampler.setCacheManager(cacheManager);
    sampler.setThreadContext(jmctx);
    boolean res = (boolean) cacheManager.getThreadContext().getVariables().getObject(SAME_USER);
    assertFalse("When test different user on the different iternation, the cache shouldn't be cleared", res);
}
Also used : HttpTestSampleGui(org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.jupiter.api.Test)

Example 4 with HttpTestSampleGui

use of org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui in project jmeter by apache.

the class TestHTTPHC4Impl method testParameterWithMultipartAndExplicitHeader.

@Test
void testParameterWithMultipartAndExplicitHeader() throws Exception {
    HTTPSamplerBase sampler = (HTTPSamplerBase) new HttpTestSampleGui().createTestElement();
    sampler.setThreadContext(jmctx);
    sampler.setDoMultipart(true);
    sampler.setDoBrowserCompatibleMultipart(true);
    HttpEntityEnclosingRequestBase post = new HttpPost();
    post.addHeader(HTTPConstants.HEADER_CONTENT_TYPE, "application/json");
    sampler.setHTTPFiles(new HTTPFileArg[] { new HTTPFileArg("filename", "file", "application/octect; charset=utf-8") });
    HTTPHC4Impl hc = new HTTPHC4Impl(sampler);
    String requestData = hc.setupHttpEntityEnclosingRequestData(post);
    assertEquals(0, post.getHeaders(HTTPConstants.HEADER_CONTENT_TYPE).length);
    assertTrue(requestData.contains("charset=utf-8"));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) HttpTestSampleGui(org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui) HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg) Test(org.junit.jupiter.api.Test)

Example 5 with HttpTestSampleGui

use of org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui in project jmeter by apache.

the class TestHTTPHC4Impl method testParameterWithMimeTypeWithCharset.

@Test
void testParameterWithMimeTypeWithCharset() throws Exception {
    HTTPSamplerBase sampler = (HTTPSamplerBase) new HttpTestSampleGui().createTestElement();
    sampler.setThreadContext(jmctx);
    sampler.setDoMultipart(true);
    HttpEntityEnclosingRequestBase post = new HttpPost();
    HTTPArgument argument = new HTTPArgument("upload", "some data");
    argument.setContentType("text/html; charset=utf-8");
    sampler.getArguments().addArgument(argument);
    HTTPHC4Impl hc = new HTTPHC4Impl(sampler);
    String requestData = hc.setupHttpEntityEnclosingRequestData(post);
    assertTrue(requestData.contains("charset=utf-8"));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) HttpTestSampleGui(org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui) HTTPArgument(org.apache.jmeter.protocol.http.util.HTTPArgument) Test(org.junit.jupiter.api.Test)

Aggregations

HttpTestSampleGui (org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui)7 Test (org.junit.jupiter.api.Test)7 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)4 HttpEntityEnclosingRequestBase (org.apache.http.client.methods.HttpEntityEnclosingRequestBase)3 HttpPost (org.apache.http.client.methods.HttpPost)3 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)2 File (java.io.File)1 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)1