// Path: eventstore-client/src/main/java/de/qyotta/eventstore/communication/EsContextDefaultImpl.java
// public class EsContextDefaultImpl implements ESContext {
// 
//    private final CloseableHttpClient httpclient;
//    private final ESReader reader;
//    private final EventStoreSettings settings;
//    private final ESWriter writer;
// 
//    public EsContextDefaultImpl(final EventStoreSettings settings) {
//       this.settings = settings;
//       httpclient = HttpClientFactory.httpClient(settings);
// 
//       reader = new EsReaderDefaultImpl(httpclient);
//       writer = new EsWriterDefaultImpl(httpclient);
//    }
// 
//    @Override
//    public ESReader getReader() {
//       return reader;
//    }
// 
//    @Override
//    public EventStoreSettings getSettings() {
//       return settings;
//    }
// 
//    @Override
//    public ESWriter getWriter() {
//       return writer;
//    }
// 
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/model/Event.java
// @Getter
// @Setter
// @Builder(toBuilder = true)
// @ToString
// @EqualsAndHashCode
// @NoArgsConstructor(access = AccessLevel.PUBLIC)
// @AllArgsConstructor(access = AccessLevel.PUBLIC)
// public class Event {
//    private String eventId;
//    private String eventType;
//    private Long eventNumber;
//    private String streamId;
//    private Boolean isLinkMetaData;
//    private Long positionEventNumber;
//    private String positionStreamId;
//    private String title;
//    private String id;
//    private String updated;
//    private Author author;
//    private String summary;
// 
//    private String eventStreamId;
//    private String data;
//    private String metadata;
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/model/EventResponse.java
// @Getter
// @Setter
// @Builder(toBuilder = true)
// @ToString
// @EqualsAndHashCode
// @NoArgsConstructor(access = AccessLevel.PUBLIC)
// @AllArgsConstructor(access = AccessLevel.PUBLIC)
// public class EventResponse {
//    private String title;
//    private String id;
//    private String updated;
//    private Author author;
//    private String summary;
// 
//    private Event content;
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/EsUtils.java
// @UtilityClass
// @SuppressWarnings("nls")
// public class EsUtils {
//    private static final String SEQUENCE_NUMBER_TITLE_SEPERATOR = "@";
// 
//    public static long getEventNumber(final Entry entry) {
//       final String title = entry.getTitle();
//       final String subsequenceNumber = title.substring(0, title.indexOf(SEQUENCE_NUMBER_TITLE_SEPERATOR));
//       return Long.valueOf(subsequenceNumber);
//    }
// 
//    public static Date timestampOf(final Entry entry) {
//       return Date.from(Instant.parse(entry.getUpdated()));
//    }
// 
//    public static Date timestampOf(final EventResponse entry) {
//       return Date.from(Instant.parse(entry.getUpdated()));
//    }
// 
// }


import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import java.time.Instant;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;
import org.exparity.hamcrest.date.DateMatchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.google.gson.Gson;
import de.qyotta.eventstore.communication.EsContextDefaultImpl;
import de.qyotta.eventstore.model.Event;
import de.qyotta.eventstore.model.EventResponse;
import de.qyotta.eventstore.utils.EsUtils;
   public void shouldSetAfterTheGivenTime() throws InterruptedException {
      numberOfStoredEvents = 100;
      createEvents(numberOfStoredEvents);

      final EventStream eventStream = client.readEvents(streamName);
      // got to event 49
      for (int i = 0; i < 50; i++) {
         eventStream.next();
      }
      // take timestamp of event nr. 50
      final EventResponse next = eventStream.next();
      final Date fromDate = EsUtils.timestampOf(next);
      // now create a new stream
      final EventStream eventStream2 = client.readEvents(streamName);
      eventStream2.setAfterTimestamp(fromDate);

      final EventResponse eventNr51 = eventStream2.next();
      assertThat(EsUtils.timestampOf(eventNr51), is(DateMatchers.after(fromDate)));
      assertThat(eventNr51.getContent()
            .getEventNumber(), is(51L));
   }

   @Test
   public void shouldSetAfterTheGivenEventId() throws InterruptedException {
      numberOfStoredEvents = 100;
      createEvents(numberOfStoredEvents);

      for (int i = 0; i < 99; i++) {
         shouldSetTo(i);
      }
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/communication/EsContextDefaultImpl.java
// public class EsContextDefaultImpl implements ESContext {
// 
//    private final CloseableHttpClient httpclient;
//    private final ESReader reader;
//    private final EventStoreSettings settings;
//    private final ESWriter writer;
// 
//    public EsContextDefaultImpl(final EventStoreSettings settings) {
//       this.settings = settings;
//       httpclient = HttpClientFactory.httpClient(settings);
// 
//       reader = new EsReaderDefaultImpl(httpclient);
//       writer = new EsWriterDefaultImpl(httpclient);
//    }
// 
//    @Override
//    public ESReader getReader() {
//       return reader;
//    }
// 
//    @Override
//    public EventStoreSettings getSettings() {
//       return settings;
//    }
// 
//    @Override
//    public ESWriter getWriter() {
//       return writer;
//    }
// 
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/model/Event.java
// @Getter
// @Setter
// @Builder(toBuilder = true)
// @ToString
// @EqualsAndHashCode
// @NoArgsConstructor(access = AccessLevel.PUBLIC)
// @AllArgsConstructor(access = AccessLevel.PUBLIC)
// public class Event {
//    private String eventId;
//    private String eventType;
//    private Long eventNumber;
//    private String streamId;
//    private Boolean isLinkMetaData;
//    private Long positionEventNumber;
//    private String positionStreamId;
//    private String title;
//    private String id;
//    private String updated;
//    private Author author;
//    private String summary;
// 
//    private String eventStreamId;
//    private String data;
//    private String metadata;
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/model/EventResponse.java
// @Getter
// @Setter
// @Builder(toBuilder = true)
// @ToString
// @EqualsAndHashCode
// @NoArgsConstructor(access = AccessLevel.PUBLIC)
// @AllArgsConstructor(access = AccessLevel.PUBLIC)
// public class EventResponse {
//    private String title;
//    private String id;
//    private String updated;
//    private Author author;
//    private String summary;
// 
//    private Event content;
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/EsUtils.java
// @UtilityClass
// @SuppressWarnings("nls")
// public class EsUtils {
//    private static final String SEQUENCE_NUMBER_TITLE_SEPERATOR = "@";
// 
//    public static long getEventNumber(final Entry entry) {
//       final String title = entry.getTitle();
//       final String subsequenceNumber = title.substring(0, title.indexOf(SEQUENCE_NUMBER_TITLE_SEPERATOR));
//       return Long.valueOf(subsequenceNumber);
//    }
// 
//    public static Date timestampOf(final Entry entry) {
//       return Date.from(Instant.parse(entry.getUpdated()));
//    }
// 
//    public static Date timestampOf(final EventResponse entry) {
//       return Date.from(Instant.parse(entry.getUpdated()));
//    }
// 
// }


// Path: eventstore-client/src/test/java/de/qyotta/eventstore/EventStreamTest.java
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import java.time.Instant;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;
import org.exparity.hamcrest.date.DateMatchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.google.gson.Gson;
import de.qyotta.eventstore.communication.EsContextDefaultImpl;
import de.qyotta.eventstore.model.Event;
import de.qyotta.eventstore.model.EventResponse;
import de.qyotta.eventstore.utils.EsUtils;

   public void shouldSetAfterTheGivenTime() throws InterruptedException {
      numberOfStoredEvents = 100;
      createEvents(numberOfStoredEvents);

      final EventStream eventStream = client.readEvents(streamName);
      // got to event 49
      for (int i = 0; i < 50; i++) {
         eventStream.next();
      }
      // take timestamp of event nr. 50
      final EventResponse next = eventStream.next();
      final Date fromDate = EsUtils.timestampOf(next);
      // now create a new stream
      final EventStream eventStream2 = client.readEvents(streamName);
      eventStream2.setAfterTimestamp(fromDate);

      final EventResponse eventNr51 = eventStream2.next();
      assertThat(EsUtils.timestampOf(eventNr51), is(DateMatchers.after(fromDate)));
      assertThat(eventNr51.getContent()
            .getEventNumber(), is(51L));
   }

   @Test
   public void shouldSetAfterTheGivenEventId() throws InterruptedException {
      numberOfStoredEvents = 100;
      createEvents(numberOfStoredEvents);

      for (int i = 0; i < 99; i++) {
         shouldSetTo(i);
      }
      final EventStream eventStream = setTo(99);