0 Replies Latest reply on Jun 23, 2012 3:56 AM by seamfalke

    arquillian seam3 jboss 7.1.1

    seamfalke Newbie

      hi,

       

      i try to test my application with arquillian. but i get following error message:

       

      my configuration:

       

      i have maven modules

       

      i wantto test my core module (dao classes). if i use @PersistenceContext for entityManager it works but i wantto use @Inject so in gui i can have my entityManager for a conversation.

       

      thanks in advance

       

       

      pom.xml for parent

       

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

          <modelVersion>4.0.0</modelVersion>

          <groupId>com.myapp</groupId>

          <artifactId>parent</artifactId>

          <version>1.0.0</version>

          <packaging>pom</packaging>

          <name>parent</name>

          <description>myapp Parent Module 4 All Sub Projects</description>

          <url>http://www.myapp.com</url>

       

          <modules>

              <module>../activiti</module>

              <module>../gui</module>

              <module>../core</module>

              <module>../util</module>

       

          </modules>

       

          <properties>

       

              <org.jboss.shrinkwrap.resolver.version>1.1.0-alpha-1</org.jboss.shrinkwrap.resolver.version>

              <jpamodelgen.version>1.1.1.Final</jpamodelgen.version>

              <org.richfaces.bom.version>4.0.0.Final</org.richfaces.bom.version>

              <activiti-engine-version>5.8</activiti-engine-version>

              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

              <seam.version>3.1.0.Final</seam.version>

              <picketlink.version>1.5.0.Alpha02</picketlink.version>

              <datavalve.version>0.9.0.CR2</datavalve.version>

              <activiti.version>5.9</activiti.version>

              <primefaces.version>3.2</primefaces.version>

              <version.arquillian_core>1.0.0.CR5</version.arquillian_core>

              <version.arquillian_drone>1.0.0.CR2</version.arquillian_drone>

              <arquillian.version>1.0.0.CR2</arquillian.version>

              <jbossas.7.version>7.0.2.Final</jbossas.7.version>

              <jboss.javaee6.version>2.0.0.Final</jboss.javaee6.version>

              <jodatime.version>1.6.2</jodatime.version>

              <prettyfaces.version>3.3.2</prettyfaces.version>

       

              <version.arquillian_core>1.0.1.Final</version.arquillian_core>

              <version.arquillian_container_jbossas>1.0.0.CR2</version.arquillian_container_jbossas>

              <version.arquillian_drone>1.0.0.Final</version.arquillian_drone>

              <version.jbossas_7>7.1.1.Final</version.jbossas_7>

              <version.jbossas_server_manager>1.0.3.GA</version.jbossas_server_manager>

              <version.jsfunit>2.0.0.Beta3-SNAPSHOT</version.jsfunit>

              <version.junit>4.8.1</version.junit>

              <version.testng>5.14.6</version.testng>

              <version.jboss_javaee6_spec>3.0.0.Beta1</version.jboss_javaee6_spec>

          </properties>

       

          <repositories>

              <repository>

                  <id>OL4JSF Local Repository</id>

                  <name>OL4JSF</name>

                  <url>https://java.net/svn/ol4jsf~svn/repository/</url>

              </repository>

              <repository>

                  <id>maven2-repository.dev.java.net</id>

                  <name>Java.net Repository for Maven</name>

                  <url>http://download.java.net/maven/2/</url>

                  <layout>default</layout>

              </repository>

              <repository>

                  <id>maven2</id>

                  <name>Java Repository for Maven</name>

                  <url>http://repo1.maven.org/maven2/</url>

              </repository>

              <repository>

                  <id>repository.jboss.org</id>

                  <name>JBoss Repository</name>

                  <url>http://repository.jboss.org/nexus/content/groups/public/</url>

              </repository>

          </repositories>

       

          <dependencyManagement>

              <dependencies>

                  <dependency>

                      <groupId>org.jboss.seam</groupId>

                      <artifactId>seam-bom</artifactId>

                      <version>${seam.version}</version>

                      <scope>import</scope>

                      <type>pom</type>

                  </dependency>

                  <dependency>

                      <groupId>org.jboss.arquillian</groupId>

                      <artifactId>arquillian-bom</artifactId>

                      <version>${version.arquillian_core}</version>

                      <type>pom</type>

                      <scope>import</scope>

                  </dependency>

                  <dependency>

                      <groupId>org.jboss.arquillian.extension</groupId>

                      <artifactId>arquillian-drone-bom</artifactId>

                      <version>${version.arquillian_drone}</version>

                      <type>pom</type>

                      <scope>import</scope>

                  </dependency>

       

              </dependencies>

          </dependencyManagement>

       

          <dependencies>

       

              <dependency>

                  <groupId>org.jboss.weld</groupId>

                  <artifactId>weld-api</artifactId>

                  <version>1.1.Final</version>

              </dependency>

       

              <dependency>

                  <groupId>org.jboss.weld</groupId>

                  <artifactId>weld-core</artifactId>

                  <!-- version>1.1.0.Final</version -->

                  <version>1.1.1.Final</version>

              </dependency>

              <dependency>

                  <groupId>org.jboss.weld.servlet</groupId>

                  <artifactId>weld-servlet</artifactId>

                  <!-- version>1.1.0.Final</version -->

                  <version>1.1.1.Final</version>

              </dependency>

       

              <!-- Seam Başlangıç -->

              <dependency>

                  <groupId>org.jboss.seam.faces</groupId>

                  <artifactId>seam-faces-api</artifactId>

              </dependency>

              <dependency>

                  <groupId>org.jboss.seam.faces</groupId>

                  <artifactId>seam-faces</artifactId>

              </dependency>

              <dependency>

                  <groupId>org.jboss.seam.international</groupId>

                  <artifactId>seam-international</artifactId>

              </dependency>

              <dependency>

                  <groupId>org.jboss.seam.security</groupId>

                  <artifactId>seam-security</artifactId>

                  <scope>compile</scope>

              </dependency>

              <dependency>

                  <groupId>org.jboss.seam.persistence</groupId>

                  <artifactId>seam-persistence</artifactId>

              </dependency>

              <dependency>

                  <groupId>org.jboss.seam.validation</groupId>

                  <artifactId>seam-validation</artifactId>

              </dependency>

              <dependency>

                  <groupId>org.jboss.seam.transaction</groupId>

                  <artifactId>seam-transaction-api</artifactId>

              </dependency>

              <!-- Seam son -->

       

       

              <dependency>

                  <groupId>com.oracle</groupId>

                  <artifactId>ojdbc6</artifactId>

                  <version>11.2.0</version>

              </dependency>

       

              <dependency>

                  <groupId>javax.enterprise</groupId>

                  <artifactId>cdi-api</artifactId>

                  <scope>provided</scope>

       

              </dependency>

       

              <dependency>

                  <groupId>joda-time</groupId>

                  <artifactId>joda-time</artifactId>

              </dependency>

       

       

       

       

              <!-- Testing -->

              <dependency>

                  <groupId>org.jboss.as</groupId>

                  <artifactId>jboss-as-arquillian-container-managed</artifactId>

                  <version>${version.jbossas_7}</version>

                  <scope>test</scope>

              </dependency>

       

              <dependency>

                  <groupId>junit</groupId>

                  <artifactId>junit</artifactId>

                  <version>${version.junit}</version>

       

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.jboss.arquillian.junit</groupId>

                  <artifactId>arquillian-junit-container</artifactId>

              </dependency>

              <dependency>

                  <groupId>org.jboss.arquillian.protocol</groupId>

                  <artifactId>arquillian-protocol-servlet</artifactId>

              </dependency>

       

              <dependency>

                  <groupId>org.jboss.arquillian.ajocado</groupId>

                  <artifactId>arquillian-ajocado-junit</artifactId>

                  <version>1.0.0.CR2</version>

                  <type>pom</type>

                  <scope>test</scope>

              </dependency>

       

              <!-- shrinkwrap resolver -->

              <dependency>

                  <groupId>org.jboss.shrinkwrap.resolver</groupId>

                  <artifactId>shrinkwrap-resolver-api</artifactId>

                  <version>${org.jboss.shrinkwrap.resolver.version}</version>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.jboss.shrinkwrap.resolver</groupId>

                  <artifactId>shrinkwrap-resolver-api-maven</artifactId>

                  <version>${org.jboss.shrinkwrap.resolver.version}</version>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.jboss.shrinkwrap.resolver</groupId>

                  <artifactId>shrinkwrap-resolver-impl-maven</artifactId>

                  <version>${org.jboss.shrinkwrap.resolver.version}</version>

                  <scope>test</scope>

              </dependency>

       

       

              <dependency>

                  <groupId>javax.inject</groupId>

                  <artifactId>javax.inject-tck</artifactId>

                  <version>1</version>

              </dependency>

       

       

          </dependencies>

       

          <pluginRepositories>

       

              <pluginRepository>

                  <id>maven.java.net</id>

                  <name>Java.net Maven2 Repository</name>

                  <url>http://download.java.net/maven/2</url>

              </pluginRepository>

       

              <pluginRepository>

                  <id>ocean glassfish</id>

                  <url>http://maven.ocean.net.au/snapshot</url>

                  <releases>

                      <enabled>false</enabled>

                      <updatePolicy>never</updatePolicy>

                  </releases>

                  <snapshots>

                      <enabled>true</enabled>

                      <updatePolicy>never</updatePolicy>

                  </snapshots>

              </pluginRepository>

          </pluginRepositories>

       

       

      </project>

       

       

      pom.xml for core

       

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

          <modelVersion>4.0.0</modelVersion>

          <artifactId>core</artifactId>

          <packaging>jar</packaging>

          <name>core</name>

          <description>myapp Core Module</description>

          <url>http://www.myapp.com</url>

          <parent>

              <groupId>com.myapp</groupId>

              <artifactId>parent</artifactId>

              <version>1.0.0</version>

              <relativePath>../parent/pom.xml</relativePath>

          </parent>

       

          <properties>

              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

          </properties>

       

          <dependencies>

       

          <dependency>

                  <groupId>org.slf4j</groupId>

                  <artifactId>slf4j-log4j12</artifactId>

                  <version>1.6.6</version>

              </dependency>

       

                  <dependency>

                  <groupId>org.hibernate</groupId>

                  <artifactId>hibernate-core</artifactId>

                  <version>3.5.6-Final</version>

              </dependency>

       

              <dependency>

                  <groupId>org.hibernate</groupId>

                  <artifactId>hibernate-entitymanager</artifactId>

                  <version>3.5.6-Final</version>

              </dependency>

       

              <dependency>

                  <groupId>org.hibernate.javax.persistence</groupId>

                  <artifactId>hibernate-jpa-2.0-api</artifactId>

                  <version>1.0.0-CR-1</version>

              </dependency>

              <dependency>

                  <groupId>org.hibernate</groupId>

                  <artifactId>hibernate-annotations</artifactId>

                  <version>3.5.6-Final</version>

              </dependency>

       

       

       

              <dependency>

                  <groupId>com.myapp</groupId>

                  <artifactId>util</artifactId>

                  <version>1.0.0</version>

                  <exclusions>

                      <exclusion>

                          <groupId>org.jboss.seam.security</groupId>

                          <artifactId>seam-security</artifactId>

                      </exclusion>

                      <exclusion>

                          <groupId>org.activiti</groupId>

                          <artifactId>activiti-cdi</artifactId>

                      </exclusion>

                  </exclusions>

              </dependency>

       

          </dependencies>

       

       

              <profiles>

       

              <profile>

                  <id>arq-jbossas-managed-7</id>

                  <activation>

                      <activeByDefault>true</activeByDefault>

                  </activation>

                  <dependencies>

       

                      <dependency>

                          <groupId>org.jboss.as</groupId>

                          <artifactId>jboss-as-arquillian-container-managed</artifactId>

                                      <version>${version.jbossas_7}</version>

       

                          <scope>test</scope>

                      </dependency>

       

       

                  </dependencies>

                  <build>

                      <testResources>

                          <testResource>

                              <directory>src/test/resources</directory>

                          </testResource>

                          <testResource>

                              <directory>src/test/resources-jbossas-7</directory>

                          </testResource>

                      </testResources>

                      <plugins>

                          <plugin>

                              <artifactId>maven-surefire-plugin</artifactId>

                              <configuration>

                                  <systemProperties>

                                      <jboss.version>${version.jbossas_7}</jboss.version>

                                  </systemProperties>

                              </configuration>

                          </plugin>

       

                      </plugins>

                  </build>

              </profile>

          </profiles>

       

       

          <build>

              <finalName>core</finalName>

              <plugins>

                  <plugin>

                      <groupId>org.apache.maven.plugins</groupId>

                      <artifactId>maven-surefire-plugin</artifactId>

                      <configuration>

                          <skip>false</skip>

                      </configuration>

                      <version>2.12</version>

                  </plugin>

                  <plugin>

                      <groupId>org.apache.maven.plugins</groupId>

                      <artifactId>maven-compiler-plugin</artifactId>

                      <version>2.3.2</version>

                      <configuration>

                          <source>1.6</source>

                          <target>1.6</target>

                      </configuration>

                  </plugin>

              </plugins>

          </build>

      </project>

       

       

      AND MY DBTEST CLASS:

       

      package com;

       

      import org.jboss.arquillian.junit.Arquillian;

      import org.junit.runner.RunWith;

      import java.util.Date;

       

      import javax.enterprise.inject.Produces;

      import javax.inject.Inject;

      import javax.inject.Named;

      import javax.persistence.EntityManager;

      import javax.persistence.PersistenceContext;

       

      import junit.framework.Assert;

       

      import org.jboss.arquillian.container.test.api.Deployment;

      import org.jboss.arquillian.container.test.api.RunAsClient;

      import org.jboss.seam.transaction.Transactional;

      import org.jboss.shrinkwrap.api.ShrinkWrap;

      import org.jboss.shrinkwrap.api.asset.EmptyAsset;

      import org.jboss.shrinkwrap.api.spec.JavaArchive;

      import org.jboss.shrinkwrap.api.spec.WebArchive;

      import org.jboss.shrinkwrap.resolver.api.DependencyResolvers;

      import org.jboss.shrinkwrap.resolver.api.maven.MavenDependencyResolver;

      import org.jboss.shrinkwrap.api.ShrinkWrap;

      import org.junit.AfterClass;

      import org.junit.Test;

      import com.myapp.core.domain.AbstractBaseEntity;

      import com.myapp.core.domain.it.Corporation;

      import com.myapp.core.domain.it.Role;

      import com.myapp.core.domain.it.User;

      import com.myapp.core.security.LoggedInUser;

      import com.myapp.core.service.base.BaseService;

       

      @RunWith(Arquillian.class)

      public class DbTest {

       

          @Inject

          private EntityManager entityManager;

       

          @Inject

          BaseService<AbstractBaseEntity> service;

       

          static Long roleId;

       

          @Deployment

          public static WebArchive createDeployment() {

       

              try {

       

                  final MavenDependencyResolver resolver = DependencyResolvers.use(

                          MavenDependencyResolver.class).loadMetadataFromPom(

                          "pom.xml");

       

                  return ShrinkWrap

                          .create(WebArchive.class, "testGUI2.war")

                          .addAsLibraries(

                                  resolver.includeDependenciesFromPom("pom.xml")

                                          .resolveAs(JavaArchive.class))

                          .addPackages(true, "com.myapp.core")

                          .addAsResource("test-persistence.xml",

                                  "META-INF/persistence.xml")

                          .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

              } catch (Exception e) {

       

                  System.out.println("Exception during creating deployment: "

                          + e);

                  return null;

              }

          }

       

       

       

          @Test

          @Transactional

          public void shouldAddCtpShareToUserPortfolio() {

       

              if (entityManager == null) {

                  System.out.println("EntityManager is null...");

                  return;

              }

       

              User user = (User) entityManager.createQuery("from User where id = " + 1)

                      .getSingleResult();

       

       

       

          }

       

          @AfterClass

          public static void tearDown() {

       

          }

       

      }

       

      MY EXCEPTION:

       

       

      org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [EntityManager] with qualifiers [@Default] at injection point [[field] @Inject private com.myapp.core.dao.AbstractHibernateDAO.entityManager]

          at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:275)

          at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:244)

          at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:107)

          at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:127)

          at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:346)

          at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:331)

          at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:366)

          at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:83)

          at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)

          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

          at java.lang.Thread.run(Thread.java:662)