// Path: spring-security-cas-extension/src/main/java/com/kakawait/spring/security/cas/LaxServiceProperties.java
// public class LaxServiceProperties extends ServiceProperties {
// 
//     private final boolean dynamicServiceResolution;
// 
//     public LaxServiceProperties() {
//         this(true);
//     }
// 
//     public LaxServiceProperties(boolean dynamicServiceResolution) {
//         this.dynamicServiceResolution = dynamicServiceResolution;
//     }
// 
//     @Override
//     public void afterPropertiesSet() {
//         if (!dynamicServiceResolution) {
//             try {
//                 super.afterPropertiesSet();
//             } catch (RuntimeException e) {
//                 throw e;
//             } catch (Exception e) {
//                 // Old version of spring security throw Exception for afterPropertiesSet()
//                 throw new RuntimeException(e);
//             }
//         } else {
//             Assert.hasLength(getArtifactParameter(), "artifactParameter cannot be empty.");
//             Assert.hasLength(getServiceParameter(), "serviceParameter cannot be empty.");
//         }
//     }
// 
//     public boolean isDynamicServiceResolution() {
//         return dynamicServiceResolution;
//     }
// }


import com.kakawait.spring.security.cas.LaxServiceProperties;
import org.junit.Test;
import org.springframework.http.HttpMethod;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import java.net.URI;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
package com.kakawait.spring.security.cas.web;




/**
 * @author Thibaud Leprêtre
 */
public class RequestAwareCasAuthenticationEntryPointTest {

    private static final String CAS_SERVER_LOGIN_URL = "http://cas.server.com/cas/login";

    @Test
    public void constructor_WithNullLoginPath_IllegalArgumentException() {
        assertThatThrownBy(() -> new RequestAwareCasAuthenticationEntryPoint(null))
                .isInstanceOf(IllegalArgumentException.class);
    }

    @Test
    public void afterPropertiesSet_WithNullOrEmptyLoginUrl_IllegalArgumentException() {
        RequestAwareCasAuthenticationEntryPoint entryPoint =
                new RequestAwareCasAuthenticationEntryPoint(URI.create("/"));
        entryPoint.setLoginUrl(null);

        assertThatThrownBy(entryPoint::afterPropertiesSet).isInstanceOf(IllegalArgumentException.class);

        entryPoint.setLoginUrl("");
        assertThatThrownBy(entryPoint::afterPropertiesSet).isInstanceOf(IllegalArgumentException.class);
    }

    @Test
    public void afterPropertiesSet_WithNullLoginUrl_IllegalArgumentException() {
        RequestAwareCasAuthenticationEntryPoint entryPoint =
                new RequestAwareCasAuthenticationEntryPoint(URI.create("/"));
        entryPoint.setServiceProperties(null);

        assertThatThrownBy(entryPoint::afterPropertiesSet).isInstanceOf(IllegalArgumentException.class);
    }

    @Test
    public void createServiceUrl_AbsoluteUrlAsLoginPath_NoTransformation() {
        String loginPath = "http://localhost/my/custom/login/path";
        RequestAwareCasAuthenticationEntryPoint entryPoint =
                new RequestAwareCasAuthenticationEntryPoint(URI.create(loginPath));
        entryPoint.setLoginUrl(CAS_SERVER_LOGIN_URL);
// Path: spring-security-cas-extension/src/main/java/com/kakawait/spring/security/cas/LaxServiceProperties.java
// public class LaxServiceProperties extends ServiceProperties {
// 
//     private final boolean dynamicServiceResolution;
// 
//     public LaxServiceProperties() {
//         this(true);
//     }
// 
//     public LaxServiceProperties(boolean dynamicServiceResolution) {
//         this.dynamicServiceResolution = dynamicServiceResolution;
//     }
// 
//     @Override
//     public void afterPropertiesSet() {
//         if (!dynamicServiceResolution) {
//             try {
//                 super.afterPropertiesSet();
//             } catch (RuntimeException e) {
//                 throw e;
//             } catch (Exception e) {
//                 // Old version of spring security throw Exception for afterPropertiesSet()
//                 throw new RuntimeException(e);
//             }
//         } else {
//             Assert.hasLength(getArtifactParameter(), "artifactParameter cannot be empty.");
//             Assert.hasLength(getServiceParameter(), "serviceParameter cannot be empty.");
//         }
//     }
// 
//     public boolean isDynamicServiceResolution() {
//         return dynamicServiceResolution;
//     }
// }


// Path: spring-security-cas-extension/src/test/java/com/kakawait/spring/security/cas/web/RequestAwareCasAuthenticationEntryPointTest.java
import com.kakawait.spring.security.cas.LaxServiceProperties;
import org.junit.Test;
import org.springframework.http.HttpMethod;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import java.net.URI;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

package com.kakawait.spring.security.cas.web;




/**
 * @author Thibaud Leprêtre
 */
public class RequestAwareCasAuthenticationEntryPointTest {

    private static final String CAS_SERVER_LOGIN_URL = "http://cas.server.com/cas/login";

    @Test
    public void constructor_WithNullLoginPath_IllegalArgumentException() {
        assertThatThrownBy(() -> new RequestAwareCasAuthenticationEntryPoint(null))
                .isInstanceOf(IllegalArgumentException.class);
    }

    @Test
    public void afterPropertiesSet_WithNullOrEmptyLoginUrl_IllegalArgumentException() {
        RequestAwareCasAuthenticationEntryPoint entryPoint =
                new RequestAwareCasAuthenticationEntryPoint(URI.create("/"));
        entryPoint.setLoginUrl(null);

        assertThatThrownBy(entryPoint::afterPropertiesSet).isInstanceOf(IllegalArgumentException.class);

        entryPoint.setLoginUrl("");
        assertThatThrownBy(entryPoint::afterPropertiesSet).isInstanceOf(IllegalArgumentException.class);
    }

    @Test
    public void afterPropertiesSet_WithNullLoginUrl_IllegalArgumentException() {
        RequestAwareCasAuthenticationEntryPoint entryPoint =
                new RequestAwareCasAuthenticationEntryPoint(URI.create("/"));
        entryPoint.setServiceProperties(null);

        assertThatThrownBy(entryPoint::afterPropertiesSet).isInstanceOf(IllegalArgumentException.class);
    }

    @Test
    public void createServiceUrl_AbsoluteUrlAsLoginPath_NoTransformation() {
        String loginPath = "http://localhost/my/custom/login/path";
        RequestAwareCasAuthenticationEntryPoint entryPoint =
                new RequestAwareCasAuthenticationEntryPoint(URI.create(loginPath));
        entryPoint.setLoginUrl(CAS_SERVER_LOGIN_URL);
        entryPoint.setServiceProperties(new LaxServiceProperties());