You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2010/07/26 15:51:02 UTC
svn commit: r979281 - in /openwebbeans/trunk:
webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
webbeans-porting/src/main/java/org/apache/webbeans/test/tck/StandaloneContainersImpl.java
Author: gerdogdu
Date: Mon Jul 26 13:51:01 2010
New Revision: 979281
URL: http://svn.apache.org/viewvc?rev=979281&view=rev
Log:
[OWB-426] Tweak EJBPlugin to work with Standalone Tests
Modified:
openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/StandaloneContainersImpl.java
Modified: openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java?rev=979281&r1=979280&r2=979281&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java (original)
+++ openwebbeans/trunk/webbeans-openejb/src/main/java/org/apache/webbeans/ejb/EjbPlugin.java Mon Jul 26 13:51:01 2010
@@ -93,7 +93,7 @@ public class EjbPlugin extends AbstractO
private Map<Class<?>, DeploymentInfo> singletonBeans = new ConcurrentHashMap<Class<?>, DeploymentInfo>();
- //EJB Interface to instances
+ // EJB Interface to instances
private Map<String, EJBInstanceProxy<?>> ejbInstances = new ConcurrentHashMap<String, EJBInstanceProxy<?>>();
private static final TransactionService TRANSACTION_SERVICE = new OpenEJBTransactionService();
@@ -102,6 +102,10 @@ public class EjbPlugin extends AbstractO
private final Map<String, JndiNameStrategy> nameStrategies = new TreeMap<String, JndiNameStrategy>();
+ // This is here for standalone tests are correctly run
+ // Not used in anywhere
+ private boolean useInTest = false;
+
public EjbPlugin()
{
@@ -174,6 +178,12 @@ public class EjbPlugin extends AbstractO
}
}
+ // Used for tests
+ public void setUseInTest(boolean useInTest)
+ {
+ this.useInTest = useInTest;
+ }
+
/**
* OpenEJB call back method It is used to get the list of deployed
* application and store the Stateless and Stateful pools localy.
@@ -210,14 +220,14 @@ public class EjbPlugin extends AbstractO
}
}
- //Means that this is not the our deployment archive
+ // Means that this is not the our deployment archive
boolean result = addBeanDeploymentInfos(statelessList.toArray(new DeploymentInfo[statelessList.size()]), SessionBeanType.STATELESS);
- if(!result)
+ if (!result)
{
deployedApplications.remove(appInfo);
return;
}
-
+
addBeanDeploymentInfos(statefulList.toArray(new DeploymentInfo[statefulList.size()]), SessionBeanType.STATEFUL);
addBeanDeploymentInfos(singletonList.toArray(new DeploymentInfo[singletonList.size()]), SessionBeanType.SINGLETON);
}
@@ -228,7 +238,7 @@ public class EjbPlugin extends AbstractO
*/
public void beforeApplicationDestroyed(AppInfo appInfo)
{
- if(this.deployedApplications.contains(appInfo))
+ if (this.deployedApplications.contains(appInfo))
{
this.deployedApplications.remove(appInfo);
for (EjbJarInfo ejbJar : appInfo.ejbJars)
@@ -252,7 +262,7 @@ public class EjbPlugin extends AbstractO
this.ejbInstances.remove(bean.ejbName);
}
- }
+ }
}
}
@@ -296,9 +306,13 @@ public class EjbPlugin extends AbstractO
public boolean isSessionBean(Class<?> clazz)
{
- //This is used in tests, because in reality containerSystem is not null
- if (this.containerSystem == null)
+ // This is used in tests, because in reality containerSystem is not
+ // null
+ if (this.containerSystem == null || useInTest)
{
+ // Used for tests
+ useInTest = false;
+
this.containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
Container[] containers = this.containerSystem.containers();
for (Container container : containers)
@@ -328,11 +342,11 @@ public class EjbPlugin extends AbstractO
for (DeploymentInfo deployment : deployments)
{
boolean inTest = Boolean.valueOf(SecurityUtil.doPrivilegedGetSystemProperty("EjbPlugin.test", "false"));
- classLoaderEquality = deployment.getBeanClass().getClassLoader().equals(WebBeansFinder.
- getSingletonClassLoader(PluginLoader.getInstance()));
-
- //Yes, this EJB archive is deployed within this web application
- if(inTest || classLoaderEquality)
+ classLoaderEquality = deployment.getBeanClass().getClassLoader().equals(WebBeansFinder.getSingletonClassLoader(PluginLoader.getInstance()));
+
+ // Yes, this EJB archive is deployed within this web
+ // application
+ if (inTest || classLoaderEquality)
{
if (type.equals(SessionBeanType.STATELESS))
{
@@ -357,10 +371,10 @@ public class EjbPlugin extends AbstractO
this.ejbInstances.put(beanName, ejb);
logger.info("Exported EJB " + deployment.getEjbName() + " with interface " + entry.getValue().getInterface().getName());
}
- }
+ }
}
- }
-
+ }
+
return classLoaderEquality;
}
@@ -452,7 +466,7 @@ public class EjbPlugin extends AbstractO
return strategy;
}
}
-
+
return null;
}
@@ -463,7 +477,7 @@ public class EjbPlugin extends AbstractO
Class<?> remoteHome = deployment.getHomeInterface();
if (remoteHome != null)
- {
+ {
bindings.put(remoteHome.getName(), new EJBInstanceProxy(deployment, remoteHome));
}
Modified: openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/StandaloneContainersImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/StandaloneContainersImpl.java?rev=979281&r1=979280&r2=979281&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/StandaloneContainersImpl.java (original)
+++ openwebbeans/trunk/webbeans-porting/src/main/java/org/apache/webbeans/test/tck/StandaloneContainersImpl.java Mon Jul 26 13:51:01 2010
@@ -47,7 +47,9 @@ import org.apache.openejb.jee.StatefulBe
import org.apache.openejb.jee.StatelessBean;
import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.corespi.ServiceLoader;
+import org.apache.webbeans.ejb.EjbPlugin;
import org.apache.webbeans.lifecycle.StandaloneLifeCycle;
+import org.apache.webbeans.plugins.PluginLoader;
import org.apache.webbeans.spi.ScannerService;
import org.apache.webbeans.test.tck.mock.TCKMetaDataDiscoveryImpl;
import org.jboss.testharness.api.DeploymentException;
@@ -56,109 +58,132 @@ import org.jboss.testharness.spi.Standal
public class StandaloneContainersImpl implements StandaloneContainers
{
private StandaloneLifeCycle lifeCycle = null;
-
+
private DeploymentException excpetion;
-
+
public void deployInternal(Iterable<Class<?>> classes) throws DeploymentException
{
- //Scanner service
- final TCKMetaDataDiscoveryImpl discovery = (TCKMetaDataDiscoveryImpl)ServiceLoader.getService(ScannerService.class);
-
- //Lifecycle container
+ // Scanner service
+ final TCKMetaDataDiscoveryImpl discovery = (TCKMetaDataDiscoveryImpl) ServiceLoader.getService(ScannerService.class);
+
+ // Lifecycle container
this.lifeCycle = new StandaloneLifeCycle()
{
protected void afterInitApplication(Properties event)
{
this.scannerService = discovery;
- }
+ }
};
-
+
try
{
Iterator<Class<?>> it = classes.iterator();
- while(it.hasNext())
+ while (it.hasNext())
{
discovery.addBeanClass(it.next());
}
-
+
this.lifeCycle.startApplication(null);
-
+
}
- catch(Throwable e)
+ catch (Throwable e)
{
e.printStackTrace();
- this.excpetion = new DeploymentException("Standalone Container Impl.",e);
+ this.excpetion = new DeploymentException("Standalone Container Impl.", e);
throw this.excpetion;
}
-
- }
+ }
public boolean deployInternal(Iterable<Class<?>> classes, Iterable<URL> beansXmls)
{
try
{
- final TCKMetaDataDiscoveryImpl discovery = (TCKMetaDataDiscoveryImpl)ServiceLoader.getService(ScannerService.class);
-
- //Lifecycle container
+ final TCKMetaDataDiscoveryImpl discovery = (TCKMetaDataDiscoveryImpl) ServiceLoader.getService(ScannerService.class);
+
+ // Lifecycle container
this.lifeCycle = new StandaloneLifeCycle()
{
protected void afterInitApplication(Properties event)
{
this.scannerService = discovery;
- }
+ }
+
+ @Override
+ public void beforeStartApplication(Object object)
+ {
+ super.beforeStartApplication(object);
+ try
+ {
+ PluginLoader.getInstance().startUp();
+ EjbPlugin plugin = (EjbPlugin) PluginLoader.getInstance().getEjbPlugin();
+ plugin.setUseInTest(true);
+ }
+ catch (Throwable e)
+ {
+ // Not worry
+ }
+ }
+
};
-
+
Iterator<Class<?>> it = classes.iterator();
- while(it.hasNext())
+ while (it.hasNext())
{
discovery.addBeanClass(it.next());
}
-
+
Iterator<URL> itUrl = beansXmls.iterator();
- while(itUrl.hasNext())
+ while (itUrl.hasNext())
{
discovery.addBeanXml(itUrl.next());
}
-
- this.lifeCycle.startApplication(null);
+
+ this.lifeCycle.startApplication(null);
}
- catch(Throwable e)
+ catch (Throwable e)
{
e.printStackTrace();
- this.excpetion = new DeploymentException("Standalone Container Impl.",e);
-
+ this.excpetion = new DeploymentException("Standalone Container Impl.", e);
+
return false;
}
-
+
return true;
}
public void setup()
{
-
+
}
-
+
public void cleanup()
{
}
-
public void undeploy()
{
try
{
this.lifeCycle.stopApplication(null);
- this.lifeCycle = null;
-
- //X TODO solve in a different way! EjbPlugin.CONFIGURED_FOR_USED_IN_TEST = false;
- }
+ this.lifeCycle = null;
+
+ try
+ {
+ EjbPlugin plugin = (EjbPlugin) PluginLoader.getInstance().getEjbPlugin();
+ plugin.setUseInTest(false);
+ }
+ catch (Throwable e)
+ {
+ // Not worry
+ }
+ }
finally
{
- ManagersImpl.cleanUp();
+ ManagersImpl.cleanUp();
}
- }
+ }
public DeploymentException getDeploymentException()
{
@@ -170,25 +195,23 @@ public class StandaloneContainersImpl im
return BeanManagerImpl.getManager();
}
-
@Override
public void deploy(Collection<Class<?>> classes) throws DeploymentException
- {
+ {
setUp(classes);
deployInternal(classes);
}
-
@Override
public boolean deploy(Collection<Class<?>> classes, Collection<URL> xmls)
{
setUp(classes);
return deployInternal(classes, xmls);
}
-
+
private void setUp(Collection<Class<?>> classes)
{
-
+
try
{
ConfigurationFactory config = new ConfigurationFactory();
@@ -209,11 +232,20 @@ public class StandaloneContainersImpl im
System.setProperty("openejb.validation.output.level", "VERBOSE");
Properties properties = new Properties(System.getProperties());
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
- new InitialContext(properties);
-
- //X TODO solve in a different way! EjbPlugin.CONFIGURED_FOR_USED_IN_TEST = true;
+ new InitialContext(properties);
+
+ try
+ {
+ EjbPlugin plugin = (EjbPlugin) PluginLoader.getInstance().getEjbPlugin();
+ plugin.setUseInTest(true);
+ }
+ catch (Throwable e)
+ {
+ // Not worry
+ }
+
}
- catch(Exception e)
+ catch (Exception e)
{
e.printStackTrace();
}
@@ -223,41 +255,40 @@ public class StandaloneContainersImpl im
{
EjbJar ejbJar = new EjbJar();
ejbJar.setId(this.getClass().getName());
-
- for(Class<?> clazz : classes)
+
+ for (Class<?> clazz : classes)
{
- if(isSingleton(clazz))
+ if (isSingleton(clazz))
{
ejbJar.addEnterpriseBean(new SingletonBean(clazz));
}
- if(isStateless(clazz))
+ if (isStateless(clazz))
{
ejbJar.addEnterpriseBean(new StatelessBean(clazz));
}
-
- if(isStatefull(clazz))
+
+ if (isStatefull(clazz))
{
ejbJar.addEnterpriseBean(new StatefulBean(clazz));
}
}
-
-
+
return new EjbModule(ejbJar);
-
+
}
private boolean isSingleton(Class<?> clazz)
{
return clazz.isAnnotationPresent(Singleton.class) ? true : false;
}
-
+
private boolean isStateless(Class<?> clazz)
{
return clazz.isAnnotationPresent(Stateless.class) ? true : false;
}
-
+
private boolean isStatefull(Class<?> clazz)
{
return clazz.isAnnotationPresent(Stateful.class) ? true : false;
- }
+ }
}