// Path: src/test/java/com/rhcloud/analytics4github/TestApplicationContext.java
// @SpringBootApplication
// public class TestApplicationContext {
// 
//     public static void main(String[] args) {
//         SpringApplication.run(Application.class, args);
//     }
// 
// }
// 
// Path: src/main/java/com/rhcloud/analytics4github/domain/RequestToAPI.java
// @Document
// public class RequestToAPI {
//     private final String repository;
//     private final String requestTime;
//     private final String endpoint;
//     @Id
//     private String id;
// 
//     public RequestToAPI(String repository, String endpoint) {
//         this.repository = repository;
//         this.endpoint = endpoint;
//         this.requestTime = Instant.now().truncatedTo(ChronoUnit.SECONDS).toString();
//     }
// 
//     public String getRequestTime() {
//         return requestTime;
//     }
// 
//     public String getEndpoint() {
//         return endpoint;
//     }
// 
//     public String getRepository() {
//         return repository;
//     }
// 
//     @Override
//     public String toString() {
//         final StringBuilder sb = new StringBuilder("RequestToAPI{");
//         sb.append("id='").append(id).append('\'');
//         sb.append(", repository='").append(repository).append('\'');
//         sb.append(", requestTime='").append(requestTime).append('\'');
//         sb.append(", endpoint='").append(endpoint).append('\'');
//         sb.append('}');
//         return sb.toString();
//     }
// }
// 
// Path: src/main/java/com/rhcloud/analytics4github/repository/RequestToApiRepository.java
// public interface RequestToApiRepository extends MongoRepository<RequestToAPI, String> {
//     List<RequestToAPI> findByRepository(String repository);
// }


import com.rhcloud.analytics4github.TestApplicationContext;
import com.rhcloud.analytics4github.domain.RequestToAPI;
import com.rhcloud.analytics4github.repository.RequestToApiRepository;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
    public void testStargazersPersisting() throws IOException, ServletException {
        when(httpServletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/stargazersPerMonth"));
        Filter filter = filtersConfiguration.requestsStatisticAggregatorFilter();
        filter.doFilter(httpServletRequest, httpServletResponse, filterChain);
        //    verify(httpServletRequest, atLeastOnce());
        RequestToAPI requestToAPI = this.repository.findByRepository(PROJECT_NAME).get(0);
        assertEquals(requestToAPI.getRepository(), PROJECT_NAME);
        //handcraft rollback
        this.repository.delete(requestToAPI);
    }

    @Test
    public void testUniqueContributorsPersisting() throws IOException, ServletException {
        when(httpServletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/uniqueContributors"));
        Filter filter = filtersConfiguration.requestsStatisticAggregatorFilter();
        filter.doFilter(httpServletRequest, httpServletResponse, filterChain);
        //  verify(httpServletRequest, atLeastOnce());
        RequestToAPI requestToAPI = this.repository.findByRepository(PROJECT_NAME).get(0);
        assertEquals(requestToAPI.getRepository(), PROJECT_NAME);
        //handcraft rollback
        this.repository.delete(requestToAPI);
    }

    @Test
    public void testCreateNewCoockies() throws IOException, ServletException {
        MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
        MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
        mockHttpServletRequest.setRequestURI("http://localhost:8080/uniqueContributors");
        assertNull("We expect no cookies", mockHttpServletResponse.getCookie(FiltersConfiguration.FREE_REQUESTS_COOKIE_NAME));
        Filter filter = filtersConfiguration.userRequestsLimitationFilter();
// Path: src/test/java/com/rhcloud/analytics4github/TestApplicationContext.java
// @SpringBootApplication
// public class TestApplicationContext {
// 
//     public static void main(String[] args) {
//         SpringApplication.run(Application.class, args);
//     }
// 
// }
// 
// Path: src/main/java/com/rhcloud/analytics4github/domain/RequestToAPI.java
// @Document
// public class RequestToAPI {
//     private final String repository;
//     private final String requestTime;
//     private final String endpoint;
//     @Id
//     private String id;
// 
//     public RequestToAPI(String repository, String endpoint) {
//         this.repository = repository;
//         this.endpoint = endpoint;
//         this.requestTime = Instant.now().truncatedTo(ChronoUnit.SECONDS).toString();
//     }
// 
//     public String getRequestTime() {
//         return requestTime;
//     }
// 
//     public String getEndpoint() {
//         return endpoint;
//     }
// 
//     public String getRepository() {
//         return repository;
//     }
// 
//     @Override
//     public String toString() {
//         final StringBuilder sb = new StringBuilder("RequestToAPI{");
//         sb.append("id='").append(id).append('\'');
//         sb.append(", repository='").append(repository).append('\'');
//         sb.append(", requestTime='").append(requestTime).append('\'');
//         sb.append(", endpoint='").append(endpoint).append('\'');
//         sb.append('}');
//         return sb.toString();
//     }
// }
// 
// Path: src/main/java/com/rhcloud/analytics4github/repository/RequestToApiRepository.java
// public interface RequestToApiRepository extends MongoRepository<RequestToAPI, String> {
//     List<RequestToAPI> findByRepository(String repository);
// }


// Path: src/test/java/com/rhcloud/analytics4github/config/FiltersConfigurationTest.java
import com.rhcloud.analytics4github.TestApplicationContext;
import com.rhcloud.analytics4github.domain.RequestToAPI;
import com.rhcloud.analytics4github.repository.RequestToApiRepository;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

    public void testStargazersPersisting() throws IOException, ServletException {
        when(httpServletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/stargazersPerMonth"));
        Filter filter = filtersConfiguration.requestsStatisticAggregatorFilter();
        filter.doFilter(httpServletRequest, httpServletResponse, filterChain);
        //    verify(httpServletRequest, atLeastOnce());
        RequestToAPI requestToAPI = this.repository.findByRepository(PROJECT_NAME).get(0);
        assertEquals(requestToAPI.getRepository(), PROJECT_NAME);
        //handcraft rollback
        this.repository.delete(requestToAPI);
    }

    @Test
    public void testUniqueContributorsPersisting() throws IOException, ServletException {
        when(httpServletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/uniqueContributors"));
        Filter filter = filtersConfiguration.requestsStatisticAggregatorFilter();
        filter.doFilter(httpServletRequest, httpServletResponse, filterChain);
        //  verify(httpServletRequest, atLeastOnce());
        RequestToAPI requestToAPI = this.repository.findByRepository(PROJECT_NAME).get(0);
        assertEquals(requestToAPI.getRepository(), PROJECT_NAME);
        //handcraft rollback
        this.repository.delete(requestToAPI);
    }

    @Test
    public void testCreateNewCoockies() throws IOException, ServletException {
        MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
        MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
        mockHttpServletRequest.setRequestURI("http://localhost:8080/uniqueContributors");
        assertNull("We expect no cookies", mockHttpServletResponse.getCookie(FiltersConfiguration.FREE_REQUESTS_COOKIE_NAME));
        Filter filter = filtersConfiguration.userRequestsLimitationFilter();
        filter.doFilter(mockHttpServletRequest, mockHttpServletResponse, filterChain);