// Path: myeslib-core/src/main/java/org/myeslib/core/Command.java
// public interface Command extends Serializable {
// 	
//     UUID getCommandId();
// 	Long getTargetVersion();
// 	
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/Event.java
// public interface Event extends Serializable {
// 	
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/data/UnitOfWork.java
// @SuppressWarnings("serial")
// @Value
// public class UnitOfWork implements Comparable<UnitOfWork>, Serializable {
// 
//     final UUID id;
// 	final Command command;
// 	final List<? extends Event> events;
// 	final long version;
// 	
// 	public UnitOfWork(UUID id, Command command, Long version, List<? extends Event> events) {
// 	    checkNotNull(id, "id cannot be null");
// 	    checkNotNull(command, "command cannot be null");
// 		checkArgument(command.getTargetVersion()>=0, "target version must be >= 0");
// 		checkArgument(version>0, "invalid version");
// 		checkNotNull(events, "events cannot be null");
// 		for (Event e: events){
// 			checkNotNull(e, "event within events list cannot be null");
// 		}
// 		this.id = id;
// 		this.command = command;
// 		this.version = version;
// 		this.events = events;
// 	}
// 	
// 	public static UnitOfWork create(UUID id, Command command, List<? extends Event> newEvents) {
// 		checkNotNull(command.getTargetVersion(), "target version cannot be null");
// 		checkArgument(command.getTargetVersion()>=0, "target version must be >= 0");
// 		return new UnitOfWork(id, command, command.getTargetVersion()+1, newEvents);
// 	}
// 	
// 	public List<Event> getEvents(){
// 		List<Event> result = new LinkedList<>();
// 		for (Event event : events) {
// 			result.add(event);
// 		}
// 		return result;
// 	}
// 	
// 	public int compareTo(UnitOfWork other) {
// 		if (version < other.version) {
// 			return -1;
// 		} else if (version > other.version) {
// 			return 1;
// 		}
// 		return 0;
// 	}
// 
// 	public Long getTargetVersion() {
// 		return command.getTargetVersion();
// 	}
// }
// 
// Path: inventory-aggregate-root/src/main/java/org/myeslib/example/SampleDomain.java
// @Value
// public static class IncreaseInventory implements Command {
//     @NonNull
//     UUID commandId;
//     @NonNull
//     UUID id;
//     @NonNull
//     Integer howMany;
//     Long targetVersion;
// }
// 
// Path: inventory-aggregate-root/src/main/java/org/myeslib/example/SampleDomain.java
// @Value
// public static class InventoryIncreased implements Event {
//     @NonNull
//     UUID id;
//     @NonNull
//     Integer howMany;
// }
// 
// Path: myeslib-util/src/main/java/org/myeslib/util/jdbi/UnitOfWorkJournalDao.java
// public interface UnitOfWorkJournalDao<K> {
// 
// 	void append(K id, UnitOfWork uow);
// 	
// }


import static org.mockito.Mockito.verify;
import java.util.Arrays;
import java.util.UUID;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.myeslib.core.Command;
import org.myeslib.core.Event;
import org.myeslib.core.data.UnitOfWork;
import org.myeslib.example.SampleDomain.IncreaseInventory;
import org.myeslib.example.SampleDomain.InventoryIncreased;
import org.myeslib.util.jdbi.UnitOfWorkJournalDao;
package org.myeslib.jdbi.storage;




@RunWith(MockitoJUnitRunner.class) 
public class JdbiUnitOfWorkJournalTest {

	@Mock
    UnitOfWorkJournalDao<UUID> dao;
	
	@Test
	public void insert() {
		
		JdbiUnitOfWorkJournal<UUID> writer = new JdbiUnitOfWorkJournal<>(dao);

	    UUID id = UUID.randomUUID();
		
		Command command1 = new IncreaseInventory(UUID.randomUUID(), id, 2, 0l);
		Event event11 = new InventoryIncreased(id, 1);
		Event event12 = new InventoryIncreased(id, 1);	
		UnitOfWork uow1 = UnitOfWork.create(UUID.randomUUID(), command1, Arrays.asList(event11, event12));

// Path: myeslib-core/src/main/java/org/myeslib/core/Command.java
// public interface Command extends Serializable {
// 	
//     UUID getCommandId();
// 	Long getTargetVersion();
// 	
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/Event.java
// public interface Event extends Serializable {
// 	
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/data/UnitOfWork.java
// @SuppressWarnings("serial")
// @Value
// public class UnitOfWork implements Comparable<UnitOfWork>, Serializable {
// 
//     final UUID id;
// 	final Command command;
// 	final List<? extends Event> events;
// 	final long version;
// 	
// 	public UnitOfWork(UUID id, Command command, Long version, List<? extends Event> events) {
// 	    checkNotNull(id, "id cannot be null");
// 	    checkNotNull(command, "command cannot be null");
// 		checkArgument(command.getTargetVersion()>=0, "target version must be >= 0");
// 		checkArgument(version>0, "invalid version");
// 		checkNotNull(events, "events cannot be null");
// 		for (Event e: events){
// 			checkNotNull(e, "event within events list cannot be null");
// 		}
// 		this.id = id;
// 		this.command = command;
// 		this.version = version;
// 		this.events = events;
// 	}
// 	
// 	public static UnitOfWork create(UUID id, Command command, List<? extends Event> newEvents) {
// 		checkNotNull(command.getTargetVersion(), "target version cannot be null");
// 		checkArgument(command.getTargetVersion()>=0, "target version must be >= 0");
// 		return new UnitOfWork(id, command, command.getTargetVersion()+1, newEvents);
// 	}
// 	
// 	public List<Event> getEvents(){
// 		List<Event> result = new LinkedList<>();
// 		for (Event event : events) {
// 			result.add(event);
// 		}
// 		return result;
// 	}
// 	
// 	public int compareTo(UnitOfWork other) {
// 		if (version < other.version) {
// 			return -1;
// 		} else if (version > other.version) {
// 			return 1;
// 		}
// 		return 0;
// 	}
// 
// 	public Long getTargetVersion() {
// 		return command.getTargetVersion();
// 	}
// }
// 
// Path: inventory-aggregate-root/src/main/java/org/myeslib/example/SampleDomain.java
// @Value
// public static class IncreaseInventory implements Command {
//     @NonNull
//     UUID commandId;
//     @NonNull
//     UUID id;
//     @NonNull
//     Integer howMany;
//     Long targetVersion;
// }
// 
// Path: inventory-aggregate-root/src/main/java/org/myeslib/example/SampleDomain.java
// @Value
// public static class InventoryIncreased implements Event {
//     @NonNull
//     UUID id;
//     @NonNull
//     Integer howMany;
// }
// 
// Path: myeslib-util/src/main/java/org/myeslib/util/jdbi/UnitOfWorkJournalDao.java
// public interface UnitOfWorkJournalDao<K> {
// 
// 	void append(K id, UnitOfWork uow);
// 	
// }


// Path: myeslib-jdbi/src/test/java/org/myeslib/jdbi/storage/JdbiUnitOfWorkJournalTest.java
import static org.mockito.Mockito.verify;
import java.util.Arrays;
import java.util.UUID;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.myeslib.core.Command;
import org.myeslib.core.Event;
import org.myeslib.core.data.UnitOfWork;
import org.myeslib.example.SampleDomain.IncreaseInventory;
import org.myeslib.example.SampleDomain.InventoryIncreased;
import org.myeslib.util.jdbi.UnitOfWorkJournalDao;

package org.myeslib.jdbi.storage;




@RunWith(MockitoJUnitRunner.class) 
public class JdbiUnitOfWorkJournalTest {

	@Mock
    UnitOfWorkJournalDao<UUID> dao;
	
	@Test
	public void insert() {
		
		JdbiUnitOfWorkJournal<UUID> writer = new JdbiUnitOfWorkJournal<>(dao);

	    UUID id = UUID.randomUUID();
		
		Command command1 = new IncreaseInventory(UUID.randomUUID(), id, 2, 0l);
		Event event11 = new InventoryIncreased(id, 1);
		Event event12 = new InventoryIncreased(id, 1);	
		UnitOfWork uow1 = UnitOfWork.create(UUID.randomUUID(), command1, Arrays.asList(event11, event12));

		writer.append(id, uow1);