Add ability to create an in-memory test key chain
diff --git a/src/main/java/com/intel/jndn/mock/MockKeyChain.java b/src/main/java/com/intel/jndn/mock/MockKeyChain.java
new file mode 100644
index 0000000..2ac92cf
--- /dev/null
+++ b/src/main/java/com/intel/jndn/mock/MockKeyChain.java
@@ -0,0 +1,57 @@
+/*
+ * jndn-mock
+ * Copyright (c) 2015, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 3, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
+ * more details.
+ */
+package com.intel.jndn.mock;
+
+import net.named_data.jndn.Name;
+import net.named_data.jndn.security.KeyChain;
+import net.named_data.jndn.security.identity.IdentityManager;
+import net.named_data.jndn.security.identity.IdentityStorage;
+import net.named_data.jndn.security.identity.MemoryIdentityStorage;
+import net.named_data.jndn.security.identity.MemoryPrivateKeyStorage;
+import net.named_data.jndn.security.identity.PrivateKeyStorage;
+import net.named_data.jndn.security.policy.SelfVerifyPolicyManager;
+
+/**
+ *
+ * @author Andrew Brown <andrew.brown@intel.com>
+ */
+public class MockKeyChain {
+
+  /**
+   * Build and configure an in-memory {@link KeyChain}.
+   *
+   * @param name the name of the default identity to create
+   * @return an in-memory {@link KeyChain} configured with the name as the
+   * default identity
+   * @throws net.named_data.jndn.security.SecurityException
+   */
+  public static KeyChain configure(Name name) throws net.named_data.jndn.security.SecurityException {
+    // access key chain in ~/.ndn; create if necessary 
+    PrivateKeyStorage keyStorage = new MemoryPrivateKeyStorage();
+    IdentityStorage identityStorage = new MemoryIdentityStorage();
+    KeyChain keyChain = new KeyChain(new IdentityManager(identityStorage, keyStorage),
+            new SelfVerifyPolicyManager(identityStorage));
+
+    // create keys, certs if necessary
+    if (!identityStorage.doesIdentityExist(name)) {
+      Name keyName = keyChain.createIdentity(name);
+      keyChain.setDefaultKeyForIdentity(keyName, name);
+    }
+
+    // set default identity
+    keyChain.getIdentityManager().setDefaultIdentity(name);
+
+    return keyChain;
+  }
+}
diff --git a/src/test/java/com/intel/jndn/mock/MockKeyChainTest.java b/src/test/java/com/intel/jndn/mock/MockKeyChainTest.java
new file mode 100644
index 0000000..137d1b4
--- /dev/null
+++ b/src/test/java/com/intel/jndn/mock/MockKeyChainTest.java
@@ -0,0 +1,37 @@
+/*
+ * jndn-mock
+ * Copyright (c) 2015, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 3, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
+ * more details.
+ */
+package com.intel.jndn.mock;
+
+import net.named_data.jndn.Name;
+import net.named_data.jndn.security.KeyChain;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Test MockKeyChain
+ * @author Andrew Brown <andrew.brown@intel.com>
+ */
+public class MockKeyChainTest {
+
+  /**
+   * Test of configure method, of class MockKeyChain.
+   */
+  @Test
+  public void testConfigure() throws Exception {
+    String identity = "/test/name";
+    KeyChain keyChain = MockKeyChain.configure(new Name(identity));
+    assertEquals(identity, keyChain.getDefaultIdentity().toUri());
+    assertTrue(keyChain.getDefaultCertificateName().toUri().startsWith(identity));
+  }
+}