// Path: esjc-axon-eventstore/tests/src/test/java/de/qyotta/axonframework/eventstore/config/AbstractIntegrationTest.java
// @RunWith(SpringJUnit4ClassRunner.class)
// //@formatter:off
// @ContextConfiguration(classes = {
//       TestConfiguration.class,
// }, loader = AnnotationConfigContextLoader.class)
// //@formatter:on
// @SuppressWarnings("nls")
// public abstract class AbstractIntegrationTest {
//    private static final InMemoryEventstoreProvider EVENT_STORE_PROVIDER = new InMemoryEventstoreProvider();
//    protected String myAggregateId;
// 
//    protected final List<Object> actualEvents = new LinkedList<>();
//    private final EventListener EVENT_LISTENER = new EventListener() {
//       @Override
//       public void handle(@SuppressWarnings("rawtypes") final EventMessage event) {
//          actualEvents.add(event.getPayload());
//       }
//    };
// 
//    @BeforeClass
//    public static void beforeClass() {
//       if (!EVENT_STORE_PROVIDER.isRunning()) {
//          EVENT_STORE_PROVIDER.start();
//       }
//    }
// 
//    @AfterClass
//    public static void afterClass() {
//       EVENT_STORE_PROVIDER.stop();
//    }
// 
//    @Autowired
//    protected EventBus eventBus;
//    @Autowired
//    protected com.github.msemys.esjc.EventStore eventStore;
// 
//    @Before
//    public final void initTest() {
//       myAggregateId = UUID.randomUUID()
//             .toString();
//       eventBus.subscribe(EVENT_LISTENER);
//    }
// 
//    protected <T extends AbstractAnnotatedAggregateRoot<?>> void deleteEventStream(final Class<T> classOfT, final String aggregateId) {
//       eventStore.deleteStream(EsjcEventstoreUtil.getStreamName(classOfT.getSimpleName(), aggregateId, "domain"), ExpectedVersion.ANY);
//    }
// 
//    protected <T> void expectEventsMatchingExactlyOnce(final List<T> expectedEvents) {
//       expectEvents(expectedEvents, true);
//    }
// 
//    protected <T> void expectEvents(final List<T> expectedEvents) {
//       expectEvents(expectedEvents, false);
//    }
// 
//    private <T> void expectEvents(final List<T> expectedEvents, final boolean exactlyOnce) {
//       for (final Object expectedEvent : expectedEvents) {
//          final AtomicInteger numberOfEventsMatching = new AtomicInteger(0);
//          actualEvents.forEach(e -> {
//             if (e.equals(expectedEvent)) {
//                numberOfEventsMatching.incrementAndGet();
//             }
//          });
//          if (numberOfEventsMatching.get() == 1) {
//             continue;
//          }
//          if (exactlyOnce && numberOfEventsMatching.get() > 1) {
//             fail("Expected event: " + expectedEvent + "found, but was matched multible times. (It matched " + numberOfEventsMatching.get() + " times.)");
//          }
//          final List<Object> eventsOfType = new LinkedList<>();
//          for (final Object actual : actualEvents) {
//             if (actual.getClass()
//                   .equals(expectedEvent.getClass())) {
//                eventsOfType.add(actual);
//             }
//          }
//          if (eventsOfType.isEmpty()) {
//             fail("Expected an event of type: " + expectedEvent.getClass()
//                   .getName() + " but none was published.");
//          }
//          fail("Expected event: " + expectedEvent + ". Found the following events of the same type but none matched: " + eventsOfType);
//       }
//    }
// }
// 
// Path: esjc-axon-eventstore/tests/src/test/java/de/qyotta/axonframework/eventstore/domain/ChangeTestAggregate.java
// @Value
// public class ChangeTestAggregate {
//    @TargetAggregateIdentifier
//    private String aggregateId;
// }
// 
// Path: esjc-axon-eventstore/tests/src/test/java/de/qyotta/axonframework/eventstore/domain/CreateTestAggregate.java
// @Value
// @Revision("1")
// public class CreateTestAggregate {
//    @TargetAggregateIdentifier
//    private String aggregateId;
// }
// 
// Path: axon-eventstore/tests/src/test/java/de/qyotta/axonframework/eventstore/domain/MyTestAggregate.java
// @NoArgsConstructor
// public class MyTestAggregate extends AbstractAnnotatedAggregateRoot<String> {
//    private static final long serialVersionUID = 1L;
// 
//    @AggregateIdentifier
//    private String aggregateId;
// 
//    @CommandHandler
//    public MyTestAggregate(final CreateTestAggregate command, final MetaData metaData) {
//       this.aggregateId = command.getAggregateId();
//       apply(new TestAggregateCreated(command.getAggregateId()), metaData);
//    }
// 
//    @CommandHandler
//    public void onCommand(final ChangeTestAggregate command, final MetaData metaData) {
//       if (!command.getAggregateId().equals(aggregateId)) {
//          throw new IllegalStateException("Maximum number of events reached ;)"); //$NON-NLS-1$
//       }
//       apply(new TestAggregateChanged(command.getAggregateId()), metaData);
//    }
// 
//    @EventSourcingHandler
//    public void onEvent(final TestAggregateCreated event) {
//       this.aggregateId = event.getAggregateId();
//    }
// 
//    @EventSourcingHandler
//    public void onEvent(@SuppressWarnings("unused") final TestAggregateChanged event) {
//       //
//    }
// }


import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import org.axonframework.commandhandling.CommandExecutionException;
import org.axonframework.commandhandling.GenericCommandMessage;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.github.msemys.esjc.StreamEventsSlice;
import de.qyotta.axonframework.eventstore.config.AbstractIntegrationTest;
import de.qyotta.axonframework.eventstore.domain.ChangeTestAggregate;
import de.qyotta.axonframework.eventstore.domain.CreateTestAggregate;
import de.qyotta.axonframework.eventstore.domain.MyTestAggregate;
package de.qyotta.axonframework.eventstore.test;





@SuppressWarnings("nls")
public class EventStoreIntegrationTest extends AbstractIntegrationTest {

   @Autowired
   private CommandGateway commandGateway;

   @After
   public final void tearDown() {
// Path: esjc-axon-eventstore/tests/src/test/java/de/qyotta/axonframework/eventstore/config/AbstractIntegrationTest.java
// @RunWith(SpringJUnit4ClassRunner.class)
// //@formatter:off
// @ContextConfiguration(classes = {
//       TestConfiguration.class,
// }, loader = AnnotationConfigContextLoader.class)
// //@formatter:on
// @SuppressWarnings("nls")
// public abstract class AbstractIntegrationTest {
//    private static final InMemoryEventstoreProvider EVENT_STORE_PROVIDER = new InMemoryEventstoreProvider();
//    protected String myAggregateId;
// 
//    protected final List<Object> actualEvents = new LinkedList<>();
//    private final EventListener EVENT_LISTENER = new EventListener() {
//       @Override
//       public void handle(@SuppressWarnings("rawtypes") final EventMessage event) {
//          actualEvents.add(event.getPayload());
//       }
//    };
// 
//    @BeforeClass
//    public static void beforeClass() {
//       if (!EVENT_STORE_PROVIDER.isRunning()) {
//          EVENT_STORE_PROVIDER.start();
//       }
//    }
// 
//    @AfterClass
//    public static void afterClass() {
//       EVENT_STORE_PROVIDER.stop();
//    }
// 
//    @Autowired
//    protected EventBus eventBus;
//    @Autowired
//    protected com.github.msemys.esjc.EventStore eventStore;
// 
//    @Before
//    public final void initTest() {
//       myAggregateId = UUID.randomUUID()
//             .toString();
//       eventBus.subscribe(EVENT_LISTENER);
//    }
// 
//    protected <T extends AbstractAnnotatedAggregateRoot<?>> void deleteEventStream(final Class<T> classOfT, final String aggregateId) {
//       eventStore.deleteStream(EsjcEventstoreUtil.getStreamName(classOfT.getSimpleName(), aggregateId, "domain"), ExpectedVersion.ANY);
//    }
// 
//    protected <T> void expectEventsMatchingExactlyOnce(final List<T> expectedEvents) {
//       expectEvents(expectedEvents, true);
//    }
// 
//    protected <T> void expectEvents(final List<T> expectedEvents) {
//       expectEvents(expectedEvents, false);
//    }
// 
//    private <T> void expectEvents(final List<T> expectedEvents, final boolean exactlyOnce) {
//       for (final Object expectedEvent : expectedEvents) {
//          final AtomicInteger numberOfEventsMatching = new AtomicInteger(0);
//          actualEvents.forEach(e -> {
//             if (e.equals(expectedEvent)) {
//                numberOfEventsMatching.incrementAndGet();
//             }
//          });
//          if (numberOfEventsMatching.get() == 1) {
//             continue;
//          }
//          if (exactlyOnce && numberOfEventsMatching.get() > 1) {
//             fail("Expected event: " + expectedEvent + "found, but was matched multible times. (It matched " + numberOfEventsMatching.get() + " times.)");
//          }
//          final List<Object> eventsOfType = new LinkedList<>();
//          for (final Object actual : actualEvents) {
//             if (actual.getClass()
//                   .equals(expectedEvent.getClass())) {
//                eventsOfType.add(actual);
//             }
//          }
//          if (eventsOfType.isEmpty()) {
//             fail("Expected an event of type: " + expectedEvent.getClass()
//                   .getName() + " but none was published.");
//          }
//          fail("Expected event: " + expectedEvent + ". Found the following events of the same type but none matched: " + eventsOfType);
//       }
//    }
// }
// 
// Path: esjc-axon-eventstore/tests/src/test/java/de/qyotta/axonframework/eventstore/domain/ChangeTestAggregate.java
// @Value
// public class ChangeTestAggregate {
//    @TargetAggregateIdentifier
//    private String aggregateId;
// }
// 
// Path: esjc-axon-eventstore/tests/src/test/java/de/qyotta/axonframework/eventstore/domain/CreateTestAggregate.java
// @Value
// @Revision("1")
// public class CreateTestAggregate {
//    @TargetAggregateIdentifier
//    private String aggregateId;
// }
// 
// Path: axon-eventstore/tests/src/test/java/de/qyotta/axonframework/eventstore/domain/MyTestAggregate.java
// @NoArgsConstructor
// public class MyTestAggregate extends AbstractAnnotatedAggregateRoot<String> {
//    private static final long serialVersionUID = 1L;
// 
//    @AggregateIdentifier
//    private String aggregateId;
// 
//    @CommandHandler
//    public MyTestAggregate(final CreateTestAggregate command, final MetaData metaData) {
//       this.aggregateId = command.getAggregateId();
//       apply(new TestAggregateCreated(command.getAggregateId()), metaData);
//    }
// 
//    @CommandHandler
//    public void onCommand(final ChangeTestAggregate command, final MetaData metaData) {
//       if (!command.getAggregateId().equals(aggregateId)) {
//          throw new IllegalStateException("Maximum number of events reached ;)"); //$NON-NLS-1$
//       }
//       apply(new TestAggregateChanged(command.getAggregateId()), metaData);
//    }
// 
//    @EventSourcingHandler
//    public void onEvent(final TestAggregateCreated event) {
//       this.aggregateId = event.getAggregateId();
//    }
// 
//    @EventSourcingHandler
//    public void onEvent(@SuppressWarnings("unused") final TestAggregateChanged event) {
//       //
//    }
// }


// Path: esjc-axon-eventstore/tests/src/test/java/de/qyotta/axonframework/eventstore/test/EventStoreIntegrationTest.java
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import org.axonframework.commandhandling.CommandExecutionException;
import org.axonframework.commandhandling.GenericCommandMessage;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.github.msemys.esjc.StreamEventsSlice;
import de.qyotta.axonframework.eventstore.config.AbstractIntegrationTest;
import de.qyotta.axonframework.eventstore.domain.ChangeTestAggregate;
import de.qyotta.axonframework.eventstore.domain.CreateTestAggregate;
import de.qyotta.axonframework.eventstore.domain.MyTestAggregate;

package de.qyotta.axonframework.eventstore.test;





@SuppressWarnings("nls")
public class EventStoreIntegrationTest extends AbstractIntegrationTest {

   @Autowired
   private CommandGateway commandGateway;

   @After
   public final void tearDown() {
      deleteEventStream(MyTestAggregate.class, myAggregateId);