当前位置: 首页>>代码示例>>Java>>正文


Java WebResponse类代码示例

本文整理汇总了Java中com.meterware.httpunit.WebResponse的典型用法代码示例。如果您正苦于以下问题:Java WebResponse类的具体用法?Java WebResponse怎么用?Java WebResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WebResponse类属于com.meterware.httpunit包,在下文中一共展示了WebResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findAnAbsoluteURLOnPage

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
private WebResponse findAnAbsoluteURLOnPage(String respAsText) throws SAXException, IOException {
// Probably safest to get the last http address on the page, make sure we don't accidently
// go to http://www.w3c.org/

int index = respAsText.lastIndexOf("\"http");
while (index != -1) {
    int indexEnd = respAsText.indexOf("\"", index + 1);
    if (indexEnd != -1) {
	String httpString = respAsText.substring(index + 1, indexEnd);
	if ((httpString.indexOf("www.w3.org") == -1) && !httpString.endsWith(".js")
		&& !httpString.endsWith(".css")) {
	    MockLearner.log.debug("Forwarding user " + username + " to discovered link " + httpString);
	    return (WebResponse) new Call(wc, test, username + " forwarded to absolute URL", httpString)
		    .execute();
	}
    }
    index = index > 0 ? respAsText.lastIndexOf("\"http", index - 1) : -1;
}
return null;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:MockLearner.java

示例2: handleActivity

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
private WebResponse handleActivity(WebResponse resp) throws SAXException, IOException, InterruptedException {
// MockLearner.log.debug(resp.getText());

WebResponse nextResp = null;
WebForm[] forms = resp.getForms();
if ((forms != null) && (forms.length > 0)) {
    MockLearner.log.debug("There " + (forms.length == 1 ? "is " : "are ") + forms.length
	    + (forms.length == 1 ? " form in the page " : " forms in the page"));
    nextResp = handlePageWithForms(resp);
} else {
    nextResp = handlePageWithoutForms(resp);
}

String asText = nextResp == null ? null : nextResp.getText();
boolean isActivityFinished = (asText != null) && (asText.contains(MockLearner.ACTIVITY_FINISHED_FLAG)
	|| asText.contains(MockLearner.LESSON_FINISHED_FLAG)
	|| asText.contains(MockLearner.LOAD_TOOL_ACTIVITY_FLAG));

return isActivityFinished ? nextResp : handleActivity(nextResp);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:MockLearner.java

示例3: handleToolForum

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
private WebResponse handleToolForum(WebResponse resp) throws SAXException, IOException, InterruptedException {
WebResponse replyResponse = null;

String replyURL = MockLearner.findURLInAHREF(resp, MockLearner.FORUM_VIEW_TOPIC_SUBSTRING);
if (replyURL != null) {
    MockLearner.log.debug("Accessing the forum view topic screen using " + replyURL);
    replyResponse = handleToolForumReply(replyURL);
}

if (replyResponse == null) {
    MockLearner.log.debug(resp.getText());
    throw new TestHarnessException("No links found on the main forum page, or unable to do reply");
}

String finishURL = MockLearner.findURLInLocationHref(replyResponse, MockLearner.FORUM_FINISH_SUBSTRING);
if (finishURL == null) {
    MockLearner.log.debug(replyResponse.getText());
    throw new TestHarnessException("Unable to finish the forum. No finish link found");
}

MockLearner.log.debug("Ending forum using url " + finishURL);
return (WebResponse) new Call(wc, test, "Finish Forum", finishURL).execute();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:MockLearner.java

示例4: handleToolLeader

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
private WebResponse handleToolLeader(WebResponse resp) throws SAXException, IOException {
String asText = resp.getText();
Matcher m = MockLearner.LEADER_SHOW_DIALOG_PATTERN.matcher(asText);
if (!m.find()) {
    throw new TestHarnessException("Could not tell whether the user can become the leader");
}
if (Boolean.valueOf(m.group(1))) {
    m = MockLearner.LEADER_BECOME_PATTERN.matcher(asText);
    if (!m.find()) {
	throw new TestHarnessException("Could not \"become leader\" URL");
    }
    String becomeLeaderQueryOptions = m.group();
    String url = "/lams/tool/lalead11/learning.do?" + becomeLeaderQueryOptions;
    MockLearner.log.debug("Becoming a leader using link: " + url);
    new Call(wc, test, username + " becomes Leader", url).execute();
}
String finishURL = MockLearner.findURLInLocationHref(resp, MockLearner.LEADER_FINISH_SUBSTRING);
if (finishURL == null) {
    throw new TestHarnessException("Unable to finish the leader, no finish link found. " + asText);
}

MockLearner.log.debug("Ending leader using url " + finishURL);
return (WebResponse) new Call(wc, test, username + " finishes Leader", finishURL).execute();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:MockLearner.java

示例5: handleToolShareResources

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
private WebResponse handleToolShareResources(WebResponse resp, String initialRedirectLink)
    throws IOException, SAXException {
WebResponse nextResponse = (WebResponse) new Call(wc, test, username + " forwarded to Share Resources",
	initialRedirectLink).execute();
String asText = nextResponse.getText();
Matcher m = MockLearner.SHARE_RESOURCES_VIEW_ITEM_URL_PATTERH.matcher(asText);
if (!m.find()) {
    throw new TestHarnessException("View Item URL in Share Resources tool not found");
}
String viewItemURL = m.group(1);
m = MockLearner.SHARE_RESOURCES_VIEW_ITEM_PATTERN.matcher(asText);
while (m.find()) {
    new Call(wc, test, username + " views Share Resources item", viewItemURL + m.group(1)).execute();
    delay();
}

String finishURL = MockLearner.findURLInLocationHref(nextResponse, MockLearner.FINISH_SUBSTRING);
return (WebResponse) new Call(wc, test, username + " finishes Share Resources", finishURL).execute();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:MockLearner.java

示例6: initLesson

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
public String initLesson(String initLessonURL, String ldId, String organisationID, String userId, String name) {
try {
    if (userId == null) {
	throw new TestHarnessException(
		"User id is missing. If you have set UserCreated (admin properties) to true, then you must set UserId in the monitor properties.");
    }

    String url = initLessonURL.replace(MockMonitor.LDID_PATTERN, ldId)
	    .replace(MockMonitor.ORGANISATION_ID_PATTERN, organisationID)
	    .replace(MockMonitor.USER_ID_PATTERN, userId).replace(MockMonitor.LESSON_NAME_PATTERN, name);
    MockMonitor.log.debug("initLessonURL:  " + url);
    WebResponse resp = (WebResponse) new Call(wc, test, username + " inits lesson", url).execute();

    String idAsString = resp.getText().trim();
    MockMonitor.log.info(username + " initialized the lesson " + name + " and the id is " + idAsString);
    return idAsString;
} catch (IOException e) {
    throw new RuntimeException(e);
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:MockMonitor.java

示例7: load

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
/**
 * load
 * @param response
 */
public void load( WebResponse response ) {
		Function onLoadEvent=null;
    try {
        Context context = Context.enter();
        context.initStandardObjects( null );

        HTMLDocument htmlDocument = ((DomWindow) response.getScriptingHandler()).getDocument();
        if (!(htmlDocument instanceof HTMLDocumentImpl)) return;

        HTMLBodyElementImpl body = (HTMLBodyElementImpl) htmlDocument.getBody();
        if (body == null) return;
        onLoadEvent = body.getOnloadEvent();
        if (onLoadEvent == null) return;
        onLoadEvent.call( context, body, body, new Object[0] );
    } catch (JavaScriptException e) {
    	ScriptingEngineImpl.handleScriptException(e, onLoadEvent.toString());
    	// HttpUnitUtils.handleException(e);
    } catch (EcmaError ee) {
    	//throw ee;
    	ScriptingEngineImpl.handleScriptException(ee, onLoadEvent.toString());        	
    } finally {
        Context.exit();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:DomBasedScriptingEngineFactory.java

示例8: testSomeFailures

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
public void testSomeFailures() throws Exception {
    ServletUnitClient client = newClient();

    WebResponse wr = client.getResponse( "http://localhost/JUnit?test=" + FailingTests.class.getName() );
    final WebTable resultsTable = wr.getTableWithID( "results" );
    assertNotNull( "Did not find results table", resultsTable );
    final String[][] results = resultsTable.asText();
    assertEquals( "Num rows", 4, results.length );
    assertEquals( "Num columns", 3, results[0].length );
    assertEquals( "First header", "3 tests", results[0][0] );
    assertEquals( "Status", "Problems Occurred", results[0][2] );
    assertEquals( "Failure header", "2 failures", results[1][1] );
    assertEquals( "Failure index 1", "1", results[2][0] );
    assertEquals( "Failure index 2", "2", results[3][0] );
    assertTrue( "Test class not found", results[2][1].indexOf( '(' + FailingTests.class.getName() + ')' ) >= 0 );
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:17,代码来源:JUnitServletTest.java

示例9: testSomeFailuresXMLFormat

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
public void testSomeFailuresXMLFormat() throws Exception {
    ServletUnitClient client = newClient();

    WebResponse wr = client.getResponse( "http://localhost/JUnit?format=xml&test=" + FailingTests.class.getName() );
    assertEquals( "Content type", "text/xml", wr.getContentType() );
    DocumentBuilder builder = HttpUnitUtils.newParser();
    Document document = builder.parse( wr.getInputStream() );
    Element element = document.getDocumentElement();
    assertEquals( "document element name", "testsuite", element.getNodeName() );
    assertEquals( "number of tests", "3", element.getAttribute( "tests" ) );
    assertEquals( "number of failures", "2", element.getAttribute( "failures" ) );
    assertEquals( "number of errors", "0", element.getAttribute( "errors" ) );
    NodeList nl = element.getElementsByTagName( "testcase" );
    verifyElementWithNameHasFailureNode( "testAddition", nl, /* failed */ "failure", true );
    verifyElementWithNameHasFailureNode( "testSubtraction", nl, /* failed */ "failure", true );
    verifyElementWithNameHasFailureNode( "testMultiplication", nl, /* failed */ "failure", false );
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:18,代码来源:JUnitServletTest.java

示例10: testSomeErrorsXMLFormat

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
public void testSomeErrorsXMLFormat() throws Exception {
    ServletUnitClient client = newClient();

    WebResponse wr = client.getResponse( "http://localhost/JUnit?format=xml&test=" + ErrorTests.class.getName() );
    assertEquals( "Content type", "text/xml", wr.getContentType() );
    DocumentBuilder builder = HttpUnitUtils.newParser();
    Document document = builder.parse( wr.getInputStream() );
    Element element = document.getDocumentElement();
    assertEquals( "document element name", "testsuite", element.getNodeName() );
    assertEquals( "number of tests", "2", element.getAttribute( "tests" ) );
    assertEquals( "number of failures", "0", element.getAttribute( "failures" ) );
    assertEquals( "number of errors", "1", element.getAttribute( "errors" ) );
    NodeList nl = element.getElementsByTagName( "testcase" );
    verifyElementWithNameHasFailureNode( "testAddition", nl, /* failed */ "error", true );
    verifyElementWithNameHasFailureNode( "testMultiplication", nl, /* failed */ "error", false );
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:17,代码来源:JUnitServletTest.java

示例11: testScriptedServletAccess

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
public void testScriptedServletAccess() throws Exception {
    WebXMLString wxs = new WebXMLString();
    Properties params = new Properties();
    params.setProperty( "color", "red" );
    params.setProperty( "age", "12" );
    wxs.addServlet( "simple", "/SimpleServlet", SimpleGetServlet.class, params );
    wxs.addServlet( "/JUnit", TestRunnerServlet.class );

    MyFactory._runner = _runner = new ServletRunner( wxs.asInputStream() );
    ServletUnitClient client = _runner.newClient();
    WebResponse wr = client.getResponse( "http://localhost/JUnit?test=" + ServletAccessTest.class.getName() );

    final WebTable resultsTable = wr.getTableWithID( "results" );
    assertNotNull( "Did not find results table", resultsTable );
    final String[][] results = resultsTable.asText();
    assertEquals( "Status", "OK", results[0][2] );
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:18,代码来源:JUnitServletTest.java

示例12: testAppletFindFromApplet

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
public void testAppletFindFromApplet() throws Exception {
    defineWebPage( "start", "<applet name=first code='" + SimpleApplet.class.getName() +
                            ".class' codebase=/classes width=100 height=100></applet>" +
                            "<applet name=second code='" + SecondApplet.class.getName() +
                            ".class' codebase=/classes width=100 height=100></applet>");
    mapToClasspath( "/classes" );
    WebConversation wc = new WebConversation();
    WebResponse response = wc.getResponse( getHostPath() + "/start.html" );
    Applet applet = response.getApplets()[0].getApplet();
    Applet applet2 = applet.getAppletContext().getApplet( "second" );
    assertNotNull( "Applet was not loaded", applet2 );
    assertEquals( "Applet class", SecondApplet.class.getName(), applet2.getClass().getName() );

    Enumeration applets = applet2.getAppletContext().getApplets();
    assertNotNull( "No applet enumeration returned", applets );
    assertTrue( "No applets in enumeration", applets.hasMoreElements() );
    assertTrue( "First is not an applet", applets.nextElement() instanceof Applet );
    assertTrue( "Only one applet in enumeration", applets.hasMoreElements() );
    assertTrue( "Second is not an applet", applets.nextElement() instanceof Applet );
    assertFalse( "More than two applets enumerated", applets.hasMoreElements() );
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:22,代码来源:WebAppletTest.java

示例13: testJavaScriptURLToParentFrame

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
/**
 * Verifies that a javascript URL which triggers refresh to the parent of a frame resolves with something sensible.
 */
public void testJavaScriptURLToParentFrame() throws Exception {
    defineResource( "Frames.html",
                    "<HTML><HEAD><TITLE>Initial</TITLE></HEAD>" +
                    "<FRAMESET cols=\"20%,80%\">" +
                    "    <FRAME src='Linker.html' name='red'>" +
                    "    <FRAME src=Form name=blue>" +
                    "</FRAMESET></HTML>" );
    defineWebPage( "Linker",  "This is a trivial page with <a href='javascript:window.parent.location.replace( \"Target\" );'>one link</a>" );
    defineResource( "Form",    "This is a page with nothing we care about");
    defineResource( "Target",  "You made it!", "text/plain" );

    _wc.getResponse( getHostPath() + "/Frames.html" );
    WebResponse result = _wc.getFrameContents( "red" ).getLinkWith( "one link" ).click();
    assertEquals( "Result of click", "You made it!", result.getText() );
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:19,代码来源:FrameScriptingTest.java

示例14: testPolicy1

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
public void testPolicy1() {
    try {
        WebConversation wc = new WebConversation();
        WebResponse resp = logOn(wc, "startComponent.do?component=Material.ItemFinder&displayResultsScreen=true", "MAHESH", "dummy");


        WebTable table = resp.getTableWithID("material_itemFinderResultsForm_rows");
        assertNotNull("Found Table For Checks", table);
        String text = null;

        text = table.getCellAsText(1,2);
        assertTrue("Serial is not D", text.equals("A"));
        text = table.getCellAsText(2,2);
        assertTrue("Serial is not  E", text.equals("B") );
        text = table.getCellAsText(3,2);
        assertTrue("Serial is not D", text.equals("C"));
        text = table.getCellAsText(4,2);
        assertTrue("Serial is not  E", text.equals("D") );
        text = table.getCellAsText(5,2);
        assertTrue("Serial is not  E", text.equals("E") );

    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:27,代码来源:JDBCPluginTest.java

示例15: testPolicy2

import com.meterware.httpunit.WebResponse; //导入依赖的package包/类
public void testPolicy2() {
    try {
        WebConversation wc = new WebConversation();
        WebResponse resp = logOn(wc, "startComponent.do?component=Material.ItemFinder&displayResultsScreen=true", "PAUL", "dummy");

        WebTable table = resp.getTableWithID("material_itemFinderResultsForm_rows");
        assertNotNull("Found Table For Checks", table);
        String text = null;


        text = table.getCellAsText(1,2);
        assertTrue("Serial is not A",text.equals("A") );

        text = table.getCellAsText(2,2);
        assertTrue( "Serial is not B", text.equals("B"));


    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:23,代码来源:JDBCPluginTest.java


注:本文中的com.meterware.httpunit.WebResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。