Skip to content

Commit

Permalink
Implemented JENKINS-24577
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNielsen committed Sep 4, 2014
1 parent 58c2c27 commit 091e2a0
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 19 deletions.
Expand Up @@ -103,7 +103,7 @@ public boolean execute(AbstractBuild<?, ?> build, BuildListener listener, Launch
listener.getLogger().println(String.format( "Test Suite %s [%s] ", rec.getTestSuite().getTestSuiteTitle(), rec.getTestSuite().getRqmObjectResourceUrl() ));
listener.getLogger().println(String.format( "Test Suite Execution Record %s [%s]",rec.getTestSuiteExecutionRecordTitle(), rec.getRqmObjectResourceUrl()) );
for(final TestCase tc : rec.getTestSuite().getTestcases()) {
listener.getLogger().println(String.format( " Test Case %s [%s]",tc.getTestCaseTitle(), tc.getRqmObjectResourceUrl()) );
listener.getLogger().println(String.format( " Test Case %s(%s) [%s]",tc.getTestCaseTitle(), tc.getExecutionOrder(), tc.getRqmObjectResourceUrl()) );

if(tc.getScripts().isEmpty()) {
listener.getLogger().println("Test case %s does not contain any scripts, setting result to unstable");
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/net/praqma/jenkins/rqm/model/TestCase.java
Expand Up @@ -30,11 +30,20 @@
*
* @author Praqma
*/
public class TestCase extends RqmObject<TestCase> {
public class TestCase extends RqmObject<TestCase> implements Comparable<TestCase>{
private static final Logger log = Logger.getLogger(TestCase.class.getName());
private final static String RESOURCE_RQM_NAME = "testcase";
private String testCaseTitle;
private int executionOrder;
private List<TestScript> scripts = new ArrayList<TestScript>();

public int getExecutionOrder() {
return this.executionOrder;
}

public void setExecutionOrder(int executionOrder) {
this.executionOrder = executionOrder;
}

/**
* @return the scripts
Expand Down Expand Up @@ -160,7 +169,9 @@ public String toString() {
builder.append(s);
}
}
}
} else {
builder.append(getTestCaseTitle());
}
return builder.toString();
}

Expand All @@ -182,4 +193,9 @@ public boolean equals(Object obj) {
public String getResourceName() {
return RESOURCE_RQM_NAME;
}

@Override
public int compareTo(TestCase t) {
return Integer.compare(this.executionOrder, t.executionOrder);
}
}
14 changes: 10 additions & 4 deletions src/main/java/net/praqma/jenkins/rqm/model/TestSuite.java
Expand Up @@ -11,6 +11,8 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.praqma.jenkins.rqm.model.exception.ClientCreationException;
Expand All @@ -35,7 +37,7 @@ public class TestSuite extends RqmObject<TestSuite> {
private static final Logger log = Logger.getLogger(TestSuite.class.getName());
private static final String RESOURCE_RQM_NAME = "testsuite";
private String testSuiteTitle;
private Set<TestCase> testcases;
private SortedSet<TestCase> testcases;
private Set<TestSuiteExecutionRecord> testSuiteExecutionRecords;

public TestSuite() { }
Expand All @@ -46,7 +48,7 @@ public TestSuite(String rqmObjectResourceUrl) {


public TestSuite(String rqmObjectResourceUrl, String suiteName) {
testcases = new HashSet<TestCase>();
testcases = new TreeSet<TestCase>();
this.testSuiteTitle = suiteName;
this.rqmObjectResourceUrl = rqmObjectResourceUrl;
}
Expand All @@ -69,11 +71,15 @@ public TestSuite initializeSingleResource(String xml) throws RQMObjectParseExcep
//Now find all suite elements
NodeList suiteElements = el.getElementsByTagName("ns4:suiteelement");
for(int selement = 0; selement<suiteElements.getLength(); selement++) {

int executionOrder = Integer.parseInt(((Element)suiteElements.item(selement)).getAttribute("elementindex"))+1;

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);
tc.setExecutionOrder(executionOrder);
getTestcases().add(tc);
}
}
Expand All @@ -91,14 +97,14 @@ public TestSuite initializeSingleResource(String xml) throws RQMObjectParseExcep
/**
* @return the testcases
*/
public Set<TestCase> getTestcases() {
public SortedSet<TestCase> getTestcases() {
return testcases;
}

/**
* @param testcases the testcases to set
*/
public void setTestcases(Set<TestCase> testcases) {
public void setTestcases(SortedSet<TestCase> testcases) {
this.testcases = testcases;
}

Expand Down
Expand Up @@ -14,6 +14,8 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.praqma.jenkins.rqm.model.exception.ClientCreationException;
Expand Down Expand Up @@ -178,8 +180,8 @@ public void setTestSuiteExecutionRecordTitle(String testSuiteExecutionRecordTitl
}

@Override
public Set<TestCase> getAllTestCases() {
HashSet<TestCase> testCases = new HashSet<TestCase>();
public SortedSet<TestCase> getAllTestCases() {
SortedSet<TestCase> testCases = new TreeSet<TestCase>();
testCases.addAll(getTestSuite().getTestcases());
return testCases;
}
Expand Down
Expand Up @@ -31,6 +31,8 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import net.praqma.jenkins.rqm.RqmCollector;
import net.praqma.jenkins.rqm.RqmCollectorDescriptor;
import net.praqma.jenkins.rqm.model.RqmObject;
Expand Down Expand Up @@ -85,7 +87,7 @@ public TestPlan defaultTestPlan() throws RQMObjectParseException {
TestScript ts2 = new TestScript("testcript:ts2");
tc2.setScripts(Arrays.asList(ts2));

HashSet<TestCase> cases = new HashSet<TestCase>();
SortedSet<TestCase> cases = new TreeSet<TestCase>();
cases.add(tc);
cases.add(tc2);

Expand Down
12 changes: 3 additions & 9 deletions src/test/java/net/praqma/jenkins/rqm/unit/RqmTestCase.java
Expand Up @@ -23,24 +23,18 @@
*/
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 java.util.SortedSet;
import java.util.TreeSet;
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 All @@ -59,7 +53,7 @@ public TestPlan defaultTestPlan() {
TestCase tc = new TestCase("TestCase1");
tc.setRqmObjectResourceUrl("testcase:tc1");

HashSet<TestCase> cases = new HashSet<TestCase>();
SortedSet<TestCase> cases = new TreeSet<TestCase>();
cases.add(tc);

suite.setTestcases(cases);
Expand Down
63 changes: 63 additions & 0 deletions src/test/java/net/praqma/jenkins/rqm/unit/TestCaseTests.java
@@ -0,0 +1,63 @@
/*
* The MIT License
*
* Copyright 2014 Mads.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package net.praqma.jenkins.rqm.unit;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import net.praqma.jenkins.rqm.model.TestCase;
import static org.junit.Assert.assertEquals;
import org.junit.Test;

/**
*
* @author Mads
*/
public class TestCaseTests {

@Test
public void sortByExecutionOrder() {
TestCase tc1 = new TestCase();
tc1.setExecutionOrder(1);
tc1.setTestCaseTitle("first");

TestCase tc2 = new TestCase();
tc2.setExecutionOrder(5);
tc2.setTestCaseTitle("third");

TestCase tc3 = new TestCase();
tc3.setExecutionOrder(2);
tc3.setTestCaseTitle("second");

List<TestCase> cases = Arrays.asList(tc1,tc2,tc3);
Collections.sort(cases);

assertEquals("first", cases.get(0).getTestCaseTitle());
assertEquals("second", cases.get(1).getTestCaseTitle());
assertEquals("third", cases.get(2).getTestCaseTitle());


}
}

0 comments on commit 091e2a0

Please sign in to comment.