WebsterMojo extends AbstractMojo { @Nullable WebsterPlan.FixtureProvider getFixtureProvider() { if (websterOakRunArgs != null && !websterOakRunArgs.trim().isEmpty()) { getLog().info("Using webster.oakRunArgsString to configure NodeStore: " + websterOakRunArgs); return () -> JcrFactory.getNodeStoreFixture(true, CliArgParser.parse(websterOakRunArgs)); } else if (websterRepositoryHome != null && websterRepositoryHome.isDirectory()) { getLog().info("Using webster.repositoryHome to configure NodeStore: " + websterRepositoryHome.getAbsolutePath()); final File segmentStore = new File(websterRepositoryHome, "segmentstore"); if (!(new File(segmentStore, "journal.log")).isFile()) { getLog().info("segmentstore/journal.log file not found in configured webster.repositoryHome."); return null; } return () -> JcrFactory.getReadOnlyFixture(segmentStore); } return null; }  @Override final void execute(); static final String PARAM_REPOSITORY_HOME; static final String PARAM_OAK_RUN_ARGS; static final String PARAM_TMPDIR; }
@Test public void testGetFixtureProvider() throws Exception { WebsterMojo mojo = newMojo(); assertNull("no fixture provider by default", mojo.getFixtureProvider()); }
@Test public void testGetFixtureProvider_withCliArgs() throws Exception { WebsterMojo mojo = newMojo(); mojo.websterOakRunArgs = "memory"; WebsterPlan.FixtureProvider cliProvider = mojo.getFixtureProvider(); assertNotNull("cli fixture provider not null", cliProvider); final CompletableFuture<Boolean> cliPerformed = new CompletableFuture<>(); final WebsterPlan.Builder cliBuilder = new WebsterPlan.Builder(); withMockTarget(cliBuilder, session -> cliPerformed.complete(true)); cliBuilder.withFixtureProvider(cliProvider); cliBuilder.build().perform(); assertTrue("should be performed with cli", cliPerformed.getNow(false)); }
@Test public void testGetFixtureProvider_withHome() throws Exception { final File testOutDir = new File(testOutBaseDir, "testGetFixtureProvider_withHome"); FileUtils.deleteDirectory(testOutDir); testOutDir.mkdirs(); WebsterMojo mojo = newMojo(); mojo.websterOakRunArgs = null; final File repositoryHome = new File(testOutDir, "websterRepositoryHome"); repositoryHome.mkdirs(); mojo.websterRepositoryHome = repositoryHome; MockMojoLog log = logFor(mojo); log.entries.clear(); assertNull("home fixture provider is null without journal.log", mojo.getFixtureProvider()); log.printAll(); assertTrue("log contains correct message", log.any(entry -> entry.message.startsWith("segmentstore/journal.log"))); prepareRepo(new File(repositoryHome, "segmentstore"), session -> { session.getRootNode().addNode("foo"); session.save(); }); WebsterPlan.FixtureProvider homeProvider = mojo.getFixtureProvider(); assertNotNull("home fixture provider not null", homeProvider); final CompletableFuture<Boolean> homePerformed = new CompletableFuture<>(); final WebsterPlan.Builder homeBuilder = new WebsterPlan.Builder(); withMockTarget(homeBuilder, session -> homePerformed.complete(true)); homeBuilder.withFixtureProvider(homeProvider); homeBuilder.build().perform(); assertTrue("should be performed with home", homePerformed.getNow(false)); }