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/09/02 00:28:52 UTC

svn commit: r265795 [2/2] - in /beehive/trunk/controls/test: infra/milton/ src/controls/org/apache/beehive/controls/test/controls/composition/ src/controls/org/apache/beehive/controls/test/controls/context/ src/controls/org/apache/beehive/controls/test...

Added: beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/MiltonInterceptorContextImpl.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/MiltonInterceptorContextImpl.java?rev=265795&view=auto
==============================================================================
--- beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/MiltonInterceptorContextImpl.java (added)
+++ beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/MiltonInterceptorContextImpl.java Thu Sep  1 15:28:23 2005
@@ -0,0 +1,96 @@
+/*
+ * 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.test.tools.milton.junit;
+
+import org.apache.beehive.controls.api.bean.ControlBean;
+
+import java.lang.reflect.Method;
+import java.beans.beancontext.BeanContextServiceProvider;
+import java.beans.beancontext.BeanContextServices;
+import java.util.Iterator;
+
+public class MiltonInterceptorContextImpl implements MiltonInterceptorContext
+{
+    /**
+     * The ResourceContextProvider inner class acts as a single BeanContext service
+     * provider for the ResourceContext service class.
+     */
+    public static class MiltonInterceptorContextProvider implements BeanContextServiceProvider
+    {
+        //
+        // BeanContextServiceProvider.getService()
+        //
+        public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass,
+                                 Object serviceSelector)
+        {
+            System.out.println( "***********************" );
+            System.out.println( "***********************" );
+            System.out.println( "MiltonInterceptorContextProvider GetService  " );
+            System.out.println( "***********************" );
+            System.out.println( "***********************" );
+            return new MiltonInterceptorContextImpl();
+        }
+
+        //
+        // BeanContextServiceProvider.releaseService()
+        //
+        public void releaseService(BeanContextServices bcs, Object requestor, Object service)
+        {
+            return; // Should not happen, service is never unregistered
+        }
+
+        //
+        // BeanContextServiceProvider.getContextServiceSelectors()
+        //
+        public Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass)
+        {
+            return null;    // no selectors
+        }
+    }
+
+    /**
+     * A singleton instance of the MiltonInterceptorContextProvider class is what will be registered
+     * on all ControlContainerContext instances.  The provider can be a singleton because it is
+     * completely stateless and thread-safe.
+     */
+    static private MiltonInterceptorContextImpl.MiltonInterceptorContextProvider _theProvider = new MiltonInterceptorContextImpl.MiltonInterceptorContextProvider();
+
+    /**
+     * Returns the provider used to create new MiltonInterceptorContext instances
+     */
+    static public MiltonInterceptorContextImpl.MiltonInterceptorContextProvider getProvider() { return _theProvider; }
+
+
+    public void preInvoke( ControlBean cb, Method m, Object [] args)
+    {
+        System.out.println( "***********************" );
+        System.out.println( "***********************" );
+        System.out.println( "PREINVOKE INTERCEPTOR  " );
+        System.out.println( "***********************" );
+        System.out.println( "***********************" );
+    }
+
+    public void postInvoke( ControlBean cb, Method m, Object [] args, Object retval, Throwable t) {}
+
+    /** Called before a control event is fired (through a client proxy) */
+    public void preEvent( ControlBean cb, Class eventSet, Method m, Object [] args) {}
+    /** Called after a control event is fired (through a client proxy) */
+    public void postEvent( ControlBean cb, Class eventSet, Method m, Object [] args) {}
+}
+

Added: beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/MiltonTestCase.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/MiltonTestCase.java?rev=265795&view=auto
==============================================================================
--- beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/MiltonTestCase.java (added)
+++ beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/MiltonTestCase.java Thu Sep  1 15:28:23 2005
@@ -0,0 +1,67 @@
+package org.apache.beehive.test.tools.milton.junit;
+
+import java.lang.reflect.Field;
+
+import java.beans.beancontext.BeanContextChild;
+import java.beans.beancontext.BeanContextServiceProvider;
+import java.beans.beancontext.BeanContextServices;
+
+import junit.framework.TestCase;
+
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.bean.Controls;
+
+/*
+ * A JUnit TestCase class which serves as a Control Container
+ * and supports Declarative instantiation.
+ */
+public abstract class MiltonTestCase extends TestCase implements java.io.Serializable
+{
+    protected MiltonControlContext mcc = null;
+    protected boolean controlClient = false;
+
+    protected static final long serialVersionUID = 16L;
+
+    public MiltonTestCase() {}
+
+    public MiltonTestCase(String name)
+    {
+	super(name);
+
+	if (isControlClient(this)) {
+	    this.controlClient = true;
+	    this.mcc = new MiltonControlContext();
+	}
+    }
+
+    public void setUp() throws Exception 
+    {
+	if (this.controlClient) {
+	    mcc.beginContext();
+	    Controls.initializeClient(null, this, mcc);
+	}
+    }
+
+    public void tearDown() {
+	if (null != this.mcc)
+	    mcc.endContext();
+    }
+
+    /*
+     * helper method to determine if this is a client contains controls
+     */
+    private boolean isControlClient(Object controlContainer)
+    {
+	Class controlContainerClass = controlContainer.getClass();
+
+	Field[] fields = controlContainerClass.getDeclaredFields();
+
+	for (int i = 0; i < fields.length; i++) {
+	    Field f = fields[i];
+	    if (null != f.getAnnotation(org.apache.beehive.controls.api.bean.Control.class))
+		return true;
+	}
+
+	return false;
+    }
+}

Added: beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/RemoteReportTestCase.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/RemoteReportTestCase.java?rev=265795&view=auto
==============================================================================
--- beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/RemoteReportTestCase.java (added)
+++ beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/RemoteReportTestCase.java Thu Sep  1 15:28:23 2005
@@ -0,0 +1,72 @@
+package org.apache.beehive.test.tools.milton.junit;
+
+import junit.framework.TestCase;
+
+import org.apache.beehive.test.tools.milton.client.TestContext;
+
+public abstract class RemoteReportTestCase extends ReportTestCase
+{
+    protected static final String HTTP_PREFIX = "http://";
+    protected static final String HTTPS_PREFIX = "https://";
+
+    private String urlPrefix = null;
+
+    public RemoteReportTestCase(String name)
+    {
+        super(name);
+
+        String hostName = TestContext.getProperty("TEST_HOSTNAME");
+        String hostNamePort = TestContext.getProperty("TEST_HOSTNAME_PORT");
+
+        if (null == hostName || hostName.equals("")) {
+            hostName = TestContext.getProperty("HOSTNAME");
+            if (null == hostName || hostName.equals(""))
+		hostName = "localhost";
+        }
+
+        if (null != hostNamePort)
+            hostName += ":" + hostNamePort;
+
+        this.urlPrefix = HTTP_PREFIX + hostName;
+    }
+
+    public String getUrlPrefix()
+    {
+        return this.urlPrefix;
+    }
+
+    public void setUrlPrefix(String p_urlPrefix)
+    {
+        if (null == p_urlPrefix)
+            throw new IllegalArgumentException("Cannot set null URI PRefix");
+
+        if (! p_urlPrefix.startsWith(HTTP_PREFIX) ||
+            ! p_urlPrefix.startsWith(HTTPS_PREFIX)) {
+            throw new IllegalArgumentException("URL Prefix must have a valid " +
+                                               "protocol: " + HTTP_PREFIX +
+                                               " or " + HTTPS_PREFIX + ": " +
+                                               p_urlPrefix);
+        }
+
+        this.urlPrefix = p_urlPrefix;
+    }
+
+    protected String createUrl(String p_url)
+    {
+        String l_url = null;
+
+        if (null == p_url)
+            throw new IllegalArgumentException("URL cannot be null");
+
+        if (p_url.startsWith(HTTP_PREFIX) || p_url.startsWith(HTTPS_PREFIX))
+            l_url = p_url;
+        else {
+            if (p_url.startsWith("/"))
+                l_url = getUrlPrefix() + p_url;
+            else
+                l_url = getUrlPrefix() + "/" + p_url;
+        }
+
+        return l_url;
+    }
+}

Modified: beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/ReportTestCase.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/ReportTestCase.java?rev=265795&r1=265794&r2=265795&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/ReportTestCase.java (original)
+++ beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/ReportTestCase.java Thu Sep  1 15:28:23 2005
@@ -1,72 +1,60 @@
 package org.apache.beehive.test.tools.milton.junit;
 
-import junit.framework.TestCase;
+import org.apache.beehive.test.tools.milton.junit.MiltonTestCase;
+import org.apache.beehive.test.tools.milton.common.Report;
 
-import org.apache.beehive.test.tools.milton.client.TestContext;
-
-public abstract class ReportTestCase extends TestCase
+/*
+ * A JUnit TestCase class which serves as a Control Container
+ * and supports Declarative instantiation.
+ */
+public abstract class ReportTestCase extends MiltonTestCase
 {
-    protected static final String HTTP_PREFIX = "http://";
-    protected static final String HTTPS_PREFIX = "https://";
-
-    private String urlPrefix = null;
-
     public ReportTestCase(String name)
     {
-        super(name);
-
-        String hostName = TestContext.getProperty("TEST_HOSTNAME");
-        String hostNamePort = TestContext.getProperty("TEST_HOSTNAME_PORT");
-
-        if (null == hostName || hostName.equals("")) {
-            hostName = TestContext.getProperty("HOSTNAME");
-            if (null == hostName || hostName.equals(""))
-                hostName = "localhost";
-        }
-
-        if (null != hostNamePort)
-            hostName += ":" + hostNamePort;
-
-        this.urlPrefix = HTTP_PREFIX + hostName;
+	super(name);
     }
 
-    public String getUrlPrefix()
+    protected void assertReport(Report p_report) throws Exception
     {
-        return this.urlPrefix;
+	if (null == p_report)
+	    throw new IllegalArgumentException("Report parameter cannot be Null");
+
+        if (Report.ABORT.equals(p_report.getStatus()))
+            throw new AbortTestException("Abort Status Dectected: \n" +
+                    p_report.toString());
+        else if (Report.FAIL.equals(p_report.getStatus()))
+            throw new junit.framework.AssertionFailedError("FAILURE: \n" +
+                    p_report.toString());
+
+        else if (!Report.PASS.equals(p_report.getStatus()))
+            throw new AbortTestException("Unknown Status Detected: \n" +
+                    p_report.toString());
+
+	printMessages(p_report);
+	printExceptionStack(p_report);
     }
 
-    public void setUrlPrefix(String p_urlPrefix)
+    protected void printMessages(Report p_report)
     {
-        if (null == p_urlPrefix)
-            throw new IllegalArgumentException("Cannot set null URI PRefix");
+	if (null == p_report) {
+	    return;
+	}
+	    
+	String l_messages = p_report.getMessage();
 
-        if (! p_urlPrefix.startsWith(HTTP_PREFIX) ||
-            ! p_urlPrefix.startsWith(HTTPS_PREFIX)) {
-            throw new IllegalArgumentException("URL Prefix must have a valid " +
-                                               "protocol: " + HTTP_PREFIX +
-                                               " or " + HTTPS_PREFIX + ": " +
-                                               p_urlPrefix);
-        }
-
-        this.urlPrefix = p_urlPrefix;
+        if (null != l_messages && !"".equals(l_messages))
+            System.out.println("\n[MESSAGES]\n\t" + l_messages);
     }
 
-    protected String createUrl(String p_url)
+    protected void printExceptionStack(Report p_report)
     {
-        String l_url = null;
-
-        if (null == p_url)
-            throw new IllegalArgumentException("URL cannot be null");
+	if (null == p_report) {
+	    return;
+	}
 
-        if (p_url.startsWith(HTTP_PREFIX) || p_url.startsWith(HTTPS_PREFIX))
-            l_url = p_url;
-        else {
-            if (p_url.startsWith("/"))
-                l_url = getUrlPrefix() + p_url;
-            else
-                l_url = getUrlPrefix() + "/" + p_url;
-        }
+	String l_exceptionStack = p_report.getExceptionStack();
 
-        return l_url;
+        if (null != l_exceptionStack && !"".equals(l_exceptionStack))
+            System.out.println("\n[EXCEPTION]\n\t" + l_exceptionStack);
     }
 }

Modified: beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/SOAPReportTestCase.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/SOAPReportTestCase.java?rev=265795&r1=265794&r2=265795&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/SOAPReportTestCase.java (original)
+++ beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/SOAPReportTestCase.java Thu Sep  1 15:28:23 2005
@@ -17,7 +17,7 @@
  * @author jacobd@bea.com 5/20/2005 Cleaned up SOAP payload creation, created methods for doc/literal payloads
  *
  */
-public abstract class SOAPReportTestCase extends ReportTestCase
+public abstract class SOAPReportTestCase extends RemoteReportTestCase
 {
     public SOAPReportTestCase(String name)
     {
@@ -37,7 +37,6 @@
         return endpoint;
     }
 
-
     /**
      * This method is used to set where soap requests will be sent
      * the value can be one of relative or full path
@@ -160,7 +159,6 @@
         return l_call;
     }
 
-
     //BUGBUG: Test this for RPC calls
     private Call createCall_RpcStyle(String endpoint, String p_uri, String p_method) throws java.net.MalformedURLException
     {
@@ -195,7 +193,6 @@
         assertReport(getEndpoint(), p_uri, p_method, false);
     }
 
-
     /**
      * Convenience method for invoking a test method. This method works for
      * doc/literal wrapped web services. If you are testing against an RPC/Encoded
@@ -228,31 +225,9 @@
             l_resp = createCall_DocLitWrappedStyle(getEndpoint(),
                     p_uri, p_method).invoke(new Object[]{});
 
-
         if (l_resp instanceof java.rmi.RemoteException)
             throw (java.rmi.RemoteException) l_resp;
 
-        Report l_report = (Report) l_resp;
-
-        String l_status = l_report.getStatus();
-        String l_message = l_report.getMessage();
-        String l_exceptionStack = l_report.getExceptionStack();
-
-        if (Report.ABORT.equals(l_status))
-            throw new AbortTestException("Abort Status Dectected: \n" +
-                    l_report.toString());
-        else if (Report.FAIL.equals(l_status))
-            throw new junit.framework.AssertionFailedError("FAILURE: \n" +
-                    l_report.toString());
-
-        else if (!Report.PASS.equals(l_status))
-            throw new AbortTestException("Unknown Status Detected: \n" +
-                    l_report.toString());
-
-        if (null != l_message && !"".equals(l_message))
-            System.out.println("\n[MESSAGES]\n\t" + l_message);
-
-        if (null != l_exceptionStack && !"".equals(l_exceptionStack))
-            System.out.println("\n[EXCEPTION]\n\t" + l_exceptionStack);
+	super.assertReport((Report) l_resp);
     }
-}
\ No newline at end of file
+}

Added: beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/SerializeUtils.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/SerializeUtils.java?rev=265795&view=auto
==============================================================================
--- beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/SerializeUtils.java (added)
+++ beehive/trunk/controls/test/tools/milton/src/org/apache/beehive/test/tools/milton/junit/SerializeUtils.java Thu Sep  1 15:28:23 2005
@@ -0,0 +1,84 @@
+/*
+ * 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.test.tools.milton.junit;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+
+/**
+ * Utility code for testing serialization behavior
+ */
+public final class SerializeUtils {
+    /**
+     * Serializes an object into a byte array, then deserializes it from the array and returns
+     * the deserialized object.
+     */
+    public static <T extends Object> T testSerialize(T obj)
+    {
+        byte [] serializedObject;
+        T returnObject;
+
+        ByteArrayOutputStream baos = null;
+        ObjectOutputStream oos = null;
+        try
+        {
+            baos = new ByteArrayOutputStream();
+            oos = new ObjectOutputStream(baos);
+            oos.writeObject(obj);
+            oos.flush();
+            serializedObject = baos.toByteArray();
+        }
+        catch (Exception e) {
+            throw new RuntimeException("Error serializing object", e);
+        }
+        finally {
+            if(oos != null)
+                try{oos.close();}catch(IOException ignore) {}
+            if(baos != null)
+                try{baos.close();}catch(IOException ignore) {}
+        }
+
+        ByteArrayInputStream bais = null;
+        ObjectInputStream ois = null;
+        try
+        {
+            bais = new ByteArrayInputStream(serializedObject);
+            ois = new ObjectInputStream(bais);
+            returnObject = (T)ois.readObject();
+            ois.close();
+            bais.close();
+        }
+        catch (Exception e) {
+            throw new RuntimeException("Error deserializing object", e);
+        }
+        finally {
+            if(bais != null)
+                try{bais.close();}catch(IOException ignore) {}
+            if(ois != null)
+                try{ois.close();}catch(IOException ignore) {}
+        }
+
+        if (!obj.equals(returnObject))
+            throw new RuntimeException("Deserialized object is not equivalent to original!");
+
+        return returnObject;
+    }
+}