sendticketgrantingticketactiontests.java

来自「CAS在Tomcat中实现单点登录项目,单点登录(Single Sign On 」· Java 代码 · 共 77 行

JAVA
77
字号
/* * Copyright 2007 The JA-SIG Collaborative. All rights reserved. See license * distributed with this file and available online at * http://www.ja-sig.org/products/cas/overview/license/ */package org.jasig.cas.web.flow;import javax.servlet.http.Cookie;import org.jasig.cas.AbstractCentralAuthenticationServiceTest;import org.jasig.cas.web.support.WebUtils;import org.springframework.mock.web.MockHttpServletRequest;import org.springframework.mock.web.MockHttpServletResponse;import org.springframework.mock.web.MockServletContext;import org.springframework.web.util.CookieGenerator;import org.springframework.webflow.context.servlet.ServletExternalContext;import org.springframework.webflow.test.MockRequestContext;public class SendTicketGrantingTicketActionTests extends AbstractCentralAuthenticationServiceTest {    private SendTicketGrantingTicketAction action;        private CookieGenerator ticketGrantingTicketCookieGenerator;        private MockRequestContext context;        protected void onSetUp() throws Exception {        this.action = new SendTicketGrantingTicketAction();                this.ticketGrantingTicketCookieGenerator = new CookieGenerator();                this.ticketGrantingTicketCookieGenerator.setCookieName("TGT");                this.action.setCentralAuthenticationService(getCentralAuthenticationService());                this.action.setTicketGrantingTicketCookieGenerator(this.ticketGrantingTicketCookieGenerator);               this.action.afterPropertiesSet();                this.context = new MockRequestContext();    }        public void testNoTgtToSet() throws Exception {        this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse()));                assertEquals("success", this.action.execute(this.context).getId());    }        public void testTgtToSet() throws Exception {        final MockHttpServletResponse response = new MockHttpServletResponse();        final String TICKET_VALUE = "test";                WebUtils.putTicketGrantingTicketInRequestScope(this.context, TICKET_VALUE);        this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), response));                assertEquals("success", this.action.execute(this.context).getId());        assertEquals(TICKET_VALUE, response.getCookies()[0].getValue());    }        public void testTgtToSetRemovingOldTgt() throws Exception {        final MockHttpServletResponse response = new MockHttpServletResponse();        final MockHttpServletRequest request = new MockHttpServletRequest();        final String TICKET_VALUE = "test";        request.setCookies(new Cookie[] {new Cookie("TGT", "test5")});        WebUtils.putTicketGrantingTicketInRequestScope(this.context, TICKET_VALUE);        this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));                assertEquals("success", this.action.execute(this.context).getId());        assertEquals(TICKET_VALUE, response.getCookies()[0].getValue());    }                     }

⌨️ 快捷键说明

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