package org.apereo.cas.adaptors.x509.authentication.principal;

import static org.junit.Assert.*;

import java.security.cert.X509Certificate;

import org.apereo.cas.authentication.CoreAuthenticationTestUtils;
import org.apereo.cas.authentication.UsernamePasswordCredential;
import org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler;
import org.junit.Test;

/**
 * @author Scott Battaglia
 * @author Jan Van der Velpen
 * @since 3.0.0.6
 *
 */
public class X509SerialNumberAndIssuerDNPrincipalResolverTests extends AbstractX509CertificateTests {

    private final X509SerialNumberAndIssuerDNPrincipalResolver resolver = 
            new X509SerialNumberAndIssuerDNPrincipalResolver(null, null);

    @Test
    public void verifyResolvePrincipalInternal() {
        final X509CertificateCredential c = new X509CertificateCredential(new X509Certificate[] {VALID_CERTIFICATE});
        c.setCertificate(VALID_CERTIFICATE);


        final String value = "SERIALNUMBER="
                + VALID_CERTIFICATE.getSerialNumber().toString()
                + ", " + VALID_CERTIFICATE.getIssuerDN().getName();

        assertEquals(value, this.resolver.resolve(c, CoreAuthenticationTestUtils.getPrincipal(),
                new SimpleTestUsernamePasswordAuthenticationHandler()).getId());
    }

    @Test
    public void verifySupport() {
        final X509CertificateCredential c = new X509CertificateCredential(new X509Certificate[] {VALID_CERTIFICATE});
        assertTrue(this.resolver.supports(c));
    }

    @Test                                                        
    public void verifySupportFalse() {
        assertFalse(this.resolver.supports(new UsernamePasswordCredential()));
    }

}

@@ -476,11 +476,8 @@
 0.6%0A
- *%0A
  */%0A
@@ -652,22 +652,17 @@
 solver =
- %0A    
+%0A
         
@@ -872,33 +872,32 @@
 509Certificate%5B%5D
- 
 %7BVALID_CERTIFICA
@@ -994,20 +994,16 @@
 UMBER=%22%0A
-    
         
@@ -1067,20 +1067,16 @@
         
-    
 + %22, %22 +
@@ -1217,20 +1217,16 @@
 ipal(),%0A
-    
         
@@ -1440,17 +1440,16 @@
 ficate%5B%5D
- 
 %7BVALID_C
@@ -1529,64 +1529,8 @@
 Test
-                                                        
 %0A   

fix checkstyle