Coverage Report - org.jbehave.core.io.rest.LoadFromREST
 
Classes in this File Line Coverage Branch Coverage Complexity
LoadFromREST
73%
11/15
N/A
1.429
 
 1  
 package org.jbehave.core.io.rest;
 2  
 
 3  
 import org.jbehave.core.io.InvalidStoryResource;
 4  
 import org.jbehave.core.io.ResourceLoader;
 5  
 import org.jbehave.core.io.rest.RESTClient.Type;
 6  
 
 7  
 /**
 8  
  * Loads resource from REST
 9  
  */
 10  
 public class LoadFromREST implements ResourceLoader {
 11  
 
 12  
     private RESTClient client; 
 13  
     
 14  
     public LoadFromREST(Type type) {
 15  0
         this(type, null, null);
 16  0
     }
 17  
 
 18  8
     public LoadFromREST(Type type, String username, String password) {
 19  8
         this.client = new RESTClient(type, username, password);
 20  8
     }
 21  
     
 22  1
     public LoadFromREST(RESTClient client) {
 23  1
         this.client = client;
 24  1
     }
 25  
     
 26  
     public String loadResourceAsText(String resourcePath) {
 27  
                 try {
 28  1
                         Type type = client.getType();
 29  1
             return text(get(uri(resourcePath, type)), type);
 30  0
                 } catch (Exception cause) {
 31  0
                         throw new InvalidStoryResource(resourcePath, cause);
 32  
                 }
 33  
         }
 34  
 
 35  
         protected String uri(String resourcePath, Type type) {
 36  1
                 return resourcePath;
 37  
         }
 38  
 
 39  
         protected String text(String entity, Type type) {
 40  1
                 return entity;
 41  
         }
 42  
 
 43  
         private String get(String uri) {
 44  1
                 return client.get(uri);
 45  
         }
 46  
 
 47  
 }