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/12 22:44:54 UTC
svn commit: r169882 - in /incubator/beehive/trunk/controls/test/src:
controls/org/apache/beehive/controls/test/controls/serialization/
units/org/apache/beehive/controls/test/java/s13n/
Author: jsong
Date: Thu May 12 13:44:53 2005
New Revision: 169882
URL: http://svn.apache.org/viewcvs?rev=169882&view=rev
Log:
Add a detailed test on controls serialization.
Added:
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/serialization/
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/serialization/HelloControl.java
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/serialization/HelloControlImpl.jcs
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/s13n/
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/s13n/Test.java
Added: incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/serialization/HelloControl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/serialization/HelloControl.java?rev=169882&view=auto
==============================================================================
--- incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/serialization/HelloControl.java (added)
+++ incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/serialization/HelloControl.java Thu May 12 13:44:53 2005
@@ -0,0 +1,29 @@
+package org.apache.beehive.controls.test.controls.serialization;
+
+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.properties.PropertySet;
+
+
+/**
+ * A control interface with propertySet
+ */
+@ControlInterface
+public interface HelloControl
+{
+
+ @PropertySet
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target( {ElementType.TYPE, ElementType.FIELD, ElementType.METHOD} )
+ public @interface Property1
+ {
+ int quantity() default 10;
+ String name();
+ }
+
+ public void changeTransient(String input);
+ public String getTransient();
+}
Added: incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/serialization/HelloControlImpl.jcs
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/serialization/HelloControlImpl.jcs?rev=169882&view=auto
==============================================================================
--- incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/serialization/HelloControlImpl.jcs (added)
+++ incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/serialization/HelloControlImpl.jcs Thu May 12 13:44:53 2005
@@ -0,0 +1,22 @@
+package org.apache.beehive.controls.test.controls.serialization;
+
+import java.io.Serializable;
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+
+/**
+ * A simple control impl
+ */
+@ControlImplementation
+public class HelloControlImpl implements HelloControl,Serializable
+{
+ transient String transientStr="init";
+ public void changeTransient(String input)
+ {
+ transientStr=input;
+ }
+
+ public String getTransient()
+ {
+ return transientStr;
+ }
+}
Added: incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/s13n/Test.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/s13n/Test.java?rev=169882&view=auto
==============================================================================
--- incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/s13n/Test.java (added)
+++ incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/s13n/Test.java Thu May 12 13:44:53 2005
@@ -0,0 +1,71 @@
+package org.apache.beehive.controls.test.java.s13n;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.test.controls.serialization.HelloControl;
+import org.apache.beehive.controls.test.controls.serialization.HelloControlBean;
+import org.apache.beehive.test.tools.mantis.annotations.tch.Freq;
+
+/**
+ * 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
+ */
+@Freq("detailed")
+public class Test extends TestCase
+{
+ // initialize declared controls once
+ public Test(String name) throws Exception
+ {
+ super(name);
+ }
+
+ public void testWriteRead() throws Exception
+ {
+ HelloControlBean hc=(HelloControlBean)java.beans.Beans.instantiate(
+ Thread.currentThread().getContextClassLoader() ,
+ "org.apache.beehive.controls.test.controls.serialization.HelloControlBean");
+
+ hc.setQuantity(100);
+ hc.setName("TheName");
+ hc.changeTransient("A different value");
+
+ try{
+ FileOutputStream fos = new FileOutputStream("objects.ser");
+ ObjectOutputStream oos = new ObjectOutputStream( fos );
+
+ oos.writeObject(hc);
+
+ //To read them back in, reverse the process with:
+
+ FileInputStream fis = new FileInputStream( "objects.ser");
+ ObjectInputStream ois = new ObjectInputStream( fis );
+
+ HelloControlBean hc2 = (HelloControlBean)ois.readObject();
+ int qty=hc2.getQuantity();
+ String name=hc2.getName();
+ String theTransient=hc2.getTransient();
+
+ Assert.assertEquals(100,qty);
+ Assert.assertEquals("TheName",name);
+ Assert.assertEquals(null,theTransient);
+
+ }
+ catch(IOException e){
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+ }
+}
\ No newline at end of file