package org.apereo.cas.support.oauth.validator.authorization;

import org.apereo.cas.authentication.principal.WebApplicationServiceFactory;
import org.apereo.cas.configuration.CasConfigurationProperties;
import org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer;
import org.apereo.cas.services.ServicesManager;
import org.apereo.cas.support.oauth.OAuth20Constants;
import org.apereo.cas.support.oauth.OAuth20ResponseTypes;
import org.apereo.cas.support.oauth.services.OAuthRegisteredService;
import org.apereo.cas.support.oauth.web.DefaultOAuth20RequestParameterResolver;
import org.apereo.cas.token.JwtBuilder;
import org.apereo.cas.util.CollectionUtils;

import lombok.val;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.pac4j.core.context.JEEContext;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;

import java.util.Collection;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
 * This is {@link OAuth20ProofKeyCodeExchangeResponseTypeAuthorizationRequestValidatorTests}.
 *
 * @author Julien Huon
 * @since 6.4.0
 */
@Tag("OAuth")
public class OAuth20ProofKeyCodeExchangeResponseTypeAuthorizationRequestValidatorTests {
    @Test
    public void verifySupports() throws Exception {
        val serviceManager = mock(ServicesManager.class);

        val service = new OAuthRegisteredService();
        service.setName("OAuth");
        service.setClientId("client");
        service.setClientSecret("secret");
        service.setServiceId("https://callback.example.org");

        when(serviceManager.getAllServices()).thenReturn((Collection) CollectionUtils.toCollection(service));
        when(serviceManager.getAllServicesOfType(any())).thenReturn((Collection) CollectionUtils.toCollection(service));
        val v = new OAuth20ProofKeyCodeExchangeResponseTypeAuthorizationRequestValidator(
            serviceManager, new WebApplicationServiceFactory(),
            new RegisteredServiceAccessStrategyAuditableEnforcer(new CasConfigurationProperties()),
            new DefaultOAuth20RequestParameterResolver(mock(JwtBuilder.class)));

        val request = new MockHttpServletRequest();
        val response = new MockHttpServletResponse();
        val context = new JEEContext(request, response);

        assertFalse(v.supports(context));

        request.setParameter(OAuth20Constants.CLIENT_ID, "client");
        request.setParameter(OAuth20Constants.REDIRECT_URI, service.getServiceId());
        request.setParameter(OAuth20Constants.RESPONSE_TYPE, OAuth20ResponseTypes.TOKEN.getType());
        request.setParameter(OAuth20Constants.CODE_VERIFIER, "abcd");
        assertFalse(v.supports(context));

        request.setParameter(OAuth20Constants.RESPONSE_TYPE, OAuth20ResponseTypes.CODE.getType());
        assertTrue(v.supports(context));
    }
}

@@ -82,254 +82,28 @@
 cas.
-authentication.principal.WebApplicationServiceFactory;%0Aimport org.apereo.cas.configuration.CasConfigurationProperties;%0Aimport org.apereo.cas.services.RegisteredServiceAccessStrategyAuditableEnforcer;%0Aimport org.apereo.cas.services.ServicesManager
+AbstractOAuth20Tests
 ;%0Aim
@@ -216,155 +216,95 @@
 es;%0A
+%0A
 import 
-org.apereo.cas.support.oauth.services.OAuthRegisteredService;%0Aimport org.apereo.cas.support.oauth.web.DefaultOAuth20RequestParameterResolver
+lombok.val;%0Aimport org.junit.jupiter.api.Tag;%0Aimport org.junit.jupiter.api.Test
 ;%0Aim
@@ -316,210 +316,163 @@
 org.
-ape
+pac4j.co
 re
-o
 .c
-as.token.JwtBuilder;%0Aimport org.apereo.cas.util.CollectionUtils;%0A%0Aimport lombok.val;%0Aimport org.junit.jupiter.api.Tag;%0Aimport org.junit.jupiter.api.Test;%0Aimport org.pac4j.core.context.JEEContext
+ontext.JEEContext;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.beans.factory.annotation.Qualifier
 ;%0Aim
@@ -595,38 +595,8 @@
 e;%0A%0A
-import java.util.Collection;%0A%0A
 impo
@@ -642,204 +642,9 @@
 ons.
-assertFalse;%0Aimport static org.junit.jupiter.api.Assertions.assertTrue;%0Aimport static org.mockito.ArgumentMatchers.*;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.when
+*
 ;%0A%0A/
@@ -891,925 +891,362 @@
 sts 
-%7B%0A    @Test%0A    public void verifySupports() throws Exception %7B%0A        val serviceManager = mock(ServicesManager.class);%0A%0A        val service = new OAuthRegisteredService();%0A        service.setName(%22OAuth%22);%0A        service.setClientId(%22client%22);%0A        service.setClientSecret(%22secret%22);%0A        service.setServiceId(%22https://callback.example.org%22);%0A%0A        when(serviceManager.getAllServices()).thenReturn((Collection) CollectionUtils.toCollection(service));%0A        when(serviceM
+extends AbstractOAuth20Tests %7B%0A    @Autowired%0A    @Qualifier(%22oauthProofKeyCodeExch
 an
-a
 ge
-r.getAllServicesOfType(any())).thenReturn((Collection) CollectionUtils.toCollection(service));%0A        val v = new OAuth20ProofKeyCodeExchangeResponseTypeAuthorizationRequestValidator(%0A            serviceManager, new WebApplicationServiceFactory(),%0A            new RegisteredServiceAccessStrategyAuditableEnforcer(new CasConfigurationProperties()),%0A            new DefaultOAuth20RequestParameterResolver(mock(JwtBuilder.class))
+ResponseTypeAuthorizationRequestValidator%22)%0A    private OAuth20AuthorizationRequestValidator validator;%0A%0A    @Test%0A    public void verifySupports() throws Exception %7B%0A        val service = getRegisteredService(%22client%22, %22secret%22);%0A        servicesManager.save(service
 );%0A%0A
@@ -1422,32 +1422,40 @@
    assertFalse(v
+alidator
 .supports(contex
@@ -1804,16 +1804,24 @@
 tFalse(v
+alidator
 .support
@@ -1953,16 +1953,24 @@
 rtTrue(v
+alidator
 .support

fix tests