本文整理匯總了Java中org.springframework.mock.web.MockServletContext類的典型用法代碼示例。如果您正苦於以下問題:Java MockServletContext類的具體用法?Java MockServletContext怎麽用?Java MockServletContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MockServletContext類屬於org.springframework.mock.web包,在下文中一共展示了MockServletContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: verifyResettingContexPath
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Test
public void verifyResettingContexPath() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath(CONST_CONTEXT_PATH);
final MockRequestContext context = new MockRequestContext();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
this.action.doExecute(context);
assertEquals(CONST_CONTEXT_PATH + '/', this.warnCookieGenerator.getCookiePath());
assertEquals(CONST_CONTEXT_PATH + '/', this.tgtCookieGenerator.getCookiePath());
request.setContextPath(CONST_CONTEXT_PATH_2);
this.action.doExecute(context);
assertNotSame(CONST_CONTEXT_PATH_2 + '/', this.warnCookieGenerator.getCookiePath());
assertNotSame(CONST_CONTEXT_PATH_2 + '/', this.tgtCookieGenerator.getCookiePath());
assertEquals(CONST_CONTEXT_PATH + '/', this.warnCookieGenerator.getCookiePath());
assertEquals(CONST_CONTEXT_PATH + '/', this.tgtCookieGenerator.getCookiePath());
}
示例2: testSuccessfulAuthenticationWithNoServiceAndWarn
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Test
public void testSuccessfulAuthenticationWithNoServiceAndWarn()
throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
final MockRequestContext context = new MockRequestContext();
request.addParameter("username", "test");
request.addParameter("password", "test");
request.addParameter("warn", "true");
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, response));
context.getRequestScope().put("credentials",
TestUtils.getCredentialsWithSameUsernameAndPassword());
// this.action.bind(context);
// assertEquals("success", this.action.submit(context).getId());
// assertNotNull(response.getCookie(this.warnCookieGenerator
// .getCookieName()));
}
示例3: setUp
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Before
public void setUp() {
applicationContext = new XmlWebApplicationContext();
applicationContext.setConfigLocations(
"file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
"file:src/main/webapp/WEB-INF/managementConfigContext.xml",
"file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
@Override
public Resource getResource(final String location) {
return new FileSystemResource("src/main/webapp" + location);
}
@Override
public ClassLoader getClassLoader() {
return getClassLoader();
}
}));
applicationContext.refresh();
}
示例4: testFailedAuthenticationWithNoService
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Test
public void testFailedAuthenticationWithNoService() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
request.addParameter("username", "test");
request.addParameter("password", "test2");
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
context.getRequestScope().put("credentials",
TestUtils.getCredentialsWithDifferentUsernameAndPassword());
context.getRequestScope().put(
"org.springframework.validation.BindException.credentials",
new BindException(TestUtils
.getCredentialsWithDifferentUsernameAndPassword(),
"credentials"));
// this.action.bind(context);
// assertEquals("error", this.action.submit(context).getId());
}
示例5: setUp
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Before
public void setUp() {
applicationContext = new XmlWebApplicationContext();
applicationContext.setConfigLocations(
"classpath:/webappContext.xml",
"file:src/main/webapp/WEB-INF/cas-servlet.xml",
"file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
"file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
@Override
public Resource getResource(final String location) {
return new FileSystemResource("src/main/webapp" + location);
}
@Override
public ClassLoader getClassLoader() {
return getClassLoader();
}
}));
applicationContext.refresh();
}
示例6: verifyBadUsername
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Test
public void verifyBadUsername() throws Exception {
final MockRequestContext context = new MockRequestContext();
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setParameter(OpenIdProtocolConstants.OPENID_IDENTITY, "fablah");
request.setParameter(OpenIdProtocolConstants.OPENID_RETURNTO, "http://www.cnn.com");
final OpenIdServiceFactory factory = new OpenIdServiceFactory();
final OpenIdService service = factory.createService(request);
context.getFlowScope().put("service", service);
context.getFlowScope().put("ticketGrantingTicketId", "tgtId");
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request,
new MockHttpServletResponse()));
assertEquals("error", this.action.execute(context).getId());
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:18,代碼來源:OpenIdSingleSignOnActionTests.java
示例7: verifySuccessfulServiceTicket
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Test
public void verifySuccessfulServiceTicket() throws Exception {
final MockRequestContext context = new MockRequestContext();
final MockHttpServletRequest request = new MockHttpServletRequest();
final Authentication authentication = org.jasig.cas.authentication.TestUtils.getAuthentication("scootman28");
final TicketGrantingTicket t = new TicketGrantingTicketImpl("TGT-11", authentication,
new NeverExpiresExpirationPolicy());
this.ticketRegistry.addTicket(t);
request.setParameter(OpenIdProtocolConstants.OPENID_IDENTITY, "http://openid.aol.com/scootman28");
request.setParameter(OpenIdProtocolConstants.OPENID_RETURNTO, "http://www.cnn.com");
final OpenIdService service = new OpenIdServiceFactory().createService(request);
context.getFlowScope().put("service", service);
context.getFlowScope().put("ticketGrantingTicketId", t.getId());
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request,
new MockHttpServletResponse()));
assertEquals("success", this.action.execute(context).getId());
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:22,代碼來源:OpenIdSingleSignOnActionTests.java
示例8: testResettingContexPath
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Test
public void testResettingContexPath() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final String CONST_CONTEXT_PATH = "/test";
final String CONST_CONTEXT_PATH_2 = "/test1";
request.setContextPath(CONST_CONTEXT_PATH);
final MockRequestContext context = new MockRequestContext();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
this.action.doExecute(context);
assertEquals(CONST_CONTEXT_PATH + "/", this.warnCookieGenerator.getCookiePath());
assertEquals(CONST_CONTEXT_PATH + "/", this.tgtCookieGenerator.getCookiePath());
request.setContextPath(CONST_CONTEXT_PATH_2);
this.action.doExecute(context);
assertNotSame(CONST_CONTEXT_PATH_2 + "/", this.warnCookieGenerator.getCookiePath());
assertNotSame(CONST_CONTEXT_PATH_2 + "/", this.tgtCookieGenerator.getCookiePath());
assertEquals(CONST_CONTEXT_PATH + "/", this.warnCookieGenerator.getCookiePath());
assertEquals(CONST_CONTEXT_PATH + "/", this.tgtCookieGenerator.getCookiePath());
}
示例9: before
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Before
public void before() throws Exception {
servlet = new CrnkServlet();
servletContext = new MockServletContext();
((MockServletContext) servletContext).setContextPath("");
MockServletConfig servletConfig = new MockServletConfig(servletContext);
servletConfig
.addInitParameter(CrnkProperties.RESOURCE_SEARCH_PACKAGE, RESOURCE_SEARCH_PACKAGE);
servletConfig
.addInitParameter(CrnkProperties.RESOURCE_DEFAULT_DOMAIN, RESOURCE_DEFAULT_DOMAIN);
servletConfig
.addInitParameter(CrnkProperties.REJECT_PLAIN_JSON, String.valueOf(true));
servlet.init(servletConfig);
nodeRepository = new NodeRepository();
}
示例10: verifyTicketGrantingTicketNotTgtButGateway
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Test
public void verifyTicketGrantingTicketNotTgtButGateway() throws Exception {
final MockRequestContext context = new MockRequestContext();
context.getFlowScope().put("service", org.jasig.cas.services.TestUtils.getService());
final MockHttpServletRequest request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
request.addParameter("service", "service");
request.addParameter("gateway", "true");
final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
when(tgt.getId()).thenReturn("bleh");
WebUtils.putTicketGrantingTicketInScopes(context, tgt);
assertEquals("gateway", this.action.execute(context).getId());
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:17,代碼來源:GenerateServiceTicketActionTests.java
示例11: verifySuccessfulAuthenticationWithNoServiceAndWarn
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Test
public void verifySuccessfulAuthenticationWithNoServiceAndWarn()
throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
final MockRequestContext context = new MockRequestContext();
WebUtils.putLoginTicket(context, "LOGIN");
request.addParameter("username", "test");
request.addParameter("password", "test");
request.addParameter("warn", "true");
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, response));
final Credential c = org.jasig.cas.authentication.TestUtils.getCredentialsWithSameUsernameAndPassword();
putCredentialInRequestScope(context, c);
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("success", this.action.submit(context, c, messageContext).getId());
assertNotNull(WebUtils.getTicketGrantingTicketId(context));
assertNotNull(response.getCookie(this.warnCookieGenerator.getCookieName()));
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:24,代碼來源:AuthenticationViaFormActionTests.java
示例12: verifyFailedAuthenticationWithNoService
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Test
public void verifyFailedAuthenticationWithNoService() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
final UsernamePasswordCredential c = org.jasig.cas.authentication.TestUtils.getCredentialsWithDifferentUsernameAndPassword();
request.addParameter("username", c.getUsername());
request.addParameter("password", c.getPassword());
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
putCredentialInRequestScope(context, c);
context.getRequestScope().put(
"org.springframework.validation.BindException.credentials",
new BindException(c, "credentials"));
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("authenticationFailure", this.action.submit(context, c, messageContext).getId());
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:21,代碼來源:AuthenticationViaFormActionTests.java
示例13: ensureHostnameAndIpShouldDoSpnego
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Test
public void ensureHostnameAndIpShouldDoSpnego() {
final HostNameSpnegoKnownClientSystemsFilterAction action =
new HostNameSpnegoKnownClientSystemsFilterAction("74\\..+", "", 0, "\\w+\\.\\w+\\.\\w+");
final MockRequestContext ctx = new MockRequestContext();
final MockHttpServletRequest req = new MockHttpServletRequest();
req.setRemoteAddr(ALTERNATE_REMOTE_IP);
final ServletExternalContext extCtx = new ServletExternalContext(
new MockServletContext(), req,
new MockHttpServletResponse());
ctx.setExternalContext(extCtx);
final Event ev = action.doExecute(ctx);
assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
示例14: verifyRenewWithServiceAndDifferentCredentials
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Test
public void verifyRenewWithServiceAndDifferentCredentials() throws Exception {
final Credential c = org.jasig.cas.authentication.TestUtils.getCredentialsWithSameUsernameAndPassword();
final AuthenticationContext ctx = org.jasig.cas.authentication.TestUtils.getAuthenticationContext(
getAuthenticationSystemSupport(), TestUtils.getService("test"), c);
final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
WebUtils.putLoginTicket(context, "LOGIN");
WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
request.addParameter("renew", "true");
request.addParameter("service", TestUtils.getService("test").getId());
request.addParameter("username", "test2");
request.addParameter("password", "test2");
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("success", this.action.submit(context, c, messageContext).getId());
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:26,代碼來源:AuthenticationViaFormActionTests.java
示例15: verifyRenewWithServiceAndBadCredentials
import org.springframework.mock.web.MockServletContext; //導入依賴的package包/類
@Test
public void verifyRenewWithServiceAndBadCredentials() throws Exception {
final Credential c = org.jasig.cas.authentication.TestUtils.getCredentialsWithSameUsernameAndPassword();
final Service service = TestUtils.getService("test");
final AuthenticationContext ctx = org.jasig.cas.authentication.TestUtils.getAuthenticationContext(
getAuthenticationSystemSupport(), service, c);
final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
request.addParameter("renew", "true");
request.addParameter("service", service.getId());
final Credential c2 = org.jasig.cas.authentication.TestUtils.getCredentialsWithDifferentUsernameAndPassword();
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
putCredentialInRequestScope(context, c2);
context.getRequestScope().put(
"org.springframework.validation.BindException.credentials",
new BindException(c2, "credentials"));
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("authenticationFailure", this.action.submit(context, c2, messageContext).getId());
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:27,代碼來源:AuthenticationViaFormActionTests.java