Package org.jmock

Examples of org.jmock.Mock


*
*/
public class CreateSessionInterceptorTest extends StrutsInternalTestCase {

    public void testCreateSession() throws Exception {
        Mock httpServletRequestMock = new Mock(HttpServletRequest.class);
        httpServletRequestMock.expects(new InvokeOnceMatcher()).method("getSession").with(new IsEqual(Boolean.FALSE));
        httpServletRequestMock.expects(new InvokeOnceMatcher()).method("getSession").with(new IsEqual(Boolean.TRUE));
        httpServletRequestMock.expects(new InvokeOnceMatcher()).method("getSession").with(new IsEqual(Boolean.FALSE));
        HttpServletRequest request = (HttpServletRequest) httpServletRequestMock.proxy();

        ServletActionContext.setRequest(request);

        CreateSessionInterceptor interceptor = new CreateSessionInterceptor();
        interceptor.intercept(new MockActionInvocation());

        httpServletRequestMock.verify();
    }
View Full Code Here


  Mock mockInvocation = null;



  public void testRender_ok() {
    final Mock mockResponse = mock(RenderResponse.class);
    mockResponse.stubs().method(ANYTHING);

    PortletMode mode = PortletMode.VIEW;

    Map<String, String[]> requestParams = new HashMap<String, String[]>();
    requestParams.put(ACTION_PARAM, new String[] { "/view/testAction" });
    requestParams.put(EVENT_ACTION, new String[] { "true" });
    requestParams.put(MODE_PARAM, new String[] { mode.toString() });

    Map<String, Object> sessionMap = new HashMap<String, Object>();

    Map<String, String> initParams = new HashMap<String, String>();
    initParams.put("viewNamespace", "/view");
    initParams.put(StrutsConstants.STRUTS_ALWAYS_SELECT_FULL_NAMESPACE,
        "true");

    initPortletConfig(initParams, new HashMap<String, Object>());
    initRequest(requestParams, new HashMap<String, Object>(), sessionMap,
        PortletMode.VIEW, WindowState.NORMAL, false, null);
    setupActionFactory("/view", "testAction", "success",
        EasyMock.createNiceMock(ValueStack.class));

    mockInvocation.expects(once()).method("getStack")
        .will(returnValue(null));
    try {
      dispatcher
          .setActionProxyFactory((ActionProxyFactory) mockActionFactory
              .proxy());
      dispatcher.init((PortletConfig) mockConfig.proxy());
      dispatcher.render((RenderRequest) mockRequest.proxy(),
          (RenderResponse) mockResponse.proxy());
    } catch (Exception e) {
      e.printStackTrace();
      fail("Error occured");
    }
  }
View Full Code Here

      fail("Error occured");
    }
  }

  public void testProcessAction_ok() {
    final Mock mockResponse = mock(ActionResponse.class);

    PortletMode mode = PortletMode.VIEW;
    Map<String, String> initParams = new HashMap<String, String>();
    initParams.put("viewNamespace", "/view");

    Map<String, String[]> requestParams = new HashMap<String, String[]>();
    requestParams.put(ACTION_PARAM, new String[] { "/view/testAction" });
    requestParams.put(MODE_PARAM, new String[] { mode.toString() });

    initParams.put(StrutsConstants.STRUTS_ALWAYS_SELECT_FULL_NAMESPACE,
        "true");
    initPortletConfig(initParams, new HashMap<String, Object>());
    initRequest(requestParams, new HashMap<String, Object>(),
        new HashMap<String, Object>(), PortletMode.VIEW,
        WindowState.NORMAL, true, null);
    setupActionFactory("/view", "testAction", "success",
        EasyMock.createNiceMock(ValueStack.class));

    try {
      dispatcher
          .setActionProxyFactory((ActionProxyFactory) mockActionFactory
              .proxy());
      dispatcher.init((PortletConfig) mockConfig.proxy());
      dispatcher.processAction((ActionRequest) mockRequest.proxy(),
          (ActionResponse) mockResponse.proxy());
    } catch (Exception e) {
      e.printStackTrace();
      fail("Error occured");
    }
  }
View Full Code Here

      fail("Error occured");
    }
  }

  public void testModeChangeUsingPortletWidgets() {
    final Mock mockResponse = mock(RenderResponse.class);
    mockResponse.stubs().method(ANYTHING);
    PortletMode mode = PortletMode.EDIT;

    Map<String, String[]> requestParams = new HashMap<String, String[]>();
    requestParams.put(ACTION_PARAM, new String[] { "/view/testAction" });
    requestParams.put(EVENT_ACTION, new String[] { "false" });
    requestParams.put(MODE_PARAM,
        new String[] { PortletMode.VIEW.toString() });

    Map<String, Object> sessionMap = new HashMap<String, Object>();

    Map<String, String> initParams = new HashMap<String, String>();
    initParams.put("viewNamespace", "/view");
    initParams.put("editNamespace", "/edit");

    initPortletConfig(initParams, new HashMap<String, Object>());
    initRequest(requestParams, new HashMap<String, Object>(), sessionMap,
        mode, WindowState.NORMAL, false, null);
    setupActionFactory("/edit", "default", "success",
        EasyMock.createNiceMock(ValueStack.class));

    mockInvocation.expects(once()).method("getStack")
        .will(returnValue(null));

    try {
      dispatcher
          .setActionProxyFactory((ActionProxyFactory) mockActionFactory
              .proxy());
      dispatcher.init((PortletConfig) mockConfig.proxy());
      dispatcher.render((RenderRequest) mockRequest.proxy(),
          (RenderResponse) mockResponse.proxy());
    } catch (Exception e) {
      e.printStackTrace();
      fail("Error occured");
    }
  }
View Full Code Here

    private final Mock continuumMock;

    public AddProjectActionTest()
    {
        action = new AddProjectActionStub();
        continuumMock = new Mock( Continuum.class );
        action.setContinuum( (Continuum) continuumMock.proxy() );
       
        Collection<ProjectGroup> projectGroups = new ArrayList<ProjectGroup>();
        ProjectGroup projectGroup = new ProjectGroup();
        projectGroups.add( projectGroup );
View Full Code Here

    private final Mock continuumMock;

    public ReleasePrepareActionTest()
    {
        action = new ReleasePrepareAction();
        continuumMock = new Mock( Continuum.class );
        //securitySessionMock = new Mock( SecuritySession.class );
        //Map map = new HashMap();
        //map.put( SecuritySystemConstants.SECURITY_SESSION_KEY, securitySessionMock );
        //action.setSession( map );
        action.setContinuum( (Continuum) continuumMock.proxy() );
View Full Code Here

    serviceImplTest = null;
  }

  public void testOperation(){
   
    Mock daoMock = mock(Dao.class);
   
    daoMock.expects(once())
      .method("find")
      .with(isA(String.class))
      .will(returnValue("String"));
   
    serviceImplTest.setDao((Dao)daoMock.proxy());
   
    assertNotNull(serviceImplTest.operation("String"));
  }
View Full Code Here

    public MessageEndpointProxyTest(String name) {
        super(name);
    }
   
    protected void setUp() {
        mockEndpoint = new Mock(EndpointAndListener.class);
        stubMessage = new Mock(Message.class);
        endpointProxy = new MessageEndpointProxy((MessageEndpoint) mockEndpoint.proxy());      
    }
View Full Code Here

        stubMessage = new Mock(Message.class);
        endpointProxy = new MessageEndpointProxy((MessageEndpoint) mockEndpoint.proxy());      
    }

    public void testInvalidConstruction() {
        Mock mockEndpoint = new Mock(MessageEndpoint.class);
        try {
            new MessageEndpointProxy((MessageEndpoint) mockEndpoint.proxy());
            fail("An exception should have been thrown");
        } catch (IllegalArgumentException e) {
            assertTrue(true);
        }
    }
View Full Code Here

    protected void setUp()
        throws Exception
    {
        super.setUp();

        listener = new Mock(IGuideListener.class);

        guide = new StandardGuide();
        guide.addListener((IGuideListener)listener.proxy());
    }
View Full Code Here

TOP

Related Classes of org.jmock.Mock

Copyright © 2018 www.massapicom. 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.