/*
 * Copyright 2005 The JA-SIG Collaborative. All rights reserved. See license
 * distributed with this file and available online at
 * http://www.uportal.org/license.html
 */
package org.jasig.cas.web;

import org.jasig.cas.AbstractCentralAuthenticationServiceTest;
import org.jasig.cas.mock.MockAuthentication;
import org.jasig.cas.ticket.TicketGrantingTicket;
import org.jasig.cas.ticket.TicketGrantingTicketImpl;
import org.jasig.cas.ticket.registry.DefaultTicketRegistry;
import org.jasig.cas.ticket.registry.TicketRegistry;
import org.jasig.cas.ticket.support.NeverExpiresExpirationPolicy;
import org.jasig.cas.web.support.WebConstants;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;

/**
 * @author Scott Battaglia
 * @version $Revision$ $Date$
 * @since 3.0
 */
public class ProxyControllerTests extends AbstractCentralAuthenticationServiceTest {

    private ProxyController proxyController;

    private TicketRegistry t;

    protected void setUp() throws Exception {
        this.t = new DefaultTicketRegistry();

        this.proxyController = new ProxyController();
        this.proxyController.setCentralAuthenticationService(getCentralAuthenticationService());
        this.centralAuthenticationService.setTicketRegistry(this.t);
        this.proxyController.afterPropertiesSet();

        StaticApplicationContext context = new StaticApplicationContext();
        context.refresh();
        ((ApplicationContextAware) this.proxyController)
            .setApplicationContext(context);
    }

    public void testNonExistantPGT() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.addParameter(WebConstants.PROXY_GRANTING_TICKET, "TestService");
        request.addParameter(WebConstants.TARGET_SERVICE, "service");

        assertTrue(this.proxyController.handleRequestInternal(request,
            new MockHttpServletResponse()).getModel().containsKey(
            WebConstants.CODE));
    }

    public void testExistingPGT() throws Exception {
        final TicketGrantingTicket ticket = new TicketGrantingTicketImpl(
            "ticketGrantingTicketId", new MockAuthentication(),
            new NeverExpiresExpirationPolicy());
        this.t.addTicket(ticket);
        MockHttpServletRequest request = new MockHttpServletRequest();
        request
            .addParameter(WebConstants.PROXY_GRANTING_TICKET, ticket.getId());
        request.addParameter(WebConstants.TARGET_SERVICE, "service");

        assertTrue(this.proxyController.handleRequestInternal(request,
            new MockHttpServletResponse()).getModel().containsKey(
            WebConstants.TICKET));
    }
}

@@ -1008,16 +1008,20 @@
  extends
+%0A   
  Abstrac
@@ -1056,16 +1056,16 @@
 eTest %7B%0A
-
 %0A    pri
@@ -1309,16 +1309,29 @@
 ntroller
+%0A            
 .setCent
@@ -1671,16 +1671,16 @@
 roller)%0A
-
         
@@ -1715,32 +1715,311 @@
 ontext);%0A    %7D%0A%0A
+    public void testNoParams() throws Exception %7B%0A        assertEquals(%22INVALID_REQUEST%22, this.proxyController%0A            .handleRequestInternal(new MockHttpServletRequest(),%0A                new MockHttpServletResponse()).getModel()%0A            .get(WebConstants.CODE));%0A    %7D%0A%0A
     public void 

test with no pgt and targetService