com.greenpepper.runner.repository.GreenPepperRepository Maven / Gradle / Ivy
package com.greenpepper.runner.repository;
import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
import com.greenpepper.dialect.SpecificationDialect;
import com.greenpepper.repository.DocumentNode;
import com.greenpepper.shaded.org.apache.xmlrpc.XmlRpcClient;
import com.greenpepper.shaded.org.apache.xmlrpc.XmlRpcException;
import com.greenpepper.shaded.org.apache.xmlrpc.XmlRpcRequest;
import com.greenpepper.Example;
import com.greenpepper.Statistics;
import com.greenpepper.document.Document;
import com.greenpepper.document.SpecificationListener;
import com.greenpepper.report.XmlReport;
import com.greenpepper.repository.DocumentNotFoundException;
import com.greenpepper.repository.DocumentRepository;
import com.greenpepper.repository.UnsupportedDocumentException;
import com.greenpepper.util.ClassUtils;
import com.greenpepper.util.CollectionUtil;
import com.greenpepper.util.ExceptionImposter;
import com.greenpepper.util.StringUtil;
import com.greenpepper.util.URIUtil;
/**
* GreenPepperRepository class.
*
* @author oaouattara
* @version $Id: $Id
*/
public class GreenPepperRepository implements DocumentRepository
{
private URI root;
private String handler;
private String sut;
private boolean includeStyle;
private Boolean implemented;
private boolean postExecutionResult;
private String username = "";
private String password = "";
private SpecificationDialect specificationDialect;
/**
* Constructor for GreenPepperRepository.
*
* @param args a {@link java.lang.String} object.
* @throws java.lang.Exception if any.
*/
public GreenPepperRepository(String... args) throws Exception
{
if (args.length == 0) throw new IllegalArgumentException("No root specified");
this.root = URI.create(URIUtil.raw(args[0]));
String includeAtt = URIUtil.getAttribute(root, "includeStyle");
includeStyle = includeAtt == null || Boolean.valueOf(includeAtt);
String implementedAtt = URIUtil.getAttribute(root, "implemented");
if(implementedAtt != null)
implemented = Boolean.parseBoolean(implementedAtt);
handler = URIUtil.getAttribute(root, "handler");
if(handler == null) throw new IllegalArgumentException("No handler specified");
sut = URIUtil.getAttribute(root, "sut");
if(sut == null) throw new IllegalArgumentException("No sut specified");
String postExecutionResultAtt = URIUtil.getAttribute(root, "postExecutionResult");
if(postExecutionResultAtt != null)
postExecutionResult = Boolean.parseBoolean(postExecutionResultAtt);
if (args.length == 3)
{
username = args[1];
password = args[2];
}
}
/** {@inheritDoc} */
public void setDocumentAsImplemeted(String location) throws Exception
{
throw new UnsupportedOperationException("Not supported");
}
@Override
public DocumentNode getSpecificationsHierarchy(String project, String systemUnderTest) {
// TODO
throw new UnsupportedOperationException("This functionnality is not yet implemented!");
}
@Override
public void setSpecificationDialect(SpecificationDialect specificationDialect) {
this.specificationDialect = specificationDialect;
}
/** {@inheritDoc} */
public List listDocuments(String uri) throws Exception
{
List documentsURI = new ArrayList();
String repoUID = getPath(uri);
if (repoUID == null) throw new UnsupportedDocumentException("Missing repo UID");
Vector> definitions = downloadSpecificationsDefinitions(repoUID);
for(Vector definition : definitions)
{
String docName = repoUID + "/" + definition.get(4);
documentsURI.add(docName);
}
return documentsURI;
}
private String getPath(String uri)
{
return URI.create(URIUtil.raw(uri)).getPath();
}
@SuppressWarnings("unchecked")
private Vector> downloadSpecificationsDefinitions(String repoUID) throws Exception
{
Vector> definitions = (Vector>) getXmlRpcClient().execute(
new XmlRpcRequest( handler + ".getListOfSpecificationLocations", CollectionUtil.toVector(repoUID, sut)) );
checkForErrors(definitions);
return definitions;
}
/**
* listDocumentsInHierarchy.
*
* @return a {@link java.util.List} object.
* @throws java.lang.Exception if any.
*/
public List