001: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
002: *
003: * Licensed under the Apache License, Version 2.0 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software
010: * distributed under the License is distributed on an "AS IS" BASIS,
011: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: * See the License for the specific language governing permissions and
013: * limitations under the License.
014: */
015:
016: package org.acegisecurity.providers.cas;
017:
018: import junit.framework.TestCase;
019:
020: import java.util.List;
021: import java.util.Vector;
022:
023: /**
024: * Tests {@link TicketResponse}.
025: *
026: * @author Ben Alex
027: * @version $Id: TicketResponseTests.java 1496 2006-05-23 13:38:33Z benalex $
028: */
029: public class TicketResponseTests extends TestCase {
030: //~ Constructors ===================================================================================================
031:
032: public TicketResponseTests() {
033: super ();
034: }
035:
036: public TicketResponseTests(String arg0) {
037: super (arg0);
038: }
039:
040: //~ Methods ========================================================================================================
041:
042: public static void main(String[] args) {
043: junit.textui.TestRunner.run(TicketResponseTests.class);
044: }
045:
046: public final void setUp() throws Exception {
047: super .setUp();
048: }
049:
050: public void testConstructorAcceptsNullProxyGrantingTicketIOU() {
051: TicketResponse ticket = new TicketResponse("marissa",
052: new Vector(), null);
053: assertEquals("", ticket.getProxyGrantingTicketIou());
054: }
055:
056: public void testConstructorAcceptsNullProxyList() {
057: TicketResponse ticket = new TicketResponse("marissa", null,
058: "PGTIOU-0-R0zlgrl4pdAQwBvJWO3vnNpevwqStbSGcq3vKB2SqSFFRnjPHt");
059: assertEquals(new Vector(), ticket.getProxyList());
060: }
061:
062: public void testConstructorRejectsNullUser() {
063: try {
064: new TicketResponse(null, new Vector(),
065: "PGTIOU-0-R0zlgrl4pdAQwBvJWO3vnNpevwqStbSGcq3vKB2SqSFFRnjPHt");
066: fail("Should have thrown IllegalArgumentException");
067: } catch (IllegalArgumentException expected) {
068: assertTrue(true);
069: }
070: }
071:
072: public void testGetters() {
073: // Build the proxy list returned in the ticket from CAS
074: List proxyList = new Vector();
075: proxyList
076: .add("https://localhost/newPortal/j_acegi_cas_security_check");
077:
078: TicketResponse ticket = new TicketResponse("marissa",
079: proxyList,
080: "PGTIOU-0-R0zlgrl4pdAQwBvJWO3vnNpevwqStbSGcq3vKB2SqSFFRnjPHt");
081: assertEquals("marissa", ticket.getUser());
082: assertEquals(proxyList, ticket.getProxyList());
083: assertEquals(
084: "PGTIOU-0-R0zlgrl4pdAQwBvJWO3vnNpevwqStbSGcq3vKB2SqSFFRnjPHt",
085: ticket.getProxyGrantingTicketIou());
086: }
087:
088: public void testNoArgConstructorDoesntExist() {
089: Class clazz = TicketResponse.class;
090:
091: try {
092: clazz.getDeclaredConstructor((Class[]) null);
093: fail("Should have thrown NoSuchMethodException");
094: } catch (NoSuchMethodException expected) {
095: assertTrue(true);
096: }
097: }
098:
099: public void testToString() {
100: TicketResponse ticket = new TicketResponse("marissa", null,
101: "PGTIOU-0-R0zlgrl4pdAQwBvJWO3vnNpevwqStbSGcq3vKB2SqSFFRnjPHt");
102: String result = ticket.toString();
103: assertTrue(result.lastIndexOf("Proxy List:") != -1);
104: assertTrue(result.lastIndexOf("Proxy-Granting Ticket IOU:") != -1);
105: assertTrue(result.lastIndexOf("User:") != -1);
106: }
107: }
|