Search in sources :

Example 21 with ParseCurlCommandAction

use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction 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 22 with ParseCurlCommandAction

use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction 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 23 with ParseCurlCommandAction

use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction 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)

Example 24 with ParseCurlCommandAction

use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction in project jmeter by apache.

the class ParseCurlCommandActionTest method testCreateHttpRequestWithQuotedFilenameAsData.

@Test
public void testCreateHttpRequestWithQuotedFilenameAsData() throws Exception {
    ParseCurlCommandAction p = new ParseCurlCommandAction();
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    ThreadGroup threadGroup = new ThreadGroup();
    TestPlan testPlan = new TestPlan();
    HashTree tree = new HashTree();
    HashTree testPlanHT = tree.add(testPlan);
    HashTree threadGroupHT = testPlanHT.add(threadGroup);
    Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -X POST --form 'pic=@\"/some/file.jpg\"'");
    Method method = getMethodFor("createHttpRequest", Request.class, HashTree.class, String.class);
    HTTPSamplerProxy httpSampler = (HTTPSamplerProxy) method.invoke(p, request, threadGroupHT, "comment");
    assertEquals("/", httpSampler.getPath(), "path should be set in httpsampler");
    assertEquals("jmeter.apache.org", httpSampler.getDomain(), "domain should be set in httpsampler");
    assertEquals(80, httpSampler.getPort(), "port should be 80 in httpsampler");
    assertEquals("POST", httpSampler.getMethod(), "method should be set in httpsampler");
    HTTPFileArg fileArg = httpSampler.getHTTPFiles()[0];
    assertEquals("pic", fileArg.getParamName());
    assertEquals("/some/file.jpg", fileArg.getPath());
    assertEquals("image/jpeg", fileArg.getMimeType());
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) HashTree(org.apache.jorphan.collections.HashTree) HTTPSamplerProxy(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy) TestPlan(org.apache.jmeter.testelement.TestPlan) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) ThreadGroup(org.apache.jmeter.threads.ThreadGroup) Method(java.lang.reflect.Method) HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg) Test(org.junit.jupiter.api.Test)

Aggregations

ParseCurlCommandAction (org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction)24 Test (org.junit.jupiter.api.Test)21 BasicCurlParser (org.apache.jmeter.protocol.http.curl.BasicCurlParser)19 Request (org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request)19 Method (java.lang.reflect.Method)17 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 Field (java.lang.reflect.Field)1 URL (java.net.URL)1 JCheckBox (javax.swing.JCheckBox)1 Arguments (org.apache.jmeter.config.Arguments)1 Header (org.apache.jmeter.protocol.http.control.Header)1