JcrFactory { public static Repository getJcr(final NodeStoreFixture nodeStoreFixture) throws IOException, CommitFailedException { return getJcr(nodeStoreFixture, new MemoryNodeStore()); } private  JcrFactory(); static Repository getJcr(final NodeStoreFixture nodeStoreFixture); static Repository getJcr(final NodeStoreFixture nodeStoreFixture,
                                    final NodeStore globalStore); static NodeStoreFixture getNodeStoreFixture(final boolean readOnly, final String... args); static NodeStoreFixture getNodeStoreFixture(final boolean readOnly, final File segmentStore, final String... args); static NodeStoreFixture getReadOnlyFixture(final File segmentStore, final String... args); static NodeStoreFixture getReadWriteFixture(final File segmentStore, final String... args);  }
@Test public void testGetJcr() throws Exception { final File seedDir = new File(testBaseDir, "testGetJcr/seedRepo/segmentstore"); final File globalDir = new File(testBaseDir, "testGetJcr/globalRepo/segmentstore"); final String superPath = "/apps/myapp/components/sup1"; final String resultPath = "/apps/myapp/components/res1"; TestUtil.prepareRepo(seedDir, session -> { final URL slingNodetypes = getClass().getResource("/sling_nodetypes.cnd"); TestUtil.installCndFromURL(session, slingNodetypes); Node sup1 = JcrUtils.getOrCreateByPath(superPath, "sling:Folder", session); Node res1 = JcrUtils.getOrCreateByPath(resultPath, "sling:Folder", session); res1.addMixin("sling:ResourceSuperType"); res1.setProperty("sling:resourceSuperType", superPath); session.save(); }); TestUtil.withReadOnlyFixture(seedDir, session -> { QueryManager qm = session.getWorkspace().getQueryManager(); final String stmt = "select * from [sling:ResourceSuperType] as a OPTION(TRAVERSAL FAIL, INDEX NAME nodetype)"; final Query query = qm.createQuery(stmt, Query.JCR_SQL2); QueryResult result = query.execute(); final NodeIterator it = result.getNodes(); assertTrue("Result hasNext()", it.hasNext()); final Node next = it.nextNode(); assertFalse("Result has no more", it.hasNext()); assertEquals("Path is correct", resultPath, next.getPath()); assertEquals("sling:resourceSuperType value is correct", superPath, next.getProperty("sling:resourceSuperType").getString()); }); }