@Override public void execute(InstallContext ctx) throws TaskExecutionException { for (Task task : tasks) { task.execute(ctx); } }
@Override public void execute(InstallContext ctx) throws TaskExecutionException { final Task task = condition(ctx) ? ifTrue : ifFalse; if (task != null) { task.execute(ctx); } }
@Test public void ifFalseTaskIsRunIfPropertyDoesNotExist() throws Exception { // GIVEN Task task = new HasPropertyDelegateTask("taskName", "/someNode", "someProperty", ifTrue, ifFalse); session.getRootNode().addNode("someNode"); // WHEN task.execute(ctx); // THEN verify(ifTrue, times(0)).execute(ctx); verify(ifFalse, times(1)).execute(ctx); }
@Test public void ifTrueTaskIsRunIfNodeAndPropertyExist() throws Exception { // GIVEN Task task = new HasPropertyDelegateTask("taskName", "/someNode", "someProperty", ifTrue, ifFalse); session.getRootNode().addNode("someNode").setProperty("someProperty", "somePropertyValue"); // WHEN task.execute(ctx); // THEN verify(ifTrue, times(1)).execute(ctx); verify(ifFalse, times(0)).execute(ctx); } }
@Test public void testExecutesDelegateTaskIfPropertyExistsWithExpectedValue() throws Exception { // GIVEN NodeUtil.createPath(session.getRootNode(), "foo/bar", NodeTypes.Content.NAME).setProperty("baz", "bleh"); Task task = new ValueOfPropertyDelegateTask("test", "test", "somerepo", "/foo/bar", "baz", "bleh", true, delegIfTrue, delegIfFalse); // WHEN task.execute(ctx); // THEN verify(delegIfFalse, times(0)).execute(ctx); verify(delegIfTrue).execute(ctx); }
@Test public void testExecutesOtherDelegateTaskIfPropertyExistsWithOtherValue() throws Exception { // GIVEN NodeUtil.createPath(session.getRootNode(), "foo/bar", NodeTypes.Content.NAME).setProperty("baz", "bleh"); Task task = new ValueOfPropertyDelegateTask("test", "test", "somerepo", "/foo/bar", "baz", "othervalue", true, delegIfTrue, delegIfFalse); // WHEN task.execute(ctx); // THEN verify(delegIfTrue, times(0)).execute(ctx); verify(delegIfFalse).execute(ctx); }
@Test public void executesAuthorDelegateTaskWhenIsAuthor() throws Exception { delegIfAuthor.execute(ctx); doTest("/server.admin=true"); }
@Test public void testExecutesDelegateTaskIfPropertyExistsWithExpectedValue() throws Exception { ifTrueDelegateTask.execute(installContext); doTest("baz", "bleh", true); }
@Test public void delegateTaskIsExecutedWhenNoConditionsAreGiven() throws Exception { // GIVEN task = new PathExistenceDelegateTask("", "", null, null, delegateTask); // WHEN task.execute(ctx); // THEN verify(delegateTask, times(1)).execute(ctx); } }
@Test public void doNotOverride() throws Exception { // GIVEN sessionConfig.getRootNode().addNode("someSrcNode").setProperty("someProperty", "somePropertyValue"); sessionConfig.getRootNode().addNode("someDestNode").setProperty("someProperty", "someOldValue"); Task task = new CopyPropertyTask("name", RepositoryConstants.CONFIG, "/someSrcNode", "/someDestNode", "someProperty", false); // WHEN task.execute(installContext); // THEN assertTrue(sessionConfig.propertyExists("/someSrcNode/someProperty")); assertEquals("someOldValue", sessionConfig.getProperty("/someDestNode/someProperty").getString()); }
@Test public void versionNodesAreRenamed() throws Exception { // WHEN task.execute(installContext); // THEN assertThat(testNode.getPath(), is("/" + getSavePath(testNode) + "/" + testNode.getIdentifier())); }
@Test public void testWithoutThePath() throws Exception { // GIVEN Task task = new NewPropertyTask("", "", RepositoryConstants.CONFIG, "/test1", "testProp", "testValue"); // WHEN task.execute(installContext); // THEN verify(installContext).error(eq("Could not create property testProp at /test1, please create it with value testValue."), isA(PathNotFoundException.class)); } }
@Test public void doesNotRemoveChildWithChildren() throws Exception { // GIVEN NodeUtil.createPath(session.getRootNode(), "/some/path/with/children", NodeTypes.ContentNode.NAME); Task task = new RemoveNodeWoChildren("", "some/path"); // WHEN task.execute(installContext); // THEN assertThat(session.getRootNode(), hasNode("/some/path/with/children")); }
@Test public void executesAuthorDelegateTaskWhenAdminPropertyDoesNotExist() throws Exception { ctx.warn("Property \"admin\" was expected to be found at /server but does not exist."); delegIfAuthor.execute(ctx); doTest("/server.bleh=bloh"); }
@Test public void executesAuthorDelegateTaskWhenAdminPropertyDoesNotExist() throws Exception { installContext.warn("Property \"admin\" was expected to be found at /server but does not exist."); ifAuthorDelegateTask.execute(installContext); doTest("/server.bleh=bloh"); }
@Test public void executeWithoutActivation() throws Exception { // GIVEN activation is not installed Task task = new SetupModuleRepositoriesTask(); // WHEN task.execute(installContext); // THEN assertFalse(sessionConfig.itemExists("/server/activation/subscribers/someSubscriber/subscriptions")); assertThat(installContext.getMessages().values(), hasSize(0)); }
@Test public void testExecute() throws RepositoryException, TaskExecutionException { // GIVEN session.getRootNode().addNode("someParent"); Task task = new CreateNodeTask("name", "/someParent", "someNode", NodeTypes.ContentNode.NAME); // WHEN task.execute(installContext); // THEN assertTrue("Node was created", session.nodeExists("/someParent/someNode")); assertEquals("Create node 'config:/someParent/someNode'.", task.getDescription()); } }
@Test public void nodesAreProperlyCreated() throws Exception { // GIVEN final Task task = new ImportNodesFromPropertiesTask("", "", RepositoryConstants.CONFIG, "/info/magnolia/module/delta/ImportNodesFromPropertiesTask.properties"); // WHEN task.execute(installContext); // THEN assertThat(session.getRootNode(), hasNode("rootNode")); assertThat(session.getRootNode(), hasNode("rootNode/subNode")); }
@Test public void testWithExpectedPathExisting() throws Exception { // GIVEN Task task = new NewPropertyTask("", "", RepositoryConstants.CONFIG, "/test", "testProp", "testValue"); // WHEN task.execute(installContext); // THEN assertThat(sessionMock.getNode("/test"), hasProperty("testProp")); }
@Test public void execute() throws Exception { // GIVEN Task task = new CreateNodePathTask("name", "/someParent/someNode", NodeTypes.ContentNode.NAME); // WHEN task.execute(installContext); // THEN assertTrue("Node was created", session.nodeExists("/someParent/someNode")); assertEquals("Create node path 'config:/someParent/someNode'.", task.getDescription()); } }