package com.clxcommunications.xms;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.net.URI;
import java.util.Set;

import org.junit.Test;
import org.junit.runner.RunWith;

import com.pholser.junit.quickcheck.Property;
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;

@RunWith(JUnitQuickcheck.class)
public class BatchFilterTest {

	@Test
	public void canGenerateQueryParameters() throws Exception {
		BatchFilter filter = ClxApi.buildBatchFilter()
		        .pageSize(20)
		        .addFrom("12345", "6789")
		        .addTag("tag1", "таг2")
		        .build();

		String actual = filter.toUrlEncodedQuery(4);
		String expected = "page=4"
		        + "&page_size=20"
		        + "&from=12345%2C6789"
		        + "&tags=tag1%2C%D1%82%D0%B0%D0%B32";

		assertThat(actual, is(expected));
	}

	@Property(trials = 50)
	public void generatesValidQueryParameters(int page, int pageSize,
	        Set<String> from, Set<String> tags) throws Exception {
		BatchFilter filter = ClxApi.buildBatchFilter()
		        .pageSize(pageSize)
		        .from(from)
		        .tags(tags)
		        .build();

		String query = filter.toUrlEncodedQuery(page);

		// Will throw IllegalArgumentException if an invalid URI is attempted.
		URI.create("http://localhost/?" + query);
	}

}

@@ -216,16 +216,50 @@
 RunWith;
+%0Aimport org.threeten.bp.LocalDate;
 %0A%0Aimport
@@ -634,16 +634,112 @@
 %22%D1%82%D0%B0%D0%B32%22)%0A
+%09%09        .startDate(LocalDate.of(2010, 10, 10))%0A%09%09        .endDate(LocalDate.of(2011, 10, 10))%0A
 %09%09      
@@ -855,16 +855,88 @@
 ize=20%22%0A
+%09%09        + %22&start_date=2010-10-10%22%0A%09%09        + %22&end_date=2011-10-10%22%0A
 %09%09      
@@ -1183,16 +1183,65 @@
 ng%3E tags
+, LocalDate startDate,%0A%09        LocalDate endDate
 ) throws
@@ -1354,16 +1354,16 @@
 m(from)%0A
-
 %09%09      
@@ -1376,16 +1376,76 @@
 s(tags)%0A
+%09%09        .startDate(startDate)%0A%09%09        .endDate(endDate)%0A
 %09%09      

Include start and end dates in batch filter test