本文整理了Java中com.meterware.httpunit.WebRequest.setParameter()
方法的一些代码示例,展示了WebRequest.setParameter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebRequest.setParameter()
方法的具体详情如下:
包路径:com.meterware.httpunit.WebRequest
类名称:WebRequest
方法名:setParameter
[英]Sets the value of a parameter in a web request.
[中]设置web请求中参数的值。
代码示例来源:origin: apache/geode
/**
* Test expiration of a session by the tomcat container, rather than gemfire expiration
*/
@Test
public void testSessionExpirationByContainer() throws Exception {
String key = "value_testSessionExpiration1";
String value = "Foo";
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
// Set an attribute
req.setParameter("cmd", QueryCommand.SET.name());
req.setParameter("param", key);
req.setParameter("value", value);
WebResponse response = wc.getResponse(req);
// Set the session timeout of this one session.
req.setParameter("cmd", QueryCommand.SET_MAX_INACTIVE.name());
req.setParameter("value", "1");
response = wc.getResponse(req);
// Wait until the session should expire
Thread.sleep(2000);
// Do a request, which should cause the session to be expired
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", key);
response = wc.getResponse(req);
assertEquals("", response.getText());
}
代码示例来源:origin: apache/geode
/**
* Test setting the session expiration
*/
@Test
public void testSessionExpiration1() throws Exception {
// TestSessions only live for a second
sessionManager.setMaxInactiveInterval(1);
String key = "value_testSessionExpiration1";
String value = "Foo";
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
// Set an attribute
req.setParameter("cmd", QueryCommand.SET.name());
req.setParameter("param", key);
req.setParameter("value", value);
WebResponse response = wc.getResponse(req);
// Sleep a while
Thread.sleep(2000);
// The attribute should not be accessible now...
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", key);
response = wc.getResponse(req);
assertEquals("", response.getText());
}
代码示例来源:origin: apache/geode
/**
* Test that a session attribute gets set into the region too.
*/
@Test
public void testBasicRegion() throws Exception {
String key = "value_testBasicRegion";
String value = "Foo";
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
// Set an attribute
req.setParameter("cmd", QueryCommand.SET.name());
req.setParameter("param", key);
req.setParameter("value", value);
WebResponse response = wc.getResponse(req);
String sessionId = response.getNewCookieValue("JSESSIONID");
assertEquals(value, region.get(sessionId).getAttribute(key));
}
代码示例来源:origin: apache/geode
/**
* Check that the basics are working
*/
@Test
public void testSanity() throws Exception {
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", "null");
WebResponse response = wc.getResponse(req);
assertEquals("JSESSIONID", response.getNewCookieNames()[0]);
}
代码示例来源:origin: apache/geode
/**
* Test that invalidating a session makes it's attributes inaccessible.
*/
@Test
public void testInvalidate() throws Exception {
String key = "value_testInvalidate";
String value = "Foo";
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
// Set an attribute
req.setParameter("cmd", QueryCommand.SET.name());
req.setParameter("param", key);
req.setParameter("value", value);
WebResponse response = wc.getResponse(req);
// Invalidate the session
req.removeParameter("param");
req.removeParameter("value");
req.setParameter("cmd", QueryCommand.INVALIDATE.name());
wc.getResponse(req);
// The attribute should not be accessible now...
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", key);
response = wc.getResponse(req);
assertEquals("", response.getText());
}
代码示例来源:origin: apache/geode
/**
* Check that our session persists. The values we pass in as query params are used to set
* attributes on the session.
*/
@Test
public void testSessionPersists1() throws Exception {
String key = "value_testSessionPersists1";
String value = "Foo";
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
req.setParameter("cmd", QueryCommand.SET.name());
req.setParameter("param", key);
req.setParameter("value", value);
WebResponse response = wc.getResponse(req);
String sessionId = response.getNewCookieValue("JSESSIONID");
assertNotNull("No apparent session cookie", sessionId);
// The request retains the cookie from the prior response...
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", key);
req.removeParameter("value");
response = wc.getResponse(req);
assertEquals(value, response.getText());
}
代码示例来源:origin: apache/geode
/**
* Test that removing a session attribute also removes it from the region
*/
@Test
public void testRemoveAttribute() throws Exception {
String key = "value_testRemoveAttribute";
String value = "Foo";
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
// Set an attribute
req.setParameter("cmd", QueryCommand.SET.name());
req.setParameter("param", key);
req.setParameter("value", value);
WebResponse response = wc.getResponse(req);
String sessionId = response.getNewCookieValue("JSESSIONID");
// Implicitly remove the attribute
req.removeParameter("value");
wc.getResponse(req);
// The attribute should not be accessible now...
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", key);
response = wc.getResponse(req);
assertEquals("", response.getText());
assertNull(region.get(sessionId).getAttribute(key));
}
代码示例来源:origin: apache/geode
@Test
public void testCommitSessionValveInvalidSession() throws Exception {
Callback c = new Callback() {
@Override
public void call(HttpServletRequest request, HttpServletResponse response)
throws IOException {
HttpSession session = request.getSession();
session.invalidate();
response.getWriter().write("done");
}
};
servlet.getServletContext().setAttribute("callback", c);
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
// Execute the callback
req.setParameter("cmd", QueryCommand.CALLBACK.name());
req.setParameter("param", "callback");
WebResponse response = wc.getResponse(req);
assertEquals("done", response.getText());
}
代码示例来源:origin: apache/geode
/**
* Test that a session attribute gets removed from the region when the session is invalidated.
*/
@Test
public void testRegionInvalidate() throws Exception {
String key = "value_testRegionInvalidate";
String value = "Foo";
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
// Set an attribute
req.setParameter("cmd", QueryCommand.SET.name());
req.setParameter("param", key);
req.setParameter("value", value);
WebResponse response = wc.getResponse(req);
String sessionId = response.getNewCookieValue("JSESSIONID");
// Invalidate the session
req.removeParameter("param");
req.removeParameter("value");
req.setParameter("cmd", QueryCommand.INVALIDATE.name());
wc.getResponse(req);
assertNull("The region should not have an entry for this session", region.get(sessionId));
}
代码示例来源:origin: apache/geode
/**
* Test callback functionality. This is here really just as an example. Callbacks are useful to
* implement per test actions which can be defined within the actual test method instead of in a
* separate servlet class.
*/
@Test
public void testCallback() throws Exception {
final String helloWorld = "Hello World";
Callback c = new Callback() {
@Override
public void call(HttpServletRequest request, HttpServletResponse response)
throws IOException {
PrintWriter out = response.getWriter();
out.write(helloWorld);
}
};
servlet.getServletContext().setAttribute("callback", c);
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
req.setParameter("cmd", QueryCommand.CALLBACK.name());
req.setParameter("param", "callback");
WebResponse response = wc.getResponse(req);
assertEquals(helloWorld, response.getText());
}
代码示例来源:origin: apache/geode
/**
* Test that multiple attribute updates, within the same request result in only the latest one
* being effective.
*/
@Test
public void testMultipleAttributeUpdates() throws Exception {
final String key = "value_testMultipleAttributeUpdates";
Callback c = new Callback() {
@Override
public void call(HttpServletRequest request, HttpServletResponse response)
throws IOException {
HttpSession session = request.getSession();
for (int i = 0; i < 1000; i++) {
session.setAttribute(key, Integer.toString(i));
}
}
};
servlet.getServletContext().setAttribute("callback", c);
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
// Execute the callback
req.setParameter("cmd", QueryCommand.CALLBACK.name());
req.setParameter("param", "callback");
WebResponse response = wc.getResponse(req);
String sessionId = response.getNewCookieValue("JSESSIONID");
assertEquals("999", region.get(sessionId).getAttribute(key));
}
代码示例来源:origin: apache/geode
req.setParameter("cmd", QueryCommand.CALLBACK.name());
req.setParameter("param", "callback");
WebResponse response = wc.getResponse(req);
代码示例来源:origin: apache/geode
/**
* Test for issue #45 Sessions are being created for every request
*/
@Test
public void testExtraSessionsNotCreated() throws Exception {
Callback c = new Callback() {
@Override
public void call(HttpServletRequest request, HttpServletResponse response)
throws IOException {
// Do nothing with sessions
response.getWriter().write("done");
}
};
servlet.getServletContext().setAttribute("callback", c);
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
// Execute the callback
req.setParameter("cmd", QueryCommand.CALLBACK.name());
req.setParameter("param", "callback");
WebResponse response = wc.getResponse(req);
assertEquals("done", response.getText());
assertEquals("The region should be empty", 0, region.size());
}
代码示例来源:origin: apache/geode
/**
* Test that calling session.isNew() works for the initial as well as subsequent requests.
*/
@Test
public void testIsNew() throws Exception {
Callback c = new Callback() {
@Override
public void call(HttpServletRequest request, HttpServletResponse response)
throws IOException {
HttpSession session = request.getSession();
response.getWriter().write(Boolean.toString(session.isNew()));
}
};
servlet.getServletContext().setAttribute("callback", c);
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
req.setParameter("cmd", QueryCommand.CALLBACK.name());
req.setParameter("param", "callback");
WebResponse response = wc.getResponse(req);
assertEquals("true", response.getText());
response = wc.getResponse(req);
assertEquals("false", response.getText());
}
代码示例来源:origin: TEAMMATES/teammates
@Deprecated
private InvocationContext invokeWebRequest(String uri, String... parameters) {
// This is not testing servlet, so any HTTP method suffices
WebRequest request = new PostMethodWebRequest(SIMULATION_BASE_URL + uri);
// TODO remove this portion once front-end migration is finished
// Reason: CSRF protection is not part of action tests
if (Const.SystemParams.PAGES_REQUIRING_ORIGIN_VALIDATION.contains(uri)) {
request.setHeaderField("referer", SIMULATION_BASE_URL);
String sessionId = sc.getSession(true).getId();
String token = StringHelper.encrypt(sessionId);
request.setParameter(Const.ParamsNames.SESSION_TOKEN, token);
}
Map<String, List<String>> paramMultiMap = new HashMap<>();
for (int i = 0; i < parameters.length; i = i + 2) {
paramMultiMap.computeIfAbsent(parameters[i], k -> new ArrayList<>()).add(parameters[i + 1]);
}
paramMultiMap.forEach((key, values) -> request.setParameter(key, values.toArray(new String[0])));
try {
return sc.newInvocation(request);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: javanettasks/httpunit
/**
* Sets the file for a parameter upload in a web request.
**/
public void selectFile( String parameterName, File file, String contentType ) {
setParameter( parameterName, new UploadFileSpec[] { new UploadFileSpec( file, contentType ) } );
}
代码示例来源:origin: org.kohsuke.httpunit/httpunit
/**
* Sets the file for a parameter upload in a web request.
**/
public void selectFile( String parameterName, File file, String contentType ) {
setParameter( parameterName, new UploadFileSpec[] { new UploadFileSpec( file, contentType ) } );
}
代码示例来源:origin: org.kohsuke.httpunit/httpunit
/**
* Sets the file for a parameter upload in a web request.
**/
public void selectFile( String parameterName, String fileName, InputStream inputStream, String contentType ) {
setParameter( parameterName, new UploadFileSpec[] { new UploadFileSpec( fileName, inputStream, contentType ) } );
}
代码示例来源:origin: javanettasks/httpunit
/**
* Sets the file for a parameter upload in a web request.
**/
public void selectFile( String parameterName, String fileName, InputStream inputStream, String contentType ) {
setParameter( parameterName, new UploadFileSpec[] { new UploadFileSpec( fileName, inputStream, contentType ) } );
}
代码示例来源:origin: httpunit/httpunit
/**
* Sets the file for a parameter upload in a web request.
**/
public void selectFile( String parameterName, File file ) {
setParameter( parameterName, new UploadFileSpec[] { new UploadFileSpec( file ) } );
}
内容来源于网络,如有侵权,请联系作者删除!