Clover Coverage Report - Kuali Student 1.1.0-SNAPSHOT (Aggregated)
Coverage timestamp: Tue Feb 15 2011 04:04:07 EST
../../../../../../img/srcFileCovDistChart0.png 48% of files have more coverage
44   129   13   7.33
10   91   0.3   6
6     2.17  
1    
 
  IntegrationServiceTestClassRunner       Line # 33 44 0% 13 60 0% 0.0
 
No Tests
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15   
16    package org.kuali.student.common.test.spring;
17   
18    import java.io.File;
19   
20    import org.junit.internal.runners.InitializationError;
21    import org.junit.internal.runners.JUnit4ClassRunner;
22    import org.junit.runner.notification.RunNotifier;
23    import org.mortbay.jetty.Connector;
24    import org.mortbay.jetty.Handler;
25    import org.mortbay.jetty.Server;
26    import org.mortbay.jetty.handler.DefaultHandler;
27    import org.mortbay.jetty.handler.HandlerCollection;
28    import org.mortbay.jetty.nio.SelectChannelConnector;
29    import org.mortbay.jetty.webapp.WebAppContext;
30    import org.slf4j.Logger;
31    import org.slf4j.LoggerFactory;
32   
 
33    public class IntegrationServiceTestClassRunner extends JUnit4ClassRunner {
34    final static Logger logger = LoggerFactory.getLogger(IntegrationServiceTestClassRunner.class);
35   
36    private Class<?> testClass;
37    private Server server;
38    private String webAppPath;
39    private String contextPath;
40    private int port = 9090;
41   
 
42  0 toggle public IntegrationServiceTestClassRunner(Class<?> klass) throws InitializationError {
43  0 super(klass);
44  0 testClass = klass;
45    }
46   
 
47  0 toggle private void getAnnotations() {
48  0 IntegrationServer webapp = this.testClass.getAnnotation(IntegrationServer.class);
49  0 this.port = webapp.port();
50  0 this.webAppPath = webapp.webappPath();
51  0 this.contextPath = webapp.contextPath();
52   
53  0 if (logger.isDebugEnabled()) {
54  0 logger.debug("port="+this.port);
55  0 logger.debug("webAppPath="+this.webAppPath);
56  0 logger.debug("contextPath="+this.contextPath);
57    }
58    }
59   
 
60  0 toggle private void setProperties() {
61  0 if (System.getProperty("catalina.base") == null) {
62  0 System.setProperty("catalina.base", "./target");
63    }
64   
65  0 SystemProperties systemProperties = this.testClass.getAnnotation(SystemProperties.class);
66  0 if (systemProperties != null) {
67  0 for(Property property : systemProperties.properties()) {
68  0 System.setProperty(property.key(), property.value());
69    }
70    }
71    }
72   
 
73  0 toggle @Override
74    public void run(RunNotifier notifier) {
75  0 startServer();
76  0 super.run(notifier);
77  0 stopServer();
78    }
79   
 
80  0 toggle private void startServer() {
81  0 getAnnotations();
82  0 setProperties();
83   
84  0 this.server = new Server();
85  0 Connector connector = new SelectChannelConnector();
86  0 connector.setPort(this.port);
87  0 this.server.setConnectors(new Connector[] { connector });
88   
89    // Metro: Additional debugging info to console
90    // com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true;
91   
92  0 String root = IntegrationServiceTestClassRunner.class.getResource("/").getPath();
93  0 File webAppsPath = new File(root + this.webAppPath);
94   
95  0 try {
96  0 if(!webAppsPath.isDirectory()) {
97  0 throw new RuntimeException("Webapps directory does not exist. " +
98    "Webapps directory must be an exploded (war) directory: " +
99    webAppsPath.getCanonicalPath());
100    }
101   
102  0 if (logger.isDebugEnabled()) {
103  0 logger.debug("WebApps Path="+webAppsPath.getCanonicalPath());
104    }
105   
106  0 WebAppContext webAppcontext = new WebAppContext();
107  0 webAppcontext.setParentLoaderPriority(true);
108  0 webAppcontext.setContextPath(this.contextPath); // e.g. /brms-ws-0.1.0-SNAPSHOT
109  0 webAppcontext.setWar(webAppsPath.getCanonicalPath());
110    //webAppcontext.setTempDirectory(new File(root));
111   
112  0 HandlerCollection handlers = new HandlerCollection();
113  0 handlers.setHandlers(new Handler[] { webAppcontext, new DefaultHandler() });
114  0 this.server.setHandler(handlers);
115   
116  0 this.server.start();
117    } catch (Exception e) {
118  0 throw new RuntimeException("Starting Jetty server failed", e);
119    }
120    }
121   
 
122  0 toggle private void stopServer() {
123  0 try {
124  0 this.server.stop();
125    } catch (Exception e) {
126  0 throw new RuntimeException("Stopping Jetty server failed", e);
127    }
128    }
129    }