Author: jsong
Date: Fri Dec  3 16:21:54 2004
New Revision: 109736

URL: http://svn.apache.org/viewcvs?view=rev&rev=109736
Log:
Add tests on constrained property and bound property.
CR:ngore

Added:
   
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/BoundPropertyControl.java
   (contents, props changed)
   
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/BoundPropertyControlImpl.jcs
   (contents, props changed)
   
incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropertyInfo.java
   (contents, props changed)
   incubator/beehive/trunk/controls/test/webapps/controlsWeb/property/veto/
   
incubator/beehive/trunk/controls/test/webapps/controlsWeb/property/veto/Controller.jpf
   (contents, props changed)
Modified:
   
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/jpf/property/TestProperty.java
   
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/jws/property/TestProperty.java
   
incubator/beehive/trunk/controls/test/webapps/controlsWeb/WEB-INF/src/jws/Property.jws

Added: 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/BoundPropertyControl.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/BoundPropertyControl.java?view=auto&rev=109736
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/BoundPropertyControl.java
     Fri Dec  3 16:21:54 2004
@@ -0,0 +1,44 @@
+package org.apache.beehive.controls.test.controls.property;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.packaging.PropertyInfo;
+import org.apache.beehive.controls.api.properties.PropertySet;
+
+/**
+ * A control interface with bound and/or constrain propertySet
+ */
[EMAIL PROTECTED]
+public interface BoundPropertyControl
+{
+       static final String BRAND_DEFAULT = "DEFAULT_BRAND";
+       static final String MATERIAL_DEFAULT = "DEFAULT_MATERIAL";
+       static final String QUALITY_DEFAULT = "DEFAULT_QUALITY";
+
+       @PropertySet
+       @Retention(RetentionPolicy.RUNTIME)
+       public @interface Wheel
+       {
+               @PropertyInfo(bound=true)
+               public String Brand() default BRAND_DEFAULT;
+    }
+
+       @PropertySet
+       @Retention(RetentionPolicy.RUNTIME)
+       public @interface Door
+       {
+               @PropertyInfo(constrained=true)
+               public String Material() default MATERIAL_DEFAULT;
+    }
+
+       @PropertySet
+       @Retention(RetentionPolicy.RUNTIME)
+       public @interface Window
+       {
+               @PropertyInfo(bound=true,constrained=true)
+               public String Quality() default QUALITY_DEFAULT;
+    }
+
+       public String sayHello();
+}

Added: 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/BoundPropertyControlImpl.jcs
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/BoundPropertyControlImpl.jcs?view=auto&rev=109736
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/BoundPropertyControlImpl.jcs
  Fri Dec  3 16:21:54 2004
@@ -0,0 +1,26 @@
+package org.apache.beehive.controls.test.controls.property;
+
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.beehive.controls.api.context.Context;
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+
+/**
+ * A control impl that accesses the property declared by its control interface 
via control context
+ */
+
[EMAIL PROTECTED]
+public class BoundPropertyControlImpl implements BoundPropertyControl
+{ 
+    @Context ControlBeanContext context;
+
+    /*Accesses the propertySet value and returns the value*/
+    public String sayHello()
+    {
+       /**BUG: could not refer to Greeting directly*/
+        //Greeting 
greeting=(SingleProperty.Greeting)context.getControlPropertySet(SingleProperty.Greeting.class);
+        
+        //return greeting.GreetWord();
+        return "Hello";
+    }
+
+} 
\ No newline at end of file

Added: 
incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropertyInfo.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropertyInfo.java?view=auto&rev=109736
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropertyInfo.java
   Fri Dec  3 16:21:54 2004
@@ -0,0 +1,154 @@
+package org.apache.beehive.controls.test.driver.property;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyVetoException;
+import java.beans.VetoableChangeListener;
+import org.apache.beehive.test.tools.milton.common.Report;
+import org.apache.beehive.controls.test.controls.property.BoundPropertyControl;
+import 
org.apache.beehive.controls.test.controls.property.BoundPropertyControlBean;
+
+/* Tests bound and constrained propertySets declared on controls
+ */
+public class DrivePropertyInfo
+{
+       private boolean propertyChanged=false;
+       private boolean vetoExceptionCaught=false;
+
+    class ChangeTestListener implements java.beans.PropertyChangeListener
+    {
+        /**
+         * Implementation of PropertyChangeListener.propertyChange().
+         * Record all the chages
+         */
+        public void propertyChange(PropertyChangeEvent pce)
+        {
+                       //record it
+                       propertyChanged=true;
+        }
+    }
+
+    class VetoableTestListener implements VetoableChangeListener
+    {
+        /**
+         * Implementation of PropertyChangeListener.propertyChange().
+         * Veto all the change
+         */
+        public void vetoableChange(PropertyChangeEvent pce) throws 
PropertyVetoException
+        {
+            // Veto attempts to set even values
+                       throw new PropertyVetoException("Sorry", pce);
+        }
+    }
+
+       private BoundPropertyControlBean myControl;
+
+       public void setControl(BoundPropertyControlBean aControl){
+
+               myControl=aControl;
+       }
+
+       /* If a constrained property change is veto-ed, the property should not 
be changed
+        * And a PropertyVetoException should be caught.
+        */
+       public Report doVetoChangeOnConstrainedProperty(){
+
+               propertyChanged=false;
+               vetoExceptionCaught=false;
+
+               Report report=new Report();
+
+               if (myControl==null){
+                       report.setStatus(Report.FAIL);
+                       report.setMessage("the control is NULL");
+               }
+               else
+               {
+               // Create a new test listener and register it on the test bean
+               ChangeTestListener ctl = new ChangeTestListener();
+               myControl.addPropertyChangeListener(ctl);
+
+               // Create a new test listener and register it on the test bean
+               VetoableTestListener vtl = new VetoableTestListener();
+               myControl.addVetoableChangeListener(vtl);
+
+                       try{
+                               myControl.setQuality("New_Quality");
+                       }
+                       catch(PropertyVetoException 
e){vetoExceptionCaught=true;}
+
+                       if (vetoExceptionCaught){
+                               if (propertyChanged){
+                                       report.setStatus(Report.FAIL);
+                                       report.setMessage("PropertyChanged 
listener is invoked");
+                               }
+                               else{
+                                       String 
theQuality=myControl.getQuality();
+
+                                       if 
(theQuality.equals(BoundPropertyControl.QUALITY_DEFAULT))
+                                               report.setStatus(Report.PASS);
+                                       else{
+                                               report.setStatus(Report.FAIL);
+                                               report.setMessage("Property 
value changed to:"+theQuality+
+                                                       ". Although 
PropertyChangedEvent not received.");
+                                       }
+                               }
+                       }
+                       else{
+                               report.setStatus(Report.FAIL);
+                               report.setMessage("PropertyVetoException not 
caught");
+                       }
+               }
+               return report;
+       }
+
+
+       /* Change on unconstrained property should go succeed.*/
+       public Report doVetoChangeOnUnConstrainedProperty(){
+
+               propertyChanged=false;
+               vetoExceptionCaught=false;
+
+               Report report=new Report();
+
+               if (myControl==null){
+                       report.setStatus(Report.FAIL);
+                       report.setMessage("the control is NULL");
+               }
+               else
+               {
+               // Create a new test listener and register it on the test bean
+               ChangeTestListener ctl = new ChangeTestListener();
+               myControl.addPropertyChangeListener(ctl);
+
+               // Create a new test listener and register it on the test bean
+               VetoableTestListener vtl = new VetoableTestListener();
+               myControl.addVetoableChangeListener(vtl);
+
+                       myControl.setBrand("New_Brand");
+
+                       if (!vetoExceptionCaught){
+                               if (!propertyChanged){
+                                       report.setStatus(Report.FAIL);
+                                       report.setMessage("PropertyChanged 
listener is NOT invoked");
+                               }
+                               else{
+                                       String theBrand=myControl.getBrand();
+
+                                       if (theBrand.equals("New_Brand"))
+                                               report.setStatus(Report.PASS);
+                                       else{
+                                               report.setStatus(Report.FAIL);
+                                               report.setMessage("Property 
value changed to:"+theBrand+
+                                                       " 
afterPropertyChangedEvent not received.");
+                                       }
+                               }
+                       }
+                       else{
+                               report.setStatus(Report.FAIL);
+                               report.setMessage("PropertyVetoException is 
caught");
+                       }
+               }
+               return report;
+       }
+}
\ No newline at end of file

Modified: 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/jpf/property/TestProperty.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/jpf/property/TestProperty.java?view=diff&rev=109736&p1=incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/jpf/property/TestProperty.java&r1=109735&p2=incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/jpf/property/TestProperty.java&r2=109736
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/jpf/property/TestProperty.java
     (original)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/jpf/property/TestProperty.java
     Fri Dec  3 16:21:54 2004
@@ -74,4 +74,13 @@
     {
                
assertReport("/controlsWeb/property/client_impl2/Controller.jpf");
     }
+
+    /**
+     * Tests vetoing the change of a constrained property
+     */
+       @Freq("checkin")
+    public void testVetoPropertyChange() throws Exception
+    {
+               assertReport("/controlsWeb/property/veto/Controller.jpf");
+    }
 }

Modified: 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/jws/property/TestProperty.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/jws/property/TestProperty.java?view=diff&rev=109736&p1=incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/jws/property/TestProperty.java&r1=109735&p2=incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/jws/property/TestProperty.java&r2=109736
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/jws/property/TestProperty.java
     (original)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/jws/property/TestProperty.java
     Fri Dec  3 16:21:54 2004
@@ -75,4 +75,22 @@
     {
                
assertReport("http://localhost:8080/controlsWeb/jws/Property.jws","testSetters2";);
     }
+
+    /**
+     * Tests vetoing change made to a constrained property
+     */
+       @Freq("checkin")
+    public void testVetoChangeOnConstrainedProperty() throws Exception
+    {
+               
assertReport("http://localhost:8080/controlsWeb/jws/Property.jws","testVetoChangeOnConstrainedProperty";);
+    }
+
+    /**
+     * Tests vetoing change made to an uncontrained property
+     */
+       @Freq("checkin")
+    public void testVetoChangeOnUnConstrainedProperty() throws Exception
+    {
+               
assertReport("http://localhost:8080/controlsWeb/jws/Property.jws","testVetoChangeOnUnConstrainedProperty";);
+    }
 }

Modified: 
incubator/beehive/trunk/controls/test/webapps/controlsWeb/WEB-INF/src/jws/Property.jws
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/webapps/controlsWeb/WEB-INF/src/jws/Property.jws?view=diff&rev=109736&p1=incubator/beehive/trunk/controls/test/webapps/controlsWeb/WEB-INF/src/jws/Property.jws&r1=109735&p2=incubator/beehive/trunk/controls/test/webapps/controlsWeb/WEB-INF/src/jws/Property.jws&r2=109736
==============================================================================
--- 
incubator/beehive/trunk/controls/test/webapps/controlsWeb/WEB-INF/src/jws/Property.jws
      (original)
+++ 
incubator/beehive/trunk/controls/test/webapps/controlsWeb/WEB-INF/src/jws/Property.jws
      Fri Dec  3 16:21:54 2004
@@ -30,6 +30,9 @@
 import org.apache.beehive.controls.test.driver.property.DriveGetters;
 import org.apache.beehive.controls.test.driver.property.DriveSetters;
 import org.apache.beehive.controls.test.driver.property.DriveContextAccess;
+
+import org.apache.beehive.controls.test.driver.property.DrivePropertyInfo;
+import 
org.apache.beehive.controls.test.controls.property.BoundPropertyControlBean;
 import org.apache.beehive.test.tools.milton.common.Report;
 
 
@@ -40,6 +43,9 @@
     @Control
     public PropertyControlBean myControl;
 
+    @Control
+    public BoundPropertyControlBean myBoundPropertyControl;
+
     /*
      * Get a control property by getters on the control bean class.
      * The control is instantiated declaratively.
@@ -172,6 +178,33 @@
                report.setStatus(Report.FAIL);
                report.setExceptionStack(e);
         }
+        return report;
+    }
+
+    /*
+     * Test veto-ing a the change on a constrained property
+     */
+    @WebMethod
+    public Report testVetoChangeOnConstrainedProperty()
+    {        
+       Report report=new Report();
+       DrivePropertyInfo driver=new DrivePropertyInfo();
+       driver.setControl(myBoundPropertyControl);
+       report=driver.doVetoChangeOnConstrainedProperty();
+        return report;
+    }
+
+
+    /*
+     * Test veto-ing a the change on a unconstrained property
+     */
+    @WebMethod
+    public Report testVetoChangeOnUnConstrainedProperty()
+    {        
+       Report report=new Report();
+       DrivePropertyInfo driver=new DrivePropertyInfo();
+       driver.setControl(myBoundPropertyControl);
+       report=driver.doVetoChangeOnUnConstrainedProperty();
         return report;
     }
     

Added: 
incubator/beehive/trunk/controls/test/webapps/controlsWeb/property/veto/Controller.jpf
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/webapps/controlsWeb/property/veto/Controller.jpf?view=auto&rev=109736
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/test/webapps/controlsWeb/property/veto/Controller.jpf
      Fri Dec  3 16:21:54 2004
@@ -0,0 +1,66 @@
+/*
+ *
+ * N E T U I
+ *
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * All Rights Reserved. Unpublished rights reserved under the copyright laws
+ * of the United States. The software contained on this media is proprietary
+ * to and embodies the confidential technology of BEA Systems, Inc. The
+ * possession or receipt of this information does not convey any right to
+ * disclose its contents, reproduce it, or use,  or license the use,
+ * for manufacture or sale, the information or anything described
+ * therein. Any use, disclosure, or reproduction without BEA System's
+ * prior written permission is strictly prohibited.
+ *
+ * $Header:$
+ */
+package property.veto;
+
+import org.apache.beehive.netui.pageflow.PageFlowController;
+import org.apache.beehive.netui.pageflow.Forward;
+import org.apache.beehive.netui.pageflow.FormData;
+import org.apache.beehive.netui.pageflow.annotations.Jpf;
+
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.bean.ControlBean;
+import 
org.apache.beehive.controls.test.controls.property.BoundPropertyControlBean;
+import org.apache.beehive.controls.test.driver.property.DrivePropertyInfo;
+import org.apache.beehive.test.tools.milton.common.Report;
+
+/* Tests client veto-ing the changing of a constrained property
+ */
+
[EMAIL PROTECTED](
+    forwards = {
+        @Jpf.Forward(name=Report.RESULTS,path = Report.RESULTSJSP) 
+    })
+public class Controller extends PageFlowController
+{
+    @Control
+    public BoundPropertyControlBean myControl;
+  
+    /**
+     * @jpf:action
+     */
+    @Jpf.Action(
+        )
+    protected Forward begin(){
+       
+       Report report=new Report();
+       DrivePropertyInfo driver=new DrivePropertyInfo();
+       try{
+               driver.setControl(myControl);
+               report=driver.doVetoChangeOnConstrainedProperty();
+        }
+        catch(Exception e){
+               
+               report.setStatus(Report.FAIL);
+               report.setExceptionStack(e);
+        }
+        return new Forward(Report.RESULTS, Report.KEY, report);
+    }
+
+}
+
+

Reply via email to