public class PropertyIndexTest {
@Test
public void test() {
MicroKernel mk = new MicroKernelImpl();
Indexer indexer = new Indexer(mk);
indexer.init();
PropertyIndex index = indexer.createPropertyIndex("id", true);
String head = mk.getHeadRevision();
// meta data
String meta = mk.getNodes(Indexer.INDEX_CONFIG_PATH, head, 1, 0, -1, null);
Assert.assertEquals("{\":childNodeCount\":2,\":data\":{\":childNodeCount\":0}," +
"\"property@id,unique\":{\":childNodeCount\":1,\":data\":{}}}", meta);
String oldHead = head;
Assert.assertEquals(null, index.getPath("1", head));
head = mk.commit("/", "+\"test\" : {\"id\":\"1\"}", head, null);
head = mk.commit("/", "+\"test2\" : {\"id\":\"2\"}", head, null);
Assert.assertEquals("/test", index.getPath("1", head));
Assert.assertEquals("/test2", index.getPath("2", head));
Assert.assertEquals("/test", index.getPath("1", oldHead));
Assert.assertEquals("/test2", index.getPath("2", oldHead));
Assert.assertEquals("/test", index.getPath("1", head));
Assert.assertEquals("/test2", index.getPath("2", head));
head = mk.commit("/", "-\"test2\"", head, null);
head = mk.commit("/test", "+\"test\" : {\"id\":\"3\"}", head, null);
Assert.assertEquals("/test/test", index.getPath("3", head));
// Recreate the indexer
indexer = new Indexer(mk);
indexer.init();
index = indexer.createPropertyIndex("id", true);
head = mk.getHeadRevision();
Assert.assertEquals("/test/test", index.getPath("3", head));
Assert.assertEquals(null, index.getPath("0", head));
Assert.assertEquals("/test", index.getPath("1", head));