tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r491607 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/test/TapestryTestCase.java test/conf/testng.xml test/java/org/apache/tapestry/validator/ test/java/org/apache/tapestry/validator/RequiredTest.java
Date Mon, 01 Jan 2007 18:22:34 GMT
Author: hlship
Date: Mon Jan  1 10:22:33 2007
New Revision: 491607

URL: http://svn.apache.org/viewvc?view=rev&rev=491607
Log:
Add test for Required validator

Added:
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/RequiredTest.java
Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java?view=diff&rev=491607&r1=491606&r2=491607
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
Mon Jan  1 10:22:33 2007
@@ -575,4 +575,9 @@
     {
         expect(model.getPersistentFieldNames()).andReturn(Arrays.asList(names)).atLeastOnce();
     }
+
+    protected final Messages newMessages()
+    {
+        return newMock(Messages.class);
+    }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml?view=diff&rev=491607&r1=491606&r2=491607
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml Mon Jan  1 10:22:33 2007
@@ -34,6 +34,7 @@
       <package name="org.apache.tapestry.runtime"/>
       <package name="org.apache.tapestry.internal.bindings"/>
       <package name="org.apache.tapestry.internal.model"/>
+      <package name="org.apache.tapestry.validator"/>
     </packages>
   </test>
 </suite>

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/RequiredTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/RequiredTest.java?view=auto&rev=491607
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/RequiredTest.java
(added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/RequiredTest.java
Mon Jan  1 10:22:33 2007
@@ -0,0 +1,102 @@
+// Copyright 2006 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.tapestry.validator;
+
+import org.apache.tapestry.Field;
+import org.apache.tapestry.ValidationException;
+import org.apache.tapestry.ioc.Messages;
+import org.apache.tapestry.test.TapestryTestCase;
+import org.testng.annotations.Test;
+
+public class RequiredTest extends TapestryTestCase
+{
+    @Test
+    public void null_value()
+    {
+        Messages messages = newMessages();
+        Field field = newField("My Field");
+
+        train_format(messages, "required", "{message}", "My Field");
+
+        replay();
+
+        try
+        {
+            new Required().check(field, null, messages, null);
+            unreachable();
+        }
+        catch (ValidationException ex)
+        {
+            assertEquals(ex.getMessage(), "{message}");
+        }
+
+        verify();
+    }
+
+    @Test
+    public void blank_value()
+    {
+        Messages messages = newMessages();
+        Field field = newField("My Field");
+
+        train_format(messages, "required", "{message}", "My Field");
+
+        replay();
+
+        try
+        {
+            new Required().check(field, null, messages, "");
+            unreachable();
+        }
+        catch (ValidationException ex)
+        {
+            assertEquals(ex.getMessage(), "{message}");
+        }
+
+        verify();
+    }
+
+    @Test
+    public void non_blank_value() throws Exception
+    {
+        Messages messages = newMessages();
+        Field field = newField();
+
+        replay();
+
+        new Required().check(field, null, messages, "not null");
+
+        verify();
+    }
+
+    protected void train_format(Messages messages, String key, String result, Object... arguments)
+    {
+        expect(messages.format(key, arguments)).andReturn(result);
+    }
+
+    protected final Field newField(String label)
+    {
+        Field field = newField();
+
+        expect(field.getLabel()).andReturn(label).atLeastOnce();
+
+        return field;
+    }
+
+    protected final Field newField()
+    {
+        return newMock(Field.class);
+    }
+}



Mime
View raw message