Package com.mockobjects.dynamic

Examples of com.mockobjects.dynamic.Mock


        assertEquals(req.getCharacterEncoding(), "UTF-8");
    }

    public void testSetEncodingIfDiffer() throws Exception {
        // given
        Mock mock = new Mock(HttpServletRequest.class);
        mock.expectAndReturn("getCharacterEncoding", "utf-8");
        mock.expectAndReturn("getHeader", "X-Requested-With", "");
        mock.expectAndReturn("getLocale", Locale.getDefault());
        mock.expectAndReturn("getCharacterEncoding", "utf-8");
        HttpServletRequest req = (HttpServletRequest) mock.proxy();
        HttpServletResponse res = new MockHttpServletResponse();

        Dispatcher du = initDispatcher(new HashMap<String, String>() {{
            put(StrutsConstants.STRUTS_I18N_ENCODING, "utf-8");
        }});


        // when
        du.prepare(req, res);

        // then

        assertEquals(req.getCharacterEncoding(), "utf-8");
        mock.verify();
    }
View Full Code Here


        ActionContext.setContext(actionContext);

        session = new HashMap();
        actionContext.setSession(session);

        invocationMock = new Mock(ActionInvocation.class);
        invocation = (ActionInvocation) invocationMock.proxy();
        invocationMock.matchAndReturn("serialize", invocation);
        invocationMock.matchAndReturn("deserialize", actionContext, invocation);

        actionContext.setValueStack(stack);
        invocationMock.matchAndReturn("getStack", stack);

        Mock proxyMock = new Mock(ActionProxy.class);
        proxyMock.matchAndReturn("getInvocation", invocation);

        ActionProxy proxy = (ActionProxy) proxyMock.proxy();

        invocationMock.matchAndReturn("getProxy", proxy);
    }
View Full Code Here

    public void testObjectFactoryDestroy() throws Exception {

        final InnerDestroyableObjectFactory destroyedObjectFactory = new InnerDestroyableObjectFactory();
        Dispatcher du = new Dispatcher(new MockServletContext(), new HashMap<String, String>());
        ConfigurationManager cm = new ConfigurationManager();
        Mock mockConfiguration = new Mock(Configuration.class);
        cm.setConfiguration((Configuration)mockConfiguration.proxy());
       
        Mock mockContainer = new Mock(Container.class);
        String reloadConfigs = container.getInstance(String.class, XWorkConstants.RELOAD_XML_CONFIGURATION);
        mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(XWorkConstants.RELOAD_XML_CONFIGURATION)),
                reloadConfigs);
        mockContainer.expectAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), destroyedObjectFactory);

        mockConfiguration.expectAndReturn("getContainer", mockContainer.proxy());
        mockConfiguration.expectAndReturn("getContainer", mockContainer.proxy());
        mockConfiguration.expect("destroy");
        mockConfiguration.matchAndReturn("getPackageConfigs", new HashMap<String, PackageConfig>());

        du.setConfigurationManager(cm);
        assertFalse(destroyedObjectFactory.destroyed);
        du.cleanup();
        assertTrue(destroyedObjectFactory.destroyed);
        mockConfiguration.verify();
        mockContainer.verify();
    }
View Full Code Here

        mockConfiguration.verify();
        mockContainer.verify();
    }
   
    public void testInterceptorDestroy() throws Exception {          
        Mock mockInterceptor = new Mock(Interceptor.class);
        mockInterceptor.matchAndReturn("hashCode", 0);
        mockInterceptor.expect("destroy");
       
        InterceptorMapping interceptorMapping = new InterceptorMapping("test", (Interceptor) mockInterceptor.proxy());
       
        InterceptorStackConfig isc = new InterceptorStackConfig.Builder("test").addInterceptor(interceptorMapping).build();
       
        PackageConfig packageConfig = new PackageConfig.Builder("test").addInterceptorStackConfig(isc).build();
       
        Map<String, PackageConfig> packageConfigs = new HashMap<String, PackageConfig>();
        packageConfigs.put("test", packageConfig);

        Mock mockContainer = new Mock(Container.class);
        mockContainer.matchAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), new ObjectFactory());
        String reloadConfigs = container.getInstance(String.class, XWorkConstants.RELOAD_XML_CONFIGURATION);
        mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(XWorkConstants.RELOAD_XML_CONFIGURATION)),
                reloadConfigs);

        Mock mockConfiguration = new Mock(Configuration.class);
        mockConfiguration.matchAndReturn("getPackageConfigs", packageConfigs);
        mockConfiguration.matchAndReturn("getContainer", mockContainer.proxy());
        mockConfiguration.expect("destroy");
       
        ConfigurationManager configurationManager = new ConfigurationManager();
        configurationManager.setConfiguration((Configuration) mockConfiguration.proxy());
       
        Dispatcher dispatcher = new Dispatcher(new MockServletContext(), new HashMap<String, String>());
        dispatcher.setConfigurationManager(configurationManager);
        dispatcher.cleanup();
       
        mockInterceptor.verify();
        mockContainer.verify();
        mockConfiguration.verify();
    }
View Full Code Here

        configurationManager = XWorkTestCaseHelper.setUp();
        configuration = configurationManager.getConfiguration();
        container = configuration.getContainer();
        actionProxyFactory = container.getInstance(ActionProxyFactory.class);
        initDispatcher(Collections.singletonMap("actionPackages", "foo.bar"));
        mockServletContext = new Mock(ServletContext.class);
        handler = new CodebehindUnknownHandler("codebehind-default", configuration);
        handler.setPathPrefix("/");
        handler.setObjectFactory(container.getInstance(ObjectFactory.class));
        handler.setServletContext((ServletContext)mockServletContext.proxy());
    }
View Full Code Here

     */
    public Context getInitialContext(Hashtable env) throws NamingException
    {
        boolean useCycles = env.containsKey(PROP_CYCLES);

        Mock mockTopCtx = createCtxMock(PREFIX);
        Mock mockCycleCtx = createCtxMock("");
        Mock mockPrfxCtx = createCtxMock("");
        Mock mockBaseCtx = new Mock(Context.class);
        mockBaseCtx.matchAndReturn(METHOD_LOOKUP, C.eq(""), mockTopCtx.proxy());
        mockBaseCtx.matchAndReturn(METHOD_LOOKUP, C.eq("test"), mockPrfxCtx
                .proxy());
        mockTopCtx.matchAndReturn(METHOD_LOOKUP, C.eq("test"), mockPrfxCtx
                .proxy());
        mockPrfxCtx.matchAndReturn(METHOD_LIST, C.eq(""), createEnumMock(
                mockPrfxCtx, PROP_NAMES, PROP_VALUES).proxy());

        if (useCycles)
        {
            mockTopCtx.matchAndReturn(METHOD_LOOKUP, C.eq("cycle"),
                    mockCycleCtx.proxy());
            mockTopCtx.matchAndReturn(METHOD_LIST, C.eq(""), createEnumMock(
                    mockTopCtx, new String[]
                    { "test", "cycle" }, new Object[]
                    { mockPrfxCtx.proxy(), mockCycleCtx.proxy() }).proxy());
            Mock mockEnum = createEnumMock(mockCycleCtx, PROP_NAMES,
                    PROP_VALUES, false);
            addEnumPair(mockEnum, "cycleCtx", mockCycleCtx.proxy());
            closeEnum(mockEnum);
            mockCycleCtx
                    .matchAndReturn(METHOD_LIST, C.eq(""), mockEnum.proxy());
            mockCycleCtx.matchAndReturn(METHOD_LOOKUP, C.eq("cycleCtx"),
                    mockCycleCtx.proxy());
        }
        else
        {
View Full Code Here

        pageContext = new StrutsMockPageContext();
        pageContext.setRequest(request);
        pageContext.setResponse(response);
        pageContext.setServletContext(servletContext);

        mockContainer = new Mock(Container.class);

        du.setConfigurationManager(configurationManager);
        session = new SessionMap(request);
        Map<String, Object> extraContext = du.createContextMap(new RequestMap(request),
                request.getParameterMap(),
View Full Code Here

    public void testCheckBox() throws Exception {
        TestAction testAction = (TestAction) action;
        testAction.setFoo("true");

        CheckboxTag tag = new CheckboxTag();
        Mock rdMock = new Mock(RequestDispatcher.class);
        rdMock.expect("include",C.args(C.isA(HttpServletRequest.class), C.isA(HttpServletResponse.class)));
        RequestDispatcher dispatcher = (RequestDispatcher) rdMock.proxy();
        request.setupGetRequestDispatcher(dispatcher);
        tag.setPageContext(pageContext);
        tag.setTemplate("/test/checkbox.jsp");
        tag.doStartTag();
        tag.doEndTag();
        rdMock.verify();
    }
View Full Code Here

    TemplateEngineManager mgr;
    Mock mockContainer;
   
    public void setUp() throws Exception {
        mgr = new TemplateEngineManager();
        mockContainer = new Mock(Container.class);
        mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("jsp")), new JspTemplateEngine());
        mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("vm")), new VelocityTemplateEngine());
        mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("ftl")), new FreemarkerTemplateEngine());
        mockContainer.matchAndReturn("getInstanceNames", C.args(C.eq(TemplateEngine.class)), new HashSet() {{
            add("jsp");
View Full Code Here

    @Override
    public Context getInitialContext(@SuppressWarnings("rawtypes") Hashtable env) throws NamingException
    {
        boolean useCycles = env.containsKey(PROP_CYCLES);

        Mock mockTopCtx = createCtxMock(PREFIX);
        Mock mockCycleCtx = createCtxMock("");
        Mock mockPrfxCtx = createCtxMock("");
        Mock mockBaseCtx = new Mock(Context.class);
        mockBaseCtx.matchAndReturn(METHOD_LOOKUP, C.eq(""), mockTopCtx.proxy());
        mockBaseCtx.matchAndReturn(METHOD_LOOKUP, C.eq("test"), mockPrfxCtx
                .proxy());
        mockTopCtx.matchAndReturn(METHOD_LOOKUP, C.eq("test"), mockPrfxCtx
                .proxy());
        mockPrfxCtx.matchAndReturn(METHOD_LIST, C.eq(""), createEnumMock(
                mockPrfxCtx, PROP_NAMES, PROP_VALUES).proxy());

        if (useCycles)
        {
            mockTopCtx.matchAndReturn(METHOD_LOOKUP, C.eq("cycle"),
                    mockCycleCtx.proxy());
            mockTopCtx.matchAndReturn(METHOD_LIST, C.eq(""), createEnumMock(
                    mockTopCtx, new String[]
                    { "test", "cycle" }, new Object[]
                    { mockPrfxCtx.proxy(), mockCycleCtx.proxy() }).proxy());
            Mock mockEnum = createEnumMock(mockCycleCtx, PROP_NAMES,
                    PROP_VALUES, false);
            addEnumPair(mockEnum, "cycleCtx", mockCycleCtx.proxy());
            closeEnum(mockEnum);
            mockCycleCtx
                    .matchAndReturn(METHOD_LIST, C.eq(""), mockEnum.proxy());
            mockCycleCtx.matchAndReturn(METHOD_LOOKUP, C.eq("cycleCtx"),
                    mockCycleCtx.proxy());
        }
        else
        {
View Full Code Here

TOP

Related Classes of com.mockobjects.dynamic.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.