Skip to content

Commit

Permalink
Ammending JENKINS-25593
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNielsen committed Nov 19, 2014
1 parent 312e108 commit 4b2b302
Show file tree
Hide file tree
Showing 23 changed files with 194 additions and 316 deletions.
6 changes: 6 additions & 0 deletions src/main/java/net/praqma/jenkins/rqm/RqmBuilder.java
Expand Up @@ -48,6 +48,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
Expand Down Expand Up @@ -133,6 +134,11 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
collectionStrategy.setup(getGlobalHostName(), getGlobalContextRoot(), getGlobalUsrName(), getGlobalPasswd(), getGlobalPort());
results = collectionStrategy.withCredentials(credentialId).collect(listener, build);
success = collectionStrategy.withCredentials(credentialId).execute(build, listener, launcher, preBuildSteps, postBuildSteps, iterativeTestCaseBuilders, results);
} catch (TimeoutException ex) {
console.println(String.format("Unable to complete retrieval of RQM data, timeout exceeded"));
log.logp(Level.SEVERE, this.getClass().getName(), "perform", "Timeout", ex);
success = false;
throw new AbortException("Unable to complete retrieval of RQM data, timeout exceeded. Trace written to log.");
} catch (Exception ex) {
success = false;
console.println(String.format("Failed to retrieve relevant test data.%n%s", ex.getMessage()));
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/net/praqma/jenkins/rqm/RqmCollector.java
Expand Up @@ -42,10 +42,14 @@
*/
public abstract class RqmCollector extends AbstractDescribableImpl<RqmCollector> implements ExtensionPoint {

@Deprecated
private String passwd;

@Deprecated
private String usrName;

private String hostName;
private String contextRoot;
private String usrName;
private String passwd;
private int port;
protected String credentialId;

Expand Down Expand Up @@ -140,27 +144,31 @@ public void setContextRoot(String contextRoot) {
/**
* @return the usrName
*/
@Deprecated
public String getUsrName() {
return usrName;
}

/**
* @param usrName the usrName to set
*/
@Deprecated
public void setUsrName(String usrName) {
this.usrName = usrName;
}

/**
* @return the passwd
*/
@Deprecated
public String getPasswd() {
return passwd;
}

/**
* @param passwd the passwd to set
*/
@Deprecated
public void setPasswd(String passwd) {
this.passwd = passwd;
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/net/praqma/jenkins/rqm/RqmObjectCreator.java
Expand Up @@ -24,6 +24,7 @@
package net.praqma.jenkins.rqm;

import hudson.FilePath;
import hudson.model.BuildListener;
import hudson.remoting.VirtualChannel;
import java.io.File;
import java.io.IOException;
Expand All @@ -38,19 +39,21 @@
*/
public class RqmObjectCreator<T extends RqmObject> implements FilePath.FileCallable<List<T>> {
private final RqmParameterList parameters;
private final BuildListener listener;
private final T target;

public RqmObjectCreator(Class<T> target, RqmParameterList parameters) throws IllegalAccessException, InstantiationException {
public RqmObjectCreator(Class<T> target, RqmParameterList parameters, BuildListener listener) throws IllegalAccessException, InstantiationException {
this.parameters = parameters;
this.listener = listener;
this.target = target.newInstance();
}

@Override
public List<T> invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
if(parameters.methodType.equals("GET")) {
return (List<T>)target.readMultiple(parameters);
return (List<T>)target.readMultiple(parameters, listener);
} else {
return (List<T>)target.createOrUpdate(parameters);
return (List<T>)target.createOrUpdate(parameters, listener);
}
}
}
51 changes: 0 additions & 51 deletions src/main/java/net/praqma/jenkins/rqm/cli/PrqmCli.java

This file was deleted.

Expand Up @@ -36,11 +36,13 @@
import hudson.model.EnvironmentContributingAction;
import hudson.model.Result;
import hudson.model.Run;
import hudson.remoting.Future;
import hudson.tasks.BuildStep;
import hudson.util.Secret;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import net.praqma.jenkins.rqm.RqmBuilder;
import net.praqma.jenkins.rqm.RqmCollector;
Expand All @@ -67,23 +69,35 @@ public class RqmTestSuiteExectionRecordCollectionStrategy extends RqmCollector {
private static final Logger log = Logger.getLogger(RqmTestSuiteExectionRecordCollectionStrategy.class.getName());
public final String executionRecordName;
public final String projectName;

@Deprecated
public transient String planName;
private String planName;

public RqmTestSuiteExectionRecordCollectionStrategy() {
this("exrecor","planname","projname");
}

@DataBoundConstructor
public RqmTestSuiteExectionRecordCollectionStrategy(final String executionRecordName, final String planName, final String projectName) {
this.planName = planName;
this.executionRecordName = executionRecordName;
this.projectName = projectName;
}

/**
* @return the planName
*/
public String getPlanName() {
return planName;
}

/**
* @param planName the planName to set
*/
public void setPlanName(String planName) {
this.planName = planName;
}

@Extension
public static class RqmTestSuiteCollectionStrategyImpl extends RqmCollectorDescriptor {

public static class RqmTestSuiteCollectionStrategyImpl extends RqmCollectorDescriptor {
@Override
public String getDisplayName() {
return "Test suite exection record selection stategy";
Expand All @@ -92,24 +106,32 @@ public String getDisplayName() {

@Override
public <T extends RqmObject> List<T> collect(BuildListener listener, AbstractBuild<?, ?> build) throws Exception {
NameValuePair[] filterProperties = TestSuiteExecutionRecord.getFilteringProperties(executionRecordName);
NameValuePair[] filterProperties = TestSuiteExecutionRecord.getFilteringProperties(executionRecordName, planName);
String request = TestSuiteExecutionRecord.getResourceFeedUrl(getHostName(), getPort(), getContextRoot(), projectName);
listener.getLogger().println( String.format ("Resource request feed is %s", request) );

RqmParameterList list;
if(!StringUtils.isBlank(credentialId) && !credentialId.equals("none")) {
listener.getLogger().println("Using credentials");
StandardUsernameCredentials usrName = CredentialsProvider.findCredentialById(credentialId, StandardUsernameCredentials.class, build, Collections.EMPTY_LIST);
UsernamePasswordCredentials userPasswordCreds = (UsernamePasswordCredentials)usrName;
String pw = Secret.toString(userPasswordCreds.getPassword());
list = new RqmParameterList(getHostName(), getPort(), getContextRoot(), projectName, userPasswordCreds.getUsername(), pw, request, filterProperties, "GET", null);
UsernamePasswordCredentials userPasswordCreds = (UsernamePasswordCredentials)usrName;
list = new RqmParameterList(getHostName(), getPort(), getContextRoot(), projectName, userPasswordCreds, request, filterProperties, "GET", null);
} else {
listener.getLogger().println("Using legacy");
list = new RqmParameterList(getHostName(), getPort(), getContextRoot(), projectName, getUsrName(), getPasswd(), request, filterProperties, "GET", null);
}

RqmObjectCreator<TestSuiteExecutionRecord> object = new RqmObjectCreator<TestSuiteExecutionRecord>(TestSuiteExecutionRecord.class, list);
return (List<T>)build.getWorkspace().act(object);
/*
TODO:
Get a list of all plans in the current project. We need to do this since the feed-url does NOT allow us to filter based on names of a test when looking for test
suite execution records.
*/


RqmObjectCreator<TestSuiteExecutionRecord> object = new RqmObjectCreator<TestSuiteExecutionRecord>(TestSuiteExecutionRecord.class, list, listener);
Future<List<TestSuiteExecutionRecord>> result = build.getWorkspace().actAsync(object);
return (List<T>) result.get(20, TimeUnit.MINUTES);

}

@Override
Expand All @@ -121,13 +143,14 @@ public boolean execute(AbstractBuild<?, ?> build, BuildListener listener, Launch

List<TestSuiteExecutionRecord> records = (List<TestSuiteExecutionRecord>)results;

for(TestSuiteExecutionRecord tser : records) {

for(TestSuiteExecutionRecord tser : records) {
for(TestCase tc : tser.getAllTestCases()) {
totalNumberOfScripts += tc.getScripts().size();
}
}

listener.getLogger().println(String.format("Found %s test cases", totalNumberOfScripts));

if(preBuildSteps != null) {
listener.getLogger().println(String.format("Performing pre build step"));
for (BuildStep bs : preBuildSteps) {
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/net/praqma/jenkins/rqm/model/RqmObject.java
Expand Up @@ -3,6 +3,7 @@
* and open the template in the editor.
*/
package net.praqma.jenkins.rqm.model;
import hudson.model.BuildListener;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -187,9 +188,9 @@ public int getInternalId() throws RQMObjectParseException{
* @return a 'constructed' rqm object. Read populates the object given an array of parameters
* @throws IOException
*/
public List<T> read(RqmParameterList parameters) throws IOException { return null; }
public List<T> readMultiple( RqmParameterList parameters ) throws IOException {
return read(parameters);
public List<T> read(RqmParameterList parameters, BuildListener listener) throws IOException { return null; }
public List<T> readMultiple( RqmParameterList parameters, BuildListener listener ) throws IOException {
return read(parameters, listener);
}

/**
Expand All @@ -199,15 +200,15 @@ public List<T> readMultiple( RqmParameterList parameters ) throws IOException {
* @return Create or updates the object given an array of parameters. Use the initializeSingleResource() method to parse the object given the returned XML
* @throws IOException
*/
public List<T> createOrUpdate(RqmParameterList parameters) throws IOException { return null; }
public List<T> createOrUpdate(RqmParameterList parameters, BuildListener listener) throws IOException { return null; }

public HashMap<String,String> attributes() {
return new HashMap<String, String>();
}

public static <T extends RqmObject> T createObject(Class<T> clazz, RqmParameterList parameters) throws InstantiationException, IllegalAccessException, IOException {
public static <T extends RqmObject> T createObject(Class<T> clazz, RqmParameterList parameters, BuildListener listener) throws InstantiationException, IllegalAccessException, IOException {
T t = clazz.newInstance();
t.read(parameters);
t.read(parameters, listener);
return t;
}
}
7 changes: 4 additions & 3 deletions src/main/java/net/praqma/jenkins/rqm/model/TestCase.java
Expand Up @@ -4,6 +4,7 @@
*/
package net.praqma.jenkins.rqm.model;

import hudson.model.BuildListener;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -74,10 +75,10 @@ public void setTestCaseTitle(String testCaseTitle) {
}

@Override
public List<TestCase> read(RqmParameterList parameters) throws IOException {
public List<TestCase> read(RqmParameterList parameters, BuildListener listener) throws IOException {
RQMHttpClient client = null;
try {
client = RQMUtilities.createClient(parameters.hostName, parameters.port, parameters.contextRoot, parameters.projectName, parameters.userName, parameters.passwd);
client = RQMUtilities.createClient(parameters);
} catch (MalformedURLException ex) {
log.logp(Level.SEVERE, this.getClass().getName(), "read", "Caught MalformedURLException in read throwing IO Exception",ex);
throw new IOException("RqmMethodInvoker exception", ex);
Expand Down Expand Up @@ -109,7 +110,7 @@ public HashMap<String, String> attributes() {
}

@Override
public List<TestCase> createOrUpdate(RqmParameterList parameters) {
public List<TestCase> createOrUpdate(RqmParameterList parameters, BuildListener listener) {
throw new UnsupportedOperationException("Not supported yet.");
}

Expand Down
Expand Up @@ -4,6 +4,7 @@
*/
package net.praqma.jenkins.rqm.model;

import hudson.model.BuildListener;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -42,12 +43,12 @@ public TestCaseExecutionRecord initializeSingleResource(String xml) throws RQMOb
}

@Override
public List<TestCaseExecutionRecord> read(RqmParameterList parameters) throws IOException {
public List<TestCaseExecutionRecord> read(RqmParameterList parameters, BuildListener listener) throws IOException {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public List<TestCaseExecutionRecord> createOrUpdate(RqmParameterList parameters) throws IOException {
public List<TestCaseExecutionRecord> createOrUpdate(RqmParameterList parameters, BuildListener listener) throws IOException {
throw new UnsupportedOperationException("Not implemented yet");
}

Expand Down

0 comments on commit 4b2b302

Please sign in to comment.