Author: jsong
Date: Fri Jan 28 08:53:41 2005
New Revision: 148901

URL: http://svn.apache.org/viewcvs?view=rev&rev=148901
Log:
Add tests for controls property constraint.

Added:
   
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/
   
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java
   
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControlImpl.jcs
   
incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropertyConstraint2.java

Added: 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java?view=auto&rev=148901
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java
 Fri Jan 28 08:53:41 2005
@@ -0,0 +1,83 @@
+package org.apache.beehive.controls.test.controls.property.constraint;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.beehive.controls.api.bean.AnnotationMemberTypes;
+import org.apache.beehive.controls.api.bean.AnnotationConstraints;
+import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.properties.PropertySet;
+
+/**
+ * A control interface that declares PropertySets with constraints
+ */
+
[EMAIL PROTECTED]
+public interface PersonControl
+{
+
+       public final static String SAVINGS_MIN_VALUE="100";
+       public final static String ISSUEDATE_MAXVALUE="2007/01/31";
+       public final static String EXPIRYDATE_MINVALUE="2007/01/32";
+       //public final static String ISSUEDATE_MAXVALUE=null;
+
+    @PropertySet
+    @Target ({ElementType.FIELD, ElementType.TYPE})
+    @Retention(RetentionPolicy.RUNTIME)
+    
@AnnotationConstraints.MembershipRule(AnnotationConstraints.MembershipRuleValues.ALL_IF_ANY)
+    public @interface Address
+    {
+        @AnnotationMemberTypes.Text(maxLength=8)
+        public String street() default "";
+        @AnnotationMemberTypes.Text(maxLength=8)
+        public String city() default "";
+        @AnnotationMemberTypes.Text(maxLength=8)
+        public String province() default "";
+        @AnnotationMemberTypes.Int(minValue=0, maxValue=100000)
+        public int zipcode() default 0;
+    }
+
+
+    @PropertySet
+    @Target ({ElementType.FIELD, ElementType.TYPE})
+    @Retention(RetentionPolicy.RUNTIME)
+    @AnnotationConstraints.AllowExternalOverride
+    public @interface Assets
+    {
+               //JIRA-203 AnnotationMemberTypes.Decimal should support float
+        @AnnotationMemberTypes.Decimal(places=2, minValue=SAVINGS_MIN_VALUE, 
maxValue="10000")
+        public String savings() default "0";
+    }
+
+    @PropertySet
+    @Target ({ElementType.FIELD, ElementType.TYPE})
+    @Retention(RetentionPolicy.RUNTIME)
+    public @interface ID
+    {
+        @AnnotationMemberTypes.Text(isLong=true)
+        public String idnumber() default "0";
+    }
+
+
+    @PropertySet
+    @Target ({ElementType.FIELD, ElementType.TYPE})
+    @Retention(RetentionPolicy.RUNTIME)
+    public @interface DriverLicense
+    {
+        @AnnotationMemberTypes.Date(maxValue=ISSUEDATE_MAXVALUE)
+        public String issuedate() default "";
+        @AnnotationMemberTypes.Date(minValue=EXPIRYDATE_MINVALUE)
+        public String expirydate() default "";
+
+        /* Test passing a null to revokedate.
+           Commented out temporarily
+        @AnnotationMemberTypes.Date(minValue=ISSUEDATE_MAXVALUE)
+        public String revokedate() default null;
+        */
+    }
+
+    public String hello();
+
+}

Added: 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControlImpl.jcs
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControlImpl.jcs?view=auto&rev=148901
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControlImpl.jcs
      Fri Jan 28 08:53:41 2005
@@ -0,0 +1,20 @@
+package org.apache.beehive.controls.test.controls.property.constraint;
+
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.beehive.controls.api.bean.Extensible;
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+import org.apache.beehive.controls.api.context.Context;
+
[EMAIL PROTECTED]
+public class PersonControlImpl implements PersonControl
+{
+    @Context ControlBeanContext ctx;
+
+    public String hello()
+    {
+        //Person person = (Person)ctx.getControlPropertySet(Person.class);
+        //return "Hello " + person.name();
+        return "Hello";
+    }
+
+}

Added: 
incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropertyConstraint2.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropertyConstraint2.java?view=auto&rev=148901
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropertyConstraint2.java
    Fri Jan 28 08:53:41 2005
@@ -0,0 +1,125 @@
+package org.apache.beehive.controls.test.driver.property;
+
+import org.apache.beehive.test.tools.milton.common.Report;
+import 
org.apache.beehive.controls.test.controls.property.constraint.PersonControl;
+import 
org.apache.beehive.controls.test.controls.property.constraint.PersonControlBean;
+import org.apache.beehive.test.tools.milton.annotations.Milton;
+
+/**
+ * Tests property constraint by exercising PersonControl
+ */
[EMAIL PROTECTED]
+public class DrivePropertyConstraint2
+{
+
+       @Milton.Test
+       public Report testPropertyConstraint(PersonControlBean control){
+
+               Report report=new Report();
+        report.setStatus(Report.PASS);
+
+               if (control==null){
+                       report.setStatus(Report.FAIL);
+                       report.setMessage("The control is NULL");
+            return report;
+               }
+
+        //Test isLong constraint for a Text
+        try
+        {
+            control.setIdnumber("A String that is not a LONG");
+            report.setStatus(Report.FAIL);
+            report.setMessage("A String which is not a long assigned to isLong 
Text.");
+            return report;
+
+        }
+        catch (IllegalArgumentException e)
+        {
+        }
+
+        //Test Decimal.places
+        try
+        {
+            control.setSavings("99.999");
+            report.setStatus(Report.FAIL);
+            report.setMessage("99.999 assigned to a property of two-place 
Decimal");
+            return report;
+        }
+        catch (IllegalArgumentException e)
+        {
+            //expected exception
+        }
+
+        //Test Decimal.minValue
+        try
+        {
+            control.setSavings("99");
+                       report.setStatus(Report.FAIL);
+                       report.setMessage("99 is less than minValue and 
assigned to the property.");
+            return report;
+        }
+        catch (IllegalArgumentException e)
+        {
+                       //expected result
+        }
+
+        //Test Decimal.maxValue
+        try
+        {
+            control.setSavings("10000.01");
+                       report.setStatus(Report.FAIL);
+                       report.setMessage("10000.01 is greater than maxValue 
and assigned to the property.");
+            return report;
+        }
+        catch (IllegalArgumentException e)
+        {
+                       //expected result
+        }
+
+
+        //Test Date.maxValue
+        try
+        {
+            control.setIssuedate("2007/02/01");
+                       report.setStatus(Report.FAIL);
+                       report.setMessage("2007/02/01 is greater than maxValue 
and assigned to the property.");
+            return report;
+        }
+        catch (IllegalArgumentException e)
+        {
+                       //expected result
+        }
+
+        //Test assigning a invalid value
+        try
+        {
+            control.setIssuedate("2006/02/30");
+                       report.setStatus(Report.FAIL);
+                       report.setMessage("2006/02/30 is invalid and assigned 
to a date property.");
+            return report;
+        }
+        catch (IllegalArgumentException e)
+        {
+                       //expected result
+        }
+
+
+        //Test invalid constraint: Person.DriverLicense.expirydate is invalid 
by design
+        try
+        {
+            control.setExpirydate("2007/02/20");
+                       report.setStatus(Report.FAIL);
+                       report.setMessage("2007/02/20 is assigned to an invalid 
date property.");
+            return report;
+        }
+        catch (IllegalArgumentException e)
+        {
+                       //expected result
+                       //report.setStatus(Report.FAIL);
+                       //report.setExceptionStack(e);
+        }
+
+               return report;
+       }
+
+}

Reply via email to