本文整理汇总了Java中org.apache.struts.mock.MockHttpServletResponse类的典型用法代码示例。如果您正苦于以下问题:Java MockHttpServletResponse类的具体用法?Java MockHttpServletResponse怎么用?Java MockHttpServletResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockHttpServletResponse类属于org.apache.struts.mock包,在下文中一共展示了MockHttpServletResponse类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.apache.struts.mock.MockHttpServletResponse; //导入依赖的package包/类
protected void setUp() throws Exception {
this.request = new MockHttpServletRequest();
this.principal =
new MockPrincipal("Mr. Macri", new String[] { "administrator" });
this.request.setUserPrincipal(principal);
MockServletConfig servletConfig = new MockServletConfig();
MockServletContext servletContext = new MockServletContext();
MockActionServlet servlet =
new MockActionServlet(servletContext, servletConfig);
servlet.initInternal();
this.saContext =
new ServletActionContext(servletContext, request,
new MockHttpServletResponse());
this.saContext.setActionServlet(servlet);
this.command = new AuthorizeAction();
}
示例2: setUp
import org.apache.struts.mock.MockHttpServletResponse; //导入依赖的package包/类
protected void setUp() throws Exception {
this.request = new MockHttpServletRequest();
this.principal =
new MockPrincipal("Mr. Macri", new String[] { "administrator" });
this.request.setUserPrincipal(principal);
MockServletConfig servletConfig = new MockServletConfig();
MockServletContext servletContext = new MockServletContext();
MockActionServlet servlet =
new MockActionServlet(servletContext, servletConfig);
servlet.initInternal();
this.saContext =
new ServletActionContext(servletContext, request,
new MockHttpServletResponse());
this.saContext.setActionServlet(servlet);
this.command = new PerformForward();
}
示例3: getToolContext
import org.apache.struts.mock.MockHttpServletResponse; //导入依赖的package包/类
private ToolContext getToolContext(String toolboxConfigLocation) throws Exception {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(new MockServletContext());
context.register(Config.class);
context.refresh();
EmbeddedVelocityToolboxView view = context
.getBean(EmbeddedVelocityToolboxView.class);
view.setToolboxConfigLocation(toolboxConfigLocation);
Map<String, Object> model = new LinkedHashMap<String, Object>();
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
ToolContext toolContext = (ToolContext) view.createVelocityContext(model, request,
response);
context.close();
return toolContext;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:EmbeddedVelocityToolboxViewTests.java
示例4: delegatingFilterProxyRegistrationBeansSkipsTargetBeanNames
import org.apache.struts.mock.MockHttpServletResponse; //导入依赖的package包/类
@Test
public void delegatingFilterProxyRegistrationBeansSkipsTargetBeanNames()
throws Exception {
addEmbeddedServletContainerFactoryBean();
DelegatingFilterProxyRegistrationBean initializer = new DelegatingFilterProxyRegistrationBean(
"filterBean");
this.context.registerBeanDefinition("initializerBean",
beanDefinition(initializer));
BeanDefinition filterBeanDefinition = beanDefinition(
new IllegalStateException("Create FilterBean Failure"));
filterBeanDefinition.setLazyInit(true);
this.context.registerBeanDefinition("filterBean", filterBeanDefinition);
this.context.refresh();
ServletContext servletContext = getEmbeddedServletContainerFactory()
.getServletContext();
verify(servletContext, atMost(1)).addFilter(anyString(),
this.filterCaptor.capture());
// Up to this point the filterBean should not have been created, calling
// the delegate proxy will trigger creation and an exception
this.thrown.expect(BeanCreationException.class);
this.thrown.expectMessage("Create FilterBean Failure");
this.filterCaptor.getValue().init(new MockFilterConfig());
this.filterCaptor.getValue().doFilter(new MockHttpServletRequest(),
new MockHttpServletResponse(), new MockFilterChain());
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:26,代码来源:EmbeddedWebApplicationContextTests.java
示例5: testModuleConfig_getModuleConfig_PageContext
import org.apache.struts.mock.MockHttpServletResponse; //导入依赖的package包/类
public void testModuleConfig_getModuleConfig_PageContext() {
MockServletConfig mockServletConfig = new MockServletConfig();
ModuleConfig moduleConfig = new ModuleConfigImpl("");
MockServletContext mockServletContext = new MockServletContext();
MockHttpServletRequest mockHttpServletRequest =
new MockHttpServletRequest();
MockHttpServletResponse mockHttpServletResponse =
new MockHttpServletResponse();
mockServletConfig.setServletContext(mockServletContext);
MockPageContext mockPageContext =
new MockPageContext(mockServletConfig, mockHttpServletRequest,
mockHttpServletResponse);
ModuleConfig foundModuleConfig = null;
try {
foundModuleConfig = tagutils.getModuleConfig(mockPageContext);
fail("Expected ModuleConfig to not be found");
} catch (NullPointerException ignore) {
// expected result
}
mockHttpServletRequest.setAttribute(Globals.MODULE_KEY, moduleConfig);
mockPageContext.getServletContext().setAttribute(Globals.MODULE_KEY,
mockPageContext);
foundModuleConfig = tagutils.getModuleConfig(mockPageContext);
assertNotNull(foundModuleConfig);
}
示例6: setUp
import org.apache.struts.mock.MockHttpServletResponse; //导入依赖的package包/类
/**
* Set up mock objects.
*/
public void setUp() {
config = new MockServletConfig();
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
pageContext = new MockPageContext(config, request, response);
htmlTag = new HtmlTag();
htmlTag.setPageContext(pageContext);
}
示例7: testSetOriginalURI
import org.apache.struts.mock.MockHttpServletResponse; //导入依赖的package包/类
public void testSetOriginalURI()
throws Exception {
MockHttpServletRequest request =
new MockHttpServletRequest("foo/", "bar.do", null, null);
MockServletConfig servletConfig = new MockServletConfig();
MockServletContext servletContext = new MockServletContext();
MockActionServlet servlet =
new MockActionServlet(servletContext, servletConfig);
servlet.initInternal();
ServletActionContext saContext =
new ServletActionContext(servletContext, request,
new MockHttpServletResponse());
saContext.setActionServlet(servlet);
boolean result = command.execute(saContext);
assertTrue(!result);
String uri = (String) request.getAttribute(Globals.ORIGINAL_URI_KEY);
assertTrue("Original uri not correct: " + uri, "bar.do".equals(uri));
request.setPathElements("foo/", "bar2.do", null, null);
uri = (String) request.getAttribute(Globals.ORIGINAL_URI_KEY);
assertTrue("Original uri not correct: " + uri, "bar.do".equals(uri));
}
示例8: createCustomerFromController
import org.apache.struts.mock.MockHttpServletResponse; //导入依赖的package包/类
@Test(groups = "createCustomerFromController", dataProvider = "setupCustomerControllerData", dataProviderClass = RegisterCustomerDataProvider.class, enabled=false)
@Transactional
@Rollback(false)
public void createCustomerFromController(RegisterCustomerForm registerCustomer) {
BindingResult errors = new BeanPropertyBindingResult(registerCustomer, "registerCustomer");
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
registerCustomerController.registerCustomer(registerCustomer, errors, request, response);
assert(errors.getErrorCount() == 0);
Customer customerFromDb = customerService.readCustomerByUsername(registerCustomer.getCustomer().getUsername());
assert(customerFromDb != null);
}
示例9: onSubmit_shouldSaveANewEncounterRoleObject
import org.apache.struts.mock.MockHttpServletResponse; //导入依赖的package包/类
/**
* @see EncounterFormController#onSubmit(javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse, java.lang.Object,
* org.springframework.validation.BindException)
*/
@Test
@Verifies(value = "transfer encounter to another patient when encounter patient was changed", method = "onSubmit(HttpServletRequest, HttpServletResponse, Object, BindException)")
public void onSubmit_shouldSaveANewEncounterRoleObject() throws Exception {
executeDataSet(ENC_INITIAL_DATA_XML);
executeDataSet(TRANSFER_ENC_DATA_XML);
EncounterFormController controller = new EncounterFormController();
MockHttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setParameter("patientId", "201");
Encounter encounter = Context.getEncounterService().getEncounter(200);
Patient oldPatient = encounter.getPatient();
Patient newPatient = Context.getPatientService().getPatient(201);
Assert.assertNotEquals(oldPatient, newPatient);
List<Encounter> newEncounter = Context.getEncounterService().getEncountersByPatientId(newPatient.getPatientId());
Assert.assertEquals(0, newEncounter.size());
BindException errors = new BindException(encounter, "encounterRole");
controller.onSubmit(request, response, encounter, errors);
Assert.assertEquals(true, encounter.isVoided());
newEncounter = Context.getEncounterService().getEncountersByPatientId(newPatient.getPatientId());
Assert.assertEquals(1, newEncounter.size());
Assert.assertEquals(false, newEncounter.get(0).isVoided());
}
示例10: setUp
import org.apache.struts.mock.MockHttpServletResponse; //导入依赖的package包/类
/**
* Helper method that creates/configures a basic configuration of Mock
* Objects.
*
*
* PageContext ServletConfig ServletContext HttpServletRequest HttpSession
* HttpServletResponse
*
* "/myapp", "/foo", null, null,
*/
public void setUp() {
// -- default Module
this.moduleConfig = new ModuleConfigImpl("");
this.moduleConfig.addForwardConfig(new ForwardConfig("foo", "/bar.jsp",
false));
this.moduleConfig.addForwardConfig(new ForwardConfig("relative1",
"relative.jsp", false));
this.moduleConfig.addForwardConfig(new ForwardConfig("relative2",
"relative.jsp", false));
this.moduleConfig.addForwardConfig(new ForwardConfig("external",
"http://struts.apache.org/", false));
// -- module "/2"
this.moduleConfig2 = new ModuleConfigImpl("/2");
this.moduleConfig2.addForwardConfig(new ForwardConfig("foo",
"/baz.jsp", false));
this.moduleConfig2.addForwardConfig(new ForwardConfig("relative1",
"relative.jsp", false));
this.moduleConfig2.addForwardConfig(new ForwardConfig("relative2",
"relative.jsp", false));
this.moduleConfig2.addForwardConfig(new ForwardConfig("external",
"http://struts.apache.org/", false));
// -- module "/3"
this.moduleConfig3 = new ModuleConfigImpl("/3");
// -- configure the ServletContext
this.servletContext = new MockServletContext();
this.servletContext.setAttribute(Globals.MODULE_KEY, moduleConfig);
this.servletContext.setAttribute(Globals.MODULE_KEY + "/2",
moduleConfig2);
this.servletContext.setAttribute(Globals.MODULE_KEY + "/3",
moduleConfig3);
// -- configure the ServletConfig
this.servletConfig = new MockServletConfig();
this.servletConfig.setServletContext(servletContext);
// -- configure the request
this.request = new MockHttpServletRequest(new MockHttpSession());
pageContext =
new MockPageContext(servletConfig, request,
new MockHttpServletResponse());
}