// Path: datomic/src/main/java/ske/folkeregister/datomic/util/IO.java
// @SuppressWarnings("unchecked")
// public class IO {
// 
//    public static void transactAllFromFile(Connection conn, String filename) throws InterruptedException, ExecutionException {
//       for (List tx : readData(filename)) {
//          conn.transact(tx).get();
//       }
//    }
// 
//    public static Connection newMemConnection() {
//       String uri = "datomic:mem://" + UUID.randomUUID();
//       Peer.createDatabase(uri);
//       return Peer.connect(uri);
//    }
// 
//    public static Map<String, Object> entityToMap(Entity entity) {
//       return entity
//          .keySet()
//          .stream()
//          .collect(Collectors.toMap(
//             key -> key.substring(key.lastIndexOf("/") + 1),
//             key -> attrToValue(entity, key)
//          ));
//    }
// 
//    public static Object attrToValue(Entity entity, Object key) {
//       Object value = entity.get(key);
//       if (value instanceof Entity) {
//          value = entityToMap((Entity) value);
//       } else if (value instanceof Keyword) {
//          value = ((Keyword) value).getName();
//       }
//       return value;
//    }
// 
//    private static List<List> readData(String filename) {
//       return Util.readAll(new InputStreamReader(
//          Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
//    }
// }


import datomic.Connection;
import org.junit.Before;
import org.junit.Test;
import ske.folkeregister.datomic.util.IO;
import java.util.List;
import java.util.Map;
import static datomic.Util.map;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
      changes.forEach(changeset -> {
         System.out.println("\nTidspunkt: " + changeset.get("timestamp"));
         System.out.println("Endringer:");
         ((List) changeset.get("changes")).forEach(obj -> System.out.println("\t" + obj));
      });
   }

   @Test
   public void testUpdateAndGet() throws Exception {
      final String ssn = "1234";
      final String name = "Test Person";

      assertTrue("Empty map == not found", personApi.getPerson(ssn).isEmpty());

      personApi.updatePerson(map(
         ":person/ssn", ssn,
         ":person/name", name
      ));

      final Map person = personApi.getPerson(ssn);

      assertEquals(ssn, person.get("ssn"));
      assertEquals(name, person.get("name"));

      assertTrue("Person not in all persons", personApi.findAllPersons().contains(person));
   }

   @Before
   public void setUp() throws Exception {
      System.out.print("Creating in-memory Datomic connection...");
// Path: datomic/src/main/java/ske/folkeregister/datomic/util/IO.java
// @SuppressWarnings("unchecked")
// public class IO {
// 
//    public static void transactAllFromFile(Connection conn, String filename) throws InterruptedException, ExecutionException {
//       for (List tx : readData(filename)) {
//          conn.transact(tx).get();
//       }
//    }
// 
//    public static Connection newMemConnection() {
//       String uri = "datomic:mem://" + UUID.randomUUID();
//       Peer.createDatabase(uri);
//       return Peer.connect(uri);
//    }
// 
//    public static Map<String, Object> entityToMap(Entity entity) {
//       return entity
//          .keySet()
//          .stream()
//          .collect(Collectors.toMap(
//             key -> key.substring(key.lastIndexOf("/") + 1),
//             key -> attrToValue(entity, key)
//          ));
//    }
// 
//    public static Object attrToValue(Entity entity, Object key) {
//       Object value = entity.get(key);
//       if (value instanceof Entity) {
//          value = entityToMap((Entity) value);
//       } else if (value instanceof Keyword) {
//          value = ((Keyword) value).getName();
//       }
//       return value;
//    }
// 
//    private static List<List> readData(String filename) {
//       return Util.readAll(new InputStreamReader(
//          Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
//    }
// }


// Path: datomic/src/test/java/ske/folkeregister/datomic/person/DatomicPersonApiTest.java
import datomic.Connection;
import org.junit.Before;
import org.junit.Test;
import ske.folkeregister.datomic.util.IO;
import java.util.List;
import java.util.Map;
import static datomic.Util.map;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;

      changes.forEach(changeset -> {
         System.out.println("\nTidspunkt: " + changeset.get("timestamp"));
         System.out.println("Endringer:");
         ((List) changeset.get("changes")).forEach(obj -> System.out.println("\t" + obj));
      });
   }

   @Test
   public void testUpdateAndGet() throws Exception {
      final String ssn = "1234";
      final String name = "Test Person";

      assertTrue("Empty map == not found", personApi.getPerson(ssn).isEmpty());

      personApi.updatePerson(map(
         ":person/ssn", ssn,
         ":person/name", name
      ));

      final Map person = personApi.getPerson(ssn);

      assertEquals(ssn, person.get("ssn"));
      assertEquals(name, person.get("name"));

      assertTrue("Person not in all persons", personApi.findAllPersons().contains(person));
   }

   @Before
   public void setUp() throws Exception {
      System.out.print("Creating in-memory Datomic connection...");
      Connection conn = IO.newMemConnection();