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.tools.setup; |
35 |
|
|
36 |
|
import static info.magnolia.test.hamcrest.NodeMatchers.*; |
37 |
|
import static org.hamcrest.CoreMatchers.not; |
38 |
|
import static org.junit.Assert.*; |
39 |
|
|
40 |
|
import info.magnolia.cms.security.MgnlRoleManager; |
41 |
|
import info.magnolia.cms.security.Permission; |
42 |
|
import info.magnolia.cms.security.SecuritySupport; |
43 |
|
import info.magnolia.cms.security.SecuritySupportImpl; |
44 |
|
import info.magnolia.context.MgnlContext; |
45 |
|
import info.magnolia.jcr.util.NodeTypes; |
46 |
|
import info.magnolia.jcr.util.NodeUtil; |
47 |
|
import info.magnolia.module.ModuleVersionHandler; |
48 |
|
import info.magnolia.module.ModuleVersionHandlerTestCase; |
49 |
|
import info.magnolia.module.model.Version; |
50 |
|
import info.magnolia.repository.RepositoryConstants; |
51 |
|
import info.magnolia.rest.RestDispatcherServlet; |
52 |
|
import info.magnolia.rest.tools.SwaggerRestDispatcherServlet; |
53 |
|
import info.magnolia.test.ComponentsTestUtil; |
54 |
|
|
55 |
|
import java.util.Arrays; |
56 |
|
import java.util.List; |
57 |
|
|
58 |
|
import javax.jcr.Node; |
59 |
|
import javax.jcr.Session; |
60 |
|
|
61 |
|
import org.junit.Before; |
62 |
|
import org.junit.Test; |
63 |
|
|
64 |
|
import io.swagger.jaxrs.listing.ApiListingResource; |
65 |
|
import io.swagger.jaxrs.listing.SwaggerSerializers; |
66 |
|
|
67 |
|
|
68 |
|
@link |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (41) |
Complexity: 6 |
Complexity Density: 0.17 |
|
70 |
|
public class RestToolsModuleVersionHandlerTest extends ModuleVersionHandlerTestCase { |
71 |
|
|
72 |
|
private static final String REST_DISPATCHER_SERVLET_PATH = "/server/filters/servlets/RestDispatcherServlet"; |
73 |
|
private static final String REST_INTEGRATION_MODULE_CONFIG_PATH = "/modules/rest-integration/config"; |
74 |
|
|
75 |
|
private Session configSession; |
76 |
|
private Session rolesSession; |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
2 |
@Override... |
79 |
|
protected String getModuleDescriptorPath() { |
80 |
2 |
return "/META-INF/magnolia/rest-tools.xml"; |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
2 |
@Override... |
84 |
|
protected List<String> getModuleDescriptorPathsForTests() { |
85 |
2 |
return Arrays.asList( |
86 |
|
"/META-INF/magnolia/core.xml" |
87 |
|
); |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
90 |
2 |
@Override... |
91 |
|
protected ModuleVersionHandler newModuleVersionHandlerForTests() { |
92 |
2 |
return new RestToolsModuleVersionHandler(); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
95 |
2 |
@Override... |
96 |
|
@Before |
97 |
|
public void setUp() throws Exception { |
98 |
2 |
super.setUp(); |
99 |
|
|
100 |
2 |
configSession = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); |
101 |
2 |
rolesSession = MgnlContext.getJCRSession(RepositoryConstants.USER_ROLES); |
102 |
|
|
103 |
|
|
104 |
2 |
final SecuritySupportImpl securitySupport = new SecuritySupportImpl(); |
105 |
2 |
securitySupport.setRoleManager(new MgnlRoleManager()); |
106 |
2 |
ComponentsTestUtil.setInstance(SecuritySupport.class, securitySupport); |
107 |
|
} |
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
109 |
1 |
@Test... |
110 |
|
public void basicInstall() throws Exception { |
111 |
|
|
112 |
1 |
Session session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); |
113 |
|
|
114 |
1 |
Node node = NodeUtil.createPath(session.getRootNode(), REST_DISPATCHER_SERVLET_PATH, NodeTypes.ContentNode.NAME); |
115 |
1 |
node.setProperty("servletClass", RestDispatcherServlet.class.getName()); |
116 |
|
|
117 |
1 |
NodeUtil.createPath(rolesSession.getRootNode(), "/rest-editor", NodeTypes.Role.NAME); |
118 |
|
|
119 |
1 |
NodeUtil.createPath(session.getRootNode(), REST_INTEGRATION_MODULE_CONFIG_PATH, NodeTypes.ContentNode.NAME); |
120 |
1 |
NodeUtil.createPath(session.getRootNode(), REST_INTEGRATION_MODULE_CONFIG_PATH + "/additionalProviders", NodeTypes.ContentNode.NAME); |
121 |
|
|
122 |
|
|
123 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null); |
124 |
|
|
125 |
|
|
126 |
1 |
assertThat(session.getNode(REST_DISPATCHER_SERVLET_PATH), hasProperty("servletClass", SwaggerRestDispatcherServlet.class.getName())); |
127 |
1 |
assertEquals(1, rolesSession.getNode("/rest-editor/acl_uri").getNodes().getSize()); |
128 |
1 |
assertThat(session.getNode(REST_INTEGRATION_MODULE_CONFIG_PATH + "/additionalProviders/apiListingResource"), hasProperty("providerClass", ApiListingResource.class.getName())); |
129 |
1 |
assertThat(session.getNode(REST_INTEGRATION_MODULE_CONFIG_PATH + "/additionalProviders/swaggerSerializers"), hasProperty("providerClass", SwaggerSerializers.class.getName())); |
130 |
|
} |
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
132 |
1 |
@Test... |
133 |
|
public void updateFrom1_1_2() throws Exception { |
134 |
|
|
135 |
1 |
setupConfigProperty("/modules/rest-integration/config/additionalProviders/apiDeclarationProvider", "providerClass", "com.whatever.it.was.Before"); |
136 |
1 |
setupConfigProperty("/modules/rest-integration/config/additionalProviders/resourceListingProvider", "providerClass", "com.whatever.it.was.Before"); |
137 |
1 |
setupConfigProperty("/modules/rest-tools/config", "apiVersion", "1.0.0"); |
138 |
|
|
139 |
1 |
setupConfigProperty("/modules/rest-tools/apps/restTools/subApps/apiDocs", "url", "/.resources/swagger-ui/index.html"); |
140 |
|
|
141 |
1 |
Node restRoleNode = NodeUtil.createPath(rolesSession.getRootNode(), "/rest", NodeTypes.Role.NAME); |
142 |
1 |
Node legacyAcl = NodeUtil.createPath(restRoleNode, "acl_uri/02", NodeTypes.ContentNode.NAME); |
143 |
1 |
legacyAcl.setProperty("path", "/.rest/api-docs*"); |
144 |
1 |
legacyAcl.setProperty("permissions", Permission.ALL); |
145 |
|
|
146 |
|
|
147 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("1.1.2")); |
148 |
|
|
149 |
|
|
150 |
1 |
assertThat(configSession.getNode("/modules/rest-integration/config/additionalProviders/apiListingResource"), hasProperty("providerClass", ApiListingResource.class.getName())); |
151 |
1 |
assertThat(configSession.getNode("/modules/rest-integration/config/additionalProviders/swaggerSerializers"), hasProperty("providerClass", SwaggerSerializers.class.getName())); |
152 |
1 |
assertThat(configSession.getNode("/modules/rest-tools/config"), hasProperty("apiVersion", "1.5.4")); |
153 |
|
|
154 |
1 |
assertThat(rolesSession.getNode("/rest/acl_uri"), hasNode(hasProperty("path", "/.rest/swagger*"))); |
155 |
1 |
assertThat(rolesSession.getNode("/rest/acl_uri"), not(hasNode(hasProperty("path", "/.rest/api-docs*")))); |
156 |
1 |
assertThat(configSession.getNode("/modules/rest-tools/apps/restTools/subApps/apiDocs"), hasProperty("url", "/.resources/rest-tools/webresources/swagger-ui/index.html")); |
157 |
|
} |
158 |
|
} |