1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.resources.app.action; |
35 |
|
|
36 |
|
import static org.hamcrest.CoreMatchers.is; |
37 |
|
import static org.junit.Assert.assertThat; |
38 |
|
import static org.mockito.BDDMockito.given; |
39 |
|
import static org.mockito.Mockito.*; |
40 |
|
|
41 |
|
import info.magnolia.i18nsystem.SimpleTranslator; |
42 |
|
import info.magnolia.jcr.util.NodeTypes; |
43 |
|
import info.magnolia.resources.app.workbench.ResourcesContainer; |
44 |
|
import info.magnolia.ui.api.app.AppContext; |
45 |
|
import info.magnolia.ui.api.context.UiContext; |
46 |
|
import info.magnolia.ui.api.event.ContentChangedEvent; |
47 |
|
import info.magnolia.ui.vaadin.integration.jcr.DefaultProperty; |
48 |
|
|
49 |
|
import javax.jcr.Node; |
50 |
|
import javax.jcr.RepositoryException; |
51 |
|
|
52 |
|
import org.junit.Before; |
53 |
|
import org.junit.Test; |
54 |
|
import org.mockito.ArgumentCaptor; |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (37) |
Complexity: 5 |
Complexity Density: 0.16 |
|
56 |
|
public class AddResourceFolderActionTest extends AbstractAddResourceActionTest { |
57 |
|
|
58 |
|
private AddResourceFolderAction action; |
59 |
|
private AddResourceFolderActionDefinition definition; |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
61 |
3 |
@Override... |
62 |
|
@Before |
63 |
|
public void setUp() throws Exception { |
64 |
3 |
super.setUp(); |
65 |
|
|
66 |
3 |
definition = new AddResourceFolderActionDefinition(); |
67 |
3 |
definition.setDialogName("addResource"); |
68 |
|
|
69 |
3 |
action = new AddResourceFolderAction(definition, resourceItem, formDialogPresenterFactory, mock(AppContext.class), mock(UiContext.class), contentConnector, mock(SimpleTranslator.class), locationController, origin, eventBus); |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
72 |
1 |
@Test... |
73 |
|
public void canAddFolderToRootNode() throws Exception { |
74 |
|
|
75 |
1 |
definition.setNodeType(NodeTypes.Folder.NAME); |
76 |
1 |
Node root = session.getRootNode(); |
77 |
1 |
given(resource.getPath()).willReturn(root.getPath()); |
78 |
1 |
given(resourceItem.getItemProperty(ResourcesContainer.RESOURCE_PATH)).willReturn(new DefaultProperty<>(root.getPath())); |
79 |
1 |
long nodeCountBefore = root.getNodes().getSize(); |
80 |
|
|
81 |
|
|
82 |
1 |
action.execute(); |
83 |
|
|
84 |
|
|
85 |
1 |
assertAddedNewNode(root, nodeCountBefore + 1); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
88 |
1 |
@Test... |
89 |
|
public void canAddFolderToAnotherFolder() throws Exception { |
90 |
|
|
91 |
1 |
definition.setNodeType(NodeTypes.Folder.NAME); |
92 |
1 |
Node node = session.getRootNode().addNode("foo", NodeTypes.Folder.NAME); |
93 |
1 |
given(resource.getPath()).willReturn(node.getPath()); |
94 |
1 |
given(resourceItem.getItemProperty(ResourcesContainer.RESOURCE_PATH)).willReturn(new DefaultProperty<>(node.getPath())); |
95 |
1 |
long nodeCountBefore = node.getNodes().getSize(); |
96 |
|
|
97 |
|
|
98 |
1 |
action.execute(); |
99 |
|
|
100 |
|
|
101 |
1 |
assertAddedNewNode(node, nodeCountBefore + 1); |
102 |
|
} |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
104 |
1 |
@Test... |
105 |
|
public void eventIsFiredWithPathOfNewFolder() throws Exception { |
106 |
|
|
107 |
1 |
definition.setNodeType(NodeTypes.Folder.NAME); |
108 |
1 |
Node root = session.getRootNode(); |
109 |
1 |
given(resource.getPath()).willReturn(root.getPath()); |
110 |
1 |
given(resourceItem.getItemProperty(ResourcesContainer.RESOURCE_PATH)).willReturn(new DefaultProperty<>(root.getPath())); |
111 |
|
|
112 |
|
|
113 |
1 |
action.execute(); |
114 |
|
|
115 |
|
|
116 |
1 |
ArgumentCaptor<ContentChangedEvent> argumentCaptor = ArgumentCaptor.forClass(ContentChangedEvent.class); |
117 |
1 |
verify(eventBus, atLeastOnce()).fireEvent(argumentCaptor.capture()); |
118 |
1 |
String result = (String) argumentCaptor.getValue().getItemId(); |
119 |
1 |
assertThat("/test", is(result)); |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
122 |
2 |
private void assertAddedNewNode(Node parentNode, long expectedNumberOfChildNodes) throws RepositoryException {... |
123 |
2 |
assertThat(parentNode.getNodes().getSize(), is(expectedNumberOfChildNodes)); |
124 |
2 |
assertThat(parentNode.hasNode("test"), is(true)); |
125 |
2 |
assertThat(eventBus.isEmpty(), is(false)); |
126 |
|
|
127 |
2 |
Node newNode = parentNode.getNode("test"); |
128 |
2 |
assertThat(NodeTypes.Folder.NAME, is(newNode.getPrimaryNodeType().getName())); |
129 |
|
} |
130 |
|
} |