tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Schlichtherle <christian-b...@schlichtherle.de>
Subject Re: Testing with TomEE, Arquillian and CDI (UnsatisfiedResolutionException)
Date Wed, 21 Aug 2013 08:47:33 GMT
I think I faced the same problem and solved it with the following Deployment:

    public static @Deployment WebArchive createDeployment() {
        final WebArchive archive = ShrinkWrap
                .create(WebArchive.class)
                .addClass(TomcatUpdateInstaller.class)
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
        logger.config(archive.toString(true));
        return archive;
    }

There are a few things to consider:

+ TomEE Embedded needs to have the class packaged in a WebArchive, not just a JavaArchive
(though the latter works with OpenEJB Embedded - I think its a bug).
+ It's enough to add the implementation class for embedded tests. Don't think this would suffice
with remote tests.
+ An empty beans.xml must exist in WEB-INF, not META-INF.

I can then ask for injection in the test by

    private @Inject UpdateInstaller installer;

Hope this helps.

Regards,
Christian

Am 21.08.2013 um 10:16 schrieb Dormouse <rabbithole@live.nl>:

> Hi,
> 
> I am currently working on an enterprise project and am now adding
> integration tests. For this I use Arquillian on a TomEE 1.5.2 runtime.
> Everything is working fine in production. Also, I have followed the
> Arquillian quickstart and TomEE integration steps. To construct my
> deployments, I use Shrinkwrap.
> Now I'm trying to test a stateless session bean doing some persistence
> stuff. My problem is that the bean doesn't get injected in my test class by
> CDI.
> The following exception is always given: 
> 
> Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Api type
> [storage.DatabaseUserStorage] is not found with the qualifiers 
> Qualifiers: [@javax.enterprise.inject.Default()]
> for injection into Field Injection Point, field name :  databaseUserStorage,
> Bean Owner : [DatabaseUserStorageTest, Name:null, WebBeans Type:ENTERPRISE,
> API
> Types:[java.lang.Object,integrationtest.DatabaseUserStorageTest,java.io.Serializable],
> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]]
> 	at
> org.apache.webbeans.util.InjectionExceptionUtils.throwUnsatisfiedResolutionException(InjectionExceptionUtils.java:77)
> 	at
> org.apache.webbeans.container.InjectionResolver.checkInjectionPoints(InjectionResolver.java:193)
> 	at
> org.apache.webbeans.container.BeanManagerImpl.validate(BeanManagerImpl.java:1034)
> 	at org.apache.openejb.cdi.BeansDeployer.validate(BeansDeployer.java:269)
> 	at
> org.apache.openejb.cdi.BeansDeployer.validateInjectionPoints(BeansDeployer.java:222)
> 	at
> org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:277)
> 	... 95 more
> 	
> I have tried all packaging variants: jar (EJB, but unable to add libs), war
> and ear. All resulting in the UnsatisfiedResolutionException. So even when
> the test and tested classes are in the same package/jar the exception
> occurs.
> For my ear, I currently have the following structure:
> 
> 2f122664-3a9e-4d74-aad4-970d64a3defd.ear:
> /lib/
> /lib/slf4j-api-1.6.2.jar
> /lib/entity-2616676154132726393.jar
> /lib/slf4j-log4j12-1.6.2.jar
> /lib/interaction-1265438374661770973.jar
> /lib/jdto-1.4.jar
> /lib/log4j-1.2.16.jar
> /lib/validation-api-1.0.0.GA.jar
> /lib/dto-8038385114298401761.jar
> /lib/commons-lang-2.4.jar
> /storage-365778680947729509.jar
> /messaging-0.0.1-SNAPSHOT.jar
> /META-INF/
> /META-INF/beans.xml
> 
> Note that an EJB in storage-365778680947729509.jar gets injected in
> /lib/interaction-1265438374661770973.jar, where its interface is defined.
> Some IoC magic to make storage pluggable. Some
> implementations seem to have problems with that (WebLogic, GlassFish) but
> not TomEE and JBoss.
> 
> The bean I want to test resides in storage-365778680947729509.jar,
> registered with the JNDI name
> Jndi(name=global/2f122664-3a9e-4d74-aad4-970d64a3defd/storage-365778680947729509/DatabaseUserStorage!interaction.UserStorageGateway)
> --> Ejb(deployment-id=DatabaseUserStorage).
> Could it be that the EJB cannot be injected with either @Inject or @EJB,
> because of the weird JNDI naming and/or it's located in another jar?
> If so, how can this be resolved. If not, what could it be? The location of
> my test class? Class files (i.e. my test class) cannot be added to the ear,
> but the test still seems to run. When I replace 
> @Inject with @EJB in my test class, I even get a NullPointerException in my
> test method.
> Same thing with the war variant, NPE in test class with @EJB, URE in test
> class with @Inject. So the bean is registered, but cannot be resolved?
> 
> A possible related post: 
> http://stackoverflow.com/questions/17420953/arquillian-integration-tests-fails-with-unsatisfiedresolutionexception
> <http://stackoverflow.com/questions/17420953/arquillian-integration-tests-fails-with-unsatisfiedresolutionexception>
 
> (unanswered)
> Another: 
> http://openejb.979440.n4.nabble.com/TomEE-1-5-1-SNAPSHOT-and-Arquillian-possible-problems-td4658337.html#a4658338
> <http://openejb.979440.n4.nabble.com/TomEE-1-5-1-SNAPSHOT-and-Arquillian-possible-problems-td4658337.html#a4658338>
 
> (removing the enricher worked? I'm not using it btw)
> Searching javax.enterprise.inject.UnsatisfiedResolutionException gave loads
> of results on the openejb forums, none of which seem to be able to help me.
> 
> I am using TomEE embedded as my Arquillian runtime:
> 
> <dependency>
> 	<groupId>org.apache.openejb</groupId>
> 	<artifactId>arquillian-tomee-embedded</artifactId>
> 	<version>1.5.2</version>
> 	<scope>test</scope>
> </dependency>
> 
> My surefire definition is as follows:
> 
> <plugin>
> 	<groupId>org.apache.maven.plugins</groupId>
> 	<artifactId>maven-surefire-plugin</artifactId>
> 	<version>2.12</version>
> 	<configuration>
> 		<systemPropertyVariables>
> 			<tomee.httpPort>-1</tomee.httpPort>
> 			<tomee.stopPort>-1</tomee.stopPort>
> 		</systemPropertyVariables>
> 	</configuration>
> </plugin
> 
> Thanks, Dormouse.
> 
> 
> 
> --
> View this message in context: http://openejb.979440.n4.nabble.com/Testing-with-TomEE-Arquillian-and-CDI-UnsatisfiedResolutionException-tp4664750.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.


Mime
View raw message