2012-03-07 12 views
1

いくつかのCDIクラスをテストしたいと思います。ELContextとExpressionFactoryを使ったCDIユニットテスト

今日、私はそのようにそれを行うためにArquillianを使用しています:

@RunWith(Arquillian.class) 
public class MyCDIBeanTest { 

    @Deployment 
    public static JavaArchive createTestArchive() { 
     return ShrinkWrap 
       .create(JavaArchive.class, "test.jar") 
       .addClasses(MyCDIBean.class) 
       .addAsManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")); 
    } 

    ... 

ここに私の現在のpom.xml次のとおりです。

<dependency> 
    <groupId>junit</groupId> 
    <artifactId>junit</artifactId> 
    <version>4.10</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>org.jboss.arquillian.junit</groupId> 
    <artifactId>arquillian-junit-container</artifactId> 
    <version>1.0.0.CR6</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>org.jboss.arquillian.container</groupId> 
    <artifactId>arquillian-container-test-spi</artifactId> 
    <version>1.0.0.CR6</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>org.jboss.arquillian.container</groupId> 
    <artifactId>arquillian-container-spi</artifactId> 
    <version>1.0.0.CR6</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>org.jboss.arquillian.container</groupId> 
    <artifactId>arquillian-weld-ee-embedded-1.1</artifactId> 
    <version>1.0.0.CR3</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>org.jboss.weld</groupId> 
    <artifactId>weld-core</artifactId> 
    <version>1.0.0.CR3</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>org.jboss.weld</groupId> 
    <artifactId>weld-api</artifactId> 
    <version>1.1.2.Final</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>org.jboss.weld</groupId> 
    <artifactId>weld-spi</artifactId> 
    <version>1.1.2.Final</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-simple</artifactId> 
    <scope>test</scope> 
</dependency> 

バージョンは親ポンポンであり、weldslf4jバージョンであります輸入された

<dependency> 
    <groupId>org.jboss.weld</groupId> 
    <artifactId>weld-core-bom</artifactId> 
    <version>1.1.2.Final</version> 
    <scope>import</scope> 
    <type>pom</type> 
</dependency> 

これまでは、すべてがうまく走っていました。

今日、javax.el.ElContextjavax.el.ExpressionFactoryを使用するいくつかのクラスをテストしたいと思います。

これらは、Seam Solder~@Injectを使用します。

.addPackage(org.jboss.solder.el.Expressions.class.getPackage())ShrinkWrapを追加しました。

しかし、今、ここでは、私が得たものである:

javax.el.ELException: Provider org.apache.el.ExpressionFactoryImpl not found 
    at javax.el.FactoryFinder.newInstance(FactoryFinder.java:97) 
    at javax.el.FactoryFinder.find(FactoryFinder.java:193) 
    at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:185) 
    at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:156) 
    at org.jboss.solder.el.ExpressionFactoryProducer.createExpressionFactory(ExpressionFactoryProducer.java:35) 

は、誰もが、私はより良いことを行うことができます方法を知っていますか? (またはちょうど働いている)

答えて

0

これは私がしたものです(that questionに触発されています)。

最初に.addPackage(Expressions.class.getPackage())を削除しました。

は、その後、私はJuelに依存関係を追加しました:

<dependency> 
    <!-- Used to simulate El expressions without Faces environment --> 
    <groupId>de.odysseus.juel</groupId> 
    <artifactId>juel-impl</artifactId> 
    <version>2.2.4</version> 
    <scope>test</scope> 
</dependency> 

その後、私のテストでは、私はコードと付け加えた:

/// Methods & variables for the elContext /// 
static SimpleContext elContext = new SimpleContext(); 
static ExpressionFactory expressionFactory = new ExpressionFactoryImpl(); 

@Produces @RequestScoped 
public static ELContext getElContext() { 
    return elContext; 
} 

@Produces @RequestScoped 
public static ExpressionFactory getExpressionFactory() { 
    return expressionFactory; 
} 

@Before 
public void reInitElContext() { 
    elContext = new SimpleContext(); 
} 

private void setElVariable(final String variableName, final Object variableValue) { 
    setElVariable(variableName, variableValue, variableValue.getClass()); 
} 

private void setElVariable(final String variableName, final Object variableValue, final Class<? extends Object> variableClass) { 
    expressionFactory.createValueExpression(elContext, "#{"+variableName+"}", variableClass).setValue(elContext, variableValue); 
} 

private void setElNullVariable(final String variableName, final Class<?> variableClass) { 
    setElVariable(variableName, null, variableClass); 
} 

/** 
* By default, set a null String variable 
* @param variableName 
*/ 
private void setElNullVariable(final String variableName) { 
    setElNullVariable(variableName, String.class); 
} 

は、今私は私のテストでsetElVariable("variableName", "value")を使用することができます!

関連する問題