1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.rice.test; |
17 |
|
|
18 |
|
import java.lang.reflect.Method; |
19 |
|
import java.util.ArrayList; |
20 |
|
import java.util.Arrays; |
21 |
|
import java.util.HashSet; |
22 |
|
import java.util.List; |
23 |
|
import java.util.Set; |
24 |
|
|
25 |
|
import org.apache.commons.lang.StringUtils; |
26 |
|
import org.kuali.rice.core.api.config.property.ConfigContext; |
27 |
|
import org.kuali.rice.core.api.lifecycle.Lifecycle; |
28 |
|
import org.kuali.rice.test.lifecycles.JettyServerLifecycle; |
29 |
|
import org.kuali.rice.test.server.JettyServer; |
30 |
|
import org.kuali.rice.test.server.JettyServers; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@author |
40 |
|
|
|
|
| 0% |
Uncovered Elements: 64 (64) |
Complexity: 18 |
Complexity Density: 0.43 |
|
41 |
|
public abstract class JettyServerTestCase extends BaselineTestCase { |
42 |
|
private static Set<String> classesHandled = new HashSet<String>(); |
43 |
|
|
44 |
|
|
45 |
|
@see@link |
46 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
0
|
public JettyServerTestCase(String moduleName, Mode mode) {... |
48 |
0
|
super(moduleName, mode); |
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
|
@see@link |
53 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
0
|
public JettyServerTestCase(String moduleName) {... |
55 |
0
|
super(moduleName); |
56 |
|
} |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
0
|
private List<JettyServer> readPerTestDefinitions(Method method) {... |
59 |
0
|
return getJettyServerDefinitions((JettyServers) method.getAnnotation(JettyServers.class), (JettyServer) method.getAnnotation(JettyServer.class)); |
60 |
|
} |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
0
|
private List<JettyServer> readSuiteServerDefinitions(Class clazz) {... |
63 |
0
|
return getJettyServerDefinitions((JettyServers) clazz.getAnnotation(JettyServers.class), (JettyServer) clazz.getAnnotation(JettyServer.class)); |
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
66 |
0
|
private List<JettyServer> getJettyServerDefinitions(JettyServers servers, JettyServer server) {... |
67 |
0
|
List<JettyServer> defs = new ArrayList<JettyServer>(); |
68 |
0
|
if (servers != null) { |
69 |
0
|
if (servers.servers() != null) { |
70 |
0
|
defs.addAll(Arrays.asList(servers.servers())); |
71 |
|
} |
72 |
|
} |
73 |
0
|
if (server != null) { |
74 |
0
|
defs.add(server); |
75 |
|
} |
76 |
0
|
return defs; |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 7 |
Complexity Density: 0.5 |
|
79 |
0
|
protected JettyServerLifecycle constructJettyServerLifecycle(JettyServer def) {... |
80 |
0
|
String portConfigParam = def.portConfigParam(); |
81 |
0
|
if (StringUtils.isBlank(portConfigParam)) { |
82 |
0
|
portConfigParam = null; |
83 |
|
} |
84 |
0
|
if (def.port() != JettyServer.CONFIG_PARAM_PORT && portConfigParam != null) { |
85 |
0
|
throw new IllegalArgumentException("Either but not both of port or portConfigParam must be specified on JettyServer annotation"); |
86 |
|
} |
87 |
0
|
if (def.port() == JettyServer.CONFIG_PARAM_PORT && portConfigParam == null) { |
88 |
0
|
portConfigParam = "unittest.jetty." + def.context() + ".port"; |
89 |
|
} |
90 |
0
|
JettyServerLifecycle lc; |
91 |
0
|
if (def.port() != JettyServer.CONFIG_PARAM_PORT) { |
92 |
0
|
lc = new RuntimePortJettyServerLifecycle(def.port(), "/" + def.context(), def.webapp()); |
93 |
|
} else { |
94 |
0
|
lc = new RuntimePortJettyServerLifecycle(def.portConfigParam(), "/" + def.context(), def.webapp()); |
95 |
|
} |
96 |
0
|
lc.setConfigMode(def.configMode()); |
97 |
0
|
lc.setAddWebappResourceLoaders(def.addWebappResourceLoader()); |
98 |
0
|
return lc; |
99 |
|
} |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.17 |
|
101 |
0
|
@Override... |
102 |
|
protected List<Lifecycle> getSuiteLifecycles() { |
103 |
0
|
List<Lifecycle> lifecycles = super.getSuiteLifecycles(); |
104 |
0
|
List<Class> classesToHandle; |
105 |
0
|
try { |
106 |
0
|
classesToHandle = TestUtilities.getHierarchyClassesToHandle(this.getClass(), new Class[] { JettyServers.class, JettyServer.class }, classesHandled); |
107 |
|
} catch (Exception e) { |
108 |
0
|
throw new RuntimeException("Error determining classes to handle", e); |
109 |
|
} |
110 |
0
|
List<JettyServer> suiteDefs = new ArrayList<JettyServer>(); |
111 |
0
|
for (Class c: classesToHandle) { |
112 |
0
|
suiteDefs.addAll(readSuiteServerDefinitions(c)); |
113 |
0
|
classesHandled.add(c.getName()); |
114 |
|
} |
115 |
|
|
116 |
0
|
for (JettyServer def: suiteDefs) { |
117 |
0
|
lifecycles.add(constructJettyServerLifecycle(def)); |
118 |
|
} |
119 |
0
|
return lifecycles; |
120 |
|
} |
121 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
122 |
0
|
@Override... |
123 |
|
protected List<Lifecycle> getPerTestLifecycles() { |
124 |
0
|
List<Lifecycle> lifecycles = super.getPerTestLifecycles(); |
125 |
0
|
List<JettyServer> defs = readPerTestDefinitions(method); |
126 |
|
|
127 |
0
|
for (JettyServer def: defs) { |
128 |
0
|
lifecycles.add(constructJettyServerLifecycle(def)); |
129 |
|
} |
130 |
0
|
return lifecycles; |
131 |
|
} |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
133 |
|
private static final class RuntimePortJettyServerLifecycle extends JettyServerLifecycle { |
134 |
|
private String portConfigParam; |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
135 |
0
|
public RuntimePortJettyServerLifecycle(int port, String contextName, String relativeWebappRoot) {... |
136 |
0
|
super(port, contextName, relativeWebappRoot); |
137 |
|
} |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
138 |
0
|
public RuntimePortJettyServerLifecycle(String portConfigParam, String contextName, String relativeWebappRoot) {... |
139 |
0
|
super(JettyServer.CONFIG_PARAM_PORT, contextName, relativeWebappRoot); |
140 |
0
|
this.portConfigParam = portConfigParam; |
141 |
|
} |
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
142 |
0
|
public void start() throws Exception {... |
143 |
0
|
if (jettyServer.getPort() == JettyServer.CONFIG_PARAM_PORT) { |
144 |
0
|
String val = ConfigContext.getCurrentContextConfig().getProperty(portConfigParam); |
145 |
0
|
if (val == null) { |
146 |
0
|
throw new RuntimeException("Jetty port not found in config param: " + portConfigParam); |
147 |
|
} |
148 |
0
|
jettyServer.setPort(Integer.parseInt(val)); |
149 |
|
} |
150 |
0
|
super.start(); |
151 |
|
} |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
152 |
0
|
@Override... |
153 |
|
public void stop() throws Exception { |
154 |
0
|
System.err.println("Shutting down jetty"); |
155 |
0
|
super.stop(); |
156 |
|
} |
157 |
|
} |
158 |
|
} |