Author: jsong
Date: Mon Jan 31 15:57:45 2005
New Revision: 149323

URL: http://svn.apache.org/viewcvs?view=rev&rev=149323
Log:
Add tests for applying generics on controls.

Added:
    
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/generic/SimpleControl.java
    
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/generic/SimpleControlImpl.jcs
    
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/generic/SimpleControlTest.java

Added: 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/generic/SimpleControl.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/generic/SimpleControl.java?view=auto&rev=149323
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/generic/SimpleControl.java
 (added)
+++ 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/generic/SimpleControl.java
 Mon Jan 31 15:57:45 2005
@@ -0,0 +1,22 @@
+package org.apache.beehive.controls.test.controls.generic;
+
+import java.util.Vector;
+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;
+
+/**
+ * A simple control interface declared with type parameter
+ * and uses an API with type parameters
+ */
[EMAIL PROTECTED]
+public interface SimpleControl<P>
+{
+
+    public void setThem(Vector<P> v);
+
+       public P getTheFirst();
+}

Added: 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/generic/SimpleControlImpl.jcs
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/generic/SimpleControlImpl.jcs?view=auto&rev=149323
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/generic/SimpleControlImpl.jcs
 (added)
+++ 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/generic/SimpleControlImpl.jcs
 Mon Jan 31 15:57:45 2005
@@ -0,0 +1,19 @@
+package org.apache.beehive.controls.test.controls.generic;
+
+import java.util.Vector;
+import java.lang.reflect.Method;
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.beehive.controls.api.bean.Extensible;
+
[EMAIL PROTECTED]
+public class SimpleControlImpl<P> implements SimpleControl<P>
+{ 
+    private  Vector<P> mylist=new Vector<P>();
+    
+    public void setThem(Vector<P> v){
+       mylist=v;
+    }
+    
+    public P getTheFirst(){return mylist.get(0);}
+
+} 

Added: 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/generic/SimpleControlTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/generic/SimpleControlTest.java?view=auto&rev=149323
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/generic/SimpleControlTest.java
 (added)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/generic/SimpleControlTest.java
 Mon Jan 31 15:57:45 2005
@@ -0,0 +1,95 @@
+package org.apache.beehive.controls.test.java.generic;
+
+import java.util.Vector;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.test.controls.generic.SimpleControl;
+import org.apache.beehive.controls.test.controls.generic.SimpleControlBean;
+import org.apache.beehive.controls.test.controls.util.TestBeanContext;
+import org.apache.beehive.test.tools.mantis.annotations.tch.Freq;
+
+/**
+ * A TestCase that tests Java generics on controls
+ */
[EMAIL PROTECTED]("detailed")
+public class SimpleControlTest extends TestCase
+{
+    // initialize declared controls once
+    public SimpleControlTest(String name) throws Exception
+    {
+        super(name);
+       _testContext = createTestBeanContext();
+    }
+
+
+    // begin and end control bean context for each test
+    public void setUp() throws Exception
+    {
+        org.apache.beehive.controls.api.bean.Controls.initializeClient( null, 
this, _testContext );
+        _testContext.beginContext();
+    }
+
+    public void tearDown() throws Exception
+    {
+        _testContext.endContext();
+    }
+
+    /**
+     * Returns a new TestBeanContext to act as a container for control testing.
+     */
+    private TestBeanContext createTestBeanContext() throws Exception
+    {
+        return new TestBeanContext();
+    }
+
+    private TestBeanContext _testContext;
+
+    /**
+     * A control that contains a nested control
+     */
+    @Control
+    public SimpleControlBean<String> stringBean;
+
+    /**
+     * Tests instantiating SimpleControlBean declaratively
+     */
+    public void testDeclarative() throws Exception
+    {
+        // Test invoking a bound operation, this should also result in the 
above event
+        // handler being called in a bound fashion
+        Vector<String> strings=new Vector<String>();
+        strings.add("One");
+        strings.add("Two");
+
+        stringBean.setThem(strings);
+
+               String s=stringBean.getTheFirst();
+
+               if (!s.equals("One"))
+                       fail("The first element retrieved is:"+s);
+    }
+
+    /**
+     * Tests instantiating SimpleControlBean programmatically
+     */
+    public void testProgrammatic() throws Exception
+    {
+        Vector<String> strings=new Vector<String>();
+        strings.add("One");
+        strings.add("Two");
+
+
+               SimpleControlBean<String> 
sbean=(SimpleControlBean<String>)java.beans.Beans.instantiate(
+                       Thread.currentThread().getContextClassLoader() ,
+                       
"org.apache.beehive.controls.test.controls.generic.SimpleControlBean<String>");
+
+        sbean.setThem(strings);
+
+               String s=stringBean.getTheFirst();
+
+               if (!s.equals("One"))
+                       fail("The first element retrieved is:"+s);
+    }
+
+}


Reply via email to