Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implemented JENKINS-24553
  • Loading branch information
MadsNielsen committed Sep 4, 2014
1 parent a281b8b commit 649c45f
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 30 deletions.
31 changes: 27 additions & 4 deletions src/main/java/net/praqma/jenkins/rqm/RqmBuildAction.java
Expand Up @@ -26,6 +26,7 @@
import hudson.model.Action;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import net.praqma.jenkins.rqm.model.RqmObject;
import net.praqma.jenkins.rqm.model.TestCase;
import net.praqma.jenkins.rqm.model.TopLevelObject;
Expand Down Expand Up @@ -59,14 +60,36 @@ public String getUrlName() {
return NAME.replaceAll(" ", "");
}

//TODO: Implement me
public List<TestCase> getSelectedTestCases() {
List<TestCase> testcases = new ArrayList<TestCase>();
for(RqmObject obj : topLevelObjects) {
if(obj instanceof TopLevelObject) {
testcases.addAll(((TopLevelObject)obj).getAllTestCases());
if(topLevelObjects != null) {
for(RqmObject obj : topLevelObjects) {
if(obj instanceof TopLevelObject) {
testcases.addAll(((TopLevelObject)obj).getAllTestCases());
}
}
}
return testcases;
}

public List<TestCase> getFailedTests() {
List<TestCase> failedTests = new ArrayList<TestCase>();
if(topLevelObjects != null) {
for(RqmObject obj : topLevelObjects) {
if(obj instanceof TopLevelObject) {
Set<TestCase> allCases = ((TopLevelObject)obj).getAllTestCases();
for(TestCase tc: allCases) {
if(tc.hasTestScriptExecutionErrors()) {
failedTests.add(tc);
}
}
}
}
}
return failedTests;
}

public boolean isProblem() {
return !getFailedTests().isEmpty();
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/praqma/jenkins/rqm/RqmBuilder.java
Expand Up @@ -232,4 +232,4 @@ public int getPort() {
}

}
}
}
Expand Up @@ -81,17 +81,23 @@ public <T extends RqmObject> List<T> collect(BuildListener listener, AbstractBui
NameValuePair[] filterProperties = TestSuiteExecutionRecord.getFilteringProperties(planName, getPort(), planName, executionRecordName);
String request = TestSuiteExecutionRecord.getResourceFeedUrl(getHostName(), getPort(), getContextRoot(), projectName);
RqmParameterList list = new RqmParameterList(getHostName(), getPort(), getContextRoot(), projectName, getUsrName(), getPasswd(), request, filterProperties, "GET", null);
log.fine(list.toString());
RqmObjectCreator<TestSuiteExecutionRecord> object = new RqmObjectCreator<TestSuiteExecutionRecord>(TestSuiteExecutionRecord.class, list);
return (List<T>)build.getWorkspace().act(object);
}

@Override
public boolean execute(AbstractBuild<?, ?> build, BuildListener listener, Launcher launcher, List<BuildStep> preBuildSteps, List<BuildStep> postBuildSteps, List<BuildStep> iterativeTestCaseBuilders, List<? extends RqmObject> results) throws Exception {

int executionCounter = 0;
int totalNumberOfScripts = 0;
boolean success = true;

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

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

if(preBuildSteps != null) {
listener.getLogger().println(String.format("Performing pre build step"));
for (BuildStep bs : preBuildSteps) {
Expand Down Expand Up @@ -139,8 +145,16 @@ public String getUrlName() {
}
};

build.addAction(envAction);
success &= bstep.perform(build, launcher, listener);
build.addAction(envAction);

boolean tsSuccess = bstep.perform(build, launcher, listener);
if(!tsSuccess) {
listener.getLogger().println( String.format( "Non-zero exit code for test script: %s", ts.getScriptTitle() ) );
ts.setExecutionSuccess(false);
} else {
executionCounter++;
}
success &= tsSuccess;
build.getActions().remove(envAction);
}
}
Expand All @@ -154,9 +168,20 @@ public String getUrlName() {
}
}

listener.getLogger().println( String.format("Successfully executed %s out of %s test scripts", executionCounter, totalNumberOfScripts) );
listener.getLogger().println( "Listing test cases which failed executing. Have you remembered to add the proper fields to your test scripts?" );

for(TestSuiteExecutionRecord tser : records) {
for(TestCase tc : tser.getAllTestCases()) {
for(TestScript tscript : tc.getScripts()) {
if(!tscript.isExecutionSuccess()) {
listener.getLogger().println(tscript);
}
}
}
}

return success;
}




}
12 changes: 12 additions & 0 deletions src/main/java/net/praqma/jenkins/rqm/model/TestCase.java
Expand Up @@ -182,4 +182,16 @@ public boolean equals(Object obj) {
public String getResourceName() {
return RESOURCE_RQM_NAME;
}

public boolean hasTestScriptExecutionErrors() {
boolean hasFailures = false;

for(TestScript tc : getScripts()) {
if(!tc.isExecutionSuccess()) {
return true;
}
}

return hasFailures;
}
}
26 changes: 22 additions & 4 deletions src/main/java/net/praqma/jenkins/rqm/model/TestScript.java
Expand Up @@ -35,8 +35,9 @@ public class TestScript extends RqmObject<TestScript> {
private final static String RESOURCE_RQM_MANUAL_NAME = "testscript";
private final static String RESOURCE_RQM_NONMANUAL_NAME = "remotescript";
private static final Logger log = Logger.getLogger(TestScript.class.getName());
private String scriptTitle = "No scipt type defined";
private String scriptTitle = "No script type defined";
private boolean manual = false;
private boolean executionSuccess = true;
public HashMap<String,String> customAttributes = new HashMap<String, String>();

public boolean isManual() {
Expand Down Expand Up @@ -94,8 +95,7 @@ public List<TestScript> createOrUpdate(RqmParameterList parameters) {
throw new UnsupportedOperationException("Not supported yet.");
}

public TestScript() {
}
public TestScript() { }

public TestScript(String rqmObjectResourceUrl) throws RQMObjectParseException {
this();
Expand Down Expand Up @@ -157,5 +157,23 @@ public String getResourceName() {
}
return RESOURCE_RQM_NONMANUAL_NAME;
}


/**
* @return the executionSuccess
*/
public boolean isExecutionSuccess() {
return executionSuccess;
}

/**
* @param executionSuccess the executionSuccess to set
*/
public void setExecutionSuccess(boolean executionSuccess) {
this.executionSuccess = executionSuccess;
}

@Override
public String toString() {
return String.format("%s, Attributes = %s%nLink to this script: %s", scriptTitle, customAttributes, rqmObjectResourceUrl);
}
}
1 change: 0 additions & 1 deletion src/main/java/net/praqma/jenkins/rqm/model/TestSuite.java
Expand Up @@ -72,7 +72,6 @@ public TestSuite initializeSingleResource(String xml) throws RQMObjectParseExcep
if(suiteElements.item(selement).getNodeType() == Node.ELEMENT_NODE) {
Element suteElem = (Element)suiteElements.item(selement);
String testCaseHref = ((Element)suteElem.getElementsByTagName("ns4:testcase").item(0)).getAttribute("href");
//String testScriptHref = ((Element)suteElem.getElementsByTagName("ns4:remotescript")).getAttribute("href");
TestCase tc = new TestCase(testCaseHref);
getTestcases().add(tc);
}
Expand Down
@@ -1,18 +1,55 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:local="local">
<l:layout title="RQM Test Plan overview">
<l:header>
<style>

.success {
color:green;
}

.rqm-table-header {
font-size:13px;
}

#rqm-results-table {
border-style:solid;
border-width:1px;
border-color:black;
}
</style>
</l:header>
<l:main-panel>
<h3>Included test cases</h3>
<table border="0">
<h3>Included test scripts</h3>
<p>Test scripts marked with red signs experienced abnormal execution</p>
<table id="rqm-results-table">
<thead>
<th>Test case title</th>
<th>Test case resource url</th>
<tr>
<th scope="col" id="rqm-table-header">Test case</th>
<th scope="col" id="rqm-table-header">Test scripts</th>
</tr>
</thead>

<tfoot>

</tfoot>

<tbody>
<j:forEach items="${it.getSelectedTestCases()}" var="case">
<tr>
<td>${case.getTestCaseTitle()}</td>
<td>${case.getRqmObjectResourceUrl()}</td>
<td class="test-case-title-cell"><a href="${case.getRqmObjectResourceUrl()}">${case.getTestCaseTitle()}</a></td>
<td class="test-scripts-cell">
<j:forEach items="${case.getScripts()}" var="ts">
<j:choose>
<j:when test="${!ts.isExecutionSuccess()}">
<div class="error" style="clear:right">${ts.getScriptTitle()}</div>
</j:when>
<j:otherwise>
<div class="success" style="clear:right">${ts.getScriptTitle()}</div>
</j:otherwise>
</j:choose>
</j:forEach>
</td>
</tr>
</j:forEach>
</tbody>
Expand Down
@@ -0,0 +1,18 @@
<j:jelly xmlns:j="jelly:core" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<t:summary icon="/plugin/rqm-plugin/images/64x64/rqm-icon.png">
<j:choose>
<j:when test="${it.isProblem()}">
<p>RQM Script Iterator failures detected in the following test cases.</p>
<ul>
<j:forEach items="${it.getFailedTests()}" var="tc">
<li>${tc.getTestCaseTitle()}</li>
</j:forEach>
</ul>
</j:when>
<j:otherwise>
No problems detected
</j:otherwise>
</j:choose>
</t:summary>
</j:jelly>
8 changes: 0 additions & 8 deletions src/test/java/net/praqma/jenkins/rqm/unit/RqmTestCase.java
Expand Up @@ -23,24 +23,16 @@
*/
package net.praqma.jenkins.rqm.unit;

import net.praqma.jenkins.rqm.collector.DummyCollectionStrategy;
import hudson.model.FreeStyleProject;
import hudson.tasks.BatchFile;
import hudson.tasks.BuildStep;
import hudson.tasks.Builder;
import hudson.tasks.Shell;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import net.praqma.jenkins.rqm.RqmBuilder;
import net.praqma.jenkins.rqm.RqmCollector;
import net.praqma.jenkins.rqm.model.TestCase;
import net.praqma.jenkins.rqm.model.TestPlan;
import net.praqma.jenkins.rqm.model.TestSuite;
import org.apache.commons.lang.SystemUtils;
import org.junit.Rule;
import org.jvnet.hudson.test.JenkinsRule;
import org.mockito.Mockito;
/**
*
* @author mads
Expand Down

0 comments on commit 649c45f

Please sign in to comment.