如何在 arquillian 嵌入式容器中为 wildfly 8.2 注入 SessionContext
How to Inject SessionContext in arquillian embedded container for wildfly 8.2
我的 wildfly 服务器在添加行
后没有 运行
@Resource
private SessionContext sessionContext;
如何使用wildfly 8.2版本在embedded arquillian中注入Session Context???
我什至尝试添加行
.addAsWebInfResource(new File("D:\wildfly-.2.0.Final\domain\configuration\domain.xml"))
mentioning the domain.xml of my wildfly server where I have crated users. but again not able to start the server. Also when I remove the line of injecting SessionContext my server starts normally.
@RunWith(Arquillian.class)
public class CRLManagerTest {
private static final Logger LOGGER = LoggerFactory.getLogger(CRLManagerTest.class);
@Deployment
public static WebArchive createDeployment() {
WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test.war")
.addClass(CrManagerFacade1.class)
.addClass(SessionContext.class)
.addClass(CrManagerFacade.class)
.addClass(CrManager.class)
.addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource(new File("D:\wildfly-.2.0.Final\domain\configuration\domain.xml"))
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
;
return webArchive;
}
@Resource
private SessionContext sessionContext;
@Test
public void testUpdateReceipt1() throws Exception {
LOGGER.info(">>>>>>>>>>>>> This is a test");
Assert.assertEquals("hello","hello");
}
Here is my arquillian.xml
<container qualifier="jboss-managed" default="true">
<configuration>
<property name="jbossHome">${jbossHome}</property>
</configuration>
</container>
看起来您没有使用 Servlet 协议,所以 Arquillian 没有执行 http 请求,这意味着任何依赖于 servlet 或请求/会话中的任何内容都将不可用。 Wildfly默认不使用servlet协议,需要开启。
将此添加到您的 arquillian.xml:
<!-- Sets the protocol which is how Arquillian talks and executes the tests inside the container -->
<defaultProtocol type="Servlet 3.0" />
这给你的 pom.xml:
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
正确答案是向 ShrinkWrat.create 方法添加类。
.addClasses(CRLManagerTest.class, CrManagerFacade.class,
CrManager.class)
我的 wildfly 服务器在添加行
后没有 运行@Resource private SessionContext sessionContext;
如何使用wildfly 8.2版本在embedded arquillian中注入Session Context??? 我什至尝试添加行
.addAsWebInfResource(new File("D:\wildfly-.2.0.Final\domain\configuration\domain.xml")) mentioning the domain.xml of my wildfly server where I have crated users. but again not able to start the server. Also when I remove the line of injecting SessionContext my server starts normally.
@RunWith(Arquillian.class)
public class CRLManagerTest {
private static final Logger LOGGER = LoggerFactory.getLogger(CRLManagerTest.class);
@Deployment
public static WebArchive createDeployment() {
WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test.war")
.addClass(CrManagerFacade1.class)
.addClass(SessionContext.class)
.addClass(CrManagerFacade.class)
.addClass(CrManager.class)
.addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource(new File("D:\wildfly-.2.0.Final\domain\configuration\domain.xml"))
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
;
return webArchive;
}
@Resource
private SessionContext sessionContext;
@Test
public void testUpdateReceipt1() throws Exception {
LOGGER.info(">>>>>>>>>>>>> This is a test");
Assert.assertEquals("hello","hello");
}
Here is my arquillian.xml
<container qualifier="jboss-managed" default="true">
<configuration>
<property name="jbossHome">${jbossHome}</property>
</configuration>
</container>
看起来您没有使用 Servlet 协议,所以 Arquillian 没有执行 http 请求,这意味着任何依赖于 servlet 或请求/会话中的任何内容都将不可用。 Wildfly默认不使用servlet协议,需要开启。
将此添加到您的 arquillian.xml:
<!-- Sets the protocol which is how Arquillian talks and executes the tests inside the container -->
<defaultProtocol type="Servlet 3.0" />
这给你的 pom.xml:
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
正确答案是向 ShrinkWrat.create 方法添加类。
.addClasses(CRLManagerTest.class, CrManagerFacade.class, CrManager.class)