Package com.google.code.rees.scope.conversation

Source Code of com.google.code.rees.scope.conversation.ConversationUtilTest

package com.google.code.rees.scope.conversation;

import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpSession;

import com.google.code.rees.scope.conversation.configuration.MockConversationSet;
import com.google.code.rees.scope.conversation.context.ConversationContext;
import com.google.code.rees.scope.conversation.context.DefaultConversationContextFactory;
import com.google.code.rees.scope.conversation.context.DefaultHttpConversationContextManagerFactory;
import com.google.code.rees.scope.conversation.context.HttpConversationContextManagerFactory;
import com.google.code.rees.scope.mocks.MockConversationAdapter;
import com.google.code.rees.scope.util.monitor.TimeoutListener;

public class ConversationUtilTest implements TimeoutListener<ConversationContext> {
 
  private static final long serialVersionUID = 1L;
 
  private boolean timedout = false;
  private String mockConversationName = "test_conversation";
  private String mockConversationId = "123";
 
  @Test
  public void testSetTimeout() {
    MockConversationSet.add(mockConversationName);
    MockHttpSession session = new MockHttpSession();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    request.setParameter(mockConversationName, mockConversationId);
    HttpConversationContextManagerFactory managerFactory = new DefaultHttpConversationContextManagerFactory();
    managerFactory.setConversationContextFactory(new DefaultConversationContextFactory());
    managerFactory.setMonitoringFrequency(1L);
    managerFactory.init();
    MockConversationAdapter.init(request, managerFactory);
    ConversationContext context = ConversationUtil.getContext(mockConversationName);
    context.addTimeoutListener(this);
    context.setMaxIdleTime(50L);
    try {
      Thread.sleep(2000L);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    assertTrue(this.timedout);
  }

  @Override
  public void onTimeout(ConversationContext timeoutable) {
    this.timedout = true;
  }

}
TOP

Related Classes of com.google.code.rees.scope.conversation.ConversationUtilTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.