Skip to content
Permalink
Browse files

[JENKINS-31999] added more tests

- avoid JENKINS-4409 in system tests
- removed unnecessary TestPluginManagerCleanUp
- added more unit tests
- added more system tests validating pipeline steps
  • Loading branch information...
cpoenisch committed May 27, 2016
1 parent a0f5632 commit 189cbd8a033bb7fb204ff7a68ad38cd0e5e90bf1
Showing with 1,678 additions and 334 deletions.
  1. +30 −6 src/test/java/de/tracetronic/jenkins/plugins/ecutest/SystemTestBase.java
  2. +0 −77 src/test/java/de/tracetronic/jenkins/plugins/ecutest/TestPluginManagerCleanUp.java
  3. +84 −8 src/test/java/de/tracetronic/jenkins/plugins/ecutest/report/atx/ATXPublisherST.java
  4. +44 −9 src/test/java/de/tracetronic/jenkins/plugins/ecutest/report/atx/ATXPublisherTest.java
  5. +86 −9 ...test/java/de/tracetronic/jenkins/plugins/ecutest/report/generator/ReportGeneratorPublisherST.java
  6. +59 −31 ...st/java/de/tracetronic/jenkins/plugins/ecutest/report/generator/ReportGeneratorPublisherTest.java
  7. +85 −5 src/test/java/de/tracetronic/jenkins/plugins/ecutest/report/junit/JUnitPublisherST.java
  8. +56 −12 src/test/java/de/tracetronic/jenkins/plugins/ecutest/report/junit/JUnitPublisherTest.java
  9. +94 −5 src/test/java/de/tracetronic/jenkins/plugins/ecutest/report/log/ETLogPublisherST.java
  10. +27 −9 src/test/java/de/tracetronic/jenkins/plugins/ecutest/report/log/ETLogPublisherTest.java
  11. +84 −4 src/test/java/de/tracetronic/jenkins/plugins/ecutest/report/trf/TRFPublisherST.java
  12. +21 −0 src/test/java/de/tracetronic/jenkins/plugins/ecutest/report/trf/TRFPublisherTest.java
  13. +102 −9 src/test/java/de/tracetronic/jenkins/plugins/ecutest/test/TestFolderBuilderST.java
  14. +46 −8 src/test/java/de/tracetronic/jenkins/plugins/ecutest/test/TestFolderBuilderTest.java
  15. +94 −7 src/test/java/de/tracetronic/jenkins/plugins/ecutest/test/TestPackageBuilderST.java
  16. +43 −8 src/test/java/de/tracetronic/jenkins/plugins/ecutest/test/TestPackageBuilderTest.java
  17. +94 −7 src/test/java/de/tracetronic/jenkins/plugins/ecutest/test/TestProjectBuilderST.java
  18. +43 −8 src/test/java/de/tracetronic/jenkins/plugins/ecutest/test/TestProjectBuilderTest.java
  19. +94 −4 src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/StartETBuilderST.java
  20. +107 −73 src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/StartETBuilderTest.java
  21. +94 −6 src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/StartTSBuilderST.java
  22. +37 −8 src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/StartTSBuilderTest.java
  23. +96 −4 src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/StopETBuilderST.java
  24. +35 −6 src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/StopETBuilderTest.java
  25. +88 −5 src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/StopTSBuilderST.java
  26. +35 −6 src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/StopTSBuilderTest.java
@@ -29,24 +29,48 @@
*/
package de.tracetronic.jenkins.plugins.ecutest;

import hudson.Functions;

import java.io.File;
import java.net.URLConnection;

import org.junit.Before;
import org.junit.Rule;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;

/**
* Base class for all Jenkins related unit tests.
* Base class for all Jenkins related system tests.
*
* @author Christian Pönisch <christian.poenisch@tracetronic.de>
*/
public class SystemTestBase {

static {
TestPluginManagerCleanUp.registerCleanup();
}

@Rule
public JenkinsRule jenkins = new JenkinsRule();
public JenkinsRule jenkins = new JenkinsRule() {

private boolean origDefaultUseCache = true;

@Override
public void before() throws Throwable {
if (Functions.isWindows()) {
// To avoid JENKINS-4409
final URLConnection connection = new File(".").toURI().toURL().openConnection();
origDefaultUseCache = connection.getDefaultUseCaches();
connection.setDefaultUseCaches(false);
}
super.before();
}

@Override
public void after() throws Exception {
super.after();
if (Functions.isWindows()) {
final URLConnection connection = new File(".").toURI().toURL().openConnection();
connection.setDefaultUseCaches(origDefaultUseCache);
}
}
};

/**
* Setups the JenkinsRule for a test.

This file was deleted.

@@ -41,13 +41,17 @@
import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Label;
import hudson.slaves.DumbSlave;
import hudson.slaves.SlaveComputer;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;

import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Before;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
@@ -73,14 +77,38 @@
@Before
public void setUp() throws Exception {
super.setUp();
final ETInstallation.DescriptorImpl etDescriptor = jenkins.jenkins
.getDescriptorByType(ETInstallation.DescriptorImpl.class);
etDescriptor.setInstallations(new ETInstallation("ECU-TEST", "C:\\ECU-TEST", JenkinsRule.NO_PROPERTIES));
final ATXPublisher.DescriptorImpl atxImpl = jenkins.jenkins
.getDescriptorByType(ATXPublisher.DescriptorImpl.class);
final ATXInstallation inst = new ATXInstallation("TEST-GUIDE", "ECU-TEST", new ATXConfig());
atxImpl.setInstallations(inst);
}

@Test
public void testRoundTripConfig() throws Exception {
public void testDefaultConfigRoundTripStep() throws Exception {
final ATXPublisher before = new ATXPublisher("TEST-GUIDE");
final ATXPublisher after = jenkins.configRoundtrip(before);
jenkins.assertEqualDataBoundBeans(before, after);
}

@Test
public void testConfigRoundTripStep() throws Exception {
final ATXPublisher before = new ATXPublisher("TEST-GUIDE");
before.setRunOnFailed(false);
before.setAllowMissing(false);
before.setRunOnFailed(false);
before.setArchiving(true);
before.setKeepAll(true);
final ATXPublisher after = jenkins.configRoundtrip(before);
jenkins.assertEqualBeans(before, after,
"allowMissing,runOnFailed,archiving,keepAll");
}

@Deprecated
@Test
public void testConfigRoundTrip() throws Exception {
final ATXPublisher before = new ATXPublisher("TEST-GUIDE", false, false, true, true);
final ATXPublisher after = jenkins.configRoundtrip(before);
jenkins.assertEqualBeans(before, after, "allowMissing,runOnFailed,archiving,keepAll");
@@ -89,7 +117,11 @@ public void testRoundTripConfig() throws Exception {
@Test
public void testConfigView() throws Exception {
final FreeStyleProject project = jenkins.createFreeStyleProject();
final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE", true, true, true, true);
final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE");
publisher.setAllowMissing(true);
publisher.setRunOnFailed(true);
publisher.setArchiving(false);
publisher.setKeepAll(false);
project.getPublishersList().add(publisher);

final HtmlPage page = getWebClient().getPage(project, "configure");
@@ -119,7 +151,7 @@ public void testDefaultConfig() {
@Test
@LocalData
public void testCurrentInstallation() {
final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE", false, false, true, true);
final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE");
assertNotNull(publisher.getInstallation());
}

@@ -129,7 +161,7 @@ public void testFormRoundTrip() throws Exception {
.getDescriptorByType(ATXPublisher.DescriptorImpl.class);
assertEquals(1, atxImpl.getInstallations().length);

final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE", false, false, true, true);
final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE");
final ATXInstallation installation = publisher.getInstallation();
assertNotNull(installation);
assertEquals(installation.getName(), "TEST-GUIDE");
@@ -145,7 +177,8 @@ public void testAllowMissing() throws Exception {

final FreeStyleProject project = jenkins.createFreeStyleProject();
project.setAssignedNode(slave);
final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE", true, false, true, true);
final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE");
publisher.setAllowMissing(false);
project.getPublishersList().add(publisher);
final FreeStyleBuild build = project.scheduleBuild2(0).get();
jenkins.assertBuildStatus(Result.FAILURE, build);
@@ -168,7 +201,8 @@ public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher,
return false;
}
});
final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE", true, false, true, true);
final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE");
publisher.setRunOnFailed(false);
project.getPublishersList().add(publisher);
final FreeStyleBuild build = project.scheduleBuild2(0).get();
jenkins.assertBuildStatus(Result.FAILURE, build);
@@ -183,7 +217,7 @@ public void testParameterizedATXName() throws Exception {
etDescriptor.setInstallations(new ETInstallation("ECU-TEST", "C:\\ECU-TEST", JenkinsRule.NO_PROPERTIES));

final FreeStyleProject project = jenkins.createFreeStyleProject();
final ATXPublisher publisher = new ATXPublisher("${TESTGUIDE}", true, false, true, true);
final ATXPublisher publisher = new ATXPublisher("${TESTGUIDE}");
project.getPublishersList().add(publisher);

final EnvVars envVars = new EnvVars(
@@ -205,7 +239,7 @@ public void testParameterizedToolName() throws Exception {
etDescriptor.setInstallations(new ETInstallation("ECU-TEST", "C:\\ECU-TEST", JenkinsRule.NO_PROPERTIES));

final FreeStyleProject project = jenkins.createFreeStyleProject();
final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE", true, false, true, true);
final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE");
project.getPublishersList().add(publisher);

final EnvVars envVars = new EnvVars(
@@ -222,4 +256,46 @@ public void testParameterizedToolName() throws Exception {
assertEquals("Tool name should be resolved", "ECU-TEST",
publisher.getToolInstallation(installation.getToolName(), envVars).getName());
}

@Test
public void testDefaultPipelineStep() throws Exception {
final String script = ""
+ "node('slaves') {\n"
+ " step([$class: 'ATXPublisher', atxName: 'TEST-GUIDE'])\n"
+ "}";
assertPipelineStep(script);
}

@Test
public void testPipelineStep() throws Exception {
final String script = ""
+ "node('slaves') {\n"
+ " step([$class: 'ATXPublisher', atxName: 'TEST-GUIDE',"
+ " allowMissing: true, runOnFailed: true,"
+ " archiving: false, keepAll: false])\n"
+ "}";
assertPipelineStep(script);
}

/**
* Asserts the pipeline step execution.
*
* @param script
* the script
* @throws Exception
* the exception
*/
private void assertPipelineStep(final String script) throws Exception {
// Windows only
final DumbSlave slave = jenkins.createOnlineSlave(Label.get("slaves"));
final SlaveComputer computer = slave.getComputer();
assumeFalse("Test is Windows only!", computer.isUnix());

final WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "pipeline");
job.setDefinition(new CpsFlowDefinition(script, true));

final WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get());
jenkins.assertLogContains("Publishing ATX reports...", run);
jenkins.assertLogContains("Starting ECU-TEST failed.", run);
}
}
@@ -30,12 +30,12 @@
package de.tracetronic.jenkins.plugins.ecutest.report.atx;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Unit tests for {@link ATXPublisher}.
*
@@ -44,13 +44,48 @@
public class ATXPublisherTest {

@Test
public void testConstructor() {
final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE", true, true, false, false);
assertNotNull(publisher);
public void testDefaultStep() {
final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE");
assertPublisher(publisher, true);
assertEquals("TEST-GUIDE", publisher.getAtxName());
assertTrue(publisher.isAllowMissing());
assertTrue(publisher.isRunOnFailed());
assertFalse(publisher.isArchiving());
assertFalse(publisher.isKeepAll());
}

@SuppressFBWarnings("NP_NONNULL_PARAM_VIOLATION")
@Test
public void testNullStep() {
final ATXPublisher publisher = new ATXPublisher(null);
assertPublisher(publisher, true);
}

@Deprecated
@Test
public void testDefault() {
final ATXPublisher publisher = new ATXPublisher("TEST-GUIDE", false, false, true, true);
assertPublisher(publisher, true);
assertEquals("TEST-GUIDE", publisher.getAtxName());
}

@Deprecated
@Test
public void testNull() {
final ATXPublisher publisher = new ATXPublisher(null, true, true, false, false);
assertPublisher(publisher, false);
}

/**
* Asserts the publisher properties.
*
* @param publisher
* the publisher
* @param isDefault
* specifies whether to check default values
*/
private void assertPublisher(final ATXPublisher publisher, final boolean isDefault) {
assertNotNull(publisher);
assertNotNull(publisher.getAtxName());
assertEquals(!isDefault, publisher.isAllowMissing());
assertEquals(!isDefault, publisher.isRunOnFailed());
assertEquals(isDefault, publisher.isArchiving());
assertEquals(isDefault, publisher.isKeepAll());
}
}

0 comments on commit 189cbd8

Please sign in to comment.
You can’t perform that action at this time.