IndexDefinitionUpdater { public void apply(NodeBuilder rootBuilder) throws IOException, CommitFailedException { for (Map.Entry<String, NodeState> cne : indexNodeStates.entrySet()) { String indexPath = cne.getKey(); apply(rootBuilder, indexPath); } } IndexDefinitionUpdater(File file);  IndexDefinitionUpdater(String json); void apply(NodeBuilder rootBuilder); NodeBuilder apply(NodeBuilder rootBuilder, String indexPath); Set<String> getIndexPaths(); NodeState getIndexState(String indexPath); static final String INDEX_DEFINITIONS_JSON; }
@Test public void applyToIndexPath() throws Exception{ String json = "{\"/oak:index/barIndex\": {\n" + " \"compatVersion\": 2,\n" + " \"type\": \"lucene\",\n" + " \"barIndexProp\": \"barbar\",\n" + " \"async\": \"async\",\n" + " \"jcr:primaryType\": \"oak:QueryIndexDefinition\"\n" + " }}"; NodeBuilder builder = store.getRoot().builder(); builder.child("oak:index"); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); IndexDefinitionUpdater updater = new IndexDefinitionUpdater(json); builder = store.getRoot().builder(); NodeBuilder idxBuilder = updater.apply(builder, "/oak:index/barIndex"); assertTrue(idxBuilder.hasProperty("barIndexProp")); }
@Test public void newIndexAndOrderableChildren() throws Exception{ String json = "{\"/oak:index/barIndex\": {\n" + " \"compatVersion\": 2,\n" + " \"type\": \"lucene\",\n" + " \"barIndexProp\": \"barbar\",\n" + " \"async\": \"async\",\n" + " \"jcr:primaryType\": \"oak:QueryIndexDefinition\"\n" + " }}"; NodeBuilder builder = store.getRoot().builder(); Tree root = TreeFactory.createTree(builder); Tree oakIndex = root.addChild("oak:index"); oakIndex.setOrderableChildren(true); Tree fooIndex = oakIndex.addChild("fooIndex"); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); IndexDefinitionUpdater updater = new IndexDefinitionUpdater(json); builder = store.getRoot().builder(); NodeBuilder idxBuilder = updater.apply(builder, "/oak:index/barIndex"); PropertyState childOrder = builder.getChildNode("oak:index").getProperty(":childOrder"); List<String> names = ImmutableList.copyOf(childOrder.getValue(Type.NAMES)); assertEquals(asList("fooIndex", "barIndex"), names); }