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.utils; |
35 |
|
|
36 |
|
import static org.hamcrest.CoreMatchers.is; |
37 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
38 |
|
import static org.hamcrest.Matchers.hasSize; |
39 |
|
import static org.mockito.BDDMockito.given; |
40 |
|
import static org.mockito.Mockito.mock; |
41 |
|
|
42 |
|
import info.magnolia.context.Context; |
43 |
|
import info.magnolia.jcr.util.NodeTypes; |
44 |
|
import info.magnolia.resourceloader.jcr.JcrResourceOrigin; |
45 |
|
import info.magnolia.resources.app.workbench.ResourcesContainer; |
46 |
|
import info.magnolia.ui.vaadin.integration.jcr.DefaultProperty; |
47 |
|
import info.magnolia.ui.vaadin.integration.jcr.JcrItemAdapter; |
48 |
|
import info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter; |
49 |
|
|
50 |
|
import java.util.List; |
51 |
|
|
52 |
|
import javax.jcr.Item; |
53 |
|
import javax.jcr.Node; |
54 |
|
import javax.jcr.Session; |
55 |
|
import javax.jcr.Workspace; |
56 |
|
import javax.jcr.nodetype.NodeType; |
57 |
|
|
58 |
|
import org.junit.Before; |
59 |
|
import org.junit.Test; |
60 |
|
|
61 |
|
import com.google.common.collect.Lists; |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (43) |
Complexity: 4 |
Complexity Density: 0.1 |
|
63 |
|
public class ResourceUtilsTest { |
64 |
|
|
65 |
|
private JcrItemAdapter jcrItemAdapter; |
66 |
|
private Node node; |
67 |
|
private Item item; |
68 |
|
private Context context; |
69 |
|
private com.vaadin.data.Item vaadinItem; |
70 |
|
private com.vaadin.data.Item vaadinItem2; |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 1 |
Complexity Density: 0.04 |
|
72 |
3 |
@Before... |
73 |
|
public void setUp() throws Exception { |
74 |
3 |
jcrItemAdapter = mock(JcrItemAdapter.class); |
75 |
3 |
node = mock(Node.class); |
76 |
3 |
item = mock(Item.class); |
77 |
|
|
78 |
3 |
given(node.isNode()).willReturn(true); |
79 |
3 |
given(node.getIdentifier()).willReturn("test-identifier"); |
80 |
3 |
NodeType nodeType = mock(NodeType.class); |
81 |
3 |
given(nodeType.getName()).willReturn(NodeTypes.Content.NAME); |
82 |
3 |
given(node.getPrimaryNodeType()).willReturn(nodeType); |
83 |
|
|
84 |
3 |
Node node2 = mock(Node.class); |
85 |
3 |
given(node2.isNode()).willReturn(true); |
86 |
3 |
given(node2.getIdentifier()).willReturn("test-identifier"); |
87 |
3 |
given(node2.getPrimaryNodeType()).willReturn(nodeType); |
88 |
3 |
context = mock(Context.class); |
89 |
|
|
90 |
3 |
vaadinItem = mock(com.vaadin.data.Item.class); |
91 |
3 |
given(vaadinItem.getItemProperty(ResourcesContainer.RESOURCE_PATH)).willReturn(new DefaultProperty<>("/node")); |
92 |
|
|
93 |
3 |
vaadinItem2 = mock(com.vaadin.data.Item.class); |
94 |
3 |
given(vaadinItem2.getItemProperty(ResourcesContainer.RESOURCE_PATH)).willReturn(new DefaultProperty<>("/node/a")); |
95 |
|
|
96 |
3 |
Session session = mock(Session.class); |
97 |
3 |
given(context.getJCRSession(JcrResourceOrigin.RESOURCES_WORKSPACE)).willReturn(session); |
98 |
3 |
given(session.getNode("/node")).willReturn(node); |
99 |
3 |
given(session.getNode("/node/a")).willReturn(node2); |
100 |
3 |
Workspace workspace = mock(Workspace.class); |
101 |
3 |
given(workspace.getName()).willReturn(JcrResourceOrigin.RESOURCES_WORKSPACE); |
102 |
3 |
given(session.getWorkspace()).willReturn(workspace); |
103 |
3 |
given(node.getSession()).willReturn(session); |
104 |
3 |
given(node2.getSession()).willReturn(session); |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
107 |
1 |
@Test... |
108 |
|
public void canGetJcrAdapters() throws Exception { |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
1 |
JcrNodeAdapter nodeAdapter = ResourceUtils.getJcrNodeAdapterFor(context, vaadinItem); |
113 |
|
|
114 |
|
|
115 |
1 |
assertThat(nodeAdapter.getPrimaryNodeTypeName(), is(NodeTypes.Content.NAME)); |
116 |
1 |
assertThat(nodeAdapter.getWorkspace(), is(JcrResourceOrigin.RESOURCES_WORKSPACE)); |
117 |
|
} |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
119 |
1 |
@Test... |
120 |
|
public void canGetJcrAdapter() throws Exception { |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
1 |
List<JcrItemAdapter> adapterList = ResourceUtils.getJcrItemAdaptersFor(context, Lists.newArrayList(vaadinItem, vaadinItem2)); |
125 |
|
|
126 |
|
|
127 |
1 |
assertThat(adapterList, hasSize(2)); |
128 |
1 |
assertThat(adapterList.get(0).getWorkspace(), is(JcrResourceOrigin.RESOURCES_WORKSPACE)); |
129 |
1 |
assertThat(adapterList.get(1).getWorkspace(), is(JcrResourceOrigin.RESOURCES_WORKSPACE)); |
130 |
|
} |
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
132 |
1 |
@Test... |
133 |
|
public void canExtractParentItem() throws Exception { |
134 |
|
|
135 |
1 |
given(jcrItemAdapter.getJcrItem()).willReturn(item); |
136 |
1 |
given(item.getParent()).willReturn(node); |
137 |
|
|
138 |
|
|
139 |
1 |
Node extractedNode = ResourceUtils.extractParentItem(jcrItemAdapter); |
140 |
|
|
141 |
|
|
142 |
1 |
assertThat(extractedNode.getIdentifier(), is(node.getIdentifier())); |
143 |
1 |
assertThat(extractedNode.getPath(), is(node.getPath())); |
144 |
1 |
assertThat(extractedNode.getName(), is(node.getName())); |
145 |
|
} |
146 |
|
} |