struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hus...@apache.org
Subject svn commit: r440438 - in /struts/struts2/trunk/apps/blank/src/test/java/example: ConfigTest.java LoginTest.java
Date Tue, 05 Sep 2006 19:01:52 GMT
Author: husted
Date: Tue Sep  5 12:01:51 2006
New Revision: 440438

URL: http://svn.apache.org/viewvc?view=rev&rev=440438
Log:
WW-1340 In blank, start to add a suite of example tests.

Modified:
    struts/struts2/trunk/apps/blank/src/test/java/example/ConfigTest.java
    struts/struts2/trunk/apps/blank/src/test/java/example/LoginTest.java

Modified: struts/struts2/trunk/apps/blank/src/test/java/example/ConfigTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/blank/src/test/java/example/ConfigTest.java?view=diff&rev=440438&r1=440437&r2=440438
==============================================================================
--- struts/struts2/trunk/apps/blank/src/test/java/example/ConfigTest.java (original)
+++ struts/struts2/trunk/apps/blank/src/test/java/example/ConfigTest.java Tue Sep  5 12:01:51
2006
@@ -8,14 +8,35 @@
 import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
 
 import java.util.Map;
+import java.util.List;
 
 public class ConfigTest extends XWorkTestCase {
 
-    protected void AssertSuccess(String result) throws Exception {
+    protected void assertSuccess(String result) throws Exception {
         assertTrue("Expected a success result!",
                 ActionSupport.SUCCESS.equals(result));
     }
 
+    protected void assertInput(String result) throws Exception {
+        assertTrue("Expected an input result!",
+                ActionSupport.INPUT.equals(result));
+    }
+
+    protected Map assertFieldErrors(ActionSupport action) throws Exception {
+        assertTrue(action.hasFieldErrors());
+        return action.getFieldErrors();
+    }
+
+    protected void assertFieldError(Map field_errors, String field_name, String error_message)
{
+
+        List errors = (List) field_errors.get(field_name);
+        assertNotNull("Expected errors for " + field_name, errors);
+        assertTrue("Expected errors for " + field_name, errors.size()>0);
+        // TODO: Should be a loop
+        assertEquals(error_message,errors.get(0));
+
+    }
+
     protected void setUp() throws Exception {
         super.setUp();
         XmlConfigurationProvider c = new XmlConfigurationProvider("struts.xml");
@@ -23,13 +44,17 @@
         configurationManager.reload();
     }
 
-    protected ActionConfig assertClass(String action_name, String class_name) {
+    protected ActionConfig assertClass(String namespace, String action_name, String class_name)
{
         RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
-        ActionConfig config = configuration.getActionConfig("", action_name);
+        ActionConfig config = configuration.getActionConfig(namespace, action_name);
         assertNotNull("Mssing action", config);
         assertTrue("Wrong class name: [" + config.getClassName() + "]",
                 class_name.equals(config.getClassName()));
         return config;
+    }
+
+    protected ActionConfig assertClass(String action_name, String class_name) {
+        return assertClass("", action_name, class_name);
     }
 
     protected void assertResult(ActionConfig config, String result_name, String result_value)
{

Modified: struts/struts2/trunk/apps/blank/src/test/java/example/LoginTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/blank/src/test/java/example/LoginTest.java?view=diff&rev=440438&r1=440437&r2=440438
==============================================================================
--- struts/struts2/trunk/apps/blank/src/test/java/example/LoginTest.java (original)
+++ struts/struts2/trunk/apps/blank/src/test/java/example/LoginTest.java Tue Sep  5 12:01:51
2006
@@ -3,12 +3,16 @@
 import com.opensymphony.xwork2.ActionSupport;
 import com.opensymphony.xwork2.config.entities.ActionConfig;
 
+import java.util.Map;
+import java.util.Collection;
+import java.util.List;
+
 public class LoginTest extends ConfigTest {
 
     public void FIXME_testLoginConfig() throws Exception {
-        ActionConfig config = assertClass("Login", "tutorial.Login");
+        ActionConfig config = assertClass("example", "Login!input", "example.Login");
         assertResult(config, ActionSupport.SUCCESS, "Menu");
-        assertResult(config, ActionSupport.INPUT, "/tutorial/Login.jsp");
+        assertResult(config, ActionSupport.INPUT, "/example/Login.jsp");
     }
 
     public void testLoginSubmit() throws Exception {
@@ -16,7 +20,17 @@
         login.setUsername("username");
         login.setPassword("password");
         String result = login.execute();
-        AssertSuccess(result);
+        assertSuccess(result);
+    }
+
+    // Needs access to an envinronment that includes validators
+    public void FIXME_testLoginSubmitInput() throws Exception {
+        Login login = new Login();
+        String result = login.execute();
+        assertInput(result);
+        Map errors = assertFieldErrors(login);
+        assertFieldError(errors,"username","Username is required.");
+        assertFieldError(errors,"password","Password is required.");
     }
 
 }



Mime
View raw message