当前位置: 首页>>代码示例>>Java>>正文


Java MockHttpServletRequest.setCookies方法代码示例

本文整理汇总了Java中org.springframework.mock.web.MockHttpServletRequest.setCookies方法的典型用法代码示例。如果您正苦于以下问题:Java MockHttpServletRequest.setCookies方法的具体用法?Java MockHttpServletRequest.setCookies怎么用?Java MockHttpServletRequest.setCookies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.mock.web.MockHttpServletRequest的用法示例。


在下文中一共展示了MockHttpServletRequest.setCookies方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verifyTgtToSetRemovingOldTgt

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifyTgtToSetRemovingOldTgt() throws Exception {
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockHttpServletRequest request = new MockHttpServletRequest();

    final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
    when(tgt.getId()).thenReturn("test");

    request.setCookies(new Cookie("TGT", "test5"));
    WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
    this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));

    assertEquals("success", this.action.execute(this.context).getId());
    request.setCookies(response.getCookies());
    assertEquals(tgt.getId(), this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:SendTicketGrantingTicketActionTests.java

示例2: verifySsoSessionCookieOnRenewAsParameter

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifySsoSessionCookieOnRenewAsParameter() throws Exception {
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");

    final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
    when(tgt.getId()).thenReturn("test");
    request.setCookies(new Cookie("TGT", "test5"));
    WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
    this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));

    this.action.setCreateSsoSessionCookieOnRenewAuthentications(false);
    assertEquals("success", this.action.execute(this.context).getId());
    assertEquals(0, response.getCookies().length);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:SendTicketGrantingTicketActionTests.java

示例3: verifySsoSessionCookieOnServiceSsoDisallowed

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifySsoSessionCookieOnServiceSsoDisallowed() throws Exception {
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockHttpServletRequest request = new MockHttpServletRequest();

    final WebApplicationService svc = mock(WebApplicationService.class);
    when(svc.getId()).thenReturn("TestSsoFalse");

    final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
    when(tgt.getId()).thenReturn("test");
    request.setCookies(new Cookie("TGT", "test5"));
    WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
    this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    this.context.getFlowScope().put("service", svc);
    this.action.setCreateSsoSessionCookieOnRenewAuthentications(false);
    assertEquals("success", this.action.execute(this.context).getId());
    assertEquals(0, response.getCookies().length);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:19,代码来源:SendTicketGrantingTicketActionTests.java

示例4: verifyTgtToSet

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifyTgtToSet() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr(LOCALHOST_IP);
    request.setLocalAddr(LOCALHOST_IP);
    ClientInfoHolder.setClientInfo(new ClientInfo(request));

    final MockHttpServletResponse response = new MockHttpServletResponse();
    request.addHeader("User-Agent", "Test");
    final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
    when(tgt.getId()).thenReturn(TEST_STRING);

    WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
    this.context.setExternalContext(new ServletExternalContext(new MockServletContext(),
            request, response));

    assertEquals(SUCCESS, this.action.execute(this.context).getId());
    request.setCookies(response.getCookies());
    assertEquals(tgt.getId(), this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request));
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:21,代码来源:SendTicketGrantingTicketActionTests.java

示例5: verifySsoSessionCookieOnRenewAsParameter

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifySsoSessionCookieOnRenewAsParameter() throws Exception {
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");

    final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
    when(tgt.getId()).thenReturn(TEST_STRING);
    request.setCookies(new Cookie("TGT", "test5"));
    WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
    this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));

    final SendTicketGrantingTicketAction action = new SendTicketGrantingTicketAction(centralAuthenticationService, servicesManager,
            ticketGrantingTicketCookieGenerator, false);
    assertEquals(SUCCESS, action.execute(this.context).getId());
    assertEquals(0, response.getCookies().length);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:18,代码来源:SendTicketGrantingTicketActionTests.java

示例6: verifySsoSessionCookieOnServiceSsoDisallowed

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifySsoSessionCookieOnServiceSsoDisallowed() throws Exception {
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockHttpServletRequest request = new MockHttpServletRequest();

    final WebApplicationService svc = mock(WebApplicationService.class);
    when(svc.getId()).thenReturn("TestSsoFalse");

    final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
    when(tgt.getId()).thenReturn(TEST_STRING);
    request.setCookies(new Cookie("TGT", "test5"));
    WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
    this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    this.context.getFlowScope().put("service", svc);

    final SendTicketGrantingTicketAction action = new SendTicketGrantingTicketAction(centralAuthenticationService, servicesManager,
            ticketGrantingTicketCookieGenerator, false);
    assertEquals(SUCCESS, action.execute(this.context).getId());
    assertEquals(0, response.getCookies().length);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:21,代码来源:SendTicketGrantingTicketActionTests.java

示例7: testServiceTicketFromCookie

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void testServiceTicketFromCookie() throws Exception {
    MockRequestContext context = new MockRequestContext();
    context.getFlowScope().put("service", TestUtils.getService());
    context.getFlowScope().put("ticketGrantingTicketId", this.ticketGrantingTicket);
    MockHttpServletRequest request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(
            new MockServletContext(), request, new MockHttpServletResponse()));
    request.addParameter("service", "service");
    request.setCookies(new Cookie[] {new Cookie("TGT",
            this.ticketGrantingTicket)});

    this.action.execute(context);

    assertNotNull(WebUtils.getServiceTicketFromRequestScope(context));
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:17,代码来源:GenerateServiceTicketActionTests.java

示例8: verifyServiceTicketFromCookie

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifyServiceTicketFromCookie() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    context.getFlowScope().put("service", org.jasig.cas.services.TestUtils.getService());
    context.getFlowScope().put("ticketGrantingTicketId", this.ticketGrantingTicket.getId());
    final MockHttpServletRequest request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(
            new MockServletContext(), request, new MockHttpServletResponse()));
    request.addParameter("service", "service");
    request.setCookies(new Cookie("TGT", this.ticketGrantingTicket.getId()));

    this.action.execute(context);

    assertNotNull(WebUtils.getServiceTicketFromRequestScope(context));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:16,代码来源:GenerateServiceTicketActionTests.java

示例9: testCookieRetrieve

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void testCookieRetrieve() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final Cookie cookie = new Cookie("test", "test");
    cookie.setDomain("cas.org");
    cookie.setMaxAge(5);
    request.setCookies(new Cookie[] {cookie});

    assertEquals("test", this.g.retrieveCookieValue(request));
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:11,代码来源:CookieRetrievingCookieGeneratorTests.java

示例10: verifyServiceTicketFromCookie

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifyServiceTicketFromCookie() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    context.getFlowScope().put("service", TestUtils.getService());
    context.getFlowScope().put("ticketGrantingTicketId", this.ticketGrantingTicket.getId());
    final MockHttpServletRequest request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(
            new MockServletContext(), request, new MockHttpServletResponse()));
    request.addParameter("service", "service");
    request.setCookies(new Cookie("TGT", this.ticketGrantingTicket.getId()));

    this.action.execute(context);

    assertNotNull(WebUtils.getServiceTicketFromRequestScope(context));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:16,代码来源:GenerateServiceTicketActionTests.java

示例11: verifyTgtToSet

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifyTgtToSet() throws Exception {
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
    when(tgt.getId()).thenReturn("test");

    WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
    this.context.setExternalContext(new ServletExternalContext(new MockServletContext(),
            request, response));

    assertEquals("success", this.action.execute(this.context).getId());
    request.setCookies(response.getCookies());
    assertEquals(tgt.getId(), this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:16,代码来源:SendTicketGrantingTicketActionTests.java

示例12: verifyCookieAddWithRememberMe

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifyCookieAddWithRememberMe() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(RememberMeCredential.REQUEST_PARAMETER_REMEMBER_ME, "true");
    final MockHttpServletResponse response = new MockHttpServletResponse();

    this.generator.addCookie(request, response, "test");
    request.setCookies(response.getCookies());

    final Cookie c = response.getCookie("test");
    assertEquals(100, c.getMaxAge());
    assertEquals("test", this.generator.retrieveCookieValue(request));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:14,代码来源:CookieRetrievingCookieGeneratorTests.java

示例13: verifyServiceTicketFromCookie

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifyServiceTicketFromCookie() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    context.getFlowScope().put(SERVICE_PARAM, RegisteredServiceTestUtils.getService());
    context.getFlowScope().put("ticketGrantingTicketId", this.ticketGrantingTicket.getId());
    final MockHttpServletRequest request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(
            new MockServletContext(), request, new MockHttpServletResponse()));
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, SERVICE_PARAM);
    request.setCookies(new Cookie("TGT", this.ticketGrantingTicket.getId()));

    this.action.execute(context);

    assertNotNull(WebUtils.getServiceTicketFromRequestScope(context));
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:16,代码来源:GenerateServiceTicketActionTests.java


注:本文中的org.springframework.mock.web.MockHttpServletRequest.setCookies方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。