-
1. Re: Problems with @Inject
bmajsak Apr 24, 2013 5:16 AM (in response to developer74)Hi Urlich,
can you give us a bit more details about your setup? Arquillian-relevant parts of pom, configuration of arquillian itself and your target container would be a good start to nail down the problem.
-
2. Re: Problems with @Inject
developer74 Apr 24, 2013 6:28 AM (in response to bmajsak)Hi Bartosz,
Thanks for your reply, I try to provide the required informations.
The WebApp should run on a Glassfish server (newst version 3.1.2)
The interesting part of the pom.xml is:
<dependencyManagement> <dependencies> <dependency> <groupId>org.jboss.arquillian</groupId> <artifactId>arquillian-bom</artifactId> <version>1.0.3.Final</version> <scope>import</scope> <type>pom</type> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.glassfish.main.extras</groupId> <artifactId>glassfish-embedded-all</artifactId> <version>3.1.2.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>rhino</groupId> <artifactId>js</artifactId> <version>1.7R2</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.1</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> </dependency> <!-- Testing Dependencies --> <!-- Arquillian --> <dependency> <groupId>org.jboss.arquillian.junit</groupId> <artifactId>arquillian-junit-container</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.jboss.arquillian.container</groupId> <artifactId>arquillian-glassfish-embedded-3.1</artifactId> <version>1.0.0.CR3</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency>
Und der Testcase sieht dann so aus:
@RunWith(Arquillian.class) public class InjectTest { @Inject A a; @Deployment public static WebArchive create() { return ShrinkWrap.create(WebArchive.class). addClasses(A.class, B.class). addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } @Test public void testExecute() throws Exception { a.execute(); } }
-
3. Re: Problems with @Inject
developer74 Apr 24, 2013 6:38 PM (in response to developer74)I think, I found out, what was wrong. For any reason, I had to add the Rhino-library to the @Deployment method. I couldn't explain why I need especially this library and not, or example, slf4j.
In the pom.xml, this dependency has to be added:
<dependency> <groupId>org.jboss.shrinkwrap.resolver</groupId> <artifactId>shrinkwrap-resolver-impl-maven</artifactId> <scope>test</scope> </dependency>
In the test-case, the @Deployment has to be extended for "addAsLibraries()":
@Deployment public static WebArchive create() { MavenDependencyResolver resolver = DependencyResolvers.use( MavenDependencyResolver.class).loadMetadataFromPom("pom.xml"); return ShrinkWrap.create(WebArchive.class). addClasses(A.class, B.class). addAsLibraries(resolver.artifact("rhino:js:1.7R2"). resolveAsFiles()). addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); }
Is there some rule, which libraries have to be added to the "test-webarchive" and which not?
-
4. Re: Problems with @Inject
aslak Apr 25, 2013 1:41 PM (in response to developer74)The general rule would be the ones you use that are not provided by the container.
-
5. Re: Problems with @Inject
developer74 Apr 26, 2013 8:47 AM (in response to aslak)Ah, ok, that explains why default logging-frameworks need not to be added (they are for sure provided by the container)...
Thanks, Arqulllian is real helpful and now it works perfectly for me...