You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by cs...@apache.org on 2006/05/20 00:12:21 UTC
svn commit: r407920 - in /beehive/trunk/system-controls/test/ejb: ./
src/tests/org/apache/beehive/test/controls/system/test/
Author: cschoett
Date: Fri May 19 15:12:20 2006
New Revision: 407920
URL: http://svn.apache.org/viewvc?rev=407920&view=rev
Log:
Cleanup of how the EJB test suite was getting a control container context, added
new class to support this usage: CactusControlTestCase
Added:
beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/CactusControlTestCase.java (with props)
Removed:
beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestContextInitializer.java
Modified:
beehive/trunk/system-controls/test/ejb/build.xml
beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestBMPEntityBeanControl.java
beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestEjbLinkControl.java
beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestMethodOverrideSessionEjbControl.java
beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestSessionEjbControl.java
Modified: beehive/trunk/system-controls/test/ejb/build.xml
URL: http://svn.apache.org/viewvc/beehive/trunk/system-controls/test/ejb/build.xml?rev=407920&r1=407919&r2=407920&view=diff
==============================================================================
--- beehive/trunk/system-controls/test/ejb/build.xml (original)
+++ beehive/trunk/system-controls/test/ejb/build.xml Fri May 19 15:12:20 2006
@@ -295,7 +295,7 @@
<include name="**/Test*.java"/>
<exclude name="**/TestContextInitializer.java"/>
<!-- BMP test disabled to to deployment issues in g1.0, needs further investigation. -->
- <exclude name="**/TestBMP*.java"/>
+ <!-- <exclude name="**/TestBMP*.java"/> -->
</fileset>
</batchtest>
</cactus>
Added: beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/CactusControlTestCase.java
URL: http://svn.apache.org/viewvc/beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/CactusControlTestCase.java?rev=407920&view=auto
==============================================================================
--- beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/CactusControlTestCase.java (added)
+++ beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/CactusControlTestCase.java Fri May 19 15:12:20 2006
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2006 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.controls.system.test;
+
+import org.apache.cactus.ServletTestCase;
+import org.apache.beehive.controls.test.util.ControlContainerContextManager;
+import org.apache.beehive.controls.test.util.ControlContainerContextManagerFactory;
+import org.apache.beehive.controls.test.container.ControlTestContainerContext;
+import org.apache.beehive.controls.test.ControlTestException;
+import org.apache.beehive.controls.api.context.ControlContainerContext;
+import org.apache.beehive.controls.api.context.ControlThreadContext;
+import org.apache.beehive.controls.api.bean.ControlBean;
+
+/**
+ * Base control test case.
+ */
+public abstract class CactusControlTestCase
+ extends ServletTestCase {
+
+ /* todo: push strings into a .properties file */
+
+ private ControlContainerContextManager _controlContainerContextManager = null;
+
+ public void setUp()
+ throws Exception {
+
+ super.setUp();
+
+ beginContext();
+ initializeControls();
+ }
+
+ public void tearDown()
+ throws Exception {
+
+ super.tearDown();
+
+ endContext();
+ }
+
+ protected ControlContainerContext initializeControlContainerContext() {
+ return new ControlTestContainerContext();
+ }
+
+ protected ControlContainerContext getControlContainerContext() {
+ return getControlContainerContextManager().getControlContainerContext();
+ }
+
+ protected void initializeControls() {
+ getControlContainerContextManager().instantiateControls(this);
+ }
+
+ protected void beginContext() {
+ getControlContainerContextManager().beginContext();
+ }
+
+ protected void endContext() {
+ getControlContainerContextManager().endContext();
+ }
+
+ protected ControlContainerContextManager getControlContainerContextManager() {
+ if(_controlContainerContextManager == null) {
+ ControlContainerContext ccc = initializeControlContainerContext();
+
+ if(ccc == null)
+ throw new ControlTestException("Could not instantiate a ControlContainerContextManager as the control container context was null");
+
+ _controlContainerContextManager = ControlContainerContextManagerFactory.getInstance(ccc);
+ }
+
+ return _controlContainerContextManager;
+ }
+
+ protected ControlBean instantiateControl(String className) {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Object controlBean = java.beans.Beans.instantiate(classLoader, className, ControlThreadContext.getContext());
+ assert controlBean instanceof ControlBean;
+ return (ControlBean)controlBean;
+ }
+ catch(Exception e) {
+ throw new ControlTestException("Could not instantiate control with class \"" + className +
+ "\". Cause: " + e.getMessage(), e);
+ }
+ }
+}
Propchange: beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/CactusControlTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestBMPEntityBeanControl.java
URL: http://svn.apache.org/viewvc/beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestBMPEntityBeanControl.java?rev=407920&r1=407919&r2=407920&view=diff
==============================================================================
--- beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestBMPEntityBeanControl.java (original)
+++ beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestBMPEntityBeanControl.java Fri May 19 15:12:20 2006
@@ -22,36 +22,20 @@
import org.apache.beehive.test.controls.system.ejb.entity.SimpleEntityHome;
import org.apache.beehive.test.controls.system.controls.BMPEntityBeanControl;
import org.apache.beehive.controls.api.bean.Control;
-import org.apache.beehive.controls.api.context.ControlThreadContext;
-import org.apache.beehive.controls.api.context.ControlContainerContext;
/**
+ * Test a Bean-Managed-Persistence Entity Bean.
*/
-public class TestBMPEntityBeanControl extends ServletTestCase
+public class TestBMPEntityBeanControl extends CactusControlTestCase
{
@Control
private BMPEntityBeanControl _ejbControl;
- private ControlContainerContext _controlContext = null;
-
- /**
- */
public void setUp() throws Exception {
-
- _controlContext = ControlThreadContext.getContext();
- if (_controlContext == null) {
- _controlContext = TestContextInitializer.initContext(this);
- } else {
- TestBMPEntityBeanControlClientInitializer.initialize(_controlContext, this);
- }
+ super.setUp();
_ejbControl.create("entbean1");
}
- public void tearDown() throws Exception {
- _controlContext.endContext();
- super.tearDown();
- }
-
public void testEjbControlName() throws Exception {
_ejbControl.setName("foo");
assertEquals("foo", _ejbControl.getName());
Modified: beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestEjbLinkControl.java
URL: http://svn.apache.org/viewvc/beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestEjbLinkControl.java?rev=407920&r1=407919&r2=407920&view=diff
==============================================================================
--- beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestEjbLinkControl.java (original)
+++ beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestEjbLinkControl.java Fri May 19 15:12:20 2006
@@ -22,35 +22,14 @@
import org.apache.beehive.test.controls.system.controls.EjbLinkControl;
import org.apache.beehive.test.controls.system.ejb.session.SimpleSessionHome;
import org.apache.beehive.controls.api.bean.Control;
-import org.apache.beehive.controls.api.context.ControlThreadContext;
-import org.apache.beehive.controls.api.context.ControlContainerContext;
/**
+ * Test an Ejb Link.
*/
-public class TestEjbLinkControl extends ServletTestCase
+public class TestEjbLinkControl extends CactusControlTestCase
{
-
@Control
private EjbLinkControl _ejbControl;
-
- private ControlContainerContext _controlContext = null;
-
- /**
- */
- public void setUp() throws Exception {
-
- _controlContext = ControlThreadContext.getContext();
- if (_controlContext == null) {
- _controlContext = TestContextInitializer.initContext(this);
- } else {
- TestEjbLinkControlClientInitializer.initialize(_controlContext, this);
- }
- }
-
- public void tearDown() throws Exception {
- _controlContext.endContext();
- super.tearDown();
- }
public void testEjbControlHello() throws Exception {
String result = _ejbControl.sayHello();
Modified: beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestMethodOverrideSessionEjbControl.java
URL: http://svn.apache.org/viewvc/beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestMethodOverrideSessionEjbControl.java?rev=407920&r1=407919&r2=407920&view=diff
==============================================================================
--- beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestMethodOverrideSessionEjbControl.java (original)
+++ beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestMethodOverrideSessionEjbControl.java Fri May 19 15:12:20 2006
@@ -18,10 +18,7 @@
package org.apache.beehive.test.controls.system.test;
-import org.apache.cactus.ServletTestCase;
import org.apache.beehive.controls.api.bean.Control;
-import org.apache.beehive.controls.api.context.ControlContainerContext;
-import org.apache.beehive.controls.api.context.ControlThreadContext;
import org.apache.beehive.test.controls.system.controls.MethodOverrideSessionEJBControl;
import org.apache.beehive.test.controls.system.ejb.session.SimpleSessionHome;
@@ -31,34 +28,10 @@
* behavior is that the EJB method is still invoked after any necessary annotation processing
* has been completed.
*/
-public class TestMethodOverrideSessionEjbControl extends ServletTestCase
+public class TestMethodOverrideSessionEjbControl extends CactusControlTestCase
{
@Control
private MethodOverrideSessionEJBControl _ejbControl;
-
- private ControlContainerContext _controlContext = null;
-
- /**
- * Setup the test.
- * @throws Exception
- */
- public void setUp() throws Exception {
- _controlContext = ControlThreadContext.getContext();
- if (_controlContext == null) {
- _controlContext = TestContextInitializer.initContext(this);
- } else {
- TestMethodOverrideSessionEjbControlClientInitializer.initialize(_controlContext, this);
- }
- }
-
- /**
- * Tear down the test.
- * @throws Exception
- */
- public void tearDown() throws Exception {
- _controlContext.endContext();
- super.tearDown();
- }
/**
* Test overridden method which has no parameters.
Modified: beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestSessionEjbControl.java
URL: http://svn.apache.org/viewvc/beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestSessionEjbControl.java?rev=407920&r1=407919&r2=407920&view=diff
==============================================================================
--- beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestSessionEjbControl.java (original)
+++ beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestSessionEjbControl.java Fri May 19 15:12:20 2006
@@ -18,53 +18,18 @@
package org.apache.beehive.test.controls.system.test;
-import org.apache.cactus.ServletTestCase;
import org.apache.beehive.test.controls.system.ejb.session.SimpleSessionHome;
import org.apache.beehive.test.controls.system.controls.SimpleSessionEJBControl;
import org.apache.beehive.controls.api.bean.Control;
-import org.apache.beehive.controls.api.context.ControlThreadContext;
-import org.apache.beehive.controls.api.context.ControlContainerContext;
/**
+ * Test an Ejb control for a Session EJB.
*/
-public class TestSessionEjbControl extends ServletTestCase
+public class TestSessionEjbControl extends CactusControlTestCase
{
-// /**
-// * Class under test
-// */
-// private SimpleSessionRemote sessionBean;
-
@Control
private SimpleSessionEJBControl _ejbControl;
- private ControlContainerContext _controlContext = null;
-
- /**
- */
- public void setUp() throws Exception {
-
-// Context ctx = getInitialContext("localhost:4201","system","manager");
-// SimpleSessionHome home = (SimpleSessionHome) ctx.lookup("SimpleSessionRemote");
-// sessionBean = home.create();
-
- _controlContext = ControlThreadContext.getContext();
- if (_controlContext == null) {
- _controlContext = TestContextInitializer.initContext(this);
- } else {
- TestSessionEjbControlClientInitializer.initialize(_controlContext, this);
- }
- }
-
- public void tearDown() throws Exception {
- _controlContext.endContext();
- super.tearDown();
- }
-
-// public void testHello() throws Exception {
-// String result = sessionBean.sayHello();
-// assertEquals("Hello!", result);
-// }
-
public void testEjbControlHello() throws Exception {
String result = _ejbControl.sayHello();
assertEquals("Hello!", result);
@@ -73,7 +38,6 @@
public void testEjbControlEcho() throws Exception {
String result = _ejbControl.echo("Hi there");
assertEquals("Hi there", result);
-
}
public void testGetHome() throws Exception {
@@ -96,22 +60,4 @@
Throwable t = _ejbControl.getEJBException();
assertNull(t);
}
-
-// /**
-// *
-// * @param url
-// * @param user
-// * @param password
-// * @return
-// * @throws Exception
-// */
-// static Context getInitialContext(String url, String user, String password) throws Exception {
-//
-// Properties h = new Properties();
-// h.put(Context.INITIAL_CONTEXT_FACTORY, "org.openejb.client.RemoteInitialContextFactory");
-// h.put(Context.PROVIDER_URL, url);
-// h.put(Context.SECURITY_PRINCIPAL, user);
-// h.put(Context.SECURITY_CREDENTIALS, password);
-// return new InitialContext(h);
-// }
}