1   /* Copyright 2004 Acegi Technology Pty Limited
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  
16  package org.acegisecurity.providers.cas;
17  
18  import junit.framework.TestCase;
19  
20  import java.util.List;
21  import java.util.Vector;
22  
23  
24  /***
25   * Tests {@link TicketResponse}.
26   *
27   * @author Ben Alex
28   * @version $Id: TicketResponseTests.java,v 1.2 2005/11/17 00:55:48 benalex Exp $
29   */
30  public class TicketResponseTests extends TestCase {
31      //~ Constructors ===========================================================
32  
33      public TicketResponseTests() {
34          super();
35      }
36  
37      public TicketResponseTests(String arg0) {
38          super(arg0);
39      }
40  
41      //~ Methods ================================================================
42  
43      public final void setUp() throws Exception {
44          super.setUp();
45      }
46  
47      public static void main(String[] args) {
48          junit.textui.TestRunner.run(TicketResponseTests.class);
49      }
50  
51      public void testConstructorAcceptsNullProxyGrantingTicketIOU() {
52          TicketResponse ticket = new TicketResponse("marissa", new Vector(), null);
53          assertEquals("", ticket.getProxyGrantingTicketIou());
54      }
55  
56      public void testConstructorAcceptsNullProxyList() {
57          TicketResponse ticket = new TicketResponse("marissa", null,
58                  "PGTIOU-0-R0zlgrl4pdAQwBvJWO3vnNpevwqStbSGcq3vKB2SqSFFRnjPHt");
59          assertEquals(new Vector(), ticket.getProxyList());
60      }
61  
62      public void testConstructorRejectsNullUser() {
63          try {
64              new TicketResponse(null, new Vector(),
65                  "PGTIOU-0-R0zlgrl4pdAQwBvJWO3vnNpevwqStbSGcq3vKB2SqSFFRnjPHt");
66              fail("Should have thrown IllegalArgumentException");
67          } catch (IllegalArgumentException expected) {
68              assertTrue(true);
69          }
70      }
71  
72      public void testGetters() {
73          // Build the proxy list returned in the ticket from CAS
74          List proxyList = new Vector();
75          proxyList.add("https://localhost/newPortal/j_acegi_cas_security_check");
76  
77          TicketResponse ticket = new TicketResponse("marissa", proxyList,
78                  "PGTIOU-0-R0zlgrl4pdAQwBvJWO3vnNpevwqStbSGcq3vKB2SqSFFRnjPHt");
79          assertEquals("marissa", ticket.getUser());
80          assertEquals(proxyList, ticket.getProxyList());
81          assertEquals("PGTIOU-0-R0zlgrl4pdAQwBvJWO3vnNpevwqStbSGcq3vKB2SqSFFRnjPHt",
82              ticket.getProxyGrantingTicketIou());
83      }
84  
85      public void testNoArgConstructor() {
86          try {
87              new TicketResponse();
88              fail("Should have thrown IllegalArgumentException");
89          } catch (IllegalArgumentException expected) {
90              assertTrue(true);
91          }
92      }
93  
94      public void testToString() {
95          TicketResponse ticket = new TicketResponse("marissa", null,
96                  "PGTIOU-0-R0zlgrl4pdAQwBvJWO3vnNpevwqStbSGcq3vKB2SqSFFRnjPHt");
97          String result = ticket.toString();
98          assertTrue(result.lastIndexOf("Proxy List:") != -1);
99          assertTrue(result.lastIndexOf("Proxy-Granting Ticket IOU:") != -1);
100         assertTrue(result.lastIndexOf("User:") != -1);
101     }
102 }