cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpfingsth...@apache.org
Subject svn commit: r278702 - in /cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel: FieldTestCase.java FieldTestCase.model.xml FieldTestCase.xtest GroupTestCase.java GroupTestCase.model.xml GroupTestCase.xtest
Date Mon, 05 Sep 2005 09:21:59 GMT
Author: mpfingsthorn
Date: Mon Sep  5 02:21:46 2005
New Revision: 278702

URL: http://svn.apache.org/viewcvs?rev=278702&view=rev
Log:
New tests for the inheritance features

Added:
    cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.java
    cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.model.xml
  (with props)
    cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.xtest
Modified:
    cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.java
    cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.model.xml
    cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.xtest

Modified: cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.java?rev=278702&r1=278701&r2=278702&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.java
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.java
Mon Sep  5 02:21:46 2005
@@ -16,11 +16,16 @@
 
 package org.apache.cocoon.forms.formmodel;
 
+import junit.framework.Assert;
+
 import org.apache.cocoon.core.container.ContainerTestCase;
 import org.apache.cocoon.environment.mock.MockRequest;
 import org.apache.cocoon.forms.FormContext;
+import org.apache.cocoon.forms.datatype.typeimpl.FloatType;
 import org.apache.cocoon.forms.event.ValueChangedEvent;
 import org.apache.cocoon.forms.event.ValueChangedListener;
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.jxpath.Pointer;
 import org.w3c.dom.Document;
 
 /**
@@ -32,6 +37,7 @@
 public class FieldTestCase extends ContainerTestCase {
     
     public static final String VALUE_PATH = "fi:fragment/fi:field/fi:value";
+    public static final String LABEL_PATH = "fi:fragment/fi:field/fi:label";
     public static final String VALIDATION_PATH = "fi:fragment/fi:field/fi:validation-message";
     
     
@@ -223,5 +229,40 @@
         
         // Should have changed now
         assertEquals("bar", field.getValue());
+    }
+    
+    /**
+     * checks for correct inheritance
+     */
+    public void testInheritance() throws Exception {
+        Form form = WidgetTestHelper.loadForm(getManager(), this, "FieldTestCase.model.xml");
+        Field field = (Field)form.getChild("floatfield2");
+        MockRequest request;
+        
+        Assert.assertTrue("Datatype set correctly", (field.getDatatype() != null &&
field.getDatatype() instanceof FloatType) );
+        
+        request = new MockRequest();
+        request.addParameter("floatfield2", "9.2");
+        form.process(new FormContext(request));
+        
+        // No parsing nor validation where performed
+        Document doc = WidgetTestHelper.getWidgetFragment(field, null);
+        WidgetTestHelper.assertXPathEquals("Displayed value", "9.2", VALUE_PATH, doc);
+        
+        // check that the label is right
+        WidgetTestHelper.assertXPathEquals("Displayed label", "FloatField2", LABEL_PATH,
doc);
+        
+        // Now do some parsing. Will return null although syntactically correct as it's invalid
+        assertNull("Field value", field.getValue());
+        
+        // Now validate
+        assertFalse("Field validation", field.validate());
+        doc = WidgetTestHelper.getWidgetFragment(field, null);
+        WidgetTestHelper.assertXPathExists("Validation error after validation", VALIDATION_PATH,
doc);
+        assertNotNull("getValidationError() not null after validation", field.getValidationError());
+        
+        request = new MockRequest();
+        request.addParameter("doublefield2", "123awd");
+        form.process(new FormContext(request));
     }
 }

Modified: cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.model.xml
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.model.xml?rev=278702&r1=278701&r2=278702&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.model.xml
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.model.xml
Mon Sep  5 02:21:46 2005
@@ -32,5 +32,18 @@
         
         <fd:action id="action" action-command="blah"/>
         
+        <fd:field id="floatfield">
+            <fd:datatype base="float">
+                <fd:convertor type="plain"/>
+            </fd:datatype>
+            <fd:validation>
+                <fd:range min="10"/>
+            </fd:validation>
+        </fd:field>
+        
+        <fd:field id="floatfield2" extends="floatfield">
+            <fd:label>FloatField2</fd:label>
+        </fd:field>
+        
     </fd:widgets>
 </fd:form>

Modified: cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.xtest
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.xtest?rev=278702&r1=278701&r2=278702&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.xtest
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/FieldTestCase.xtest
Mon Sep  5 02:21:46 2005
@@ -35,11 +35,11 @@
 
   <role name="org.apache.cocoon.forms.validation.WidgetValidatorBuilderSelector"
         shorthand="forms-validators"
-        default-class="org.apache.cocoon.components.ExtendedComponentSelector"/>
+        default-class="org.apache.cocoon.core.container.DefaultServiceSelector"/>
 
   <role name="org.apache.cocoon.forms.event.WidgetListenerBuilderSelector"
         shorthand="forms-widgetlisteners"
-        default-class="org.apache.cocoon.components.ExtendedComponentSelector"/>
+        default-class="org.apache.cocoon.core.container.DefaultServiceSelector"/>
 </roles>
 
  <components>
@@ -55,7 +55,12 @@
           <convertor name="plain" src="org.apache.cocoon.forms.datatype.convertor.PlainIntegerConvertorBuilder"/>
           <convertor name="formatting" src="org.apache.cocoon.forms.datatype.convertor.FormattingIntegerConvertorBuilder"/>
         </convertors>
-      </datatype>  
+      </datatype>
+      <datatype name="float" src="org.apache.cocoon.forms.datatype.typeimpl.FloatTypeBuilder">
+        <convertors default="formatting" plain="plain">
+          <convertor name="plain" src="org.apache.cocoon.forms.datatype.convertor.PlainFloatConvertorBuilder"/>
+        </convertors>
+      </datatype>
     </datatypes>
     <!--validation-rules>
       <validation-rule name="range" src="org.apache.cocoon.forms.datatype.validationruleimpl.RangeValidationRuleBuilder"/>
@@ -75,6 +80,10 @@
   </forms-formmanager>
   
   <forms-expression logger="forms.expression"/>
+  
+  <forms-cachemanager logger="forms.cache"/>
+  
+  <forms-widgetlisteners logger="forms.listeners"/>
 
  </components>
 

Added: cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.java?rev=278702&view=auto
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.java
(added)
+++ cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.java
Mon Sep  5 02:21:46 2005
@@ -0,0 +1,52 @@
+/*
+ * Copyright 1999-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.cocoon.forms.formmodel;
+
+import junit.framework.Assert;
+
+import org.apache.cocoon.core.container.ContainerTestCase;
+import org.apache.cocoon.forms.datatype.typeimpl.IntegerType;
+
+/**
+ * Test case for CForm's Field widget
+ *
+ * @version $Id: FieldTestCase.java 106132 2004-11-21 22:29:26Z sylvain $
+ */
+
+public class GroupTestCase extends ContainerTestCase {
+    
+    
+    
+    
+    /**
+     * checks for correct inheritance
+     */
+    public void testInheritance() throws Exception {
+        Form form = WidgetTestHelper.loadForm(getManager(), this, "GroupTestCase.model.xml");
+        Field field1 = (Field)((Group)form.getChild("group2")).getChild("field1");
+        Field field2 = (Field)((Group)form.getChild("group2")).getChild("field2");
+        Field field3 = (Field)((Group)form.getChild("group2")).getChild("field3");
+        Group group2 = (Group)form.getChild("group2");
+        
+        Assert.assertNotNull("Inherited field present", field1 );
+        Assert.assertNotNull("Added field present", field2 );
+        Assert.assertNotNull("Internally inherited field present", field3 );
+        
+        // check datatype
+        Assert.assertTrue("Datatype of internally inherited field", field3.getDatatype()
instanceof IntegerType);
+    }
+}

Added: cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.model.xml
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.model.xml?rev=278702&view=auto
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.model.xml
(added)
+++ cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.model.xml
Mon Sep  5 02:21:46 2005
@@ -0,0 +1,41 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 2005 The Apache Software Foundation or its licensors,
+  as applicable.
+
+  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.
+-->
+<fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition">
+    <fd:widgets>
+        
+        <fd:group id="group1">
+            <fd:widgets>
+                <fd:field id="field1">
+                    <fd:label>Field1</fd:label>
+                    <fd:datatype base="integer"/>
+                 </fd:field>
+            </fd:widgets>
+        </fd:group>
+        
+        <fd:group id="group2" extends="group1">
+            <fd:widgets>
+                <fd:field id="field2">
+                    <fd:label>Field2</fd:label>
+                    <fd:datatype base="string"/>
+                </fd:field>
+                <fd:field id="field3" extends="field1"/>
+            </fd:widgets>
+        </fd:group>
+        
+    </fd:widgets>
+</fd:form>

Propchange: cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.model.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.xtest
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.xtest?rev=278702&view=auto
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.xtest
(added)
+++ cocoon/gsoc/mpfingsthorn/forms/test/org/apache/cocoon/forms/formmodel/GroupTestCase.xtest
Mon Sep  5 02:21:46 2005
@@ -0,0 +1,91 @@
+<?xml version="1.0" ?>
+<!--
+  Copyright 1999-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.
+-->
+<testcase>
+ <roles>
+
+  <role name="org.apache.cocoon.forms.datatype.DatatypeManager"
+        shorthand="forms-datatype"
+        default-class="org.apache.cocoon.forms.datatype.DefaultDatatypeManager"/>
+
+  <role name="org.apache.cocoon.forms.expression.ExpressionManager"
+    shorthand="forms-expression"
+    default-class="org.apache.cocoon.forms.expression.DefaultExpressionManager"/>
+
+  <role name="org.apache.cocoon.forms.FormManager"
+        shorthand="forms-formmanager"
+        default-class="org.apache.cocoon.forms.DefaultFormManager"/>
+
+  <role name="org.apache.cocoon.forms.CacheManager"
+        shorthand="forms-cachemanager"
+        default-class="org.apache.cocoon.forms.DefaultCacheManager"/>
+
+  <role name="org.apache.cocoon.forms.validation.WidgetValidatorBuilderSelector"
+        shorthand="forms-validators"
+        default-class="org.apache.cocoon.core.container.DefaultServiceSelector"/>
+
+  <role name="org.apache.cocoon.forms.event.WidgetListenerBuilderSelector"
+        shorthand="forms-widgetlisteners"
+        default-class="org.apache.cocoon.core.container.DefaultServiceSelector"/>
+</roles>
+
+ <components>
+  <forms-datatype logger="forms">
+    <datatypes>
+      <datatype name="string" src="org.apache.cocoon.forms.datatype.typeimpl.StringTypeBuilder">
+        <convertors default="dummy" plain="dummy">
+          <convertor name="dummy" src="org.apache.cocoon.forms.datatype.convertor.DummyStringConvertorBuilder"/>
+        </convertors>
+      </datatype>
+      <datatype name="integer" src="org.apache.cocoon.forms.datatype.typeimpl.IntegerTypeBuilder">
+        <convertors default="formatting" plain="plain">
+          <convertor name="plain" src="org.apache.cocoon.forms.datatype.convertor.PlainIntegerConvertorBuilder"/>
+          <convertor name="formatting" src="org.apache.cocoon.forms.datatype.convertor.FormattingIntegerConvertorBuilder"/>
+        </convertors>
+      </datatype>
+      <datatype name="float" src="org.apache.cocoon.forms.datatype.typeimpl.FloatTypeBuilder">
+        <convertors default="formatting" plain="plain">
+          <convertor name="plain" src="org.apache.cocoon.forms.datatype.convertor.PlainFloatConvertorBuilder"/>
+        </convertors>
+      </datatype>
+    </datatypes>
+    <!--validation-rules>
+      <validation-rule name="range" src="org.apache.cocoon.forms.datatype.validationruleimpl.RangeValidationRuleBuilder"/>
+    </validation-rules-->
+  </forms-datatype>
+ 	
+  <forms-validators>
+    <validator name="range" class="org.apache.cocoon.forms.validation.impl.RangeValidatorBuilder"/>
+  </forms-validators>
+  
+  <forms-formmanager>
+    <widgets>
+      <widget name="form" src="org.apache.cocoon.forms.formmodel.FormDefinitionBuilder"/>
+      <widget name="group" src="org.apache.cocoon.forms.formmodel.GroupDefinitionBuilder"/>
+      <widget name="field" src="org.apache.cocoon.forms.formmodel.FieldDefinitionBuilder"/>
+      <widget name="action" src="org.apache.cocoon.forms.formmodel.ActionDefinitionBuilder"/>
+    </widgets>
+  </forms-formmanager>
+  
+  <forms-expression logger="forms.expression"/>
+  
+  <forms-cachemanager logger="forms.cache"/>
+  
+  <forms-widgetlisteners logger="forms.listeners"/>
+
+ </components>
+
+</testcase>



Mime
View raw message