2016-08-29 15 views
0

私は@Statelessとして注釈を付け、私のサービスクラスのためにArquillianとJUnitテストを実行しようとしているが、それは動作しません...Arquillian JUnitテストは

@Deploymentパステストが、@Testアサーションを動作しません。注入されたサービスのためにNullPointer例外で失敗します。

@RunWith(Arquillian.class) 
public class GenericDaoTest { 
@Inject 
private EmployeeService employeeService; 

@Deployment 
public static JavaArchive createTestableDeployment() { 
    final JavaArchive jar = ShrinkWrap 
      .create(JavaArchive.class) 
      .addPackage("it.smartit.application.timesheet.service") 
      .addPackage("it.smartit.application.timesheet.service.impl") 
      .addAsManifestResource("META-INF/persistence.xml", 
        "persistence.xml") 
      .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") 
      .addPackage("it.smartit.application.timesheet.entity"); 
    return jar; 
} 

@Test 
public void should_crud() { 
    assertNotNull(employeeService); 
    Employee initialSize = employeeService.findById(new Integer(1)); 
} 
} 

注入されたサービスがある:「ビュークラスのプロキシ:EJBのEmployeeService:mployeeServiceImpl」と私はそれを返すメソッド呼び出ししよう:最初に

を私はDAOを使用した時間が、私はJPAと一緒に今serviでは有用ではありませんCE私は、エンティティ・マネージャを使用して、まだそれはこのエラーを返すこの資産を使う:(

@Local 
public interface GenericService<T, PK extends Serializable>{ 
    T findById(PK id); 
} 


@Stateless(name = "GenericServiceImpl", mappedName = "GenericServiceImpl") 
public class GenericServiceImpl<T, PK extends Serializable> implements 
    GenericService<T, PK> { 

@PersistenceContext(unitName = "timesheet") 
protected EntityManager entityManager; 

private Class<T> entityClass; 

public GenericServiceImpl() { 
} 

public GenericServiceImpl(Class<T> entityClass) { 
    this.entityClass = entityClass; 
} 

@Override 
public T findById(PK id) { 
    return entityManager.find(entityClass, id); 

} 

} 


public interface EmployeeService extends 
    GenericService<Employee,Integer> { 
} 


@Stateless(name = "EmployeeServiceImpl", mappedName = "EmployeeServiceImpl") 
public class EmployeeServiceImpl extends GenericServiceImpl<Employee,Integer> implements EmployeeService{ 

public EmployeeServiceImpl() { 
    super(Employee.class); 
} 

} 

動作していないよ:

javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement 
at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:190) 

.... 
Caused by: org.jboss.arquillian.test.spi.ArquillianProxyException: org.h2.jdbc.JdbcSQLException : Table "EMPLOYEES" not found; SQL statement: 

がemployee1_3_0_としてemployee0_.employeed_id選択し、employee0_.addressとして....

私は、この問題の原因はデータベースの構成定義であると信じてWildfly8とMySQL

+0

依存関係を共有できますか? –

+0

投稿されたメッセージはthanks @ bartosz.majsak – antonio

答えて

0

上のJava EE 7を使用しています。 (中

<property name="hibernate.hbm2ddl.auto" value="create-drop" /> 

は、この行は、休止状態告げる:

私の最初の推測では、あなたが作成するか、またはこのようなあなたのpersistence.xmlでドロップを作成するためにあなたのhibernate.hbm2ddl.auto値を設定していないということだろうこの場合)、起動時にデータベーステーブルを作成し、シャットダウン時にデータベーステーブルを削除します。この行を追加しないと、テーブルがデータベースに存在しない可能性があります。

これは問題ではない場合は、Employeeクラスを追加した場合に役立ちます。