[ 
https://issues.apache.org/jira/browse/OWB-190?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Mark Struberg resolved OWB-190.
-------------------------------

    Resolution: Fixed

Moved the TestLifeCycle to a visible package.

A unittest in a project using OpenWebBeans could be using

META-INF/openwebbeans/openwebbeans.properties:
{noformat}
# the service section:
# The key is the Interface, the value the implementation of the service

# use the static HashMap instead of storing objects in JNDI as default  
org.apache.webbeans.spi.JNDIService=org.apache.webbeans.spi.se.JNDIServiceStaticImpl

# lookup the javax.transaction.TransactionManager via JNDI as default 
org.apache.webbeans.spi.TransactionService=org.apache.webbeans.spi.se.TransactionServiceNonJTA

#use the web metadata as default
org.apache.webbeans.spi.deployer.MetaDataDiscoveryService=org.apache.webbeans.spi.se.deployer.MetaDataDiscoveryStandard

#Lifecycle to start container
org.apache.webbeans.spi.Lifecycle=org.apache.webbeans.lifecycle.test.EnterpriseTestLifeCycle
{noformat}


And utilise it from the unit tests by using the following class to bootstrap 
OWB in a @BeforeClass or similar:
{noformat}
import java.util.Set;

import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;

import org.apache.webbeans.lifecycle.LifecycleFactory;
import org.apache.webbeans.spi.Lifecycle;
import org.testng.Assert;

public class ContainerStarter {

    private Lifecycle lifecycle = null;

    public  void boot(Object startupObject) throws Exception {
        lifecycle = LifecycleFactory.getInstance().getLifecycle();
        lifecycle.applicationStarted(startupObject);
    }

    public void shutdown(Object endObject) throws Exception {
        lifecycle = LifecycleFactory.getInstance().getLifecycle();
        if (lifecycle != null) {
            lifecycle.applicationEnded(endObject);
        }
    }

    public  BeanManager getBeanManager() {
        return lifecycle.getBeanManager();
    }
    
    public <T> T getInstance(Class<T> clazz) {
        Set<Bean<?>> beans = getBeanManager().getBeans(clazz);
        Assert.assertNotNull(beans, "cannot find beans for class " + 
clazz.getCanonicalName());
        Assert.assertTrue(!beans.isEmpty(), "cannot find beans for class " + 
clazz.getCanonicalName());

        @SuppressWarnings("unchecked")
        Bean<T> bean = (Bean<T>)beans.iterator().next();

        @SuppressWarnings("unchecked")
        T instance = (T) getBeanManager().getReference(bean, clazz, 
getBeanManager().createCreationalContext(bean));
        return instance;
    }

}
{noformat}

> Make the TestLifeCycles available in webbeans-impl
> --------------------------------------------------
>
>                 Key: OWB-190
>                 URL: https://issues.apache.org/jira/browse/OWB-190
>             Project: OpenWebBeans
>          Issue Type: Improvement
>          Components: Lifecycle
>    Affects Versions: M3
>            Reporter: Mark Struberg
>            Assignee: Mark Struberg
>             Fix For: M4
>
>
> Currently the OpenWebBeansTestLifecycle is only available internally for the 
> tests and via the tests.jar.
> This is not usable for running automated function tests in projects which use 
> OWB.
> I'd like to move over the OpenWebBeansTestLifeCycle (where one has to 
> manually select all classes which should get scanned) to a new lifecycle.test 
> package and also add a new EnterpriseTestLifeCycle which scanns all classes 
> on the classpaths according to the spec.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to