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/06/04 00:22:57 UTC

svn commit: r179904 - in /incubator/beehive/trunk/controls/test/src: controls/org/apache/beehive/controls/test/controls/property/constraint/BookControl.java units/org/apache/beehive/controls/test/java/property/ConstraintTest.java

Author: jsong
Date: Fri Jun  3 15:22:55 2005
New Revision: 179904

URL: http://svn.apache.org/viewcvs?rev=179904&view=rev
Log:
Update tests on controls property constraint, controls drt passed.

Modified:
    incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/BookControl.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=179904&r1=179903&r2=179904&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 Jun  3 15:22:55 2005
@@ -47,11 +47,11 @@
     public @interface Price
     {
         @AnnotationMemberTypes.Decimal(minValue=10)
-        public String us_price();
+        public String us_price() default "";
         @AnnotationMemberTypes.Decimal(minValue=10)
-        public String ca_price();
+        public String ca_price() default "";
         @AnnotationMemberTypes.Decimal(minValue=10)
-        public String eu_price();
+        public String eu_price() default "";
 	}
 
 	/**
@@ -65,12 +65,12 @@
     @AnnotationConstraints.MembershipRule(AnnotationConstraints.MembershipRuleValues.AT_MOST_ONE)
     public @interface Language
     {
-        @AnnotationMemberTypes.Text(maxLength=8)
-        public String coverlanguage();
-        @AnnotationMemberTypes.Text(maxLength=8)
-        public String contentlanguage();
-        @AnnotationMemberTypes.Text(maxLength=8)
-        public String authorlanguage();
+        @AnnotationMemberTypes.Text(maxLength=10)
+        public String coverlanguage() default "";
+        @AnnotationMemberTypes.Text(maxLength=10)
+        public String contentlanguage() default "";
+        @AnnotationMemberTypes.Text(maxLength=10)
+        public String authorlanguage() default "";
 	}
 
 	/**
@@ -85,15 +85,42 @@
     public @interface Intro
     {
         @AnnotationMemberTypes.Text(maxLength=8)
-        public String title();
+        public String title() default "";
         @AnnotationMemberTypes.Text(maxLength=8)
-        public String subject();
+        public String subject() default "";
         @AnnotationMemberTypes.Text(maxLength=8)
-        public String content();
+        public String content() default "";
+	}
+
+
+	/**
+	 * Negative tests: members without @AnnotationMemberTypes causes compile errors
+	 */
+
+	@PropertySet
+    @Target ({ElementType.FIELD, ElementType.TYPE})
+    @Retention(RetentionPolicy.RUNTIME)
+    @AnnotationConstraints.MembershipRule(AnnotationConstraints.MembershipRuleValues.AT_LEAST_ONE)
+    public @interface Material
+    {
+		/*
+        public Object paper;
+        public Object cover;
+        */
 	}
 
-	//A PropertySet to test ALL_IF_ANY
-	//Covered by PersonControl.Address
+
+	@PropertySet
+    @Target ({ElementType.FIELD, ElementType.TYPE})
+    @Retention(RetentionPolicy.RUNTIME)
+    @AnnotationConstraints.MembershipRule(AnnotationConstraints.MembershipRuleValues.EXACTLY_ONE)
+    public @interface Publisher
+    {
+		/*
+        public Object paper;
+        public Object cover;
+        */
+	}
 
     public String hello();
 }

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=179904&r1=179903&r2=179904&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 Jun  3 15:22:55 2005
@@ -22,6 +22,7 @@
 import java.beans.Beans;
 import junit.framework.Assert;
 import junit.framework.TestCase;
+import org.apache.beehive.controls.api.bean.Control;
 import org.apache.beehive.controls.api.bean.ControlBean;
 import org.apache.beehive.controls.test.controls.util.TestBeanContext;
 import org.apache.beehive.controls.test.controls.property.constraint.BookControl;
@@ -41,88 +42,52 @@
  */
 @Freq("detailed")
 @Status("inactive")
-@Misc("Propperty membership rules are not validated in runtime.")
+@Misc("Negative compile error tests")
 public class ConstraintTest extends TestCase
 {
-    public ConstraintTest( String s ) { super( s ); }
+    //Start of unique client programming to instantiate controls declaratively in java container
+    private TestBeanContext _testContext;
 
-    public void setUp() { }
+    public ConstraintTest(String s)throws Exception {
 
-    /**
-     * Returns a new TestBeanContext to act as a container for control testing.
-     */
-    private TestBeanContext createTestBeanContext() throws Exception
-    {
-        return new TestBeanContext();
-    }
-
-	public void testRule_AT_LEAST_ONE()throws Exception{
-
-		Report report=new Report();
-		BookControlBean book=(BookControlBean)java.beans.Beans.instantiate(
-			Thread.currentThread().getContextClassLoader() ,
-			"org.apache.beehive.controls.test.controls.property.constraint.BookControlBean");
-
-		String usprice=book.getUs_price();
-		String caprice=book.getCa_price();
-		String euprice=book.getEu_price();
-		if ((usprice==null)&&(caprice==null)&&(euprice==null))
-			fail("Rule AT_LEAST_ONE is not enforced");
-	}
-
-	public void testRule_AT_MOST_ONE()throws Exception{
-
-		Report report=new Report();
-		BookControlBean book=(BookControlBean)java.beans.Beans.instantiate(
-			Thread.currentThread().getContextClassLoader() ,
-			"org.apache.beehive.controls.test.controls.property.constraint.BookControlBean");
-
-		try{
-			book.setCoverlanguage("English");
-			book.setContentlanguage("French");
-			book.setAuthorlanguage("Spanish");
-
-			fail("No runtime exception caught when AT_MOST_ONE is violated at runtime");
-
-		}
-		catch(Exception e){
-			e.printStackTrace();
-			//when catching a membership constaint exception, test passes
-		}
-	}
+		super(s);
+    	_testContext = new TestBeanContext();
+        org.apache.beehive.controls.api.bean.Controls.initializeClient( null, this, _testContext );
 
-	public void testRule_EXACTLY_ONE()throws Exception{
-
-		Report report=new Report();
-		BookControlBean book=(BookControlBean)java.beans.Beans.instantiate(
-			Thread.currentThread().getContextClassLoader() ,
-			"org.apache.beehive.controls.test.controls.property.constraint.BookControlBean");
-
-		try{
-			book.setTitle("Title");
-			book.setSubject("Subject");
-			book.setContent("content");
-
-			fail("No runtime exception caught when EXACT_ONE is violated at runtime");
-
-		}
-		catch(Exception e){
-			e.printStackTrace();
-			//when catching a membership constaint exception, test passes
-		}
 	}
 
-	public void testRule_ALL_IF_ANY()throws Exception{
-
-		Report report=new Report();
-		PersonControlBean person=(PersonControlBean)java.beans.Beans.instantiate(
-			Thread.currentThread().getContextClassLoader() ,
-			"org.apache.beehive.controls.test.controls.property.constraint.PersonControlBean");
-
-		String province=person.getProvince();
+    public void setUp() throws Exception
+    {
+        _testContext.beginContext();
+    }
 
-		if (province==null)
-			fail("province is null:"+province);
-	}
+    public void tearDown() throws Exception
+    {
+        _testContext.endContext();
+    }
+	//End of unique client programming to instantiate controls declaratively in java container
 
+	/**
+	 * Violating AT_LEAST_ONE, should see a compile error
+	 */
+	@Control
+	//@BookControl.Publisher uncomment this line will introduce a compile error
+	//@BookControl.Material uncomment this line will introduce a compile error
+	//@BookControl.Language uncomment this line will introduce a compile error
+	private BookControlBean myAtLeastOneBook;
+
+	/**
+	 * Violating AT_MOST_ONE, should see a compile error
+	 */
+	@Control
+	//@BookControl.Language(coverlanguage="Japanese",contentlanguage="Korean") uncomment this line will cause compile error
+	private BookControlBean myAtMostOneBook;
+
+
+	/**
+	 * Violating EXACTLY_ONE, should see a compile error
+	 */
+	@Control
+	//@BookControl.Intro(title="atitle", subject="asubject") uncomment this line will cause compile error
+	private BookControlBean myExactOneBook;
 }