Search in sources :

Example 16 with Request

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request in project jmeter by apache.

the class ParseCurlCommandActionTest method testCommentText.

private void testCommentText(String cmdLine, String expectedComment) {
    ParseCurlCommandAction p = new ParseCurlCommandAction();
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    Request request = basicCurlParser.parse(cmdLine);
    String comment = p.createCommentText(request);
    assertEquals(expectedComment, comment.trim());
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction)

Example 17 with Request

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request in project jmeter by apache.

the class ParseCurlCommandActionTest method testCanUpdateAuthManagerInThreadGroupt.

@Test
public void testCanUpdateAuthManagerInThreadGroupt() throws Exception {
    ParseCurlCommandAction p = new ParseCurlCommandAction();
    AuthManager authManager = new AuthManager();
    Authorization authorization = new Authorization();
    authorization.setPass("passwd");
    authorization.setUser("user");
    authorization.setURL("http://jmeter.apache.org/");
    authorization.setMechanism(Mechanism.BASIC);
    authManager.addAuth(authorization);
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -u 'user:passwd'");
    Method method = getMethodFor("canUpdateAuthManagerInThreadGroup", Request.class, AuthManager.class);
    assertFalse((boolean) method.invoke(p, request, authManager), "When AuthManager contains this url, shouldn't add a AuthManager in ThreadGroup");
    request = basicCurlParser.parse("curl 'http://jmeter.apache.fr/' -u 'user:passwd'");
    assertTrue((boolean) method.invoke(p, request, authManager), "The AuthManager doesn't contain this url , should add a AuthManager in ThreadGroup");
}
Also used : Authorization(org.apache.jmeter.protocol.http.control.Authorization) BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) AuthManager(org.apache.jmeter.protocol.http.control.AuthManager) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 18 with Request

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request in project jmeter by apache.

the class ParseCurlCommandActionTest method testCanAddDnsResolverInHttpRequest.

@Test
public void testCanAddDnsResolverInHttpRequest() throws Exception {
    ParseCurlCommandAction p = new ParseCurlCommandAction();
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    DNSCacheManager dnsCacheManager = new DNSCacheManager();
    dnsCacheManager.addHost("moonagic.com", "127.0.0.2");
    Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/'  --resolve 'moonagic.com:443:127.0.0.2'");
    Method method = getMethodFor("canAddDnsResolverInHttpRequest", Request.class, DNSCacheManager.class);
    dnsCacheManager = new DNSCacheManager();
    dnsCacheManager.addHost("moonagic.com", "127.0.0.2");
    method.invoke(p, request, dnsCacheManager);
    assertFalse((boolean) method.invoke(p, request, dnsCacheManager), "When the Dns servers are the same, shouldn't add the DnsCacheManager in Http Request");
    request = basicCurlParser.parse("curl 'http://jmeter.apache.org/'  --resolve 'moonagic.com:9090:127.0.0.1'");
    method.invoke(p, request, dnsCacheManager);
    assertTrue((boolean) method.invoke(p, request, dnsCacheManager), "When the Dns servers aren't the same, should add the DnsCacheManager in Http Request");
    dnsCacheManager = new DNSCacheManager();
    dnsCacheManager.addHost("moonagic.com", "127.0.0.1");
    dnsCacheManager.addHost("moonagic.com", "127.0.0.2");
    method.invoke(p, request, dnsCacheManager);
    assertTrue((boolean) method.invoke(p, request, dnsCacheManager), "When the Dns servers aren't the same, should add the DnsCacheManager in Http Request");
    request = basicCurlParser.parse("curl 'http://jmeter.apache.org/'  --resolve 'moonagic.com:9090:127.0.0.1'");
    method.invoke(p, request, dnsCacheManager);
    assertTrue((boolean) method.invoke(p, request, dnsCacheManager), "When the Dns servers aren't the same, should add the DnsCacheManager in Http Request");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) Method(java.lang.reflect.Method) DNSCacheManager(org.apache.jmeter.protocol.http.control.DNSCacheManager) Test(org.junit.jupiter.api.Test)

Example 19 with Request

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request in project jmeter by apache.

the class ParseCurlCommandActionTest method testCanAddDnsServerInHttpRequest.

@Test
public void testCanAddDnsServerInHttpRequest() throws Exception {
    ParseCurlCommandAction p = new ParseCurlCommandAction();
    DNSCacheManager dnsCacheManager = new DNSCacheManager();
    dnsCacheManager.addServer("0.0.0.0");
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' --dns-servers '0.0.0.0'");
    Method method = getMethodFor("canAddDnsServerInHttpRequest", Request.class, DNSCacheManager.class);
    assertFalse((boolean) method.invoke(p, request, dnsCacheManager), "When the Dns servers are  the same, shouldn't add the DnsCacheManager in Http Request");
    request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' --dns-servers '1.1.1.1'");
    assertTrue((boolean) method.invoke(p, request, dnsCacheManager), "When the Dns servers aren't the same, should add the DnsCacheManager in Http Request");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) Method(java.lang.reflect.Method) DNSCacheManager(org.apache.jmeter.protocol.http.control.DNSCacheManager) Test(org.junit.jupiter.api.Test)

Example 20 with Request

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request in project jmeter by apache.

the class ParseCurlCommandActionTest method testCreateAuthManager.

@Test
public void testCreateAuthManager() throws Exception {
    ParseCurlCommandAction p = new ParseCurlCommandAction();
    AuthManager authManager = new AuthManager();
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -u 'user:passwd'");
    Method method = getMethodFor("createAuthManager", Request.class, AuthManager.class);
    method.invoke(p, request, authManager);
    assertEquals("user", authManager.get(0).getUser());
    assertEquals("passwd", authManager.get(0).getPass());
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) AuthManager(org.apache.jmeter.protocol.http.control.AuthManager) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Aggregations

BasicCurlParser (org.apache.jmeter.protocol.http.curl.BasicCurlParser)21 Request (org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request)21 ParseCurlCommandAction (org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction)19 Test (org.junit.jupiter.api.Test)17 Method (java.lang.reflect.Method)16 HTTPSamplerProxy (org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy)6 DNSCacheManager (org.apache.jmeter.protocol.http.control.DNSCacheManager)4 AuthManager (org.apache.jmeter.protocol.http.control.AuthManager)3 HttpTestSampleGui (org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Authorization (org.apache.jmeter.protocol.http.control.Authorization)2 CookieManager (org.apache.jmeter.protocol.http.control.CookieManager)2 TestPlan (org.apache.jmeter.testelement.TestPlan)2 ThreadGroup (org.apache.jmeter.threads.ThreadGroup)2 HashTree (org.apache.jorphan.collections.HashTree)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1