You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by js...@apache.org on 2005/05/06 22:39:08 UTC
svn commit: r168650 - in /incubator/beehive/trunk/controls/test/src:
controls/org/apache/beehive/controls/test/controls/property/constraint/BookControl.java
controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java
units/org/apache/beehive/controls/test/java/property/ConstraintTest.java
Author: jsong
Date: Fri May 6 13:39:08 2005
New Revision: 168650
URL: http://svn.apache.org/viewcvs?rev=168650&view=rev
Log:
Update detailed tests for controls property constraint.
Modified:
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/BookControl.java
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/property/ConstraintTest.java
Modified: incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/BookControl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/BookControl.java?rev=168650&r1=168649&r2=168650&view=diff
==============================================================================
--- incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/BookControl.java (original)
+++ incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/BookControl.java Fri May 6 13:39:08 2005
@@ -17,7 +17,11 @@
@ControlInterface
public interface BookControl
{
- //A PropertySet to test AT_LEAST_ONE
+ /**
+ * A propertySet with AT_LEAST_ONE constraint
+ * User needs to set at least one value when instantiating controls declaratively;
+ * It is unknow what will happens when instantiating controls programmatically.
+ */
@PropertySet
@Target ({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@@ -32,7 +36,11 @@
public String eu_price();
}
- //A PropertySet to test AT_MOST_ONE
+ /**
+ * A propertySet with AT_MOST_ONE
+ * User can not set more than one value when instantiating controls declaratively;
+ * It is unknow what will happens when instantiating controls programmatically.
+ */
@PropertySet
@Target ({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@@ -40,15 +48,19 @@
public @interface Language
{
@AnnotationMemberTypes.Text(maxLength=8)
- public String coverlanguage() default "English";
+ public String coverlanguage();
@AnnotationMemberTypes.Text(maxLength=8)
- public String contentlanguage() default "French";
+ public String contentlanguage();
@AnnotationMemberTypes.Text(maxLength=8)
public String authorlanguage();
}
- //A PropertySet to test EXACTLY_ONE
- @PropertySet
+ /**
+ * A propertySet with EXACTLY_ONE
+ * User must set one value, and only one value when instantiating controls declaratively;
+ * It is unknow what will happens when instantiating controls programmatically.
+ */
+ @PropertySet
@Target ({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@AnnotationConstraints.MembershipRule(AnnotationConstraints.MembershipRuleValues.EXACTLY_ONE)
Modified: 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?rev=168650&r1=168649&r2=168650&view=diff
==============================================================================
--- incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java (original)
+++ incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java Fri May 6 13:39:08 2005
@@ -23,6 +23,11 @@
public final static String EXPIRYDATE_MINVALUE="2007/02/28";
//public final static String ISSUEDATE_MAXVALUE=null;
+ /**
+ * A propertySet with ALL_IF_ANY
+ * Rule is enforced at build time when users instantiate the control declaratively.
+ * It is unknow what will happens when instantiating controls programmatically.
+ */
@PropertySet
@Target ({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@@ -30,14 +35,11 @@
public @interface Address
{
@AnnotationMemberTypes.Text(maxLength=8)
- public String street() default "";
+ public String street();
@AnnotationMemberTypes.Text(maxLength=8)
- public String city() default "";
+ public String city();
@AnnotationMemberTypes.Text(maxLength=8)
public String province();
- //public String province() default "";
- //Test ALL_IF_ANY
-
@AnnotationMemberTypes.Int(minValue=0, maxValue=100000)
public int zipcode() default 0;
Modified: incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/property/ConstraintTest.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/property/ConstraintTest.java?rev=168650&r1=168649&r2=168650&view=diff
==============================================================================
--- incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/property/ConstraintTest.java (original)
+++ incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/property/ConstraintTest.java Fri May 6 13:39:08 2005
@@ -15,9 +15,12 @@
import org.apache.beehive.test.tools.mantis.annotations.tch.Freq;
import org.apache.beehive.test.tools.mantis.annotations.tch.Status;
+import org.apache.beehive.controls.runtime.bean.AnnotationConstraintValidator;
-
-
+/**
+ * Test objective: to trigger runtime validation for property constraint rule.
+ * Condition: According to dev, runtime validation is trigger when all properties are set.
+ */
public class ConstraintTest extends TestCase
{
public ConstraintTest( String s ) { super( s ); }
@@ -32,6 +35,7 @@
return new TestBeanContext();
}
@Freq("detailed")
+ @Status("inactive")
public void testRule_AT_LEAST_ONE()throws Exception{
Report report=new Report();
@@ -52,42 +56,19 @@
BookControlBean book=(BookControlBean)java.beans.Beans.instantiate(
Thread.currentThread().getContextClassLoader() ,
"org.apache.beehive.controls.test.controls.property.constraint.BookControlBean");
- /*
- int count=0;
- String coverlanguage=book.getCoverlanguage();
- String contentlanguage=book.getContentlanguage();
- String authorlanguage=book.getAuthorlanguage();
-
- if(coverlanguage!=null)
- count=count+1;
- if(contentlanguage!=null)
- count=count+1;
- if(authorlanguage!=null)
- count=count+1;
-
- if (count>1)
- fail("AT_MOST_ONE is not enforced");
- */
+
try{
book.setCoverlanguage("English");
+ book.setContentlanguage("French");
+ //This should trigger AnnotationConstraintValidator.validateMembership by setting ALL the properties
book.setAuthorlanguage("Spanish");
- String cover=book.getCoverlanguage();
- String author=book.getAuthorlanguage();
-
- System.out.println("******************************************************");
- System.out.println(cover);
- System.out.println(author);
- System.out.println("******************************************************");
-
- Assert.assertEquals("English",book.getCoverlanguage());
- Assert.assertNull(book.getAuthorlanguage());
+ fail("No runtime exception caught when AT_MOST_ONE is violated at runtime");
}
catch(Exception e){
e.printStackTrace();
- fail(e.getMessage());
-
+ //runtime exception caught, test passes
}
}
@Freq("detailed")
@@ -98,22 +79,23 @@
Thread.currentThread().getContextClassLoader() ,
"org.apache.beehive.controls.test.controls.property.constraint.BookControlBean");
- int count=0;
- String coverlanguage=book.getCoverlanguage();
- String contentlanguage=book.getContentlanguage();
- String authorlanguage=book.getAuthorlanguage();
-
- if(coverlanguage!=null)
- count=count+1;
- if(contentlanguage!=null)
- count=count+1;
- if(authorlanguage!=null)
- count=count+1;
+ try{
+ book.setTitle("Book Title");
+ //This should cause runtime exception by violating EXACT_ONE rule
+ book.setSubject("Book Subject");
+ //Problem: rule validation is triggered BEFORE all properties is set
+ //book.setContent("Book content");
+
+ fail("No runtime exception caught when EXACT_ONE is violated at runtime");
- if (!(count==1))
- fail("EXACTLY_ONE is not enforced");
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ //runtime exception caught, test passes
+ }
}
@Freq("detailed")
+ @Status("inactive")
public void testRule_ALL_IF_ANY()throws Exception{
Report report=new Report();