// Path: src/test/java/org/jboss/elasticsearch/river/jira/testtools/ProjectInfoMatcher.java
// public class ProjectInfoMatcher extends BaseMatcher<ProjectIndexingInfo> {
// 
//   String project;
//   boolean fullUpdate;
//   boolean finishedOK;
//   int issuesUpdated;
//   int issuesDeleted;
//   String errorMessage;
// 
//   /**
//    * @param project
//    * @param fullUpdate
//    * @param finishedOK
//    * @param issuesUpdated
//    * @param issuesDeleted
//    * @param errorMessage
//    */
//   public ProjectInfoMatcher(String project, boolean fullUpdate, boolean finishedOK, int issuesUpdated,
//       int issuesDeleted, String errorMessage) {
//     super();
//     this.project = project;
//     this.fullUpdate = fullUpdate;
//     this.finishedOK = finishedOK;
//     this.issuesUpdated = issuesUpdated;
//     this.issuesDeleted = issuesDeleted;
//     this.errorMessage = errorMessage;
//   }
// 
//   @Override
//   public boolean matches(Object arg0) {
//     ProjectIndexingInfo info = (ProjectIndexingInfo) arg0;
//     Assert.assertEquals(project, info.projectKey);
//     Assert.assertEquals(fullUpdate, info.fullUpdate);
//     Assert.assertEquals(finishedOK, info.finishedOK);
//     Assert.assertEquals(issuesUpdated, info.issuesUpdated);
//     Assert.assertEquals(issuesDeleted, info.issuesDeleted);
//     Assert.assertEquals(errorMessage, info.errorMessage);
//     Assert.assertNotNull(info.startDate);
//     return true;
//   }
// 
//   @Override
//   public void describeTo(Description arg0) {
//   }
// 
// }


import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.joda.time.format.ISODateTimeFormat;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.text.StringText;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.internal.InternalSearchHit;
import org.elasticsearch.search.internal.InternalSearchHits;
import org.elasticsearch.search.internal.InternalSearchResponse;
import org.jboss.elasticsearch.river.jira.testtools.ProjectInfoMatcher;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
	public void run() throws Exception {
		IJIRAClient jiraClientMock = mock(IJIRAClient.class);
		IESIntegration esIntegrationMock = mockEsIntegrationComponent();
		IJIRAIssueIndexStructureBuilder jiraIssueIndexStructureBuilderMock = mock(IJIRAIssueIndexStructureBuilder.class);
		JIRAProjectIndexer tested = new JIRAProjectIndexer("ORG", false, jiraClientMock, esIntegrationMock,
				jiraIssueIndexStructureBuilderMock);

		List<Map<String, Object>> issues = new ArrayList<Map<String, Object>>();
		Date lastUpdatedDate = DateTimeUtils.parseISODateTime("2012-08-14T07:00:00.000-0400");

		addIssueMock(issues, "ORG-45", "2012-08-14T08:00:00.000-0400");
		addIssueMock(issues, "ORG-46", "2012-08-14T08:00:10.000-0400");
		addIssueMock(issues, "ORG-47", "2012-08-14T08:00:20.000-0400");

		Client client = Mockito.mock(Client.class);
		BulkRequestBuilder brb = new BulkRequestBuilder(client);
		SearchRequestBuilder srb = new SearchRequestBuilder(client);

		// test case with indexing finished OK
		{
			when(
					esIntegrationMock.readDatetimeValue("ORG",
							JIRAProjectIndexer.STORE_PROPERTYNAME_LAST_INDEXED_ISSUE_UPDATE_DATE)).thenReturn(lastUpdatedDate);
			when(jiraClientMock.getJIRAChangedIssues("ORG", 0, lastUpdatedDate, null)).thenReturn(
					new ChangedIssuesResults(issues, 0, 50, 3));
			when(esIntegrationMock.prepareESBulkRequestBuilder()).thenReturn(brb);
			configureStructureBuilderMockDefaults(jiraIssueIndexStructureBuilderMock);

			tested.run();
			verify(esIntegrationMock, times(1)).reportIndexingFinished(
// Path: src/test/java/org/jboss/elasticsearch/river/jira/testtools/ProjectInfoMatcher.java
// public class ProjectInfoMatcher extends BaseMatcher<ProjectIndexingInfo> {
// 
//   String project;
//   boolean fullUpdate;
//   boolean finishedOK;
//   int issuesUpdated;
//   int issuesDeleted;
//   String errorMessage;
// 
//   /**
//    * @param project
//    * @param fullUpdate
//    * @param finishedOK
//    * @param issuesUpdated
//    * @param issuesDeleted
//    * @param errorMessage
//    */
//   public ProjectInfoMatcher(String project, boolean fullUpdate, boolean finishedOK, int issuesUpdated,
//       int issuesDeleted, String errorMessage) {
//     super();
//     this.project = project;
//     this.fullUpdate = fullUpdate;
//     this.finishedOK = finishedOK;
//     this.issuesUpdated = issuesUpdated;
//     this.issuesDeleted = issuesDeleted;
//     this.errorMessage = errorMessage;
//   }
// 
//   @Override
//   public boolean matches(Object arg0) {
//     ProjectIndexingInfo info = (ProjectIndexingInfo) arg0;
//     Assert.assertEquals(project, info.projectKey);
//     Assert.assertEquals(fullUpdate, info.fullUpdate);
//     Assert.assertEquals(finishedOK, info.finishedOK);
//     Assert.assertEquals(issuesUpdated, info.issuesUpdated);
//     Assert.assertEquals(issuesDeleted, info.issuesDeleted);
//     Assert.assertEquals(errorMessage, info.errorMessage);
//     Assert.assertNotNull(info.startDate);
//     return true;
//   }
// 
//   @Override
//   public void describeTo(Description arg0) {
//   }
// 
// }


// Path: src/test/java/org/jboss/elasticsearch/river/jira/JIRAProjectIndexerTest.java
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.joda.time.format.ISODateTimeFormat;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.text.StringText;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.internal.InternalSearchHit;
import org.elasticsearch.search.internal.InternalSearchHits;
import org.elasticsearch.search.internal.InternalSearchResponse;
import org.jboss.elasticsearch.river.jira.testtools.ProjectInfoMatcher;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

	public void run() throws Exception {
		IJIRAClient jiraClientMock = mock(IJIRAClient.class);
		IESIntegration esIntegrationMock = mockEsIntegrationComponent();
		IJIRAIssueIndexStructureBuilder jiraIssueIndexStructureBuilderMock = mock(IJIRAIssueIndexStructureBuilder.class);
		JIRAProjectIndexer tested = new JIRAProjectIndexer("ORG", false, jiraClientMock, esIntegrationMock,
				jiraIssueIndexStructureBuilderMock);

		List<Map<String, Object>> issues = new ArrayList<Map<String, Object>>();
		Date lastUpdatedDate = DateTimeUtils.parseISODateTime("2012-08-14T07:00:00.000-0400");

		addIssueMock(issues, "ORG-45", "2012-08-14T08:00:00.000-0400");
		addIssueMock(issues, "ORG-46", "2012-08-14T08:00:10.000-0400");
		addIssueMock(issues, "ORG-47", "2012-08-14T08:00:20.000-0400");

		Client client = Mockito.mock(Client.class);
		BulkRequestBuilder brb = new BulkRequestBuilder(client);
		SearchRequestBuilder srb = new SearchRequestBuilder(client);

		// test case with indexing finished OK
		{
			when(
					esIntegrationMock.readDatetimeValue("ORG",
							JIRAProjectIndexer.STORE_PROPERTYNAME_LAST_INDEXED_ISSUE_UPDATE_DATE)).thenReturn(lastUpdatedDate);
			when(jiraClientMock.getJIRAChangedIssues("ORG", 0, lastUpdatedDate, null)).thenReturn(
					new ChangedIssuesResults(issues, 0, 50, 3));
			when(esIntegrationMock.prepareESBulkRequestBuilder()).thenReturn(brb);
			configureStructureBuilderMockDefaults(jiraIssueIndexStructureBuilderMock);

			tested.run();
			verify(esIntegrationMock, times(1)).reportIndexingFinished(
					Mockito.argThat(new ProjectInfoMatcher("ORG", false, true, 3, 0, null)));