本文整理汇总了Java中com.meterware.httpunit.HttpUnitOptions类的典型用法代码示例。如果您正苦于以下问题:Java HttpUnitOptions类的具体用法?Java HttpUnitOptions怎么用?Java HttpUnitOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpUnitOptions类属于com.meterware.httpunit包,在下文中一共展示了HttpUnitOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
/**
* @see junit.framework.TestCase#setUp()
*/
@Before
public void setUp() throws Exception
{
// need to pass a web.xml file to setup servletunit working directory
ClassLoader classLoader = getClass().getClassLoader();
URL webXmlUrl = classLoader.getResource("WEB-INF/web.xml");
String path = URLDecoder.decode(webXmlUrl.getFile(), "UTF-8");
HttpUnitOptions.setDefaultCharacterSet("utf-8");
System.setProperty("file.encoding", "utf-8");
// start servletRunner
runner = new ServletRunner(new File(path), CONTEXT);
Hashtable<String, String> params = new Hashtable<String, String>();
params.put("javaEncoding", "utf-8");
runner.registerServlet("*.jsp", "org.apache.jasper.servlet.JspServlet", params);
log.debug("ServletRunner setup OK");
}
示例2: setUp
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
/**
* @see junit.framework.TestCase#setUp()
* @throws Exception e
*/
@Before
public void setUp() throws Exception
{
// need to pass a web.xml file to setup servletunit working directory
Properties p = new Properties();
p.setProperty("export.pdf.class", "org.displaytag.export.FopExportView");
TableProperties.setUserProperties(p);
ClassLoader classLoader = getClass().getClassLoader();
URL webXmlUrl = classLoader.getResource("WEB-INF/web.xml");
String path = URLDecoder.decode(webXmlUrl.getFile(), "UTF-8");
HttpUnitOptions.setDefaultCharacterSet("utf-8");
System.setProperty("file.encoding", "utf-8");
// start servletRunner
runner = new ServletRunner(new File(path), CONTEXT);
Hashtable<String, String> params = new Hashtable<String, String>();
params.put("javaEncoding", "utf-8");
runner.registerServlet("*.jsp", "org.apache.jasper.servlet.JspServlet", params);
log.debug("ServletRunner setup OK");
}
示例3: testPing
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
/**
* Test ping().
*/
@Test
public void testPing() {
Server server = null;
String dataDir = "data-test-ping1";
try {
String host = "localhost";
int port = 18983;
// start Solr
server = SimpleAnuenueInstanceFactory.createSolrInstance(port,
dataDir, NODE_CONF_FILE);
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
SolrClient client = new SolrClient(host, port);
client.ping();
} catch (Exception e) {
fail();
} finally {
AnuenueTestUtil.stopServerQuietly(server);
assertTrue(FileUtils.deleteQuietly(new File(dataDir)));
}
}
示例4: testBrowseCatalog
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
public void testBrowseCatalog() throws Exception {
try {
// Disable scripting support until HttpUnit has better support for AJAX, Dojo...
HttpUnitOptions.setScriptingEnabled(false);
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
// Start with the home page
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest("http://" + serverHost + ":" + serverPort + "/" + context);
WebResponse resp = wc.getResponse(req);
testMainPage(wc, resp);
testSellerPage(wc, resp);
testSearchPage(wc, resp);
testCatalogPage(wc, resp);
testMapPage(wc, resp);
testTagsPage(wc, resp);
} catch (ConnectException e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
fail("Could not connect to the server. Received Exception: \n" + sw.toString());
}
}
示例5: getAccesToken
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
private String getAccesToken(
final String applicationKey,
final String username,
final String password) throws IOException {
try {
HttpUnitOptions.setScriptingEnabled(false);
WebConversation wc = new WebConversation();
WebResponse resp = wc.getResponse(String.format(OAUTH_GET_ACCESS_TOKEN_URL, applicationKey));
WebForm form = findLoginForm(resp.getForms());
form.setParameter("login", username);
form.setParameter("password", password);
resp = form.submit();
if(!resp.getURL().toString().contains("code=")) {
resp = resp.getLinkWith("Allow").click();
}
return resp.getURL().toString().split("code=")[1];
} catch (SAXException ex) {
throw new IOException(ex);
}
}
示例6: setUp
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
String configuration = getConfiguration();
InputStream is = this.getClass().getResourceAsStream(configuration);
sr = new ServletRunner(is, CONTEXT);
HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
}
示例7: setUp
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
InputStream is = this.getClass().getResourceAsStream(getConfiguration());
assertNotNull("The configuration input stream should not be null", is);
sr = new ServletRunner(is, CONTEXT);
HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
if (startCamelContext) {
super.setUp();
}
}
示例8: setUp
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
InputStream is = this.getClass().getResourceAsStream(getConfiguration());
assertNotNull("The configuration input stream should not be null", is);
sr = new ServletRunner(is, CONTEXT);
HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
}
示例9: testInvalidInput
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
/**
* Test of adding file including invalid line.
*/
@Test
public void testInvalidInput() {
Server server = null;
String dataDir = "data-test-invalid-input";
try {
int port = 18983;
server = SimpleAnuenueInstanceFactory.createSolrInstance(port, dataDir, NODE_CONF_FILE);
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
assertSame("initial size", 0, AnuenueTestUtil.getNumberOfIndexedDocumentViaLocalhostSolr(port));
NodeDatabase database = new NodeDatabaseBuilder("resources/anuenue-nodes-single.xml").build();
AnuenueDistCommandFactory.createDistCommand("addDir", "resources/example-failure-docs", database).execute();
assertSame("addDir, before commit", 0, AnuenueTestUtil.getNumberOfIndexedDocumentViaLocalhostSolr(port));
AnuenueDistCommandFactory.createDistCommand("commit", "", database).execute();
assertSame("addDir and commit", 2, AnuenueTestUtil.getNumberOfIndexedDocumentViaLocalhostSolr(port));
} catch (Exception e) {
fail();
} finally {
AnuenueTestUtil.stopServerQuietly(server);
assertTrue(FileUtils.deleteQuietly(new File(dataDir)));
}
}
示例10: getMessageEncoding
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
private String getMessageEncoding() {
return _messageEncoding == null ?
/* Fixing 1705925: HttpUnitUtils.DEFAULT_CHARACTER_SET */
HttpUnitOptions.getDefaultCharacterSet() : _messageEncoding;
}
示例11: getContentType
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
/**
* Returns the content type of this message body.
**/
public String getContentType() {
return "application/x-www-form-urlencoded" +
(!HttpUnitOptions.isPostIncludesCharset() ? ""
: "; charset=" + getCharacterSet());
}
示例12: testParse
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
/**
* Test of parse method, of class StreamParser.
* @throws Exception
*/
@Test
public void testParse() throws Exception {
System.out.println("parse");
HttpUnitOptions.setDefaultCharacterSet("utf-8");
ServletRunner sr = new ServletRunner();
sr.registerServlet("ExampleServlet", ExampleServlet.class.getName());
ServletUnitClient sc = sr.newClient();
PostMethodWebRequest postRequest = new PostMethodWebRequest("http://zoeey.org/ExampleServlet", true);
postRequest.setParameter("name1", new String[]{"name1_value"});
postRequest.setParameter("name2", new String[]{"name2_value"});
postRequest.setParameter("name3", new String[]{"name3_value"});
postRequest.setParameter("name5", new String[]{"中文字符串"});
postRequest.setParameter("name6", new String[]{"路人甲"});
postRequest.setParameter("MAX_FILE_SIZE", new String[]{"30000"});
postRequest.selectFile("bugFile", new File(TestUtil.getBugPng()));
postRequest.selectFile("bugFile2", new File(TestUtil.getBugPng()));
//
InvocationContext ic = sc.newInvocation(postRequest);
HttpServletRequest request = ic.getRequest();
String contentType = request.getContentType();
String boundary = contentType.substring(contentType.indexOf('=') + 1);
InputStream inStream = request.getInputStream();
//
UploadConfig config = new UploadConfig();
File tempDir = new File(TestUtil.getResourceDir().concat("/temp"));
FileHelper.tryMakeDirs(tempDir);
config.setTempFileDir(tempDir);
StreamParser sp = new StreamParser(boundary, config);
sp.parse(inStream);
assertEquals("{name5=[中文字符串], name6=[路人甲], name3=[name3_value], name1=[name1_value], name2=[name2_value], MAX_FILE_SIZE=[30000]}",//
sp.getParamMap().toString());
for (List<FileItem> fileItemList : sp.getFileMap().values()) {
for (FileItem fileItem : fileItemList) {
assertEquals("bug.png", fileItem.getOriginalName());
assertEquals(fileItem.getError(), FileError.OK);
}
}
FileHelper.tryDelete(tempDir, true);
}
示例13: setDefaultContentType
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
/**
* Sets the default content type for pages which do not specify one.
**/
public void setDefaultContentType(String contentType) {
HttpUnitOptions.setDefaultContentType(contentType);
}
示例14: setLoggingHttpHeaders
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
/**
* If true, tells HttpUnit to log HTTP headers to system output. The default is false.
**/
public void setLoggingHttpHeaders(String enabled) {
HttpUnitOptions.setLoggingHttpHeaders(Boolean.getBoolean(enabled));
}
示例15: setScriptingEnabled
import com.meterware.httpunit.HttpUnitOptions; //导入依赖的package包/类
/**
* Method setScriptingEnabled.
* @param scriptingEnabled
*/
public void setScriptingEnabled(String scriptingEnabled) {
boolean enabled = (scriptingEnabled.equalsIgnoreCase("true")) ? true : false;
HttpUnitOptions.setScriptingEnabled(enabled);
verbose("ScriptingEnabled: " + HttpUnitOptions.isScriptingEnabled());
}