Author: craigmcc
Date: Thu Jun  1 11:38:45 2006
New Revision: 410909

URL: http://svn.apache.org/viewvc?rev=410909&view=rev
Log:
Add a system integration to validate the token processing behavior.  There is
a section of this test that is commented out until SHALE-182 is fixed in the
token processing implementation.

Added:
    
struts/shale/trunk/use-cases/src/systest/org/apache/shale/usecases/systest/TokenTestCase.java
   (with props)
Modified:
    struts/shale/trunk/use-cases/src/web/token/test.jsp

Added: 
struts/shale/trunk/use-cases/src/systest/org/apache/shale/usecases/systest/TokenTestCase.java
URL: 
http://svn.apache.org/viewvc/struts/shale/trunk/use-cases/src/systest/org/apache/shale/usecases/systest/TokenTestCase.java?rev=410909&view=auto
==============================================================================
--- 
struts/shale/trunk/use-cases/src/systest/org/apache/shale/usecases/systest/TokenTestCase.java
 (added)
+++ 
struts/shale/trunk/use-cases/src/systest/org/apache/shale/usecases/systest/TokenTestCase.java
 Thu Jun  1 11:38:45 2006
@@ -0,0 +1,248 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.usecases.systest;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlHiddenInput;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
+import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * <p>Test case for the [EMAIL PROTECTED] Token} ViewController 
implementation.</p>
+ */
+public class TokenTestCase extends AbstractTestCase {
+
+
+    // ------------------------------------------------------------ 
Constructors
+
+
+    // Construct a new instance of this test case.
+    public TokenTestCase(String name) {
+        super(name);
+    }
+
+
+    // ---------------------------------------------------- Overall Test 
Methods
+
+
+    // Set up instance variables required by this test case.
+    public void setUp() throws Exception {
+
+        super.setUp();
+        page("/token/test.faces");
+
+    }
+
+    // Return the tests included in this test case.
+    public static Test suite() {
+
+        return (new TestSuite(TokenTestCase.class));
+
+    }
+
+
+    // Tear down instance variables required by this test case.
+    public void tearDown() {
+
+        super.tearDown();
+
+    }
+
+
+    // ------------------------------------------------------------ Test 
Methods
+
+
+    /**
+     * <p>Test that a double submit causes a validation error.</p>
+     */
+    public void testDouble() throws Exception {
+
+        // Save the current page so we can resubmit it
+        HtmlPage save = this.page;
+        HtmlElement message = null;
+        String text = null;
+
+        // setUp() should have put us on the page
+        assertEquals("Shale Token Test", title());
+
+        // Fill in the required value and submit the form
+        HtmlTextInput value = (HtmlTextInput) element("form:value");
+        value.setValueAttribute("Value");
+        HtmlSubmitInput submit = (HtmlSubmitInput) element("form:submit");
+        submit(submit);
+
+        // Restore the saved page and submit it again
+        this.page = save;
+        value = (HtmlTextInput) element("form:value");
+        value.setValueAttribute("Value");
+        submit = (HtmlSubmitInput) element("form:submit");
+        submit(submit);
+
+        // Verify we stayed on the same page with appropriate error messages
+        assertEquals("Shale Token Test", title());
+        HtmlElement messages = element("form:messages");
+        assertNotNull(messages);
+        text = messages.asText();
+        assertTrue(text.contains("Invalid resubmit of the same form"));
+        message = element("form:valueMessage");
+        assertNull(message);
+        message = element("form:tokenMessage");
+        assertNotNull(message);
+// FIXME - for some reason the text is not displayed???  MyFaces issue???
+//        assertTrue(message.asText().contains("Invalid resubmit of the same 
form"));
+
+    }
+
+
+    /**
+     * <p>Test the "normal" flow of submitting a correctly entered form.</p>
+     */
+    public void testNormal() throws Exception {
+
+        // setUp() should have put us on the page
+        assertEquals("Shale Token Test", title());
+
+        // Fill in the required value and submit the form
+        HtmlTextInput value = (HtmlTextInput) element("form:value");
+        value.setValueAttribute("Value");
+        HtmlSubmitInput submit = (HtmlSubmitInput) element("form:submit");
+        submit(submit);
+
+        // Validate that we have returned to the main page
+        assertEquals("Shale Framework Use Cases", title());
+
+    }
+
+
+    /**
+     * <p>Validate pristine instance of the "Token" test page.</p>
+     */
+    public void testPristine() throws Exception {
+
+        HtmlForm form = null;
+        HtmlElement message = null;
+        HtmlElement messages = null;
+        HtmlHiddenInput token = null;
+        HtmlSubmitInput submit = null;
+        HtmlTextInput value = null;
+
+        // setUp() should have put us on the page
+        assertEquals("Shale Token Test", title());
+        form = (HtmlForm) element("form");
+        assertNotNull(form);
+        messages = element("form:messages");
+        assertNull(messages);
+        value = (HtmlTextInput) element("form:value");
+        assertNotNull(value);
+        assertEquals("", value.getValueAttribute());
+        message = element("form:valueMessage");
+        assertNull(message);
+        token = (HtmlHiddenInput) element("form:token");
+        assertNotNull(token);
+        assertNotNull(token.getValueAttribute());
+        message = element("form:tokenMessage");
+        assertNull(message);
+        submit = (HtmlSubmitInput) element("form:submit");
+        assertNotNull(submit);
+
+    }
+
+
+    /**
+     * <p>Test that a validation error correctly stays on the same page
+     */
+    public void testValidate() throws Exception {
+
+        // Save the current page so we can resubmit it
+        HtmlPage save = this.page;
+        HtmlElement message = null;
+        String text = null;
+
+        // setUp() should have put us on the page
+        assertEquals("Shale Token Test", title());
+
+        // Submit the form without setting the value
+        HtmlSubmitInput submit = (HtmlSubmitInput) element("form:submit");
+        submit(submit);
+
+        // Verify we stayed on the same page with appropriate error messages
+        assertEquals("Shale Token Test", title());
+        HtmlElement messages = element("form:messages");
+        assertNotNull(messages);
+        // Cannot accurately test for implementation-defined message
+        message = element("form:valueMessage");
+        assertNotNull(message);
+        // Cannot accurately test for implementation-defined message
+        message = element("form:tokenMessage");
+        assertNull(message);
+
+    }
+
+
+    /**
+     * <p>Test that fixing a validation error correctly allows the form
+     * to be submitted, but not resubmitted.</p>
+     */
+    public void testValidateRetry() throws Exception {
+
+        // Reproduce the steps that testValidate() performs
+        testValidate();
+
+        // Fix the validation error and submit the form
+        HtmlPage save = this.page;
+        HtmlTextInput value = (HtmlTextInput) element("form:value");
+        value.setValueAttribute("Value");
+        HtmlSubmitInput submit = (HtmlSubmitInput) element("form:submit");
+        submit(submit);
+
+        // Verify that we were returned to the main menu
+/* FIXME - Comment out remaining assertions due to SHALE-182 until it is fixed
+        assertEquals("Shale Framework Use Cases", title());
+
+        // Restore the saved page and submit it again
+        this.page = save;
+        value = (HtmlTextInput) element("form:value");
+        value.setValueAttribute("Value");
+        submit = (HtmlSubmitInput) element("form:submit");
+        submit(submit);
+
+        // Verify we stayed on the same page with appropriate error messages
+        assertEquals("Shale Token Test", title());
+        HtmlElement messages = element("form:messages");
+        assertNotNull(messages);
+        String text = messages.asText();
+        assertTrue(text.contains("Invalid resubmit of the same form"));
+        HtmlElement message = element("form:valueMessage");
+        assertNull(message);
+        message = element("form:tokenMessage");
+        assertNotNull(message);
+// FIXME - for some reason the text is not displayed???  MyFaces issue???
+//        assertTrue(message.asText().contains("Invalid resubmit of the same 
form"));
+*/
+
+    }
+
+
+}

Propchange: 
struts/shale/trunk/use-cases/src/systest/org/apache/shale/usecases/systest/TokenTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/shale/trunk/use-cases/src/systest/org/apache/shale/usecases/systest/TokenTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: struts/shale/trunk/use-cases/src/web/token/test.jsp
URL: 
http://svn.apache.org/viewvc/struts/shale/trunk/use-cases/src/web/token/test.jsp?rev=410909&r1=410908&r2=410909&view=diff
==============================================================================
--- struts/shale/trunk/use-cases/src/web/token/test.jsp (original)
+++ struts/shale/trunk/use-cases/src/web/token/test.jsp Thu Jun  1 11:38:45 2006
@@ -33,7 +33,8 @@
 
   <h:form                  id="form">
 
-    <h:messages    globalOnly="false"/>
+    <h:messages            id="messages"
+                   globalOnly="false"/>
 
     <h:panelGrid           id="grid"
                       columns="3">
@@ -43,15 +44,18 @@
       <h:inputText         id="value"
                       required="true"
                         value="#{token$test.value}"/>
-      <h:message          for="value"/>
+      <h:message           id="valueMessage"
+                          for="value"/>
 
       <h:outputLabel      for="token"
                         value=""/>
       <s:token             id="token"/>
-      <h:message          for="token"/>
+      <h:message           id="tokenMessage"
+                          for="token"/>
 
       <h:outputText     value=""/>
-      <h:commandButton  value="Submit"
+      <h:commandButton     id="submit"
+                        value="Submit"
                        action="usecases$toplevel"/>
       <h:outputText     value=""/>
 


Reply via email to