📄 testmockbase.java.svn-base
字号:
"/module/redirect", true)); // Redirect, same module moduleConfig.addForwardConfig(new ForwardConfig("contextForward", "/forward", false, // No redirect "/context")); // Specify module moduleConfig.addForwardConfig(new ForwardConfig("contextRedirect", "/redirect", true, // Redirect "/context")); // Specify module moduleConfig.addForwardConfig(new ForwardConfig("moduleNoslash", "module/noslash", false)); // No redirect, same module moduleConfig.addForwardConfig(new ForwardConfig("contextNoslash", "noslash", false, // No redirect "/context")); // Specify module } 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)); // Forward "foo" to "/baz.jsp" (different from default) moduleConfig2.addForwardConfig(new ActionForward("foo", "/baz.jsp", false)); // Forward "relative1" to "relative.jsp" non-context-relative moduleConfig2.addForwardConfig(new ActionForward("relative1", "relative.jsp", false)); // Forward "relative2" to "relative.jsp" context-relative moduleConfig2.addForwardConfig(new ActionForward("relative2", "relative.jsp", false)); // 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, same module moduleConfig2.addForwardConfig(new ForwardConfig("moduleRedirect", "/module/redirect", true)); // Redirect, same module moduleConfig2.addForwardConfig(new ForwardConfig("contextForward", "/forward", false, // No redirect "/context")); // Specify module moduleConfig2.addForwardConfig(new ForwardConfig("contextRedirect", "/redirect", true, // Redirect "/context")); // Specify module moduleConfig2.addForwardConfig(new ForwardConfig("moduleNoslash", "module/noslash", false)); // No redirect, same module moduleConfig2.addForwardConfig(new ForwardConfig("contextNoslash", "noslash", false, // No redirect "/context")); // Specify module } // 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, same module moduleConfig3.addForwardConfig(new ForwardConfig("moduleRedirect", "/module/redirect", true)); // Redirect, same module moduleConfig3.addForwardConfig(new ForwardConfig("contextForward", "/forward", false, // No redirect "/context")); // Specify module moduleConfig3.addForwardConfig(new ForwardConfig("contextRedirect", "/redirect", true, // Redirect "/context")); // Specify module moduleConfig3.addForwardConfig(new ForwardConfig("moduleNoslash", "module/noslash", false)); // No redirect, same module moduleConfig3.addForwardConfig(new ForwardConfig("contextNoslash", "noslash", false, // No redirect "/context")); // specify module } 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 + -