-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
159 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
.../main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/ReorderNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package de.valtech.aecu.core.groovy.console.bindings.actions.resource; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import javax.jcr.Node; | ||
import javax.jcr.RepositoryException; | ||
|
||
import org.apache.sling.api.resource.PersistenceException; | ||
import org.apache.sling.api.resource.Resource; | ||
|
||
import de.valtech.aecu.core.groovy.console.bindings.actions.Action; | ||
import de.valtech.aecu.core.groovy.console.bindings.impl.BindingContext; | ||
|
||
/** | ||
* Reorders a subnode of a resource. | ||
* | ||
* @author Roland Gruber | ||
*/ | ||
public class ReorderNode implements Action { | ||
|
||
protected String nameOfNodeToMove; | ||
protected String newSuccessor; | ||
private BindingContext context; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param nameOfNodeToMove node to move | ||
* @param newSuccessor new successor node name | ||
* @param context binding context | ||
*/ | ||
public ReorderNode(@Nonnull String nameOfNodeToMove, @Nullable String newSuccessor, @Nonnull BindingContext context) { | ||
this.nameOfNodeToMove = nameOfNodeToMove; | ||
this.newSuccessor = newSuccessor; | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
public String doAction(@Nonnull Resource resource) throws PersistenceException { | ||
Node node = resource.adaptTo(Node.class); | ||
try { | ||
if (null != node) { | ||
if (!context.isDryRun()) { | ||
node.orderBefore(nameOfNodeToMove, newSuccessor); | ||
} | ||
return "Reordered " + nameOfNodeToMove + " on resource " + resource.getPath(); | ||
} | ||
} catch (RepositoryException e) { | ||
throw new PersistenceException("ERROR: could not reorder " + nameOfNodeToMove + " on resource " + resource.getPath(), | ||
e); | ||
} | ||
return "WARNING: could not reorder " + nameOfNodeToMove; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...t/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/ReorderNodeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package de.valtech.aecu.core.groovy.console.bindings.actions.resource; | ||
|
||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import javax.jcr.Node; | ||
import javax.jcr.RepositoryException; | ||
|
||
import org.apache.sling.api.resource.PersistenceException; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import de.valtech.aecu.core.groovy.console.bindings.impl.BindingContext; | ||
|
||
/** | ||
* Tests ReorderNode | ||
* | ||
* @author Roland Gruber | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class ReorderNodeTest { | ||
|
||
private static final String NODE_TO_MOVE = "toMove"; | ||
|
||
private static final String NEW_SUCCESSOR = "newSuccessor"; | ||
|
||
@Mock | ||
private Resource resource; | ||
|
||
@Mock | ||
private Node node; | ||
|
||
@Mock | ||
private BindingContext context; | ||
|
||
@Before | ||
public void setup() { | ||
when(resource.adaptTo(Node.class)).thenReturn(node); | ||
} | ||
|
||
@Test | ||
public void test_doAction_dryRun() throws RepositoryException, PersistenceException { | ||
when(context.isDryRun()).thenReturn(true); | ||
|
||
ReorderNode action = new ReorderNode(NODE_TO_MOVE, NEW_SUCCESSOR, context); | ||
action.doAction(resource); | ||
|
||
verify(node, never()).orderBefore(NODE_TO_MOVE, NEW_SUCCESSOR); | ||
} | ||
|
||
@Test | ||
public void test_doAction_run() throws RepositoryException, PersistenceException { | ||
when(context.isDryRun()).thenReturn(false); | ||
|
||
ReorderNode action = new ReorderNode(NODE_TO_MOVE, NEW_SUCCESSOR, context); | ||
action.doAction(resource); | ||
|
||
verify(node, times(1)).orderBefore(NODE_TO_MOVE, NEW_SUCCESSOR); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters