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 2004/10/14 00:45:28 UTC

svn commit: rev 54756 - in incubator/beehive/trunk/controls/test: src/controls/org/apache/beehive/controls/test/controls/contextevent src/drivers/org/apache/beehive/controls/test/driver/contextevent src/units/org/apache/beehive/controls/test/java/contextevent webapps/controlsWeb/contextevent/beanrecord

Author: jsong
Date: Wed Oct 13 15:45:27 2004
New Revision: 54756

Added:
   incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/contextevent/BeanContextRecorder.java   (contents, props changed)
   incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/contextevent/BeanContextRecorderImpl.jcs   (contents, props changed)
   incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/contextevent/DriveBeanContextRecorder.java   (contents, props changed)
   incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/contextevent/ContextEventTest.java   (contents, props changed)
Removed:
   incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/contextevent/LifeCycleTest.java
Modified:
   incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/contextevent/Recorder.java
   incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/contextevent/RecorderImpl.jcs
   incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/contextevent/DriveBeanRecorder.java
   incubator/beehive/trunk/controls/test/webapps/controlsWeb/contextevent/beanrecord/Controller.jpf
Log:
Activate more tests on control context events. Adding more comments,
checkin.tests pass on WinXP.


Added: incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/contextevent/BeanContextRecorder.java
==============================================================================
--- (empty file)
+++ incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/contextevent/BeanContextRecorder.java	Wed Oct 13 15:45:27 2004
@@ -0,0 +1,15 @@
+package org.apache.beehive.controls.test.controls.contextevent;
+
+import org.apache.beehive.controls.api.bean.ControlInterface;
+
+/**
+ * A control interface to test control context events.
+ * There are two sources of control context events: ControlBeanContext and
+ * ResouceContext.
+ * The implementation of this interface only listens to context events from ControlBeanContext.
+ */
+@ControlInterface
+public interface BeanContextRecorder
+{
+    public String getRecord();
+}

Added: incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/contextevent/BeanContextRecorderImpl.jcs
==============================================================================
--- (empty file)
+++ incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/contextevent/BeanContextRecorderImpl.jcs	Wed Oct 13 15:45:27 2004
@@ -0,0 +1,47 @@
+package org.apache.beehive.controls.test.controls.contextevent;
+
+import org.apache.beehive.controls.api.context.Context;
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+import org.apache.beehive.controls.api.context.ResourceContext;
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.beehive.controls.api.events.EventHandler;
+
+/**
+ * A control impl that listens to and records its lifecycle events
+ * This impl listens to context event by declaring EventHandler
+ *
+ * There are two sources of control context events: ControlBeanContext and
+ * ResouceContext.
+ * This class only listens to context events from ControlBeanContext. 
+ */
+
+@ControlImplementation 
+public class BeanContextRecorderImpl implements BeanContextRecorder
+{
+
+    private String event_log="init";
+    
+    @Context ControlBeanContext context;
+    
+    /*A EventHandler that listens to onCreate event*/
+    @EventHandler(field="context", eventSet=ControlBeanContext.LifeCycle.class, eventName="onCreate")
+    public void onCreate()
+    {
+    	System.out.println("++++++++++++++++++++++++++++++++++++++++++++++");
+        System.out.println("onCreate invoked on BeanContextRecorderImpl");
+        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++");
+
+	event_log=event_log+"onCreate";
+    }
+
+    
+    /*Returns the event log*/
+    public String getRecord()
+    {
+    	System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++");
+        System.out.println("getRecord on BeanContextRecorderImpl invoked");
+        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++");
+        
+	return event_log;
+    }
+}

Modified: incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/contextevent/Recorder.java
==============================================================================
--- incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/contextevent/Recorder.java	(original)
+++ incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/contextevent/Recorder.java	Wed Oct 13 15:45:27 2004
@@ -3,7 +3,10 @@
 import org.apache.beehive.controls.api.bean.ControlInterface;
 
 /**
- * A control interface to test control context event
+ * A control interface to test control context events.
+ * There are two sources of control context events: ControlBeanContext and
+ * ResouceContext.
+ * The implementation of this interface listens to context events from both sources.
  */
 @ControlInterface
 public interface Recorder

Modified: incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/contextevent/RecorderImpl.jcs
==============================================================================
--- incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/contextevent/RecorderImpl.jcs	(original)
+++ incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/contextevent/RecorderImpl.jcs	Wed Oct 13 15:45:27 2004
@@ -7,8 +7,12 @@
 import org.apache.beehive.controls.api.events.EventHandler;
 
 /**
- * A control impl that listens to and records its lifecycle events
- * This impl listens to context event by declaring EventHandler
+ * A control impl that listens to and records context events
+ * This impl listens to context events by declaring EventHandler.
+ *
+ * There are two sources of control context events: ControlBeanContext and
+ * ResouceContext.
+ * This class listens to context events from both sources. 
  */
 
 @ControlImplementation 
@@ -25,7 +29,7 @@
     public void onCreate()
     {
     	System.out.println("+++++++++++++++++++++++++++++++++++++++++");
-        System.out.println("onCreate on SimpleControlImpl");
+        System.out.println("onCreate invoked on RecorderImpl");
         System.out.println("++++++++++++++++++++++++++++++++++++++++++");
 
 	event_log=event_log+"onCreate";
@@ -36,17 +40,17 @@
     public void onAcquire()
     {
     	System.out.println("+++++++++++++++++++++++++++++++++++++++++");
-        System.out.println("onAcquire on SimpleControlImpl");
+        System.out.println("onAcquire invoked on RecorderImpl");
         System.out.println("++++++++++++++++++++++++++++++++++++++++++");
 	event_log=event_log+"onAcquire";
     }
-
+    
     /*A EventHandler that listens to onRelease event*/
     @EventHandler(field="resourceContext", eventSet=ResourceContext.ResourceEvents.class, eventName="onRelease")
     public void onRelease()
     {
     	System.out.println("+++++++++++++++++++++++++++++++++++++++++");
-        System.out.println("onRelease on SimpleControlImpl");
+        System.out.println("onRelease invoked on RecorderImpl");
         System.out.println("++++++++++++++++++++++++++++++++++++++++++");
 
 	event_log=event_log+"onRelease";
@@ -55,9 +59,9 @@
     /*Returns the event log*/
     public String getRecord()
     {
-    	System.out.println("+++++++++++++++++++++++++++++++++++++++++");
-        System.out.println("method on SimpleControlImpl invoked");
-        System.out.println("++++++++++++++++++++++++++++++++++++++++++");
+    	System.out.println("++++++++++++++++++++++++++++++++++++++++++++++");
+        System.out.println("getRecord method invoked on RecorderImpl");
+        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++");
         
 	return event_log;
     }

Added: incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/contextevent/DriveBeanContextRecorder.java
==============================================================================
--- (empty file)
+++ incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/contextevent/DriveBeanContextRecorder.java	Wed Oct 13 15:45:27 2004
@@ -0,0 +1,45 @@
+package org.apache.beehive.controls.test.driver.contextevent;
+
+import org.apache.beehive.test.tools.milton.common.Report;
+import org.apache.beehive.controls.test.controls.contextevent.BeanContextRecorderBean;
+
+/* Tests context event raised by ControlBeanContext.
+ */
+
+public class DriveBeanContextRecorder
+{
+
+	/*A contol that listens to the context event raised by its ControlBeanContext*/
+	private BeanContextRecorderBean myControl;
+
+	public void setControl(BeanContextRecorderBean aControl){
+
+		myControl=aControl;
+	}
+
+	/*
+	 * Retrieves the context events recorded by the control implementation class
+	 */
+	public Report doTest(){
+
+		Report report=new Report();
+
+		if (myControl==null){
+			report.setStatus(Report.FAIL);
+			report.setMessage("the custom control is NULL");
+		}
+		else{
+
+			String record=myControl.getRecord();
+
+			if (record.equals("initonCreate"))
+				report.setStatus(Report.PASS);
+			else{
+				report.setStatus(Report.FAIL);
+				report.setMessage("The events recorded by control impl:"+record);
+			}
+		}
+
+		return report;
+	}
+}

Modified: incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/contextevent/DriveBeanRecorder.java
==============================================================================
--- incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/contextevent/DriveBeanRecorder.java	(original)
+++ incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/contextevent/DriveBeanRecorder.java	Wed Oct 13 15:45:27 2004
@@ -1,16 +1,24 @@
 package org.apache.beehive.controls.test.driver.contextevent;
 
-import  org.apache.beehive.controls.api.context.ControlBeanContext;
-import org.apache.beehive.test.tools.milton.common.Report;
+import java.lang.Class;
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+import org.apache.beehive.controls.api.context.ResourceContext;
 import org.apache.beehive.controls.test.controls.contextevent.RecorderBean;
+import org.apache.beehive.test.tools.milton.common.Report;
 
-/* This class contains the logic to test control life cycle events.
+/* This class contains the logic to test control context events.
+ * There are two souces for control context events: ControlBeanContext and ResourceContext.
+ *
+ * This class listens to context events by adding listeners to ControlBeanContext and
+ * ResourceContext.
  */
 public class DriveBeanRecorder
 {
 
 	private RecorderBean myControl;
 	private boolean onCreateReceived=false;
+	private boolean onAcquireReceived=false;
+	private boolean onReleaseReceived=false;
 
 	public void setControl(RecorderBean aControl){
 
@@ -18,9 +26,12 @@
 	}
 
     /*
-     * Listens to control life cycle events by adding listener to control bean class.
+     * Listens to control context events raised by ControlBeanContext by adding listener
+     * to ControlBeanContext.
+     *
+     * We can not catch onCreate event in this way. These code just verifies the compilation.
      */
-	public Report doTest(){
+	public Report testBeanContextEvent(){
 
 		Report report=new Report();
 
@@ -29,19 +40,12 @@
 			report.setMessage("the custom control is NULL");
 		}
 		else{
-			//There is only one method onCreate() in ControlBeanContext.LifeCycle
 
-			ControlBeanContext peerContext = myControl.getControlBeanContext();
-			peerContext.addLifeCycleListener( new ControlBeanContext.LifeCycle()
+			ControlBeanContext beanContext = myControl.getControlBeanContext();
+			beanContext.addLifeCycleListener( new ControlBeanContext.LifeCycle()
 				{
 					public void onCreate() {
-
-
 						onCreateReceived=true; };
-				  	/*
-				  	public void onAcquire() { //do recording};
-					public void onRelease() { //do recording};
-					*/
 					});
 
 			report.setStatus(Report.PASS);
@@ -51,7 +55,54 @@
 	}
 
     /*
-     * Listens to control life cycle events by adding listener to control bean class.
+     * Listens to control context events raised by ResourceContext by adding listener
+     * to ResourceContext.
+     *
+     * We can only capture onAcquire event by this way.
+     */
+	public Report testResourceContextEvent(){
+
+		Report report=new Report();
+
+		if (myControl==null){
+			report.setStatus(Report.FAIL);
+			report.setMessage("the custom control is NULL");
+		}
+		else{
+
+			ControlBeanContext beanContext = myControl.getControlBeanContext();
+			try{
+				ResourceContext resourceContext=(ResourceContext)beanContext.getService(
+					Class.forName("org.apache.beehive.controls.api.context.ResourceContext"),null);
+				resourceContext.addResourceEventsListener( new ResourceContext.ResourceEvents()
+					{
+					  	public void onAcquire(){
+							/*
+							System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
+							System.out.println("onAcquire invoked on DriveBeanRecorder");
+							System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
+							*/
+							onAcquireReceived=true;
+						};
+						public void onRelease(){onReleaseReceived=true;};
+					});
+
+				report.setStatus(Report.PASS);
+			}
+			catch(Exception e){
+				report.setStatus(Report.FAIL);
+				report.setExceptionStack(e);
+			}
+		}
+
+		return report;
+	}
+
+    /*
+     * Report the context events captured.
+     *
+     * Listening to context events by adding listeners, only allows to catch onAcquire.
+     * onCreate and onRelease could not be caught in this way.
      */
 	public Report getResult(){
 
@@ -62,15 +113,14 @@
 			report.setMessage("the custom control is NULL");
 		}
 		else{
-			if (onCreateReceived)
+			if (onAcquireReceived)
 				report.setStatus(Report.PASS);
 			else{
 				report.setStatus(Report.FAIL);
-				report.setMessage("onCreate is not received.");
+				report.setMessage("onAcquire is not received.");
 			}
 		}
 
 		return report;
 	}
-
-}
+}
\ No newline at end of file

Added: incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/contextevent/ContextEventTest.java
==============================================================================
--- (empty file)
+++ incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/contextevent/ContextEventTest.java	Wed Oct 13 15:45:27 2004
@@ -0,0 +1,98 @@
+package org.apache.beehive.controls.test.java.contextevent;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import java.beans.Beans;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.bean.ControlBean;
+import org.apache.beehive.controls.test.controls.contextevent.RecorderBean;
+import org.apache.beehive.controls.test.controls.contextevent.BeanContextRecorderBean;
+import org.apache.beehive.controls.test.driver.contextevent.DriveBeanRecorder;
+import org.apache.beehive.controls.test.driver.contextevent.DriveBeanContextRecorder;
+import org.apache.beehive.test.tools.mantis.annotations.tch.Freq;
+import org.apache.beehive.test.tools.mantis.annotations.tch.Status;
+import org.apache.beehive.test.tools.milton.common.Report;
+
+/**
+ * A TestCase that tests control's context event by listening to and recording controls'
+ * context event.
+ * All tests on controls instantiated declaratively are deactivated until this feature is supported.
+ *
+ * There are two sources of context events: ControlBeanContext and ResourceContext.
+ * ResourceContext is unavaliable for Java test by default.
+ */
+public class ContextEventTest extends TestCase
+{
+	/*
+	 * A control that listens to and records context events in its impl
+	 */
+    @Control
+    public BeanContextRecorderBean myRecorder;
+
+    public ContextEventTest(String s) { super(s); }
+
+    /**
+     * Tests control impl listening to context events.
+     * The control is instantiated by declaration
+     */
+	@Freq("checkin")
+	@Status("inactive")
+    public void testRecordedByImplDeclaration() throws Exception
+    {
+		Report report=new Report();
+		DriveBeanContextRecorder driver=new DriveBeanContextRecorder();
+		driver.setControl(myRecorder);
+		report=driver.doTest();
+
+		String result=report.getStatus();
+
+		if (!result.equals(Report.PASS)){
+			fail(report.getMessage());
+		}
+	}
+
+    /**
+     * Tests control impl listening to its context events.
+     * The control is instantiated programmatically
+     */
+	@Freq("checkin")
+    public void testRecordedByImplProgram() throws Exception
+    {
+		Report report=new Report();
+		DriveBeanContextRecorder driver=new DriveBeanContextRecorder();
+		BeanContextRecorderBean recorderbean=(BeanContextRecorderBean)Beans.instantiate(
+			Thread.currentThread().getContextClassLoader(),
+            "org.apache.beehive.controls.test.controls.contextevent.BeanContextRecorderBean");
+		driver.setControl(recorderbean);
+    	report=driver.doTest();
+
+		String result=report.getStatus();
+
+		if (!result.equals(Report.PASS)){
+			fail(report.getMessage());
+		}
+    }
+
+    /**
+     * Tests listening to control's context events by registering a listener
+     * Only onAcquire event can be captured by this way.
+     */
+	@Freq("checkin")
+	@Status("inactive")
+    public void testRecordFromBeanInstance() throws Exception
+    {
+		DriveBeanRecorder driver=new DriveBeanRecorder();
+		RecorderBean recorderbean=(RecorderBean)Beans.instantiate(
+			Thread.currentThread().getContextClassLoader(),
+			"org.apache.beehive.controls.test.controls.contextevent.RecorderBean");
+		driver.setControl(recorderbean);
+		Report report1=driver.testBeanContextEvent();
+		Assert.assertEquals(Report.PASS,report1.getStatus());
+		try{
+			Thread.currentThread().sleep(500);
+		}
+		catch(Exception e){}
+		Report report2=driver.getResult();
+		Assert.assertEquals(Report.PASS,report2.getStatus());
+    }
+}

Modified: incubator/beehive/trunk/controls/test/webapps/controlsWeb/contextevent/beanrecord/Controller.jpf
==============================================================================
--- incubator/beehive/trunk/controls/test/webapps/controlsWeb/contextevent/beanrecord/Controller.jpf	(original)
+++ incubator/beehive/trunk/controls/test/webapps/controlsWeb/contextevent/beanrecord/Controller.jpf	Wed Oct 13 15:45:27 2004
@@ -21,7 +21,7 @@
 import org.apache.beehive.netui.pageflow.Forward;
 import org.apache.beehive.netui.pageflow.FormData;
 import org.apache.beehive.netui.pageflow.annotations.Jpf;
-
+import java.lang.Thread;
 import org.apache.beehive.controls.api.bean.Control;
 import org.apache.beehive.controls.api.bean.ControlBean;
 import org.apache.beehive.controls.test.controls.contextevent.RecorderBean;
@@ -52,7 +52,17 @@
     	
 	DriveBeanRecorder driver=new DriveBeanRecorder();
 	driver.setControl(recorder);
-	Report report=driver.doTest();
+	Report report=driver.testBeanContextEvent();
+	report=driver.testResourceContextEvent();
+	
+	try{
+		Thread.currentThread().sleep(500);
+		report=driver.getResult();
+	}
+	catch(Exception e){
+		report.setStatus(Report.FAIL);
+		report.setExceptionStack(e);
+	}
 	
         return new Forward(Report.RESULTS, Report.KEY, report);
     }