// ----- execute
// create conversation
ConversationContext conversationContext = new ConversationContext();
conversationContext.setActive(true);
Conversation conversation = new ConversationImpl(session.getId(), getWebBeansContext());
conversation.begin();
ConversationManager conversationManager = getWebBeansContext().getConversationManager();
conversationManager.addConversationContext(conversation, conversationContext);
getWebBeansContext().registerService(ConversationService.class, new MockConversationService(session, conversation));
// set sample text
getInstance(ConversationScopedBean.class, conversationContext).setText(CONVERSATION_SCOPED_SAMPLE_TEXT);
// store beans in session
failoverService.sessionIsIdle(session);
// serialize / deserialize and store deserialized bag back to session
FailOverBag failOverBag;
failOverBag = (FailOverBag) session.getAttribute(FailOverBag.SESSION_ATTRIBUTE_NAME);
failOverBag = (FailOverBag) serialize(failOverBag);
session.setAttribute(FailOverBag.SESSION_ATTRIBUTE_NAME, failOverBag);
// remove sample text
getInstance(ConversationScopedBean.class, conversationContext).setText(null);
getWebBeansContext().getContextsService().endContext(ConversationScoped.class, conversationContext);
// restore beans from session
failoverService.sessionDidActivate(session);
// ----- assert
// get and activate conversation
Map<Conversation, ConversationContext> conversationMap =
conversationManager.getConversationMapWithSessionId(session.getId());
Conversation propogatedConversation =
conversationManager.getPropogatedConversation(conversation.getId(), session.getId());
ConversationContext propogatedConversationContext = conversationMap.get(propogatedConversation);
propogatedConversationContext.setActive(true);
ConversationScopedBean beanInstance = getInstance(ConversationScopedBean.class, propogatedConversationContext);
Assert.assertEquals(CONVERSATION_SCOPED_SAMPLE_TEXT, beanInstance.getText());
Assert.assertTrue(beanInstance.isBeanManagerNotNull());