1 Reply Latest reply on Apr 23, 2015 9:25 AM by mrazjava

    Arqullian starting embedded Wildfly incorrectly: not logging hibenate sql

    b1102

      Hello,

      I have EAR with the following structure

      /lib/

      /lib/log4j-1.2.17.jar

      /lib/domain.jar

      /lib/dao.jar

      /META-INF/

      /META-INF/log4j.properties

      /META-INF/MANIFEST.MF

      /META-INF/application.xml

      /ejb.jar

      /web.war

      When I deploy this EAR on the WildFLy I can see the logging of hibenate SQL.

      I am trying to create the Arqulian test, and creating almost the same EAR, by the folowing code:

      final JavaArchive ejb = ShrinkWrap.create(JavaArchive.class, "ejb.jar").addClasses(ServiceLevelBean.class, TestService.class);

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

                                    .addAsModule(ejb)

                                    .addAsLibraries(new File("../dao/build/libs/dao.jar"))

                                    .addAsLibraries(new File("../domain/build/libs/domain.jar"))

                                    .addAsLibraries(new File("../libs/log4j-1.2.17.jar"))

                                    .addAsResource(new File("../src/main/resources/META-INF/log4j.properties"));

      And the result is (according to the ear.toString(true)):

      /lib/

      /lib/log4j-1.2.17.jar

      /lib/domain.jar

      /lib/dao.jar

      /META-INF/

      /META-INF/log4j.properties

      /ejb.jar

      But problem that when test is runnig, in the log file I see all my loggin. But when I have a real wildfly running, and run the Arquillian unit test. On the stage where Arquillian tries to start embedded server there are many errors in logs (that address already occupied), but test not fails and it deploys the artifact on the running real Wildfly. And what a pleasant surprise: I see all hibenate logging. So looks like the problem in that Arquillian starts Wildfly not properly, and a big question how to teach it start server nicely?

        • 1. Re: Arqullian starting embedded Wildfly incorrectly: not logging hibenate sql
          mrazjava

          I'm on AS 7.1.0 but my setup is very similar to yours and does work. Perhaps try first running against 7.1.0 if you get the same error compare with setup below. Note that I'm not pulling manually any libs (inluding log) since they're commin off of maven resolver.

           

          package myapp.ejb.api.test;
          
          
          import javax.inject.Inject;
          import javax.persistence.EntityManager;
          import javax.persistence.PersistenceContext;
          import javax.transaction.UserTransaction;
          
          
          import org.jboss.arquillian.container.test.api.Deployment;
          import org.jboss.shrinkwrap.api.ArchivePaths;
          import org.jboss.shrinkwrap.api.ShrinkWrap;
          import org.jboss.shrinkwrap.api.asset.EmptyAsset;
          import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
          import org.jboss.shrinkwrap.api.spec.JavaArchive;
          import org.jboss.shrinkwrap.resolver.api.maven.Maven;
          
          
          /**
           * Base for all persistance tests that require full ear.
           *
           * @author Adam Zimowski (mrazjava)
           */
          public abstract class ArquillianPersistenceTest {
          
          
            @PersistenceContext
              protected EntityManager em;
          
            @Inject
              protected UserTransaction utx;
          
          
          
            @Deployment
              public static EnterpriseArchive createDeployment() {
          
            final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "myapp-ejb-test.jar")
            .addPackages(true, "myapp.ejb")
                      .addAsManifestResource("test-persistence.xml", ArchivePaths.create("persistence.xml"))
            .addAsManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
          
            return ShrinkWrap.create(EnterpriseArchive.class, "myapp-test.ear")
            .addAsModule(jar)
            .addAsLibraries(Maven.resolver().resolve("org.gnu:gnu-crypto:2.0.1").withTransitivity().asFile())
            .addAsLibraries(Maven.resolver().resolve("org.hibernate:hibernate-entitymanager:4.3.8.Final").withTransitivity().asFile());
              }
          
            protected void startTransaction() throws Exception {
               utx.begin();
               em.joinTransaction();
            }
          
            protected void commitTransaction() throws Exception {
               utx.commit();
            }
          }
          

           

          For maven resolver you need this in your pom.xml:

          <dependency>
            <groupId>org.jboss.shrinkwrap.resolver</groupId>
            <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
            <scope>test</scope>
          </dependency>
          

           

          Again, not sure about wildfly but in 7.1x I don't even bother defining my log config. Simply edit jboss standalone.xml to define your logger there and hibernate log will show in your console or wherever you redirect it to.

           

          Hope this helps.