5 Replies Latest reply: Mar 21, 2012 10:36 AM by gboro54 RSS

@Inject across WAR and JAR

gboro54 Novice

I am using Arquillian to test an application packaged as ear with a jar and a war. My first unit test was to test the injection of a bean hosted in the jar but that the war is going to need. However when I do the @Inject in the unit test(running from the web project) The bean is always null. Do I need to add something to the confuration to handle this?

  • 1. Re: @Inject across WAR and JAR
    Aslak Knutsen Master

    It shouldn't be required.

     

    Can you copy/paste your deploy method ?

  • 2. Re: @Inject across WAR and JAR
    gboro54 Novice

    Here is my code for the deployment:

    public static JavaArchive getEJBJar() {
              JavaArchive imported = DependencyResolvers
                                            .use(MavenDependencyResolver.class)
                                            .goOffline()
                                            .artifact(
                                                                "com.example:example-common:0.0.1-SNAPSHOT")
                                            .resolveAs(JavaArchive.class).iterator().next();
              JavaArchive ja = ShrinkWrap.create(JavaArchive.class, "common.jar")
                                       .merge(imported).addAsManifestResource("test-ds.xml");
    
              return ja;
    
    }
    @Deployment(order = 2, name = "build_ear")
              public static EnterpriseArchive buildTestableArchive() {
    
                        WebArchive web = ShrinkWrap
                                            .create(WebArchive.class, "mtd.war")
                                            .addClasses(RuleCompilationTest.class, AbstractBaseTest.class)
                                            .addAsWebInfResource(EmptyAsset.INSTANCE,
                                                                ArchivePaths.create("beans.xml"))
                                            .addAsWebInfResource("web.xml")
              return ShrinkWrap
                        .create(EnterpriseArchive.class, "core-test.ear")
    .addAsLibraries(DependencyResolvers.use(MavenDependencyResolver.class)
    .includeDependenciesFromPom("pom.xml")
    .goOffline().resolveAs(JavaArchive.class))
    .addAsModule(web).addAsModule(getEJBJar())
    .setApplicationXML("application.xml");
    
    
    }
    
    
    

     

     

     

  • 3. Re: @Inject across WAR and JAR
    gboro54 Novice

    Am I doing anything wrong with my deploy methods? I can't even seem to inject BeanManager. Do I need to do something else to setup my beans.xml in this case(I have tried doing a copy of a blank one as well)

  • 4. Re: @Inject across WAR and JAR
    gboro54 Novice

    I have attached my whole test case to be sure I am doing this correctly. Can anyone provide insight?

  • 5. Re: @Inject across WAR and JAR
    gboro54 Novice

    I figured it out. I am using Arquillian to deploy a driver as well. In this case you need to specify which deployment the test should run against.