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.module.blossom.suite; |
35 |
|
|
36 |
|
import static org.junit.Assert.fail; |
37 |
|
|
38 |
|
import javax.servlet.ServletContext; |
39 |
|
|
40 |
|
import org.junit.After; |
41 |
|
import org.junit.Before; |
42 |
|
import org.springframework.mock.web.MockServletContext; |
43 |
|
|
44 |
|
import info.magnolia.module.blossom.dialog.DialogCreationContext; |
45 |
|
import info.magnolia.module.blossom.dialog.DialogCreationContextHolder; |
46 |
|
import info.magnolia.module.blossom.module.BlossomModuleSupport; |
47 |
|
import info.magnolia.module.site.DefaultSiteManager; |
48 |
|
import info.magnolia.module.site.SiteManager; |
49 |
|
import info.magnolia.module.site.functions.SiteFunctions; |
50 |
|
import info.magnolia.objectfactory.Components; |
51 |
|
import info.magnolia.registry.RegistrationException; |
52 |
|
import info.magnolia.rendering.template.TemplateAvailability; |
53 |
|
import info.magnolia.rendering.template.configured.DefaultTemplateAvailability; |
54 |
|
import info.magnolia.repository.RepositoryConstants; |
55 |
|
import info.magnolia.test.ComponentsTestUtil; |
56 |
|
import info.magnolia.test.MgnlTestCase; |
57 |
|
import info.magnolia.test.mock.MockUtil; |
58 |
|
import info.magnolia.test.mock.jcr.MockSession; |
59 |
|
import info.magnolia.test.mock.jcr.SessionTestUtil; |
60 |
|
import info.magnolia.ui.dialog.definition.DialogDefinition; |
61 |
|
import info.magnolia.ui.dialog.registry.DialogDefinitionRegistry; |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
@since |
68 |
|
|
|
|
| 95% |
Uncovered Elements: 2 (40) |
Complexity: 9 |
Complexity Density: 0.28 |
|
69 |
|
public abstract class AbstractBlossomTestCase extends MgnlTestCase { |
70 |
|
|
71 |
|
protected MockSession session; |
72 |
|
protected BlossomModuleSupport moduleSupport; |
73 |
|
protected MockServletContext servletContext; |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 2 |
Complexity Density: 0.13 |
|
75 |
3 |
@Override... |
76 |
|
@Before |
77 |
|
public void setUp() throws Exception { |
78 |
3 |
super.setUp(); |
79 |
|
|
80 |
3 |
ComponentsTestUtil.setImplementation(TemplateAvailability.class, DefaultTemplateAvailability.class); |
81 |
|
|
82 |
3 |
DefaultSiteManager siteManager = new DefaultSiteManager(null, null); |
83 |
3 |
SiteFunctions siteFunctions = new SiteFunctions(siteManager, null, null); |
84 |
3 |
ComponentsTestUtil.setInstance(SiteManager.class, siteManager); |
85 |
3 |
ComponentsTestUtil.setInstance(SiteFunctions.class, siteFunctions); |
86 |
|
|
87 |
3 |
session = SessionTestUtil.createSession(RepositoryConstants.CONFIG, "/modules/blossom"); |
88 |
|
|
89 |
3 |
MockUtil.setSystemContextSessionAndHierarchyManager(session); |
90 |
|
|
91 |
3 |
servletContext = new MockServletContext(); |
92 |
|
|
93 |
3 |
servletContext = new MockServletContext(); |
94 |
3 |
moduleSupport = new BlossomModuleSupport() { |
95 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
96 |
|
@Override... |
97 |
|
public ServletContext getServletContext() { |
98 |
|
return servletContext; |
99 |
|
} |
100 |
|
}; |
101 |
|
|
102 |
3 |
String rootWebApplicationConfigLocation = getRootWebApplicationConfigLocation(); |
103 |
3 |
if (rootWebApplicationConfigLocation != null) { |
104 |
1 |
moduleSupport.initRootWebApplicationContext(rootWebApplicationConfigLocation); |
105 |
|
} |
106 |
|
|
107 |
3 |
moduleSupport.initBlossomDispatcherServlet("blossom", getDispatcherServletConfigLocation()); |
108 |
|
} |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
110 |
3 |
@After... |
111 |
|
@Override |
112 |
|
public void tearDown() throws Exception { |
113 |
3 |
moduleSupport.destroyDispatcherServlets(); |
114 |
3 |
moduleSupport.closeRootWebApplicationContext(); |
115 |
3 |
ComponentsTestUtil.clear(); |
116 |
3 |
super.tearDown(); |
117 |
|
} |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
119 |
1 |
protected String getRootWebApplicationConfigLocation() {... |
120 |
1 |
return null; |
121 |
|
} |
122 |
|
|
123 |
|
protected abstract String getDispatcherServletConfigLocation(); |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
125 |
8 |
protected DialogDefinition getDialogDefinition(String id) throws RegistrationException {... |
126 |
8 |
DialogDefinitionRegistry dialogDefinitionRegistry = Components.getComponent(DialogDefinitionRegistry.class); |
127 |
8 |
try { |
128 |
8 |
DialogCreationContext context = new DialogCreationContext(); |
129 |
8 |
DialogCreationContextHolder.set(context); |
130 |
8 |
return dialogDefinitionRegistry.getDialogDefinition(id); |
131 |
|
} finally { |
132 |
8 |
DialogCreationContextHolder.remove(); |
133 |
|
} |
134 |
|
} |
135 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
136 |
2 |
protected void assertDialogIsNotRegistered(String id) {... |
137 |
2 |
try { |
138 |
2 |
getDialogDefinition(id); |
139 |
0 |
fail("Dialog [" + id + "] should not be registered"); |
140 |
|
} catch (RegistrationException e) { |
141 |
|
|
142 |
|
} |
143 |
|
} |
144 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
145 |
6 |
protected void assertDialogIsRegistered(String id) {... |
146 |
6 |
try { |
147 |
6 |
getDialogDefinition(id); |
148 |
|
} catch (RegistrationException e) { |
149 |
0 |
fail("Dialog [" + id + "] is not registered"); |
150 |
|
} |
151 |
|
} |
152 |
|
} |