// Path: src/main/java/net/klakegg/pkix/ocsp/api/OcspFetcher.java
// public interface OcspFetcher {
// 
//     OcspFetcherResponse fetch(URI uri, byte[] content) throws IOException;
// 
// }
// 
// Path: src/main/java/net/klakegg/pkix/ocsp/api/OcspFetcherResponse.java
// public interface OcspFetcherResponse extends Closeable {
// 
//     int getStatus() throws IOException;
// 
//     String getContentType() throws IOException;
// 
//     InputStream getContent() throws IOException;
// 
// }
// 
// Path: src/test/java/net/klakegg/pkix/ocsp/util/CertificateHelper.java
// public class CertificateHelper {
// 
//     private static final CertificateFactory certFactory;
// 
//     static {
//         try {
//             certFactory = CertificateFactory.getInstance("X.509");
//         } catch (CertificateException e) {
//             throw new IllegalStateException(e.getMessage(), e);
//         }
//     }
// 
//     public static X509Certificate parse(InputStream inputStream) {
//         try {
//             return (X509Certificate) certFactory.generateCertificate(inputStream);
//         } catch (CertificateException e) {
//             throw new IllegalStateException(e.getMessage(), e);
//         }
//     }
// 
// }


import net.klakegg.pkix.ocsp.api.OcspFetcher;
import net.klakegg.pkix.ocsp.api.OcspFetcherResponse;
import net.klakegg.pkix.ocsp.util.CertificateHelper;
import org.mockito.Mockito;
import org.testng.annotations.Test;
import java.io.IOException;
import java.net.URI;
import java.security.cert.X509Certificate;
package net.klakegg.pkix.ocsp;



/**
 * @author erlend
 */
public class AbstractOcspClientTest {

    private X509Certificate subject =
            CertificateHelper.parse(getClass().getResourceAsStream("/buypass-test/certificate-valid-01.cer"));

    private X509Certificate issuer =
            CertificateHelper.parse(getClass().getResourceAsStream("/buypass-test/issuer.cer"));

    @Test(expectedExceptions = OcspException.class, expectedExceptionsMessageRegExp = ".*404.*")
    public void httpResponse404() throws OcspException, IOException {
        OcspFetcherResponse fetcherResponse = Mockito.mock(OcspFetcherResponse.class);
        Mockito.when(fetcherResponse.getStatus()).thenReturn(404);

        OcspClient ocspClient = OcspClient.builder()
                .set(OcspClient.FETCHER, createOcspFetcher(fetcherResponse))
                .build();

        ocspClient.verify(subject, issuer);
    }

    @Test(expectedExceptions = OcspException.class, expectedExceptionsMessageRegExp = ".*text/html.*")
    public void invalidContentType() throws OcspException, IOException {
// Path: src/main/java/net/klakegg/pkix/ocsp/api/OcspFetcher.java
// public interface OcspFetcher {
// 
//     OcspFetcherResponse fetch(URI uri, byte[] content) throws IOException;
// 
// }
// 
// Path: src/main/java/net/klakegg/pkix/ocsp/api/OcspFetcherResponse.java
// public interface OcspFetcherResponse extends Closeable {
// 
//     int getStatus() throws IOException;
// 
//     String getContentType() throws IOException;
// 
//     InputStream getContent() throws IOException;
// 
// }
// 
// Path: src/test/java/net/klakegg/pkix/ocsp/util/CertificateHelper.java
// public class CertificateHelper {
// 
//     private static final CertificateFactory certFactory;
// 
//     static {
//         try {
//             certFactory = CertificateFactory.getInstance("X.509");
//         } catch (CertificateException e) {
//             throw new IllegalStateException(e.getMessage(), e);
//         }
//     }
// 
//     public static X509Certificate parse(InputStream inputStream) {
//         try {
//             return (X509Certificate) certFactory.generateCertificate(inputStream);
//         } catch (CertificateException e) {
//             throw new IllegalStateException(e.getMessage(), e);
//         }
//     }
// 
// }


// Path: src/test/java/net/klakegg/pkix/ocsp/AbstractOcspClientTest.java
import net.klakegg.pkix.ocsp.api.OcspFetcher;
import net.klakegg.pkix.ocsp.api.OcspFetcherResponse;
import net.klakegg.pkix.ocsp.util.CertificateHelper;
import org.mockito.Mockito;
import org.testng.annotations.Test;
import java.io.IOException;
import java.net.URI;
import java.security.cert.X509Certificate;

package net.klakegg.pkix.ocsp;



/**
 * @author erlend
 */
public class AbstractOcspClientTest {

    private X509Certificate subject =
            CertificateHelper.parse(getClass().getResourceAsStream("/buypass-test/certificate-valid-01.cer"));

    private X509Certificate issuer =
            CertificateHelper.parse(getClass().getResourceAsStream("/buypass-test/issuer.cer"));

    @Test(expectedExceptions = OcspException.class, expectedExceptionsMessageRegExp = ".*404.*")
    public void httpResponse404() throws OcspException, IOException {
        OcspFetcherResponse fetcherResponse = Mockito.mock(OcspFetcherResponse.class);
        Mockito.when(fetcherResponse.getStatus()).thenReturn(404);

        OcspClient ocspClient = OcspClient.builder()
                .set(OcspClient.FETCHER, createOcspFetcher(fetcherResponse))
                .build();

        ocspClient.verify(subject, issuer);
    }

    @Test(expectedExceptions = OcspException.class, expectedExceptionsMessageRegExp = ".*text/html.*")
    public void invalidContentType() throws OcspException, IOException {
        OcspFetcherResponse fetcherResponse = Mockito.mock(OcspFetcherResponse.class);