⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testmockbase.java

📁 这是STRUTS1.2。6的开发包。。这是我从芝APACHE网站下下来
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                               "module/noslash",
                               false,   // No redirect
                               false)); // Not context relative

        moduleConfig.addForwardConfig
            (new ForwardConfig("contextNoslash",
                               "context/noslash",
                               false,   // No redirect
                               true));  // Not context relative

    }


    protected void setUpSecondApp() {

        ActionFormBean formBean = null;
        ActionMapping mapping = null;


        ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
        moduleConfig2 = factoryObject.createModuleConfig("/2");

        context.setAttribute(Globals.MODULE_KEY + "/2", moduleConfig2);

        // Forward "external" to "http://jakarta.apache.org/"
        moduleConfig2.addForwardConfig
            (new ActionForward("external", "http://jakarta.apache.org/",
                               false, false));

        // Forward "foo" to "/baz.jsp" (different from default)
        moduleConfig2.addForwardConfig
            (new ActionForward("foo", "/baz.jsp", false, false));

        // Forward "relative1" to "relative.jsp" non-context-relative
        moduleConfig2.addForwardConfig
            (new ActionForward("relative1", "relative.jsp", false, false));

        // Forward "relative2" to "relative.jsp" context-relative
        moduleConfig2.addForwardConfig
            (new ActionForward("relative2", "relative.jsp", false, true));

        // Form Bean "static" is a standard ActionForm subclass (same as default)
        formBean = new ActionFormBean
            ("static",
             "org.apache.struts.mock.MockFormBean");
        moduleConfig2.addFormBeanConfig(formBean);

        // Action "/static" uses the "static" form bean in request scope (same as default)
        mapping = new ActionMapping();
        mapping.setInput("/static.jsp");
        mapping.setName("static");
        mapping.setPath("/static");
        mapping.setScope("request");
        mapping.setType("org.apache.struts.mock.MockAction");
        moduleConfig2.addActionConfig(mapping);

        // Form Bean "dynamic2" is a DynaActionForm with the same properties
        formBean = new ActionFormBean
            ("dynamic2",
             "org.apache.struts.action.DynaActionForm");
        formBean.addFormPropertyConfig
            (new FormPropertyConfig("booleanProperty", "boolean", "false"));
        formBean.addFormPropertyConfig
            (new FormPropertyConfig("stringProperty", "java.lang.String",
                                    null));
        moduleConfig2.addFormBeanConfig(formBean);

        // Action "/dynamic2" uses the "dynamic2" form bean in session scope
        mapping = new ActionMapping();
        mapping.setInput("/dynamic2.jsp");
        mapping.setName("dynamic2");
        mapping.setPath("/dynamic2");
        mapping.setScope("session");
        mapping.setType("org.apache.struts.mock.MockAction");
        moduleConfig2.addActionConfig(mapping);

        // Action "/noform" has no form bean associated with it (same as default)
        mapping = new ActionMapping();
        mapping.setPath("/noform");
        mapping.setType("org.apache.struts.mock.MockAction");
        moduleConfig2.addActionConfig(mapping);

        // Configure global forward declarations
        moduleConfig2.addForwardConfig
            (new ForwardConfig("moduleForward",
                               "/module/forward",
                               false,   // No redirect
                               false)); // Not context relative

        moduleConfig2.addForwardConfig
            (new ForwardConfig("moduleRedirect",
                               "/module/redirect",
                               true,    // Redirect
                               false)); // Not context relative

        moduleConfig2.addForwardConfig
            (new ForwardConfig("contextForward",
                               "/context/forward",
                               false,   // No redirect
                               true));  // Context relative

        moduleConfig2.addForwardConfig
            (new ForwardConfig("contextRedirect",
                               "/context/redirect",
                               true,    // Redirect
                               true));  // Context relative

        moduleConfig2.addForwardConfig
            (new ForwardConfig("moduleNoslash",
                               "module/noslash",
                               false,   // No redirect
                               false)); // Not context relative

        moduleConfig2.addForwardConfig
            (new ForwardConfig("contextNoslash",
                               "context/noslash",
                               false,   // No redirect
                               true));  // Not context relative

    }


    // Set up third app for testing URL mapping
    protected void setUpThirdApp() {


        ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
        moduleConfig3 = factoryObject.createModuleConfig("/3");

        context.setAttribute(Globals.MODULE_KEY + "/3", moduleConfig3);

        // Instantiate the controller configuration for this app
        ControllerConfig controller = new ControllerConfig();
        moduleConfig3.setControllerConfig(controller);

        // Configure the properties we will be testing
        controller.setForwardPattern("/forwarding$M$P");
        controller.setInputForward(true);
        controller.setPagePattern("/paging$M$P");

        // Configure global forward declarations
        moduleConfig3.addForwardConfig
            (new ForwardConfig("moduleForward",
                               "/module/forward",
                               false,   // No redirect
                               false)); // Not context relative

        moduleConfig3.addForwardConfig
            (new ForwardConfig("moduleRedirect",
                               "/module/redirect",
                               true,    // Redirect
                               false)); // Not context relative

        moduleConfig3.addForwardConfig
            (new ForwardConfig("contextForward",
                               "/context/forward",
                               false,   // No redirect
                               true));  // Context relative

        moduleConfig3.addForwardConfig
            (new ForwardConfig("contextRedirect",
                               "/context/redirect",
                               true,    // Redirect
                               true));  // Context relative

        moduleConfig3.addForwardConfig
            (new ForwardConfig("moduleNoslash",
                               "module/noslash",
                               false,   // No redirect
                               false)); // Not context relative

        moduleConfig3.addForwardConfig
            (new ForwardConfig("contextNoslash",
                               "context/noslash",
                               false,   // No redirect
                               true));  // Not context relative

    }


    public void tearDown() {

        moduleConfig3 = null;
        moduleConfig2 = null;
        moduleConfig = null;
        config = null;
        context = null;
        page = null;
        principal = null;
        request = null;
        response = null;
        session = null;

    }


    // ------------------------------------------------------- Individual Tests


    // Test the basic setup of the mock object environment
    public void testUtilBaseEnvironment() {

        // Validate the servlet API objects and inter-relationships
        assertNotNull("config is present", config);
        assertNotNull("context is present", context);
        assertNotNull("page is present", page);
        assertNotNull("principal is present", principal);
        assertNotNull("request is present", request);
        assertNotNull("response is present", response);
        assertNotNull("session is present", session);
        assertEquals("page-->config",
                     config, page.getServletConfig());
        assertEquals("config-->context",
                     context, config.getServletContext());
        assertEquals("page-->context",
                     context, page.getServletContext());
        assertEquals("page-->request",
                     request, page.getRequest());
        assertEquals("page-->response",
                     response, page.getResponse());
        assertEquals("page-->session",
                     session, page.getSession());
        assertEquals("request-->principal",
                     principal, request.getUserPrincipal());
        assertEquals("request-->session",
                     session, request.getSession());
        assertEquals("session-->context",
                     context, session.getServletContext());

        // Validate the configuration for the default module
        assertNotNull("moduleConfig is present", moduleConfig);
        assertEquals("context-->moduleConfig",
                     moduleConfig,
                     context.getAttribute(Globals.MODULE_KEY));

        // Validate the configuration for the second module
        assertNotNull("moduleConfig2 is present", moduleConfig2);
        assertEquals("context-->moduleConfig2",
                     moduleConfig2,
                     context.getAttribute(Globals.MODULE_KEY + "/2"));

    }


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -