Coverage Report - org.kuali.maven.plugins.WaitMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
WaitMojo
0%
0/32
0%
0/4
1.417
 
 1  
 package org.kuali.maven.plugins;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.List;
 5  
 
 6  
 import org.apache.commons.beanutils.BeanUtils;
 7  
 import org.apache.commons.lang.StringUtils;
 8  
 import org.apache.maven.plugin.AbstractMojo;
 9  
 import org.apache.maven.plugin.MojoExecutionException;
 10  
 import org.apache.maven.plugin.MojoFailureException;
 11  
 
 12  
 /**
 13  
  * Repeatedly contact the specified HTTP URL until a valid HTTP response code is returned or the maximum wait timeout is
 14  
  * exceeded, whichever comes first.
 15  
  * 
 16  
  * @author Jeff Caddel
 17  
  * @goal wait
 18  
  * @execute phase="validate"
 19  
  * @since 1.0
 20  
  */
 21  0
 public class WaitMojo extends AbstractMojo {
 22  
 
 23  
         /**
 24  
          * The url to contact
 25  
          * 
 26  
          * @parameter expression="${http.url}" default-value="http://localhost"
 27  
          */
 28  
         private String url;
 29  
 
 30  
         /**
 31  
          * The maximum number of seconds to wait for the url to respond correctly
 32  
          * 
 33  
          * @parameter expression="${http.timeout}" default-value="180"
 34  
          */
 35  
         private int timeout;
 36  
 
 37  
         /**
 38  
          * The maximum number of milliseconds to wait for an individual HTTP request to complete
 39  
          * 
 40  
          * @parameter expression="${http.requestTimeout}" default-value="3000"
 41  
          */
 42  
         private int requestTimeout;
 43  
 
 44  
         /**
 45  
          * The number of milliseconds to sleep in between HTTP requests
 46  
          * 
 47  
          * @parameter expression="${http.sleepInterval}" default-value="3000"
 48  
          */
 49  
         private int sleepInterval;
 50  
 
 51  
         /**
 52  
          * Comma separated list of HTTP status codes that represent success
 53  
          * 
 54  
          * @parameter expression="${http.successCodes}" default-value="200,302,304"
 55  
          */
 56  
         private String httpSuccessCodes;
 57  
 
 58  
         protected HttpInspector getHttpInspector() throws MojoExecutionException {
 59  0
                 HttpInspector inspector = new HttpInspector();
 60  
                 try {
 61  0
                         BeanUtils.copyProperties(inspector, this);
 62  0
                 } catch (Exception e) {
 63  0
                         throw new MojoExecutionException("Error copying properties", e);
 64  0
                 }
 65  0
                 String[] successCodeStrings = StringUtils.splitByWholeSeparator(httpSuccessCodes, ",");
 66  0
                 List<Integer> successCodeList = new ArrayList<Integer>();
 67  0
                 for (String successCodeString : successCodeStrings) {
 68  0
                         successCodeList.add(new Integer(successCodeString));
 69  
                 }
 70  0
                 inspector.setSuccessCodes(successCodeList);
 71  0
                 return inspector;
 72  
         }
 73  
 
 74  
         @Override
 75  
         public void execute() throws MojoExecutionException, MojoFailureException {
 76  0
                 HttpInspector inspector = getHttpInspector();
 77  0
                 boolean success = inspector.wait(url);
 78  0
                 if (!success) {
 79  0
                         throw new MojoExecutionException("Waiting for a response from '" + url + "' was not successful");
 80  
                 }
 81  0
         }
 82  
 
 83  
         public String getUrl() {
 84  0
                 return url;
 85  
         }
 86  
 
 87  
         public void setUrl(String url) {
 88  0
                 this.url = url;
 89  0
         }
 90  
 
 91  
         public int getTimeout() {
 92  0
                 return timeout;
 93  
         }
 94  
 
 95  
         public void setTimeout(int timeout) {
 96  0
                 this.timeout = timeout;
 97  0
         }
 98  
 
 99  
         public int getRequestTimeout() {
 100  0
                 return requestTimeout;
 101  
         }
 102  
 
 103  
         public void setRequestTimeout(int requestTimeout) {
 104  0
                 this.requestTimeout = requestTimeout;
 105  0
         }
 106  
 
 107  
         public int getSleepInterval() {
 108  0
                 return sleepInterval;
 109  
         }
 110  
 
 111  
         public void setSleepInterval(int sleepInterval) {
 112  0
                 this.sleepInterval = sleepInterval;
 113  0
         }
 114  
 
 115  
         public String getHttpSuccessCodes() {
 116  0
                 return httpSuccessCodes;
 117  
         }
 118  
 
 119  
         public void setHttpSuccessCodes(String httpSuccessCodes) {
 120  0
                 this.httpSuccessCodes = httpSuccessCodes;
 121  0
         }
 122  
 
 123  
 }