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.rest.setup; |
35 |
|
|
36 |
|
import static info.magnolia.repository.RepositoryConstants.USER_ROLES; |
37 |
|
import static info.magnolia.test.hamcrest.NodeMatchers.*; |
38 |
|
import static org.hamcrest.CoreMatchers.allOf; |
39 |
|
import static org.junit.Assert.assertThat; |
40 |
|
import static org.mockito.Mockito.*; |
41 |
|
|
42 |
|
import info.magnolia.context.MgnlContext; |
43 |
|
import info.magnolia.jcr.util.NodeTypes; |
44 |
|
import info.magnolia.jcr.util.NodeUtil; |
45 |
|
import info.magnolia.jcr.util.PropertyUtil; |
46 |
|
import info.magnolia.module.InstallContext; |
47 |
|
import info.magnolia.test.RepositoryTestCase; |
48 |
|
|
49 |
|
import javax.jcr.Node; |
50 |
|
import javax.jcr.Session; |
51 |
|
|
52 |
|
import org.junit.Before; |
53 |
|
import org.junit.Test; |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 2 |
Complexity Density: 0.12 |
|
55 |
|
public class UpdateRestEditorRoleTaskTest extends RepositoryTestCase { |
56 |
|
|
57 |
|
private Session session; |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
59 |
1 |
@Before... |
60 |
|
@Override |
61 |
|
public void setUp() throws Exception { |
62 |
1 |
super.setUp(); |
63 |
1 |
session = MgnlContext.getJCRSession(USER_ROLES); |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
66 |
1 |
@Test... |
67 |
|
public void updateRestRole() throws Exception { |
68 |
|
|
69 |
1 |
Node restNode = NodeUtil.createPath(session.getRootNode(), "/rest", NodeTypes.Role.NAME); |
70 |
1 |
PropertyUtil.setProperty(restNode, "description", "test"); |
71 |
1 |
PropertyUtil.setProperty(restNode, "title", "test"); |
72 |
|
|
73 |
1 |
Node aclRole = NodeUtil.createPath(restNode, "acl_userroles/0", NodeTypes.ContentNode.NAME); |
74 |
1 |
Node aclUri = NodeUtil.createPath(restNode, "acl_uri/0", NodeTypes.ContentNode.NAME); |
75 |
|
|
76 |
1 |
aclRole.setProperty("path", "/rest"); |
77 |
1 |
aclUri.setProperty("path", "/.rest*"); |
78 |
|
|
79 |
|
|
80 |
1 |
InstallContext context = mock(InstallContext.class); |
81 |
1 |
when(context.getJCRSession(USER_ROLES)).thenReturn(session); |
82 |
1 |
UpdateRestEditorRoleTask task = new UpdateRestEditorRoleTask("Test Task", "test"); |
83 |
1 |
task.execute(context); |
84 |
|
|
85 |
|
|
86 |
1 |
assertThat(restNode, allOf( |
87 |
|
nodeName("rest-editor"), |
88 |
|
hasProperty("description", "This role grants GET/POST permissions to REST services APIs (nodes, properties), for a limited set of workspaces."), |
89 |
|
hasProperty("title", "REST Editor"))); |
90 |
|
|
91 |
1 |
assertThat(aclRole, hasProperty("path", "/rest-editor")); |
92 |
1 |
assertThat(aclUri, hasProperty("path", "/.rest/*")); |
93 |
|
} |
94 |
|
} |