Ho do create an Arquillian test for converscation scope??
dandii Feb 28, 2011 10:22 AMHi again,
I have still troubles with arquillian tests.
During testing my EntityHome and using the persist Method I get the Exception: “javax.enterprise.context.ContextNotActiveException: Conversation Context not active when method called on conversation Transient conversation“.
My test looks like:
@Test
public void testAppInstituteHome() throws LoginException, PermissionException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException, SystemException, NotSupportedException{
AppInstitute ai = new AppInstitute("Test Institute", "Location", "Street", new Integer(6020), "URL", new Long(854139751));
transaction.begin(); AppInstituteHome.setInstance(ai);
AppInstituteHome.persist();
transaction.commit();
}
The persist method in the AppInstituteHome is:
@Transactional
public String persist() throws LoginException, PermissionException
{
if (!isPermissionToPersist()) {
throw createPermissionException(DroolsConstants.CREATE);
}
entityManager.persist(getInstance());
entityManager.flush();
// some additional code
conversationManager.endConversation();
return returnTarget(getListOutcome());
}
Where the Code from the ConversationManager is:
@Named
@Stateless
public class ConversationManager implements Serializable
{
@Inject private Conversation conversation;
public void beginConversation() { if (!conversation.isTransient()) { conversation.end(); }
conversation.begin();
}
public void endConversation() {
if (!conversation.isTransient())
{
log.info("endConversation - really ending one");
conversation.end();
}
}
public String currentConversationId() {
return conversation.getId();
}
}
The problem is (as I understand it), that I do not have a conversation in the test case. That's why I can not begin or end a conversation, and I get the "javax.enterprise.context.ContextNotActiveException: Conversation Context not active when method called on conversation Transient
conversation".
I found some related topics with the solution of using the following code snipped (see for example http://seamframework.org/Community/ConversationScopedInArquillianWithWeldEmbedded) but I have no class ContextLifecycle.
Container.instance().services().get(ContextLifecycle.class).setupConversationContext();
Do you know how I can create a conversation, which is necessary for my test?