use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request in project jmeter by apache.
the class ParseCurlCommandActionTest method testCommentTextStartsWith.
private void testCommentTextStartsWith(String cmdLine, String expectedComment) {
ParseCurlCommandAction p = new ParseCurlCommandAction();
BasicCurlParser basicCurlParser = new BasicCurlParser();
Request request = basicCurlParser.parse(cmdLine);
String comment = p.createCommentText(request);
assertTrue(comment.trim().startsWith(expectedComment));
}
use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request in project jmeter by apache.
the class ParseCurlCommandActionTest method testCanAddAuthManagerInHttpRequest.
@Test
public void testCanAddAuthManagerInHttpRequest() 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("canAddAuthManagerInHttpRequest", Request.class, AuthManager.class);
assertFalse((boolean) method.invoke(p, request, authManager), "When AuthManager contains this authorization, shouldn't add a AuthManager in Http Request");
request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -u 'user1:passwd1'");
assertTrue((boolean) method.invoke(p, request, authManager), "When AuthManager contains this url, but the username or password isn't the same," + "should add a AuthManager in Http Request");
}
use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request in project jmeter by apache.
the class ParseCurlCommandActionTest method testCreateProxyServer.
@Test
public void testCreateProxyServer() throws Exception {
ParseCurlCommandAction p = new ParseCurlCommandAction();
HTTPSamplerProxy httpSampler = (HTTPSamplerProxy) HTTPSamplerFactory.newInstance(HTTPSamplerFactory.DEFAULT_CLASSNAME);
httpSampler.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());
httpSampler.setProperty(TestElement.NAME, "HTTP Request");
BasicCurlParser basicCurlParser = new BasicCurlParser();
Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -x 'https://aa:bb@example.com:8042'");
Method method = getMethodFor("createProxyServer", Request.class, HTTPSamplerProxy.class);
method.invoke(p, request, httpSampler);
assertEquals("example.com", httpSampler.getProxyHost(), "proxy host should be set in httpsampler");
assertEquals("aa", httpSampler.getProxyUser(), "proxy user should be set in httpsampler");
assertEquals("bb", httpSampler.getProxyPass(), "proxy pass should be set in httpsampler");
assertEquals("https", httpSampler.getProxyScheme(), "proxy scheme should be set in httpsampler");
assertEquals("example.com", httpSampler.getProxyHost(), "proxy host should be set in httpsampler");
assertEquals(8042, httpSampler.getProxyPortInt(), "The command line should be parsed in turn");
}
use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request in project jmeter by apache.
the class ParseCurlCommandActionTest method testCreateCookieManager.
@Test
public void testCreateCookieManager(@TempDir Path tempDir) throws Exception {
ParseCurlCommandAction p = new ParseCurlCommandAction();
CookieManager cookieManager = new CookieManager();
BasicCurlParser basicCurlParser = new BasicCurlParser();
Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -b 'name=Tom'");
Method method = getMethodFor("createCookieManager", CookieManager.class, Request.class);
method.invoke(p, cookieManager, request);
assertEquals("jmeter.apache.org", cookieManager.get(0).getDomain(), "the domain of cookie should be set in cookieManager");
assertEquals("/", cookieManager.get(0).getPath(), "the path of cookie should be set in cookieManager");
assertEquals("name", cookieManager.get(0).getName(), "the name of cookie should be set in cookieManager");
assertEquals("Tom", cookieManager.get(0).getValue(), "the password of cookie should be set in cookieManager");
cookieManager = new CookieManager();
String filepath = tempDir.resolve("test.txt").toAbsolutePath().toString();
assertTrue(tempDir.resolve("test.txt").toFile().createNewFile());
request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -b '" + filepath + "'");
method.invoke(p, cookieManager, request);
request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -b 'test1.txt'");
try {
method.invoke(p, cookieManager, request);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof IllegalArgumentException) {
assertTrue(cause.getMessage().contains("File test1.txt doesn't exist"));
}
}
}
use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request in project jmeter by apache.
the class ParseCurlCommandActionTest method testDnsServer.
@Test
public void testDnsServer() throws Exception {
ParseCurlCommandAction p = new ParseCurlCommandAction();
DNSCacheManager dnsCacheManager = new DNSCacheManager();
BasicCurlParser basicCurlParser = new BasicCurlParser();
Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' --dns-servers '0.0.0.0'");
Method method = getMethodFor("createDnsServer", Request.class, DNSCacheManager.class);
method.invoke(p, request, dnsCacheManager);
assertEquals("0.0.0.0", dnsCacheManager.getServers().get(0).getStringValue(), "the dns server should be set in DNSCacheManager");
}
Aggregations