You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2006/04/26 21:13:24 UTC

svn commit: r397275 - in /beehive/trunk/controls/test: infra/milton/ src/junit-controls/org/apache/beehive/controls/test/controls/composition/ src/junit-tests/org/apache/beehive/controls/test/junit/ src/units/org/apache/beehive/controls/test/java/compo...

Author: ekoneil
Date: Wed Apr 26 12:13:21 2006
New Revision: 397275

URL: http://svn.apache.org/viewcvs?rev=397275&view=rev
Log:
Additional Controls test cleanup.  This duplicates a TCH test called DeclarativeTest from the <tch> suite into the <junit> suite so that it can be debugged from IDEA.  It's not clear how to hook a debugger up when TCH runs, and it just works for JUnit.

The Controls used in this test and the test itself moved.

BB: self
Test: Controls pass


Added:
    beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/
    beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControl.java
    beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControlEventListener.java
    beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControlImpl.java
    beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/OuterControl.java
    beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/OuterControlImpl.java
    beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/DeclarativeTest.java
Modified:
    beehive/trunk/controls/test/infra/milton/milton.jar
    beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/composition/DeclarativeTest.java
    beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/MiltonControlContext.java
    beehive/trunk/controls/test/webapps/src/composition/Controller.java

Modified: beehive/trunk/controls/test/infra/milton/milton.jar
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/infra/milton/milton.jar?rev=397275&r1=397274&r2=397275&view=diff
==============================================================================
Binary files - no diff available.

Added: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControl.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControl.java?rev=397275&view=auto
==============================================================================
--- beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControl.java (added)
+++ beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControl.java Wed Apr 26 12:13:21 2006
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.controls.test.controls.composition;
+
+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.ControlInterface;
+import org.apache.beehive.controls.api.events.EventSet;
+import org.apache.beehive.controls.api.properties.PropertySet;
+
+/**
+ * A control interface designed to test control composition
+ */
+@ControlInterface
+public interface InnerControl
+{
+	static final String DEFAULT_NAME="Bob";
+	static final String DEFAULT_JOB="cleaner";
+
+    @PropertySet
+    @Target( {ElementType.TYPE, ElementType.FIELD} )
+    @Retention(RetentionPolicy.RUNTIME)
+    public @interface Identity {
+        public String name() default DEFAULT_NAME;
+        //does not have a default value assigned
+		public String job();
+        public int rank() default 0;
+    }
+
+    @EventSet(unicast=true)
+    public interface Activity {
+        void wakeup();
+        int readMessage(String message);
+        String report();
+    }
+
+    @EventSet(unicast=true)
+    public interface Action {
+        public Object[] shopping (double credit);
+        public void doStuff(String value);
+    }
+
+	public void fireAllEvents();
+    public void fireEvent(String eventSet, String eventName);
+
+	/*Gets property value from context*/
+    public String getNameFromContext();
+
+    /*Gets property value from context*/
+    public String getJobFromContext();
+}

Added: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControlEventListener.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControlEventListener.java?rev=397275&view=auto
==============================================================================
--- beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControlEventListener.java (added)
+++ beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControlEventListener.java Wed Apr 26 12:13:21 2006
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.controls.test.controls.composition;
+
+/**
+ * A listener class for event raised by InnerControl
+ */
+public class InnerControlEventListener
+    implements InnerControl.Activity,
+    InnerControl.Action,
+    java.io.Serializable {
+
+	private boolean wakeupReceived=false;
+	private boolean readMessageReceived=false;
+	private boolean reportReceived=false;
+	private boolean shoppingReceived=false;
+	private boolean doStuffReceived=false;
+
+	/*
+	 * BUG!!?? although the event declares methods wakeup, readMessage and
+	 * report using default accessor,
+	 * implmentation must change the method accessor to public,
+	 * or, a compile error!
+	 *
+	 *  attempting to assign weaker access privileges; was public
+     * [apt]     void wakeup(){wakeupReceived=true;}
+     *
+	 */
+
+	public void wakeup(){
+        wakeupReceived=true;
+    }
+
+    public int readMessage(String message){
+		readMessageReceived=true;
+		return 0;
+    }
+
+    public String report(){
+		reportReceived=true;
+		return "a report from event listener";
+    }
+
+    public Object[] shopping (double credit){
+		shoppingReceived=true;
+		//return (Object){"clothes","shoes","food"};
+		return null;
+    }
+
+    public void doStuff(String value){
+		doStuffReceived=true;
+    }
+
+	public boolean getWakeupResult(){
+        return wakeupReceived;
+    }
+
+	public boolean getReadMessageResult(){
+        return readMessageReceived;
+    }
+
+	public boolean getReportResult(){
+        return reportReceived;
+    }
+
+	public boolean getShoppingResult(){
+        return shoppingReceived;
+    }
+
+	public boolean getDoStuffResult(){
+        return doStuffReceived;
+    }
+
+	/**
+     * Checks all the event records and returns '0' if all the events have been received.
+	 */
+	public String getFinalResult(){
+
+		String result="";
+
+		if (!wakeupReceived)
+			result="WakeUp not received.";
+		if (!readMessageReceived)
+			result=result+"readMessage not received.";
+		if (!reportReceived)
+			result=result+"report not received.";
+		if (!shoppingReceived)
+			result=result+"shopping not received.";
+		if (!doStuffReceived)
+			result=result+"dostuff not received.";
+
+		if (result.length()==0)
+			result="0";
+
+		return result;
+	}
+}

Added: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControlImpl.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControlImpl.java?rev=397275&view=auto
==============================================================================
--- beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControlImpl.java (added)
+++ beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/InnerControlImpl.java Wed Apr 26 12:13:21 2006
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.controls.test.controls.composition;
+
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.beehive.controls.api.events.Client;
+import org.apache.beehive.controls.api.context.Context;
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+
+/*
+ * A control impl to test control composition.
+ * This control shall be instantiated by another control.
+ */
+@ControlImplementation
+public class InnerControlImpl
+    implements InnerControl, java.io.Serializable {
+
+    @Context
+    ControlBeanContext context;
+
+    @Client
+    Activity activity;
+
+    @Client
+    Action action;
+
+    /*Gets property value from context*/
+    public String getNameFromContext(){
+        Identity identity = context.getControlPropertySet(InnerControl.Identity.class);
+        return identity.name();
+    }
+
+    /*Gets property value from context*/
+    public String getJobFromContext(){
+        Identity identity = context.getControlPropertySet(InnerControl.Identity.class);
+        return identity.job();
+    }
+    
+    public void fireEvent(String eventSet, String eventName){
+    	
+    	if ((eventSet!=null)&&(eventName!=null)){
+    	
+    		if (eventSet.equalsIgnoreCase("Activity")){
+    			if (eventName.equalsIgnoreCase("wakeup"))
+    				activity.wakeup();
+    			else if(eventName.equalsIgnoreCase("readMessage"))
+    				activity.readMessage("message from nested control");
+    			else if(eventName.equalsIgnoreCase("report"))
+    				activity.report();    			
+    		}
+    		else if (eventSet.equalsIgnoreCase("Action")){
+    		    	if (eventName.equalsIgnoreCase("shopping"))
+		    		action.shopping(999.99d);
+		    	else if(eventName.equalsIgnoreCase("doStuff"))
+		    		action.doStuff("stuff to do");
+    		}
+    	}
+    	
+    }
+
+    public void fireAllEvents(){
+    	activity.wakeup();
+        activity.readMessage("message from nested control");
+        activity.report();
+        action.shopping(999.99d);
+        action.doStuff("stuff to do");
+    }
+}

Added: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/OuterControl.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/OuterControl.java?rev=397275&view=auto
==============================================================================
--- beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/OuterControl.java (added)
+++ beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/OuterControl.java Wed Apr 26 12:13:21 2006
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.controls.test.controls.composition;
+
+import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.events.EventSet;
+
+/**
+ * A control interface to test control composition.
+ */
+@ControlInterface
+public interface OuterControl {
+
+    @EventSet(unicast=true)
+    public interface OuterEvents {
+        int report(String message);
+    }
+
+    public void fireOuterEvents(String message);
+
+	public InnerControlBean getDeclaredNestedControl();
+	public InnerControlBean getDeclaredNestedControl2();
+	public InnerControlBean instantiateNestedControlProgrammatically();
+	public InnerControlBean instantiateNestedControlWithProperty();
+
+	/*
+	 * Test outer control receiving event from nested control using
+	 * EventHandler.
+	 */
+	public String testActivityWakeup();
+	public String testActivityReadMessage();
+	public String testActivityReport();
+	public String testActionShopping();
+	public String testActionDostuff();
+
+	/*
+	 * Tests outer control receiving event from nested control using
+	 * event listener. The nested control is instantiated programmatically
+	 */
+	public String testEventListener();
+
+	/*
+	 * Tests outer control receiving event from nested control using
+	 * event listener. The nested control is instantiated decalratively
+	 */
+	public String testEventListenerByDeclare();
+
+	/*
+	 * Tests outer control receiving event from nested control using
+	 * inner class listener. The nested control is instantiated programmatically
+	 */
+	public String testInnerClassListener();
+
+	/*
+	 * Tests outer control receiving event from nested control using
+	 * inner class listener. The nested control is instantiated decalratively
+	 */
+	public String testInnerClassListenerByDeclare();
+}

Added: beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/OuterControlImpl.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/OuterControlImpl.java?rev=397275&view=auto
==============================================================================
--- beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/OuterControlImpl.java (added)
+++ beehive/trunk/controls/test/src/junit-controls/org/apache/beehive/controls/test/controls/composition/OuterControlImpl.java Wed Apr 26 12:13:21 2006
@@ -0,0 +1,501 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.controls.test.controls.composition;
+
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.events.Client;
+import org.apache.beehive.controls.api.events.EventHandler;
+import org.apache.beehive.controls.api.properties.BeanPropertyMap;
+
+/**
+ * A control implementation to test control composition.  Makes two instances of nested control be declaration.
+ */
+@ControlImplementation
+public class OuterControlImpl
+    implements OuterControl, java.io.Serializable {
+
+    static final long serialVersionUID = 1L;
+    static final String EVENT_RECEIVED = "Event Received";
+
+    private String innerControlEventHandlerWakeUp = "";
+    private String innerControlEventHandlerReadMessage = "";
+    private String innerControlEventHandlerReport = "";
+    private String innerControlEventHandlerShopping = "";
+    private String innerControlEventHandlerDoStuff = "";
+
+    private boolean innerClassWakeUp = false;
+    private boolean innerClassReadMessage = false;
+    private boolean innerClassReport = false;
+    private boolean innerClassShopping = false;
+    private boolean innerClassDoStuff = false;
+
+    private boolean innerControlInnerClassWakeUp = false;
+    private boolean innerControlInnerClassReadMessage = false;
+    private boolean innerControlInnerClassReport = false;
+    private boolean innerControlInnerClassShopping = false;
+    private boolean innerControlInnerClassDoStuff = false;
+
+    @Client
+    transient OuterEvents outerEvents;
+
+    /*Instantiates a nested control without reconfiguring the property*/
+    @Control
+    InnerControlBean innerControl;
+
+    @Control
+    @InnerControl.Identity(job = "farmer")
+    InnerControlBean innerControl2;
+
+    //
+    // Define various event handlers for the nested controls
+    //
+    @EventHandler(field = "innerControl", eventSet = InnerControl.Activity.class, eventName = "wakeup")
+    public void innerControlwakeup() {
+        innerControlEventHandlerWakeUp = EVENT_RECEIVED;
+    }
+
+    @EventHandler(field = "innerControl", eventSet = InnerControl.Activity.class, eventName = "readMessage")
+    public int innerControlreadMessage(String message) {
+        innerControlEventHandlerReadMessage = EVENT_RECEIVED;
+        return 0;
+    }
+
+    @EventHandler(field = "innerControl", eventSet = InnerControl.Activity.class, eventName = "report")
+    public String innerControlreport() {
+        innerControlEventHandlerReport = EVENT_RECEIVED;
+        return "a report";
+    }
+
+    @EventHandler(field = "innerControl", eventSet = InnerControl.Action.class, eventName = "shopping")
+    public Object [] innerControlshopping(double credit) {
+        innerControlEventHandlerShopping = EVENT_RECEIVED;
+        return null;
+    }
+
+    @EventHandler(field = "innerControl", eventSet = InnerControl.Action.class, eventName = "doStuff")
+    public void innerControldoStuff(String vakue) {
+        innerControlEventHandlerDoStuff = EVENT_RECEIVED;
+    }
+
+    @EventHandler(field = "innerControl2", eventSet = InnerControl.Activity.class, eventName = "wakeup")
+    public void innerControl2wakeup() {
+    }
+
+    @EventHandler(field = "innerControl2", eventSet = InnerControl.Activity.class, eventName = "readMessage")
+    public int innerControl2readMessage(String message) {
+        return 0;
+    }
+
+    @EventHandler(field = "innerControl2", eventSet = InnerControl.Activity.class, eventName = "report")
+    public String innerControl2report() {
+        return "a report";
+    }
+
+    @EventHandler(field = "innerControl2", eventSet = InnerControl.Action.class, eventName = "shopping")
+    public Object [] innerControl2shopping(double credit) {
+        return null;
+    }
+
+    @EventHandler(field = "innerControl2", eventSet = InnerControl.Action.class, eventName = "doStuff")
+    public void innerControl2doStuff(String vakue) {
+    }
+
+    public void fireOuterEvents(String message) {
+        outerEvents.report(message);
+    }
+
+    public InnerControlBean getDeclaredNestedControl() {
+        return innerControl;
+    }
+
+    public InnerControlBean getDeclaredNestedControl2() {
+        return innerControl2;
+    }
+
+    public InnerControlBean instantiateNestedControlProgrammatically() {
+        try {
+            InnerControlBean inner =
+                (InnerControlBean) java.beans.Beans.instantiate(Thread.currentThread().getContextClassLoader(),
+                    "org.apache.beehive.controls.test.controls.composition.InnerControlBean");
+            return inner;
+        }
+        catch (Exception e) {
+            return null;
+        }
+    }
+
+    public InnerControlBean instantiateNestedControlWithProperty() {
+        try {
+            BeanPropertyMap props = new BeanPropertyMap(InnerControl.Identity.class);
+            props.setProperty(InnerControlBean.NameKey, "ken");
+            props.setProperty(InnerControlBean.JobKey, "engineer");
+            props.setProperty(InnerControlBean.RankKey, new Integer(2));
+            InnerControlBean inner = (InnerControlBean) org.apache.beehive.controls.api.bean.Controls.instantiate(
+                Thread.currentThread().getContextClassLoader(),
+                "org.apache.beehive.controls.test.controls.composition.InnerControlBean", props);
+            return inner;
+        }
+        catch (Exception e) {
+            throw new RuntimeException("Failed to instantiate nested control", e);
+        }
+    }
+
+    public String testActivityWakeup() {
+
+        String result = "";
+        if (innerControl == null)
+            result = "inner control is NULL";
+        else {
+            innerControl.fireEvent("Activity", "wakeup");
+            /*Wait for the events*/
+            try {
+                Thread.sleep(1000);
+                if (innerControlEventHandlerWakeUp.equals(EVENT_RECEIVED))
+                    result = "0";
+                else
+                    result = "Acivity.wakeup not received by EventHandler";
+            }
+            catch (Exception e) {
+                result = "Thread sleep interrupted." + e.toString();
+            }
+        }
+        return result;
+    }
+
+    public String testActivityReadMessage() {
+
+        String result = "";
+        if (innerControl == null)
+            result = "inner control is NULL";
+        else {
+            innerControl.fireEvent("Activity", "readMessage");
+            /*Wait for the events*/
+            try {
+                Thread.sleep(1000);
+
+                if (innerControlEventHandlerReadMessage.equals(EVENT_RECEIVED))
+                    result = "0";
+                else
+                    result = "Acivity.readMessage not received by EventHandler";
+            }
+            catch (Exception e) {
+                result = "Thread sleep interrupted." + e.toString();
+            }
+        }
+        return result;
+
+    }
+
+    public String testActivityReport() {
+
+        String result = "";
+        if (innerControl == null)
+            result = "inner control is NULL";
+        else {
+            innerControl.fireEvent("Activity", "report");
+            /*Wait for the events*/
+            try {
+                Thread.sleep(1000);
+
+                if (innerControlEventHandlerReport.equals(EVENT_RECEIVED))
+                    result = "0";
+                else
+                    result = "Acivity.report not received by EventHandler";
+            }
+            catch (Exception e) {
+                result = "Thread sleep interrupted." + e.toString();
+            }
+        }
+        return result;
+
+    }
+
+    public String testActionShopping() {
+
+        String result = "";
+        if (innerControl == null)
+            result = "inner control is NULL";
+        else {
+            innerControl.fireEvent("Action", "shopping");
+            /*Wait for the events*/
+            try {
+                Thread.sleep(1000);
+
+                if (innerControlEventHandlerShopping.equals(EVENT_RECEIVED))
+                    result = "0";
+                else
+                    result = "Action.shopping not received by EventHandler";
+            }
+            catch (Exception e) {
+                result = "Thread sleep interrupted." + e.toString();
+            }
+        }
+        return result;
+
+    }
+
+    public String testActionDostuff() {
+
+        String result = "";
+        if (innerControl == null)
+            result = "inner control is NULL";
+        else {
+            innerControl.fireEvent("Action", "doStuff");
+            /*Wait for the events*/
+            try {
+                Thread.sleep(1000);
+
+                if (innerControlEventHandlerDoStuff.equals(EVENT_RECEIVED))
+                    result = "0";
+                else
+                    result = "Action.doStuff not received by EventHandler";
+            }
+            catch (Exception e) {
+                result = "Thread sleep interrupted." + e.toString();
+            }
+        }
+        return result;
+
+    }
+
+    /*Tests outer control receiving event from nested control using
+     * event listener. The nested control is instantiated programmatically
+     */
+    public String testEventListener() {
+
+        String result = "init";
+        try {
+
+            InnerControlBean nested = (InnerControlBean) java.beans.Beans.instantiate(
+                Thread.currentThread().getContextClassLoader(),
+                "org.apache.beehive.controls.test.controls.composition.InnerControlBean");
+            if (nested == null)
+                result = "Nested control instantiated programmatically is NULL.";
+            else {
+                //Create an Event Listener
+                InnerControlEventListener listener = new InnerControlEventListener();
+                nested.addActivityListener(listener);
+                nested.addActionListener(listener);
+                nested.fireAllEvents();
+                try {
+                    Thread.sleep(1000);
+                    result = listener.getFinalResult();
+                }
+                catch (Exception e) {
+                    result = "Thread sleep interrupted." + e.toString();
+                }
+
+
+            }
+        }
+        catch (Exception e) {
+            result = "Exception caught:" + e.toString();
+        }
+        return result;
+    }
+
+    /*Tests outer control receiving event from nested control using
+     * event listener. The nested control is instantiated decalratively
+     */
+    public String testEventListenerByDeclare() {
+
+        String result = "init";
+
+        if (innerControl == null)
+            result = "Nested control instantiated declaratively is NULL.";
+        else {
+            try {
+                //Create an Event Listener
+                InnerControlEventListener listener = new InnerControlEventListener();
+                innerControl.addActivityListener(listener);
+                innerControl.addActionListener(listener);
+                innerControl.fireAllEvents();
+
+                Thread.sleep(1000);
+                result = listener.getFinalResult();
+            }
+            catch (Exception e) {
+                result = "Thread sleep interrupted." + e.toString();
+            }
+
+
+        }
+        return result;
+
+    }
+
+    /*Tests outer control receiving event from nested control using
+     * inner class listener. The nested control is instantiated programmatically
+     */
+    public String testInnerClassListener() {
+
+        String result = "init";
+        try {
+            InnerControlBean nested = (InnerControlBean) java.beans.Beans.instantiate(
+                Thread.currentThread().getContextClassLoader(),
+                "org.apache.beehive.controls.test.controls.composition.InnerControlBean");
+            if (nested == null)
+                result = "Nested control instantiated programmatically is NULL.";
+            else {
+                nested.addActivityListener(
+                    new InnerControl.Activity() {
+
+                        public void wakeup() {
+                            innerClassWakeUp = true;
+                        }
+
+                        public int readMessage(String message) {
+                            innerClassReadMessage = true;
+                            return 0;
+                        }
+
+                        public String report() {
+                            innerClassReport = true;
+                            return "event received.";
+                        }
+                    }
+                );
+                nested.addActionListener(
+                    new InnerControl.Action() {
+
+                        public Object[] shopping(double credit) {
+                            innerClassShopping = true;
+                            //return {"food","drinks","candies"};
+                            return null;
+                        }
+
+                        public void doStuff(String value) {
+                            innerClassDoStuff = true;
+                        }
+                    }
+                );
+                nested.fireAllEvents();
+                try {
+                    Thread.sleep(1000);
+                }
+                catch (Exception e) {
+                    /* ignore */
+                }
+
+                result = getInnerClassListenerResult();
+            }
+        }
+        catch (Exception e) {
+            result = "Exception caught:" + e.toString();
+        }
+        return result;
+    }
+
+    /*Tests outer control receiving event from nested control using
+     * inner class listener. The nested control is instantiated decalratively
+     */
+    public String testInnerClassListenerByDeclare() {
+
+        String result = "init";
+
+        if (innerControl == null)
+            result = "Nested control instantiated declaratively is NULL.";
+        else {
+            try {
+                innerControl.addActivityListener(
+                    new InnerControl.Activity() {
+                        public void wakeup() {
+                            innerControlInnerClassWakeUp = true;
+                        }
+
+                        public int readMessage(String message) {
+                            innerControlInnerClassReadMessage = true;
+                            return 0;
+                        }
+
+                        public String report() {
+                            innerControlInnerClassReport = true;
+                            return "event received.";
+                        }
+                    }
+                );
+                innerControl.addActionListener(
+                    new InnerControl.Action() {
+
+                        public Object[] shopping(double credit) {
+                            innerControlInnerClassShopping = true;
+                            //return {"food","drinks","candies"};
+                            return null;
+                        }
+
+                        public void doStuff(String value) {
+                            innerControlInnerClassDoStuff = true;
+                        }
+                    }
+                );
+                innerControl.fireAllEvents();
+
+                Thread.currentThread().sleep(1000);
+            }
+            catch (Exception e) {
+            }
+
+            result = getInnerControlInnerClassListenerResult();
+        }
+        return result;
+
+    }
+
+    private String getInnerClassListenerResult() {
+
+        String result = "";
+
+        if (!innerClassWakeUp)
+            result = "WakeUp not received.";
+        if (!innerClassReadMessage)
+            result = result + "readMessage not received.";
+        if (!innerClassReport)
+            result = result + "report not received.";
+        if (!innerClassShopping)
+            result = result + "shopping not received.";
+        if (!innerClassDoStuff)
+            result = result + "dostuff not received.";
+
+        if (result.length() == 0)
+            result = "0";
+
+        return result;
+    }
+
+    private String getInnerControlInnerClassListenerResult() {
+
+        String result = "";
+
+        if (!innerControlInnerClassWakeUp)
+            result = "WakeUp not received.";
+        if (!innerControlInnerClassReadMessage)
+            result = result + "readMessage not received.";
+        if (!innerControlInnerClassReport)
+            result = result + "report not received.";
+        if (!innerControlInnerClassShopping)
+            result = result + "shopping not received.";
+        if (!innerControlInnerClassDoStuff)
+            result = result + "dostuff not received.";
+
+        if (result.length() == 0)
+            result = "0";
+
+        return result;
+    }
+}

Added: beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/DeclarativeTest.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/DeclarativeTest.java?rev=397275&view=auto
==============================================================================
--- beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/DeclarativeTest.java (added)
+++ beehive/trunk/controls/test/src/junit-tests/org/apache/beehive/controls/test/junit/DeclarativeTest.java Wed Apr 26 12:13:21 2006
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.controls.test.junit;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import junit.framework.Assert;
+
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.events.EventHandler;
+import org.apache.beehive.controls.test.controls.composition.OuterControl;
+import org.apache.beehive.controls.test.controls.composition.OuterControlBean;
+import org.apache.beehive.controls.test.controls.composition.InnerControlBean;
+
+/**
+ * A TestCase that tests control composition.
+ * The outer control is instantiated declaratively, and the outer
+ * control instantiates the nested control declaratively
+ *
+ * Instantiating controls declaratively is not supported currently.
+ * All tests are deactivated until this is supported
+ */
+public class DeclarativeTest
+    extends ControlTestCase
+    implements java.io.Serializable {
+
+    @Control
+    private OuterControlBean outerControl;
+
+    private String _onReportMessage;
+
+    /**
+     * Tests outer control instantiats nested control by declaration
+     */
+    public void testInstantiation()
+        throws Exception {
+		Assert.assertNotNull(outerControl);
+		Assert.assertNotNull(outerControl.getDeclaredNestedControl());
+		Assert.assertNotNull(outerControl.getDeclaredNestedControl2());
+    }
+
+    /**
+     * Tests outer control getting inner control property from control context
+     */
+    public void testGetPropertyByContext() {
+        Assert.assertNotNull(outerControl);
+		InnerControlBean innercontrol=outerControl.getDeclaredNestedControl();
+		Assert.assertNotNull(innercontrol);
+		Assert.assertEquals("Bob",innercontrol.getNameFromContext());
+		Assert.assertNull(innercontrol.getJobFromContext());
+    }
+
+    /**
+     * Tests reconfigured property.
+     * Outer control reconfigures the inner control's property when instantiating it
+     */
+    public void testReconfiguredProperty() {
+		Assert.assertNotNull(outerControl);
+		InnerControlBean innercontrol=outerControl.getDeclaredNestedControl2();
+		Assert.assertNotNull(innercontrol);
+		Assert.assertEquals("Bob",innercontrol.getNameFromContext());
+		Assert.assertEquals("farmer",innercontrol.getJobFromContext());
+    }
+
+    /**
+     * Tests outer control receiving events from nested control using
+     * EventHandler
+     */
+    public void testEventHandler() {
+		Assert.assertNotNull(outerControl);
+		Assert.assertEquals("0",outerControl.testActivityWakeup());
+		Assert.assertEquals("0",outerControl.testActivityReadMessage());
+		Assert.assertEquals("0",outerControl.testActivityReport());
+		Assert.assertEquals("0",outerControl.testActionShopping());
+		Assert.assertEquals("0",outerControl.testActionDostuff());
+    }
+
+    /**
+     * Tests outer control firing events to us
+     */
+    public void testOuterEvents() {
+        System.out.println( "_onReportMessage=" + _onReportMessage );
+        Assert.assertNotNull(outerControl);
+        outerControl.fireOuterEvents("this is the reported msg");
+        Assert.assertEquals("this is the reported msg", _onReportMessage );
+        System.out.println( "_onReportMessage=" + _onReportMessage );
+    }
+
+    /**
+     * Tests that control IDS properly represent the composition relationship
+     */
+    public void testControlIDs()
+        throws Exception {
+
+        Assert.assertEquals("outerControl", outerControl.getControlID());
+        Assert.assertEquals("outerControl/innerControl", outerControl.getDeclaredNestedControl().getControlID());
+
+        // Test the relationships and identifiers are preserved across serialization and deserialization
+        ByteArrayOutputStream baos = null;
+        ObjectOutputStream oos = null;
+        try {
+            baos = new ByteArrayOutputStream();
+            oos = new ObjectOutputStream(baos);
+
+            System.out.println("outerControl is serializable: " + (outerControl instanceof java.io.Serializable));
+            oos.writeObject(outerControl);
+            oos.close();
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+        }
+        finally {
+            if(oos != null)
+                oos.close();
+            if(baos != null)
+                baos.close();
+        }
+
+        OuterControlBean outerCopy = null;
+
+        ByteArrayInputStream bais = null;
+        ObjectInputStream ois = null;
+        try {
+            bais = new ByteArrayInputStream(baos.toByteArray());
+            ois = new ObjectInputStream(bais);
+            outerCopy = (OuterControlBean)ois.readObject();
+        }
+        finally {
+            if(ois != null)
+                ois.close();
+            if(bais != null)
+                bais.close();
+        }
+
+        Assert.assertEquals("outerControl", outerCopy.getControlID());
+        Assert.assertEquals("outerControl/innerControl", outerCopy.getDeclaredNestedControl().getControlID());
+    }
+
+    @EventHandler(field="outerControl", eventSet=OuterControl.OuterEvents.class, eventName="report")
+    public int onReport( String msg ) {
+        _onReportMessage = msg;
+        return 0;
+    }
+}

Modified: beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/composition/DeclarativeTest.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/composition/DeclarativeTest.java?rev=397275&r1=397274&r2=397275&view=diff
==============================================================================
--- beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/composition/DeclarativeTest.java (original)
+++ beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/composition/DeclarativeTest.java Wed Apr 26 12:13:21 2006
@@ -119,6 +119,8 @@
         Assert.assertEquals("outerControl", outerControl.getControlID());
         Assert.assertEquals("outerControl/innerControl", outerControl.getDeclaredNestedControl().getControlID());
 
+	Thread.dumpStack();
+
         // Test the relationships and identifiers are preserved across serialization and deserialization
         ByteArrayOutputStream baos = null;
         ObjectOutputStream oos = null;

Modified: beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/MiltonControlContext.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/MiltonControlContext.java?rev=397275&r1=397274&r2=397275&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/MiltonControlContext.java (original)
+++ beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/MiltonControlContext.java Wed Apr 26 12:13:21 2006
@@ -84,18 +84,6 @@
     }
 
     /**
-     * Override default getBeanAnnotationMap to not depend on ControlBean
-     * @param bean
-     * @param annotElem
-     * @return the property map
-     */
-    /*
-    protected PropertyMap getBeanAnnotationMap( ControlBean bean, AnnotatedElement annotElem ) {
-        return super.getBeanAnnotationMap( bean, annotElem );
-    }
-    */
-
-    /**
      * The ControlBeanContextProvider inner class acts as a single BeanContext service
      * provider for the ControlBeanContext service class.  The implementation is simple,
      * because the runtime ControlBeanContext implementation class directly implements

Modified: beehive/trunk/controls/test/webapps/src/composition/Controller.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/webapps/src/composition/Controller.java?rev=397275&r1=397274&r2=397275&view=diff
==============================================================================
--- beehive/trunk/controls/test/webapps/src/composition/Controller.java (original)
+++ beehive/trunk/controls/test/webapps/src/composition/Controller.java Wed Apr 26 12:13:21 2006
@@ -38,7 +38,6 @@
     @Control
     public OuterControlBean outercontrol;
 
-
     @Jpf.Action()
     protected Forward begin() {
         Report report = new Report();