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 org.junit.Assert.assertEquals; |
37 |
|
|
38 |
|
import info.magnolia.cms.security.MgnlRoleManager; |
39 |
|
import info.magnolia.cms.security.SecuritySupport; |
40 |
|
import info.magnolia.cms.security.SecuritySupportImpl; |
41 |
|
import info.magnolia.context.MgnlContext; |
42 |
|
import info.magnolia.jcr.util.NodeTypes; |
43 |
|
import info.magnolia.jcr.util.NodeUtil; |
44 |
|
import info.magnolia.module.ModuleVersionHandler; |
45 |
|
import info.magnolia.module.ModuleVersionHandlerTestCase; |
46 |
|
import info.magnolia.module.model.Version; |
47 |
|
import info.magnolia.repository.RepositoryConstants; |
48 |
|
import info.magnolia.rest.service.setup.RestServicesModuleVersionHandler; |
49 |
|
import info.magnolia.test.ComponentsTestUtil; |
50 |
|
|
51 |
|
import java.util.Arrays; |
52 |
|
import java.util.List; |
53 |
|
|
54 |
|
import javax.jcr.Node; |
55 |
|
import javax.jcr.Session; |
56 |
|
|
57 |
|
import org.junit.Before; |
58 |
|
import org.junit.Test; |
59 |
|
|
60 |
|
|
61 |
|
@link |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (34) |
Complexity: 7 |
Complexity Density: 0.26 |
|
63 |
|
public class RestServicesModuleVersionHandlerTest extends ModuleVersionHandlerTestCase { |
64 |
|
|
65 |
|
private Session session; |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
3 |
@Override... |
68 |
|
protected String getModuleDescriptorPath() { |
69 |
3 |
return "/META-INF/magnolia/rest-services.xml"; |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
3 |
@Override... |
73 |
|
protected List<String> getModuleDescriptorPathsForTests() { |
74 |
3 |
return Arrays.asList( |
75 |
|
"/META-INF/magnolia/core.xml" |
76 |
|
); |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
3 |
@Override... |
80 |
|
protected ModuleVersionHandler newModuleVersionHandlerForTests() { |
81 |
3 |
return new RestServicesModuleVersionHandler(); |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
84 |
3 |
@Override... |
85 |
|
@Before |
86 |
|
public void setUp() throws Exception { |
87 |
3 |
super.setUp(); |
88 |
|
|
89 |
3 |
session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); |
90 |
|
|
91 |
|
|
92 |
3 |
final SecuritySupportImpl securitySupport = new SecuritySupportImpl(); |
93 |
3 |
securitySupport.setRoleManager(new MgnlRoleManager()); |
94 |
3 |
ComponentsTestUtil.setInstance(SecuritySupport.class, securitySupport); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
97 |
1 |
@Test... |
98 |
|
public void basicInstallAndCheckThatMethodsWereAdded() throws Exception { |
99 |
|
|
100 |
1 |
Node node = NodeUtil.createPath(session.getRootNode(), "/server/IPConfig/allow-all", NodeTypes.ContentNode.NAME); |
101 |
1 |
node.setProperty("methods", "GET,POST"); |
102 |
|
|
103 |
1 |
Session rolesSession = MgnlContext.getJCRSession(RepositoryConstants.USER_ROLES); |
104 |
1 |
NodeUtil.createPath(rolesSession.getRootNode(), "/rest-editor", NodeTypes.Role.NAME); |
105 |
|
|
106 |
|
|
107 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null); |
108 |
|
|
109 |
|
|
110 |
1 |
assertEquals("GET,POST,PUT,DELETE", node.getProperty("methods").getString()); |
111 |
|
|
112 |
1 |
assertEquals(5, rolesSession.getNode("/rest-editor/acl_uri").getNodes().getSize()); |
113 |
|
|
114 |
1 |
assertEquals("rest-editor", session.getProperty("/modules/rest-services/rest-endpoints/commands/enabledCommands/markAsDeleted/access/roles/rest").getString()); |
115 |
1 |
assertEquals("rest-editor", session.getProperty("/modules/rest-services/rest-endpoints/commands/enabledCommands/activate/access/roles/rest").getString()); |
116 |
|
|
117 |
|
} |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
119 |
1 |
@Test... |
120 |
|
public void updateTo1_1CommandEndpointIsUpdatedToV2() throws Exception { |
121 |
|
|
122 |
1 |
setupConfigProperty("/modules/rest-services/rest-endpoints/commands", "implementationClass", "info.magnolia.rest.service.command.v1.CommandEndpoint"); |
123 |
1 |
setupConfigProperty("/modules/rest-services/rest-endpoints/commands/enabledCommands/activate/access/roles", "rest", "rest"); |
124 |
1 |
setupConfigProperty("/modules/rest-services/rest-endpoints/commands/enabledCommands/markAsDeleted/access/roles", "rest", "rest"); |
125 |
|
|
126 |
|
|
127 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("1.0")); |
128 |
|
|
129 |
|
|
130 |
1 |
assertEquals("info.magnolia.rest.service.command.v2.CommandEndpoint", session.getProperty("/modules/rest-services/rest-endpoints/commands/implementationClass").getString()); |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
133 |
1 |
@Test... |
134 |
|
public void updateTo2_0CommandEndpointRolesIsUpdatedToRestEditor() throws Exception { |
135 |
|
|
136 |
1 |
setupConfigProperty("/modules/rest-services/rest-endpoints/commands/enabledCommands/activate/access/roles", "rest", "rest"); |
137 |
1 |
setupConfigProperty("/modules/rest-services/rest-endpoints/commands/enabledCommands/markAsDeleted/access/roles", "rest", "rest"); |
138 |
|
|
139 |
|
|
140 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("1.1")); |
141 |
|
|
142 |
|
|
143 |
1 |
assertEquals("rest-editor", session.getProperty("/modules/rest-services/rest-endpoints/commands/enabledCommands/markAsDeleted/access/roles/rest").getString()); |
144 |
1 |
assertEquals("rest-editor", session.getProperty("/modules/rest-services/rest-endpoints/commands/enabledCommands/activate/access/roles/rest").getString()); |
145 |
|
} |
146 |
|
} |