@Override public void execute(final InstallContext installContext) throws TaskExecutionException { try { bootstrap(installContext, importUUIDBehavior); } catch (IOException | RepositoryException e) { throw new TaskExecutionException("Could not bootstrap: " + e.getMessage(), e); } }
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); }
@Test(expected = TaskExecutionException.class) public void nonExistingSource() throws Exception { // GIVEN Task task = new CopyPropertyTask("name", RepositoryConstants.CONFIG, "/someSrcNode", "/someDestNode", "someProperty", false); // WHEN try { task.execute(installContext); // THEN } catch (TaskExecutionException e) { assertTrue(e.getCause() instanceof PathNotFoundException); throw e; } }
@Test public void testThrowsExceptionIfPropertyMustExistAndDoesNot() throws Exception { try { doTest("nonexistingproperty", "bleh", true); fail(); } catch (TaskExecutionException e) { assertEquals("Property \"nonexistingproperty\" was expected to exist at /foo/bar", e.getMessage()); } }
@Test(expected = TaskExecutionException.class) public void testNonexistingSource() throws Exception { // GIVEN Task task = new MovePropertyTask("name", RepositoryConstants.CONFIG, "/someSrcNode/someProperty", "/someDestNode/someProperty", true); // WHEN try { task.execute(installContext); // THEN } catch (TaskExecutionException e) { assertTrue(e.getCause() instanceof PathNotFoundException); throw e; } }
@Override public void execute( @Nonnull InstallContext ctx ) throws TaskExecutionException { try { executeImpl( ctx ); } catch( Exception ex ) { throw new TaskExecutionException( ex.getLocalizedMessage(), ex ); } }
@Test public void testUnknownRootThrowsException() throws Exception { NodeUtil.createPath(MgnlContext.getJCRSession("config").getRootNode(), "/hello/world", NodeTypes.Content.NAME, true); Task passing = new NodeBuilderTask("Passing", "This task should work since it uses a known root", ErrorHandling.strict, "config", "/hello/world", addProperty("foo", "bar")); Task failing = new NodeBuilderTask("Failing", "This task should not work since it uses an unknown root", ErrorHandling.strict, "config", "/hello/boo", addProperty("foo", "bar")); final InstallContextImpl ctx = new InstallContextImpl(null); passing.execute(ctx); try { failing.execute(ctx); fail("should have failed"); } catch (TaskExecutionException e) { assertEquals("Could not execute task: Path not found: /hello/boo", e.getMessage()); } }
@Override public void execute( @Nonnull InstallContext ctx ) throws TaskExecutionException { try { executeImpl(); } catch( Exception ex ) { throw new TaskExecutionException( ex.getLocalizedMessage(), ex ); } }
@Test public void testUnknownRootThrowsException() throws Exception { ContentUtil.createPath(HierarchyManagerUtil.asHierarchyManager(MgnlContext.getJCRSession(RepositoryConstants.CONFIG)), "/hello/world", true); Task passing = new NodeBuilderTask("Passing", "This task should work since it uses a known root", ErrorHandling.strict, "config", "/hello/world", addProperty("foo", "bar")); Task failing = new NodeBuilderTask("Failing", "This task should not work since it uses an unknown root", ErrorHandling.strict, "config", "/hello/boo", addProperty("foo", "bar")); final InstallContextImpl ctx = new InstallContextImpl(null); passing.execute(ctx); try { failing.execute(ctx); fail("should have failed"); } catch (TaskExecutionException e) { assertEquals("Could not execute task: Path not found: hello/boo", e.getMessage()); } }
@Override protected boolean checkNode(Node node, InstallContext ctx) throws TaskExecutionException, RepositoryException { if (node.hasProperty(propertyName)) { final Property prop = node.getProperty(propertyName); return expectedValue.equals(prop.getString()); } else if (propertyMustExist) { throw new TaskExecutionException("Property \"" + propertyName + "\" was expected to exist at " + nodePath); } else { ctx.warn("Property \"" + propertyName + "\" was expected to be found at " + nodePath + " but does not exist."); return false; } } }
@Override public void execute( @Nonnull InstallContext ctx ) throws TaskExecutionException { try { executeImpl(); } catch( TaskExecutionException ex ) { throw ex; } catch( Exception ex ) { throw new TaskExecutionException( ex.getLocalizedMessage(), ex ); } }
@Override public void execute(InstallContext ctx) throws TaskExecutionException { try { String outputResourceName = getOutputResourceName(resource, itemPath); //bootstrap bootstrap(outputResourceName, itemName, importUUIDBehavior, getNodeStream(resource, itemPath)); } catch (IOException e) { throw new TaskExecutionException("Cant find resource file"); } catch (RepositoryException e) { throw new TaskExecutionException("Cant bootstrap resource file"); } }
@Override public void execute(InstallContext installContext) throws TaskExecutionException { try { SecurityUtil.updateKeys(SecurityUtil.generateKeyPair(1024)); } catch (NoSuchAlgorithmException e) { throw new TaskExecutionException(e.getMessage(), e); } } }));
@Override public void execute(InstallContext installContext) throws TaskExecutionException { try { SecurityUtil.updateKeys(SecurityUtil.generateKeyPair(1024)); } catch (NoSuchAlgorithmException e) { throw new TaskExecutionException(e.getMessage(), e); } } }));
@Override public void execute(InstallContext installContext) throws TaskExecutionException { try { SecurityUtil.updateKeys(SecurityUtil.generateKeyPair(1024)); } catch (NoSuchAlgorithmException e) { throw new TaskExecutionException(e.getMessage(), e); } } }))
@Override public void execute(InstallContext installContext) throws TaskExecutionException { try { doExecute(installContext); } catch (RepositoryException e) { throw new TaskExecutionException("Could not execute task: " + ExceptionUtil.exceptionToWords(e), e); } }
@Override protected boolean condition(InstallContext ctx) throws TaskExecutionException { final Session session; final Node rootNode; final String nodePath = StringUtils.removeStart(this.nodePath, "/"); try { session = ctx.getJCRSession(workspaceName); rootNode = session.getRootNode(); } catch (RepositoryException e) { throw new TaskExecutionException(String.format("Can't check for property %s in %s.", propertyName, nodePath), e); } try { if (!rootNode.hasNode(nodePath)) { return false; } } catch (RepositoryException e) { return false; } try { final Node node = rootNode.getNode(nodePath); final Content content = ContentUtil.asContent(node); return checkNode(content, ctx); } catch (RepositoryException e) { throw new TaskExecutionException(String.format("Can't check for property %s in %s.", propertyName, nodePath), e); } }
@Override public void execute(InstallContext installContext) throws TaskExecutionException { if (this.command == null) { String message = "Couldn't find command " + this.commandClass.getName() + "."; installContext.warn(message); return; } try { this.command.execute(MgnlContext.getInstance()); } catch (Exception e) { throw new TaskExecutionException(e.getMessage(), e); } } }
@Override protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException { try { final InputStream propsStream = ClasspathResourcesUtil.getStream(resource); final Node root = installContext.getJCRSession(workspace).getRootNode(); new PropertiesImportExport().createNodes(root, propsStream); } catch (IOException e) { throw new TaskExecutionException(String.format("Could not load properties: %s", e.getMessage()), e); } } }
@Override public void execute(InstallContext ctx) throws TaskExecutionException { try { Session session = ctx.getJCRSession(RepositoryConstants.WEBSITE); Node rootNode = session.getRootNode(); NodeUtil.visit(rootNode, nodeVisitor); } catch (RepositoryException e) { throw new TaskExecutionException(e.getMessage(), e); } }