You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by tv...@apache.org on 2009/09/10 10:06:08 UTC

svn commit: r813291 - in /turbine/fulcrum/trunk/intake: src/java/org/apache/fulcrum/intake/model/ src/test/ src/test/org/apache/fulcrum/intake/ src/test/org/apache/fulcrum/intake/test/ xdocs/

Author: tv
Date: Thu Sep 10 08:06:08 2009
New Revision: 813291

URL: http://svn.apache.org/viewvc?rev=813291&view=rev
Log:
Intake will now support interfaces for the mapTo() method. Added a test to prove this. Fixes TRB-11

Added:
    turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/LoginFormInterface.java   (with props)
Modified:
    turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Group.java
    turbine/fulcrum/trunk/intake/src/test/intake1.xml
    turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/IntakeTest.java
    turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/LoginForm.java
    turbine/fulcrum/trunk/intake/xdocs/changes.xml

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Group.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Group.java?rev=813291&r1=813290&r2=813291&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Group.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/Group.java Thu Sep 10 08:06:08 2009
@@ -206,6 +206,21 @@
                 }
             }
 
+            // Also check any interfaces
+            Class[] interfaces = cls.getInterfaces();
+            for (int idx = 0; idx < interfaces.length; idx++)
+            {
+                Field[] interfaceFields =
+                    (Field[]) mapToObjectFields.get(interfaces[idx].getName());
+                if (interfaceFields != null)
+                {
+                    for (int i = 0; i < interfaceFields.length; i++)
+                    {
+                        interfaceFields[i].init(obj);
+                    }
+                }
+            }
+            
             cls = cls.getSuperclass();
         }
 
@@ -369,8 +384,24 @@
                 }
             }
 
+            // Also check any interfaces
+            Class[] interfaces = cls.getInterfaces();
+            for (int idx = 0; idx < interfaces.length; idx++)
+            {
+                Field[] interfaceFields =
+                    (Field[]) mapToObjectFields.get(interfaces[idx].getName());
+                if (interfaceFields != null)
+                {
+                    for (int i = 0; i < interfaceFields.length; i++)
+                    {
+                        interfaceFields[i].setProperty(obj);
+                    }
+                }
+            }            
+
             cls = cls.getSuperclass();
         }
+        
         log.debug("setProperties() finished");
     }
 
@@ -402,6 +433,28 @@
                 }
             }
 
+            // Also check any interfaces
+            Class[] interfaces = cls.getInterfaces();
+            for (int idx = 0; idx < interfaces.length; idx++)
+            {
+                Field[] interfaceFields =
+                    (Field[]) mapToObjectFields.get(interfaces[idx].getName());
+                if (interfaceFields != null)
+                {
+                    for (int i = 0; i < interfaceFields.length; i++)
+                    {
+                        try
+                        {
+                            interfaceFields[i].setProperty(obj);
+                        }
+                        catch(Exception e)
+                        {
+                            // just move on to next field
+                        }
+                    }
+                }
+            }            
+
             cls = cls.getSuperclass();
         }
     }
@@ -430,6 +483,21 @@
                 }
             }
 
+            // Also check any interfaces
+            Class[] interfaces = cls.getInterfaces();
+            for (int idx = 0; idx < interfaces.length; idx++)
+            {
+                Field[] interfaceFields =
+                    (Field[]) mapToObjectFields.get(interfaces[idx].getName());
+                if (interfaceFields != null)
+                {
+                    for (int i = 0; i < interfaceFields.length; i++)
+                    {
+                        interfaceFields[i].getProperty(obj);
+                    }
+                }
+            }
+
             cls = cls.getSuperclass();
         }
     }

Modified: turbine/fulcrum/trunk/intake/src/test/intake1.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/test/intake1.xml?rev=813291&r1=813290&r2=813291&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/test/intake1.xml (original)
+++ turbine/fulcrum/trunk/intake/src/test/intake1.xml Thu Sep 10 08:06:08 2009
@@ -23,10 +23,15 @@
 	<group name="LoginGroup" key="loginGroupKey" mapToObject="LoginForm">
 		<field name="Username" key="loginUsernameKey" type="String"
 			mapToProperty="Username">
-
 		</field>
 	</group>
 
+    <group name="LoginIfcGroup" key="loginIfcGroupKey" mapToObject="LoginFormInterface">
+        <field name="Username" key="loginUsernameKey" type="String"
+            mapToProperty="Username">
+        </field>
+    </group>
+
 	<group name="BooleanTest" key="bt">
 		<field name="EmptyBooleanTestField" key="ebtf" type="boolean"/>
 		<field name="BooleanTestField" key="btf" type="boolean">

Modified: turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/IntakeTest.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/IntakeTest.java?rev=813291&r1=813290&r2=813291&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/IntakeTest.java (original)
+++ turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/IntakeTest.java Thu Sep 10 08:06:08 2009
@@ -19,11 +19,15 @@
  * under the License.
  */
 
-import org.apache.fulcrum.testcontainer.BaseUnitTest;
 import org.apache.fulcrum.intake.model.Field;
 import org.apache.fulcrum.intake.model.Group;
+import org.apache.fulcrum.intake.test.LoginForm;
 import org.apache.fulcrum.intake.validator.BooleanValidator;
 import org.apache.fulcrum.intake.validator.ValidationException;
+import org.apache.fulcrum.parser.DefaultParameterParser;
+import org.apache.fulcrum.parser.ParserService;
+import org.apache.fulcrum.parser.ValueParser;
+import org.apache.fulcrum.testcontainer.BaseUnitTest;
 /**
  * Test the facade class for the service
  *
@@ -72,6 +76,27 @@
 		assertNotNull(group);
     }
 
+    public void testInterfaceMapTo() throws Exception
+    {
+        IntakeService is = (IntakeService) this.resolve( IntakeService.class.getName() );
+        Group group = is.getGroup("LoginIfcGroup");
+        assertNotNull(group);
+        
+        Field userNameField = group.get("Username");
+        
+        ParserService ps = (ParserService) this.resolve( ParserService.class.getName() );
+        ValueParser pp = ps.getParser(DefaultParameterParser.class);
+        
+        pp.setString(userNameField.getKey(), "Joe");
+        userNameField.init(pp);
+        userNameField.validate();
+        
+        LoginForm form = new LoginForm();
+        group.setProperties(form);
+        
+        assertEquals("User names should be equal", "Joe", form.getUsername());
+    }
+
     public void testEmptyBooleanField() throws Exception
     {
         IntakeService is = (IntakeService) this.resolve( IntakeService.class.getName() );

Modified: turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/LoginForm.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/LoginForm.java?rev=813291&r1=813290&r2=813291&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/LoginForm.java (original)
+++ turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/LoginForm.java Thu Sep 10 08:06:08 2009
@@ -1,6 +1,5 @@
 package org.apache.fulcrum.intake.test;
 
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -20,29 +19,32 @@
  * under the License.
  */
 
-
 /**
  * Test form for Intake
- *
+ * 
  * @author <a href="mailto:epugh@upstate.com">epugh@upstate.com</a>
  * @version $Id$
  */
 
-public class LoginForm {
+public class LoginForm implements LoginFormInterface
+{
 
-private String username;
-/**
- * @return
- */
-public String getUsername() {
-  return username;
-}
+    private String username;
 
-/**
- * @param username
- */
-public void setUsername(String username) {
-  this.username = username;
-}
+    /**
+     * @return the user name
+     */
+    public String getUsername()
+    {
+        return username;
+    }
+
+    /**
+     * @param username the user name
+     */
+    public void setUsername(String username)
+    {
+        this.username = username;
+    }
 
 }

Added: turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/LoginFormInterface.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/LoginFormInterface.java?rev=813291&view=auto
==============================================================================
--- turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/LoginFormInterface.java (added)
+++ turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/LoginFormInterface.java Thu Sep 10 08:06:08 2009
@@ -0,0 +1,40 @@
+package org.apache.fulcrum.intake.test;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * Test form interface for Intake
+ * 
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id: LoginForm.java 535465 2007-05-05 06:58:06Z tv $
+ */
+
+public interface LoginFormInterface
+{
+    /**
+     * @return the user name
+     */
+    String getUsername();
+
+    /**
+     * @param username the user name
+     */
+    void setUsername(String username);
+}

Propchange: turbine/fulcrum/trunk/intake/src/test/org/apache/fulcrum/intake/test/LoginFormInterface.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: turbine/fulcrum/trunk/intake/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/xdocs/changes.xml?rev=813291&r1=813290&r2=813291&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/xdocs/changes.xml (original)
+++ turbine/fulcrum/trunk/intake/xdocs/changes.xml Thu Sep 10 08:06:08 2009
@@ -26,6 +26,9 @@
 
   <body>
   	 <release version="1.0.4-dev" date="in Subversion">
+      <action type="fix" dev="tv" issue="TRB-11" due-to="Evan Koffler">
+        Intake won't use interfaces for the mapTo() method.
+      </action>
       <action type="fix" dev="tv" issue="TRB-74" due-to="Susi Berrington">
         The number validators did not set an invalid number message when initialized with
         the default constructor