@Override public void execute(InstallContext installContext) throws TaskExecutionException { if (SystemProperty.getBooleanProperty(SystemProperty.MAGNOLIA_BOOTSTRAP_SAMPLES)) { new BootstrapConditionally("Bootstrap templater role", "", "/mgnl-bootstrap-samples/inplace-templating/userroles.templater.xml").execute(installContext); User tim = Security.getUserManager().getUser("tim"); // check is the sample user with no modifications if (tim.getAllRoles().size() == 0 && tim.getAllGroups().size() == 0) { // overwrite tim as addRole does not work because tim has a reference to a role that does not exist new BootstrapSingleResource("Overwrite user Tim", "Tim will be overwritted with the right permissions.", "/mgnl-bootstrap-samples/inplace-templating/users.admin.tim.xml", ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING).execute(installContext); installContext.warn("User Tim has been overwritten."); } } }
private void doTest(String resourceToBootstrap, boolean shouldBootstrap, boolean shouldExecuteDelegateTask) throws Exception { final MockSession session = SessionTestUtil.createSession("somerepo", SOME_PROPERTY); final InstallContext ctx = createStrictMock(InstallContext.class); final Task delegateTask = createStrictMock(Task.class); expect(ctx.getJCRSession("somerepo")).andReturn(session); if (shouldExecuteDelegateTask) { delegateTask.execute(ctx); } replay(ctx, delegateTask); final BootstrapConditionally task = new BootstrapConditionally("test", "test", resourceToBootstrap, delegateTask); try { task.execute(ctx); // TODO : ugly hack until BootstrapUtil is refactored / mockable / testable } catch (TaskExecutionException e) { if (shouldBootstrap) { assertEquals("Could not bootstrap: Can't find resource to bootstrap at /some-dir/test/foobar/somerepo.bleh.blih.xml", e.getMessage()); } else { fail("Failed! NullPointerException: " + e.getMessage() + " : " + ExceptionUtils.getStackTrace(e)); } } verify(ctx, delegateTask); }