// Path: src/main/java/com/cisco/cta/taxii/adapter/settings/ProxySettings.java
// @ConfigurationProperties(prefix="proxy")
// @Data
// public class ProxySettings {
// 
//     private URL url;
// 
//     private ProxyAuthenticationType authenticationType;
// 
//     private String domain;
// 
//     private String username;
// 
//     private String password;
// 
//     private String workstation;
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/settings/TaxiiServiceSettings.java
// @ConfigurationProperties(prefix="taxii-service")
// @Data
// @Validated
// public class TaxiiServiceSettings {
// 
//     private static final Charset UTF8 = Charset.forName("UTF-8");
// 
//     @NotNull
//     private URL pollEndpoint;
// 
//     @NotNull
//     private String username;
// 
//     @NotNull
//     private String password;
// 
//     private List<String> feeds;
// 
//     private File feedNamesFile;
// 
//     private File statusFile = new File("taxii-status.xml");
// 
//     @PostConstruct
//     public void loadFeedNames() throws IOException {
//         Preconditions.checkState(
//             feeds != null ^ feedNamesFile != null,
//             "taxii-service.feeds or taxii-service.feedNamesFile must be set");
//         if (feedNamesFile != null) {
//             feeds = Files.readLines(feedNamesFile, UTF8);
//         }
//     }
// }
// 
// Path: src/test/java/com/cisco/cta/taxii/adapter/settings/TaxiiServiceSettingsFactory.java
// public class TaxiiServiceSettingsFactory {
// 
//     public static TaxiiServiceSettings createDefaults() {
//         try {
//             TaxiiServiceSettings connSettings = new TaxiiServiceSettings();
//             connSettings.setPollEndpoint(new URL("http://localhost:8080/service"));
//             connSettings.setUsername("user");
//             connSettings.setPassword("pass");
//             return connSettings;
//         } catch (MalformedURLException e) {
//             throw new RuntimeException(e);
//         }
//     }
// }
// 
// Path: src/test/java/com/cisco/cta/taxii/adapter/IsEventContaining.java
// public static void verifyLog(Appender<ILoggingEvent> mockAppender, final String substring) {
//     verify(mockAppender, atLeastOnce())
//             .doAppend(argThat(isEventContaining(substring)));
// }


import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.core.Appender;
import com.cisco.cta.taxii.adapter.settings.ProxySettings;
import com.cisco.cta.taxii.adapter.settings.TaxiiServiceSettings;
import com.cisco.cta.taxii.adapter.settings.TaxiiServiceSettingsFactory;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.protocol.RequestAuthCache;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.impl.client.HttpClients;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpRequestFactory;
import javax.net.ServerSocketFactory;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.SocketTimeoutException;
import static com.cisco.cta.taxii.adapter.IsEventContaining.verifyLog;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;
    }

    @Test(expected=SocketTimeoutException.class)
    public void timeoutConnection() throws Exception {
        BasicAuthHttpRequestFactory factoryImpl = (BasicAuthHttpRequestFactory) factory;
        factoryImpl.setReadTimeout(10);
        Thread server = null;
        try (ServerRunnable serverRunnable = new ServerRunnable()) {
            server = new Thread(serverRunnable);
            ClientHttpRequest req = factory.createRequest(connSettings.getPollEndpoint().toURI(), HttpMethod.POST);
            req.execute();
        } finally {
            server.join(10);
        }
    }


    private static class ServerRunnable implements Runnable, AutoCloseable {
        
        private final ServerSocket serverSocket;
        private Exception runException;

        public ServerRunnable() throws Exception {
            InetAddress localhost = InetAddress.getByName("localhost"); 
            serverSocket = ServerSocketFactory.getDefault().createServerSocket(8080, 1, localhost);
        }

        @Override
        public void run() {
            try {
// Path: src/main/java/com/cisco/cta/taxii/adapter/settings/ProxySettings.java
// @ConfigurationProperties(prefix="proxy")
// @Data
// public class ProxySettings {
// 
//     private URL url;
// 
//     private ProxyAuthenticationType authenticationType;
// 
//     private String domain;
// 
//     private String username;
// 
//     private String password;
// 
//     private String workstation;
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/settings/TaxiiServiceSettings.java
// @ConfigurationProperties(prefix="taxii-service")
// @Data
// @Validated
// public class TaxiiServiceSettings {
// 
//     private static final Charset UTF8 = Charset.forName("UTF-8");
// 
//     @NotNull
//     private URL pollEndpoint;
// 
//     @NotNull
//     private String username;
// 
//     @NotNull
//     private String password;
// 
//     private List<String> feeds;
// 
//     private File feedNamesFile;
// 
//     private File statusFile = new File("taxii-status.xml");
// 
//     @PostConstruct
//     public void loadFeedNames() throws IOException {
//         Preconditions.checkState(
//             feeds != null ^ feedNamesFile != null,
//             "taxii-service.feeds or taxii-service.feedNamesFile must be set");
//         if (feedNamesFile != null) {
//             feeds = Files.readLines(feedNamesFile, UTF8);
//         }
//     }
// }
// 
// Path: src/test/java/com/cisco/cta/taxii/adapter/settings/TaxiiServiceSettingsFactory.java
// public class TaxiiServiceSettingsFactory {
// 
//     public static TaxiiServiceSettings createDefaults() {
//         try {
//             TaxiiServiceSettings connSettings = new TaxiiServiceSettings();
//             connSettings.setPollEndpoint(new URL("http://localhost:8080/service"));
//             connSettings.setUsername("user");
//             connSettings.setPassword("pass");
//             return connSettings;
//         } catch (MalformedURLException e) {
//             throw new RuntimeException(e);
//         }
//     }
// }
// 
// Path: src/test/java/com/cisco/cta/taxii/adapter/IsEventContaining.java
// public static void verifyLog(Appender<ILoggingEvent> mockAppender, final String substring) {
//     verify(mockAppender, atLeastOnce())
//             .doAppend(argThat(isEventContaining(substring)));
// }


// Path: src/test/java/com/cisco/cta/taxii/adapter/httpclient/BasicAuthHttpRequestFactoryTest.java
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.core.Appender;
import com.cisco.cta.taxii.adapter.settings.ProxySettings;
import com.cisco.cta.taxii.adapter.settings.TaxiiServiceSettings;
import com.cisco.cta.taxii.adapter.settings.TaxiiServiceSettingsFactory;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.protocol.RequestAuthCache;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.impl.client.HttpClients;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpRequestFactory;
import javax.net.ServerSocketFactory;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.SocketTimeoutException;
import static com.cisco.cta.taxii.adapter.IsEventContaining.verifyLog;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;

    }

    @Test(expected=SocketTimeoutException.class)
    public void timeoutConnection() throws Exception {
        BasicAuthHttpRequestFactory factoryImpl = (BasicAuthHttpRequestFactory) factory;
        factoryImpl.setReadTimeout(10);
        Thread server = null;
        try (ServerRunnable serverRunnable = new ServerRunnable()) {
            server = new Thread(serverRunnable);
            ClientHttpRequest req = factory.createRequest(connSettings.getPollEndpoint().toURI(), HttpMethod.POST);
            req.execute();
        } finally {
            server.join(10);
        }
    }


    private static class ServerRunnable implements Runnable, AutoCloseable {
        
        private final ServerSocket serverSocket;
        private Exception runException;

        public ServerRunnable() throws Exception {
            InetAddress localhost = InetAddress.getByName("localhost"); 
            serverSocket = ServerSocketFactory.getDefault().createServerSocket(8080, 1, localhost);
        }

        @Override
        public void run() {
            try {
                serverSocket.accept();