// Path: src/test/java/com/cisco/cta/taxii/adapter/PollFulfillmentMatcher.java
// public static PollFulfillmentMatcher pollFulfillment(String messageId, String collection, String resultId, String resultPartNumber) {
//     return new PollFulfillmentMatcher(messageId, collection, resultId, resultPartNumber);
// }
// 
// Path: src/test/java/com/cisco/cta/taxii/adapter/PollRequestMatcher.java
// public static PollRequestMatcher initialPollRequest(String messageId, String collection) {
//     return new PollRequestMatcher(messageId, collection, null);
// }
// 
// Path: src/test/java/com/cisco/cta/taxii/adapter/httpclient/HasHeaderMatcher.java
// public static Matcher<HttpHeaders> hasAllTaxiiHeaders() {
//     return allOf(
//         hasHeader("Content-Type", is("application/xml")),
//         hasHeader("Accept", is("application/xml")),
//         hasHeader("X-Taxii-Accept", is("urn:taxii.mitre.org:message:xml:1.1")),
//         hasHeader("X-TAXII-Content-Type", is("urn:taxii.mitre.org:message:xml:1.1")),
//         hasHeader("X-Taxii-Protocol", is("urn:taxii.mitre.org:protocol:https:1.0")),
//         hasHeader("X-TAXII-Services", is("urn:taxii.mitre.org:services:1.1"))
//     );
// }


import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import static com.cisco.cta.taxii.adapter.PollFulfillmentMatcher.pollFulfillment;
import static com.cisco.cta.taxii.adapter.PollRequestMatcher.initialPollRequest;
import static com.cisco.cta.taxii.adapter.httpclient.HasHeaderMatcher.hasAllTaxiiHeaders;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
        configurator.doConfigure("src/test/resources/logback-test.xml");
    }

    @After
    public void tearDown() throws Exception {
        taxiiPollRespBodyInitial.close();
        taxiiPollRespBodyNext.close();
    }

    @Test
    public void runFromEpochBegin() throws Exception {
        initialMultipartRequestResponse();
        assertThat(statistics.getPolls(), is(2L));
        assertThat(statistics.getLogs(), is(2L));
        assertThat(statistics.getErrors(), is(0L));
        assertThat(OUTPUT_FILE + " content expected same as " + EXPECTED_OUTPUT_FILE,
                FileUtils.readFileToString(OUTPUT_FILE), is(FileUtils.readFileToString(EXPECTED_OUTPUT_FILE)));
    }

    private void initialMultipartRequestResponse() throws IOException {
        when(httpResp.getRawStatusCode()).thenReturn(200);
        when(httpResp.getBody()).thenReturn(taxiiPollRespBodyInitial);
        when(httpResp2.getRawStatusCode()).thenReturn(200);
        when(httpResp2.getBody()).thenReturn(taxiiPollRespBodyNext);
        task.run();
        verify(httpRequestFactory, times(2)).createRequest(pollServiceUri, HttpMethod.POST);
        assertThat(httpReqHeaders, hasAllTaxiiHeaders());
        verify(httpReq).execute();
        verify(httpReq2).execute();
        assertThat(httpReqBody, is(initialPollRequest("123", "collection_name")));
// Path: src/test/java/com/cisco/cta/taxii/adapter/PollFulfillmentMatcher.java
// public static PollFulfillmentMatcher pollFulfillment(String messageId, String collection, String resultId, String resultPartNumber) {
//     return new PollFulfillmentMatcher(messageId, collection, resultId, resultPartNumber);
// }
// 
// Path: src/test/java/com/cisco/cta/taxii/adapter/PollRequestMatcher.java
// public static PollRequestMatcher initialPollRequest(String messageId, String collection) {
//     return new PollRequestMatcher(messageId, collection, null);
// }
// 
// Path: src/test/java/com/cisco/cta/taxii/adapter/httpclient/HasHeaderMatcher.java
// public static Matcher<HttpHeaders> hasAllTaxiiHeaders() {
//     return allOf(
//         hasHeader("Content-Type", is("application/xml")),
//         hasHeader("Accept", is("application/xml")),
//         hasHeader("X-Taxii-Accept", is("urn:taxii.mitre.org:message:xml:1.1")),
//         hasHeader("X-TAXII-Content-Type", is("urn:taxii.mitre.org:message:xml:1.1")),
//         hasHeader("X-Taxii-Protocol", is("urn:taxii.mitre.org:protocol:https:1.0")),
//         hasHeader("X-TAXII-Services", is("urn:taxii.mitre.org:services:1.1"))
//     );
// }


// Path: src/test/java/com/cisco/cta/taxii/adapter/AdapterTaskMultipartIT.java
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import static com.cisco.cta.taxii.adapter.PollFulfillmentMatcher.pollFulfillment;
import static com.cisco.cta.taxii.adapter.PollRequestMatcher.initialPollRequest;
import static com.cisco.cta.taxii.adapter.httpclient.HasHeaderMatcher.hasAllTaxiiHeaders;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

        configurator.doConfigure("src/test/resources/logback-test.xml");
    }

    @After
    public void tearDown() throws Exception {
        taxiiPollRespBodyInitial.close();
        taxiiPollRespBodyNext.close();
    }

    @Test
    public void runFromEpochBegin() throws Exception {
        initialMultipartRequestResponse();
        assertThat(statistics.getPolls(), is(2L));
        assertThat(statistics.getLogs(), is(2L));
        assertThat(statistics.getErrors(), is(0L));
        assertThat(OUTPUT_FILE + " content expected same as " + EXPECTED_OUTPUT_FILE,
                FileUtils.readFileToString(OUTPUT_FILE), is(FileUtils.readFileToString(EXPECTED_OUTPUT_FILE)));
    }

    private void initialMultipartRequestResponse() throws IOException {
        when(httpResp.getRawStatusCode()).thenReturn(200);
        when(httpResp.getBody()).thenReturn(taxiiPollRespBodyInitial);
        when(httpResp2.getRawStatusCode()).thenReturn(200);
        when(httpResp2.getBody()).thenReturn(taxiiPollRespBodyNext);
        task.run();
        verify(httpRequestFactory, times(2)).createRequest(pollServiceUri, HttpMethod.POST);
        assertThat(httpReqHeaders, hasAllTaxiiHeaders());
        verify(httpReq).execute();
        verify(httpReq2).execute();
        assertThat(httpReqBody, is(initialPollRequest("123", "collection_name")));
        assertThat(httpReq2Body, is(pollFulfillment("123", "collection_name", "1000#2000", "2")));