You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ri...@apache.org on 2006/05/13 02:49:48 UTC
svn commit: r405965 - in /incubator/tuscany/java/testing/tomcat:
bigbank/src/test/java/org/apache/tuscany/test/bigbank/BigBankTestCase.java
helloworldweb/src/test/java/org/apache/tuscany/test/helloworldweb/HelloWorldWebTestCase.java
pom.xml
Author: rineholt
Date: Fri May 12 17:49:47 2006
New Revision: 405965
URL: http://svn.apache.org/viewcvs?rev=405965&view=rev
Log:
close to getting it all automated again
Modified:
incubator/tuscany/java/testing/tomcat/bigbank/src/test/java/org/apache/tuscany/test/bigbank/BigBankTestCase.java
incubator/tuscany/java/testing/tomcat/helloworldweb/src/test/java/org/apache/tuscany/test/helloworldweb/HelloWorldWebTestCase.java
incubator/tuscany/java/testing/tomcat/pom.xml
Modified: incubator/tuscany/java/testing/tomcat/bigbank/src/test/java/org/apache/tuscany/test/bigbank/BigBankTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/testing/tomcat/bigbank/src/test/java/org/apache/tuscany/test/bigbank/BigBankTestCase.java?rev=405965&r1=405964&r2=405965&view=diff
==============================================================================
--- incubator/tuscany/java/testing/tomcat/bigbank/src/test/java/org/apache/tuscany/test/bigbank/BigBankTestCase.java (original)
+++ incubator/tuscany/java/testing/tomcat/bigbank/src/test/java/org/apache/tuscany/test/bigbank/BigBankTestCase.java Fri May 12 17:49:47 2006
@@ -24,87 +24,213 @@
import junit.framework.TestCase;
-import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
-
public class BigBankTestCase extends TestCase {
- // public static final String testUrl = "http://localhost:8080/tuscany-samples-bigbank-webclient";
- public static final String testUrl = "http://localhost:8080/webclient-SNAPSHOT/login.html";
-
-
- public void testBigBankDefault() throws Exception
- {
- System.err.println("Running: testcase:");
- // New HTMLunit web client
- WebClient client = new WebClient();
- client.setRedirectEnabled(true);
-
- // Going to have the WebClient connect to this URL
- URL url = new URL(testUrl);
- HtmlPage page = (HtmlPage)client.getPage(url);
- //System.out.println(page.getTitleText());
-
- // Check response code
- WebResponse resp = page.getWebResponse();
- assertTrue(resp.getStatusCode() <= 200);
- List forms = page.getForms();
- Iterator iter = forms.iterator();
-
- // Iterate over all forms on page, should only be one.
- while(iter.hasNext())
- {
- HtmlForm form = (HtmlForm)iter.next();
-
-
- HtmlInput login = form.getInputByName("login");
- HtmlInput password = form.getInputByName("password");
- login.setValueAttribute("test");
- password.setValueAttribute("password");
-
- Page resultPage = form.submit();
- // Check response from servlet
- WebResponse resultResponse = resultPage.getWebResponse();
- assertTrue(resultResponse.getStatusCode() <= 200);
-
- // TODO Check response content..
- String response = resultResponse.getContentAsString();
- assertTrue(-1 != response.indexOf("Account"));
- assertTrue(-1 != response.indexOf("Balance"));
- assertTrue(-1 != response.indexOf("12345_CHA12345"));
- assertTrue(-1 != response.indexOf("1200.0"));
-
-
-
- /**
- * or..
- *
- * HtmlPage htmlResponse = (HtmlPage)resultPage;
- * HtmlElement element = htmlResponse.getHtmlElementById("ELEMENT-ID");
- * assertEquals(element.getNodeValue(), ... );
- *
- * or..
- *
- * String resultString = resultResponse.getContentAsString();
- * assertEquals(resultString, ... );
- *
- * etc.
- *
- **/
- }
-
- }
-
- /**
- * @param args
- */
- public static void main(String[] args) {
-
+ // public static final String testUrl = "http://localhost:8080/tuscany-samples-bigbank-webclient";
+ public static final String testUrl = "http://localhost:8080/sample-bigbank-webclient-SNAPSHOT/";
+
+ public void testBigBankDefault() throws Exception {
+ System.err.println("Running: testcase:");
+ // New HTMLunit web client
+ WebClient client = new WebClient();
+ client.setRedirectEnabled(true);
+
+ // Going to have the WebClient connect to this URL
+ URL url = new URL(testUrl);
+ HtmlPage page = (HtmlPage) client.getPage(url);
+ // System.out.println(page.getTitleText());
+
+ // Check response code
+ WebResponse resp = page.getWebResponse();
+ assertTrue(resp.getStatusCode() <= 200);
+ List forms = page.getForms();
+
+
+ HtmlPage resultPage = null;
+ WebResponse resultResponse= null;
+ boolean formfound = false;
+ for (Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
+ HtmlForm form = (HtmlForm) iter.next();
+
+ if ("loginAction".equals(form.getActionAttribute())) {
+ formfound = true;
+ HtmlInput login = form.getInputByName("login");
+ HtmlInput password = form.getInputByName("password");
+ login.setValueAttribute("test");
+ password.setValueAttribute("password");
+
+ resultPage = (HtmlPage) form.submit();
+ // Check response from servlet
+ resultResponse = resultPage.getWebResponse();
+ assertTrue(resultResponse.getStatusCode() <= 200);
+
+
+ String response = resultResponse.getContentAsString();
+ assertTrue(-1 != response.indexOf("Account Information for"));
+ assertTrue(-1 != response.indexOf("test"));
+ assertTrue(-1 != response.indexOf("134-42-6231"));
+ assertTrue(-1 != response.indexOf("123.43"));
+ assertTrue(-1 != response.indexOf("134-43-3941"));
+ assertTrue(-1 != response.indexOf("23.12"));
+
+ Pattern pat = Pattern.compile("LU.*7", Pattern.DOTALL);
+ Matcher test = pat.matcher(response);
+ assertTrue(test.find());
+ }
+
+ }
+ forms = resultPage.getForms();
+
+ formfound = false;
+ for(Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
+ HtmlForm form = (HtmlForm) iter.next();
+
+ if ("purchaseStock.jsp".equals(form.getActionAttribute())) {
+ formfound = true;
+ resultPage = (HtmlPage) form.submit();
+ }
+
+ }
+ assertTrue(formfound);
+ forms = resultPage.getForms();
+ formfound = false;
+ for (Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
+ HtmlForm form = (HtmlForm) iter.next();
+
+ if ("FormServlet".equals(form.getActionAttribute())) {
+ formfound = true;
+
+ HtmlInput login = form.getInputByName("symbol");
+ HtmlInput password = form.getInputByName("quantity");
+ login.setValueAttribute("EDS");
+ password.setValueAttribute("131");
+
+ resultPage = (HtmlPage) form.submit();
+ // Check response from servlet
+ resultResponse = resultPage.getWebResponse();
+ assertTrue(resultResponse.getStatusCode() <= 200);
+
+
+ String response = resultResponse.getContentAsString();
+ assertTrue(-1 != response.indexOf("Account Information for"));
+ assertTrue(-1 != response.indexOf("test"));
+ assertTrue(-1 != response.indexOf("134-42-6231"));
+ assertTrue(-1 != response.indexOf("123.43"));
+ assertTrue(-1 != response.indexOf("134-43-3941"));
+ assertTrue(-1 != response.indexOf("23.12"));
+
+ Pattern pat = Pattern.compile("LU.*7", Pattern.DOTALL);
+ Matcher test = pat.matcher(response);
+ assertTrue(test.find());
+ pat = Pattern.compile("EDS.*131", Pattern.DOTALL);
+ test = pat.matcher(response);
+ assertTrue(test.find());
+
+ }
+
+ }
+ assertTrue(formfound);
+ forms = resultPage.getForms();
+ formfound = false;
+ for (Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
+ HtmlForm form = (HtmlForm) iter.next();
+
+ if ("stockSale.jsp".equals(form.getActionAttribute())) {
+// System.err.println(form.asText());
+
+
+
+ Pattern pat = Pattern.compile("EDS.*131", Pattern.DOTALL);
+
+ Matcher test = pat.matcher(form.asText());
+ if(!test.find()) continue;
+
+
+
+
+ formfound = true;
+ resultPage = (HtmlPage) form.submit();
+ // Check response from servlet
+ resultResponse = resultPage.getWebResponse();
+ assertTrue(resultResponse.getStatusCode() <= 200);
+
+
+ }
+
+ }
+ forms = resultPage.getForms();
+
+
+
+ formfound = false;
+ for(Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
+ HtmlForm form = (HtmlForm) iter.next();
+
+ if ("FormServlet".equals(form.getActionAttribute())) {
+ formfound = true;
+
+
+ HtmlInput password = form.getInputByName("quantity");
+
+ password.setValueAttribute("131");
+
+ resultPage = (HtmlPage) form.submit();
+ // Check response from servlet
+ resultResponse = resultPage.getWebResponse();
+ assertTrue(resultResponse.getStatusCode() <= 200);
+
+
+ String response = resultResponse.getContentAsString();
+ assertTrue(-1 != response.indexOf("Account Information for"));
+ assertTrue(-1 != response.indexOf("test"));
+ assertTrue(-1 != response.indexOf("134-42-6231"));
+ assertTrue(-1 != response.indexOf("123.43"));
+ assertTrue(-1 != response.indexOf("134-43-3941"));
+ assertTrue(-1 != response.indexOf("23.12"));
+
+ Pattern pat = Pattern.compile("LU.*7", Pattern.DOTALL);
+ Matcher test = pat.matcher(response);
+ assertTrue(test.find());
+ // pat = Pattern.compile("EDS.*131", Pattern.DOTALL);
+ // test = pat.matcher(response);
+ // assertFalse(test.find());
+
+
+ }
+
+ }
+ assertTrue(formfound);
+
+ forms = resultPage.getForms();
+ formfound = false;
+ for (Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
+ HtmlForm form = (HtmlForm) iter.next();
+
+ if ("loginAction".equals(form.getActionAttribute())) {
+ formfound = true;
+
+ resultPage = (HtmlPage) form.submit();
+
+ }
+
+ }
+ assertTrue(formfound);
+
+
+
+
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
- }
+ }
}
Modified: incubator/tuscany/java/testing/tomcat/helloworldweb/src/test/java/org/apache/tuscany/test/helloworldweb/HelloWorldWebTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/testing/tomcat/helloworldweb/src/test/java/org/apache/tuscany/test/helloworldweb/HelloWorldWebTestCase.java?rev=405965&r1=405964&r2=405965&view=diff
==============================================================================
--- incubator/tuscany/java/testing/tomcat/helloworldweb/src/test/java/org/apache/tuscany/test/helloworldweb/HelloWorldWebTestCase.java (original)
+++ incubator/tuscany/java/testing/tomcat/helloworldweb/src/test/java/org/apache/tuscany/test/helloworldweb/HelloWorldWebTestCase.java Fri May 12 17:49:47 2006
@@ -33,7 +33,7 @@
public class HelloWorldWebTestCase extends TestCase {
- public static final String testUrl = "http://localhost:8080/helloworldWeb-SNAPSHOT/";
+ public static final String testUrl = "http://localhost:8080/sample-helloworldweb-SNAPSHOT/";
public void testHelloWorldDefault() throws Exception
{
Modified: incubator/tuscany/java/testing/tomcat/pom.xml
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/testing/tomcat/pom.xml?rev=405965&r1=405964&r2=405965&view=diff
==============================================================================
--- incubator/tuscany/java/testing/tomcat/pom.xml (original)
+++ incubator/tuscany/java/testing/tomcat/pom.xml Fri May 12 17:49:47 2006
@@ -29,6 +29,8 @@
<modules>
<module>helloworldws</module>
+ <module>helloworldweb</module>
+ <module>bigbank</module>
<!--
these can't seem to run cause they need htmlunit and the dependencies download
seems broken for htmlunit