4 Replies Latest reply: Aug 21, 2012 7:14 AM by Jakub Narloch RSS

IlegalStateException - could not run test

cmr cmr Newbie

@Deployment

    public static EnterpriseArchive createTestArchive() {

        MavenDependencyResolver resolver = DependencyResolvers.use(

                MavenDependencyResolver.class).loadMetadataFromPom("pom.xml");

 

        EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "test.ear").

                addAsLibraries(resolver.artifact("<artifactid:groupid>").

                resolveAsFiles());

 

        return ear;

    }

 

 

 

    @Test

    public void testInjection() {

        Object obj = new Object ();

        Objec .setName("TESO1");

        Object result = service.save(null, null, null);

        assertNotNull(result);

    }

 

There is a test.war in my output ear files. I don't understand why this is there.

 

And i'm getting the attached error.

 

 

Please help!!

  • 1. Re: IlegalStateException - could not run test
    Bartosz Majsak Master

    Would it be possible to share the whole stacktrace / server log?

     

    That might help us understanding the problem you are facing in a bit broader context.

  • 2. Re: IlegalStateException - could not run test
    cmr cmr Newbie

    The deployment is working fine. But I guess the ear file is not being created properly. The ejb.jar should be outside the lib folder but when I add as library it adds ejb.jar and ejb modules dependencies all in the lib folder and I don't know why the test.war file is being added in the ear folder. The embedded glassfish server starts up fine.

     

    That is the complete stacktrace

     

    loads all jndi names

    ...

    INFO: WEB0671: Loading application [test#test.war] at [test]

    20/08/2012 5:01:14 PM org.glassfish.deployment.admin.DeployCommand execute

    INFO: test was successfully deployed in 27,506 milliseconds.

    2012-08-20 17:01:16,179 [main] INFO  SessionFactoryImpl - closing

    2012-08-20 17:01:16,182 [main] INFO  SessionFactoryImpl - closing

    classLoader = WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)

    SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@306d94ee

    20/08/2012 5:01:16 PM com.sun.ejb.containers.EJBTimerService _destroyTimers

    INFO: No timers to be deleted for id: 88175152348725248

    PlainTextActionReporterSUCCESSNo monitoring data to report.

     

    and the test case shows the attached error

     

    error2.png

     

    Can you please tell me what is a proper way of creating an ear file ? I've got an EJB module which has dependencies to other modules.

     

    I've been stuck on this for dayss ... please suggest something.

     

    Thanks

  • 3. Re: IlegalStateException - could not run test
    cmr cmr Newbie

    Basically all I'm trying to figure out is how to create an EAR file using Arquillian.

     

    This is my project structure.

     

    - Parent Module

    -- EAR Module (maven-ear plugin creates the ear file)

    -- UI Module

    -- EJB Module (has dependencies to Entities, Utilities & reports module and the one that I have to test)

    -- Entities Module

    -- Utilities Module

    -- Reports Module

    -- WebServices Module

    - Integration Test module (Arquillian, Glassfish 3.1 Integration tests)

     

    This is how the Ear file is structured in the EAR module using maven-ear-plugin

    - ejb.jar

    - ui.war

    - webservices.war

    -- Lib Folder

    --- utilities.jar

    --- entities.jar

    --- Plus other jars

     

    All I'm trying to figure out is how to create a Ear file using Arquillian using ShrinkWrap to test just the ejb.jar which depends on utilites.jar, entities.jar and reports.jar.

     

    Please suggest ?

     

    Thanks

  • 4. Re: IlegalStateException - could not run test
    Jakub Narloch Novice

    Hi,

     

    I tend to believe that the exception is not realted with the creation of the ear itself. Basiclly all you have to do is create the archive add the modules and libraries:

     

     

            EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "test.ear")
                    .addAsModule(....)
                    .addAsLibraries(...);
    
    

     

     

    Also you have second posibility, if you can build your ear using maven you could try to import it and at least see if you can run your test case using it. Providing that you had build it and placed somewhere in file system.

     

     

    ZipFile ear = new ZipFile("path to the ear");EnterpriseArchivearchive = ShrinkWrap.create(ZipImporter.class, "test.ear")                         .importZip(ear)                         .as(EnterpriseArchive.class);
    

     

    https://community.jboss.org/wiki/ShrinkWrap