Skip to content

Commit

Permalink
Merge branch 'master' into JENKINS-41196
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/org/jvnet/hudson/test/AltWebXmlConfiguration.java
  • Loading branch information
oleg-nenashev committed Sep 1, 2017
2 parents 75b0b1e + 1ec4f46 commit 564ffeb
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 267 deletions.
25 changes: 25 additions & 0 deletions Jenkinsfile
@@ -0,0 +1,25 @@
pipeline {
options {
buildDiscarder(logRotator(numToKeepStr: '20'))
timeout(time: 1, unit: 'HOURS')
}
agent {
docker {
image 'maven:3.5.0-jdk-8'
label 'docker'
}
}
stages {
stage('main') {
// TODO Windows build in parallel
steps {
sh 'mvn -B clean verify'
}
post {
success {
junit '**/target/surefire-reports/TEST-*.xml'
}
}
}
}
}
33 changes: 33 additions & 0 deletions README.md
Expand Up @@ -4,6 +4,39 @@ See [wiki page](//wiki.jenkins-ci.org/display/JENKINS/Unit+Test)

## Changelog

### 2.24 (2017 Aug 02)

* Added `RestartableJenkinsRule.then` with a Java 8-friendly signature.
* Upgrade to Jetty 9.4.

### 2.23 (2017 Jun 26)

* JENKINS-41631: removing the Maven Embedder dependency from the harness.
* JENKINS-44453: `JenkinsRule` should ensure that Jenkins reaches the `COMPLETED` milestone.

### 2.22 (2017 May 02)

* Make `FakeChangeLogSCM` support `Run` rather than just `AbstractBuild`.

### 2.21 (2017 Apr 25)

* Fixed a regression in 2.20 affecting especially `InjectedTest` on Jenkins 2.x.

### 2.20 (2017 Apr 20)

* “Detached” plugins in Jenkins 2.x are no longer loaded implicitly during tests. You should declare `test`-scoped dependencies on plugins you expect to use during your tests, in the desired versions. `TestPluginManager.installResourcePlugin` has been removed, and `installDetachedPlugin` added for unusual cases.
* Avoid using methods deleted in newer version of HtmlUnit.
* `waitForMessage` can fail immediately if the build is completed.
* Possible to override `JenkinsRule.createWebServer` more easily.
* Deprecating `CLICommandInvoker.authorizedTo` in favor of a simpler `asUser`.
* Make Jetty be quiet during functional tests.
* Pick up `jetty-io` and `jetty-util` from our specified version to avoid conflicts.

### 2.19 (2017 Feb 27)

* Introduced `allowSoft` parameter to `assertGC`.
* Avoid any fixed timeout on `waitUntilNoActivity`.

### 2.18 (2016 Dec 20)

* Fixed `JenkinsComputerConnectorTester` so `ComputerConnector`s can be tested through `JenkinsRule.configRoundTrip`.
Expand Down
49 changes: 24 additions & 25 deletions pom.xml
Expand Up @@ -28,12 +28,12 @@ THE SOFTWARE.
<parent>
<groupId>org.jenkins-ci</groupId>
<artifactId>jenkins</artifactId>
<version>1.36</version>
<version>1.37</version>
</parent>

<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-test-harness</artifactId>
<version>2.19-SNAPSHOT</version>
<version>2.25-SNAPSHOT</version>

<name>Test harness for Jenkins and plugins</name>
<description>Harness used to run functional tests of Jenkins core and plugins.</description>
Expand All @@ -47,7 +47,10 @@ THE SOFTWARE.

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>9.2.15.v20160210</jetty.version>
<jetty.version>9.4.5.v20170502</jetty.version>
<maven-surefire-plugin.version>2.20</maven-surefire-plugin.version>
<maven-compiler-plugin.version>3.6.1</maven-compiler-plugin.version>
<java.level>8</java.level>
</properties>

<licenses>
Expand All @@ -73,14 +76,10 @@ THE SOFTWARE.

<dependencies>
<dependency>
<!--
put hudson.war in the classpath. we can't pull in the war artifact directly
because Maven excludes all wars from classpath automatically. so we need a jar artifact.
-->
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-war</artifactId>
<version>1.580.1</version>
<classifier>war-for-test</classifier>
<type>executable-war</type>
<exclusions>
<exclusion>
<groupId>org.jenkins-ci.modules</groupId>
Expand All @@ -89,7 +88,7 @@ THE SOFTWARE.
</exclusions>
<!--
To ensure consistent set of core artifacts are used, force the users to declare
a dependency to war-for-test
a dependency to war
-->
<optional>true</optional>
</dependency>
Expand Down Expand Up @@ -117,6 +116,16 @@ THE SOFTWARE.
<groupId>${project.groupId}</groupId>
<artifactId>jenkins-test-harness-htmlunit</artifactId>
<version>2.18-1</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jvnet.hudson</groupId>
Expand All @@ -139,22 +148,6 @@ THE SOFTWARE.
<artifactId>findbugs-annotations</artifactId>
<version>1.3.9-1</version>
</dependency>
<dependency> <!-- TODO can we switch this to use Aether directly? -->
<groupId>org.jenkins-ci.lib</groupId>
<artifactId>lib-jenkins-maven-embedder</artifactId>
<version>3.11</version>
<exclusions>
<exclusion>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-guice</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <!-- lib-jenkins-maven-embedder uses sisuInjectVersion=0.0.0.M2a which has uses ASM 3.0 which clashes with 4.0 on ClassVisitor -->
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>test-annotations</artifactId>
Expand All @@ -171,6 +164,12 @@ THE SOFTWARE.

<build>
<plugins>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<version>2.0</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.kohsuke.stapler</groupId>
<artifactId>maven-stapler-plugin</artifactId>
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/hudson/cli/CLICommandInvoker.java
Expand Up @@ -48,10 +48,10 @@
import org.acegisecurity.acls.sid.PrincipalSid;
import org.acegisecurity.acls.sid.Sid;

import org.apache.maven.plugin.lifecycle.Execution;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockAuthorizationStrategy;

/**
* Helper class to invoke {@link CLICommand} and check the response.
Expand All @@ -63,12 +63,16 @@ public class CLICommandInvoker {
private static final String username = "user";
private final JenkinsRule rule;
private final CLICommand command;
@Deprecated
private SecurityRealm originalSecurityRealm = null;
@Deprecated
private AuthorizationStrategy originalAuthorizationStrategy = null;
@Deprecated
private SecurityContext originalSecurityContext = null;

private InputStream stdin;
private List<String> args = Collections.emptyList();
@Deprecated
private List<Permission> permissions = Collections.emptyList();
private Locale locale = Locale.ENGLISH;

Expand All @@ -93,12 +97,29 @@ public CLICommandInvoker(final JenkinsRule rule, final String command) {
if (this.command == null) throw new AssertionError("No such command: " + command);
}

/**
* @deprecated Rather use {@link #asUser}.
*/
@Deprecated
public CLICommandInvoker authorizedTo(final Permission... permissions) {

this.permissions = Arrays.asList(permissions);
return this;
}

/**
* Run the command as a given username.
* Test setup should have first defined a meaningful security realm and authorization strategy.
* @see Jenkins#setSecurityRealm
* @see JenkinsRule#createDummySecurityRealm
* @see Jenkins#setAuthorizationStrategy
* @see MockAuthorizationStrategy
*/
public CLICommandInvoker asUser(String user) {
command.setTransportAuth(User.get(user).impersonate());
return this;
}

public CLICommandInvoker withStdin(final InputStream stdin) {

if (stdin == null) throw new NullPointerException("No stdin provided");
Expand Down Expand Up @@ -201,6 +222,10 @@ private void restoreAuth() {
}
}

/**
* @deprecated only used with {@link #authorizedTo}
*/
@Deprecated
public User user() {

return User.get(username);
Expand Down
41 changes: 28 additions & 13 deletions src/main/java/org/jvnet/hudson/test/FakeChangeLogSCM.java
Expand Up @@ -25,20 +25,23 @@

import hudson.FilePath;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.InvisibleAction;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.model.User;
import hudson.scm.ChangeLogParser;
import hudson.scm.ChangeLogSet;
import hudson.scm.ChangeLogSet.Entry;
import hudson.scm.NullSCM;
import hudson.scm.RepositoryBrowser;
import hudson.scm.SCM;
import hudson.scm.SCMDescriptor;
import hudson.scm.SCMRevisionState;
import org.xml.sax.SAXException;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -50,7 +53,7 @@
*
* @author Kohsuke Kawaguchi
*/
public class FakeChangeLogSCM extends NullSCM {
public class FakeChangeLogSCM extends NullSCM implements Serializable {

/**
* Changes to be reported in the next build.
Expand All @@ -64,11 +67,10 @@ public EntryImpl addChange() {
}

@Override
public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath remoteDir, BuildListener listener, File changeLogFile) throws IOException, InterruptedException {
public void checkout(Run<?, ?> build, Launcher launcher, FilePath remoteDir, TaskListener listener, File changeLogFile, SCMRevisionState baseline) throws IOException, InterruptedException {
new FilePath(changeLogFile).touch(0);
build.addAction(new ChangelogAction(entries));
build.addAction(new ChangelogAction(entries, changeLogFile.getName()));
entries = new ArrayList<EntryImpl>();
return true;
}

@Override
Expand All @@ -87,25 +89,32 @@ public String getDisplayName() {

public static class ChangelogAction extends InvisibleAction {
private final List<EntryImpl> entries;
private final String changeLogFile;

public ChangelogAction(List<EntryImpl> entries) {
public ChangelogAction(List<EntryImpl> entries, String changeLogFile) {
this.entries = entries;
this.changeLogFile = changeLogFile;
}
}

public static class FakeChangeLogParser extends ChangeLogParser {
@SuppressWarnings("rawtypes")
@Override
public FakeChangeLogSet parse(AbstractBuild build, File changelogFile) throws IOException, SAXException {
return new FakeChangeLogSet(build, build.getAction(ChangelogAction.class).entries);
public FakeChangeLogSet parse(Run build, RepositoryBrowser<?> browser, File changelogFile) throws IOException, SAXException {
for (ChangelogAction action : build.getActions(ChangelogAction.class)) {
if (changelogFile.getName().equals(action.changeLogFile)) {
return new FakeChangeLogSet(build, action.entries);
}
}
return new FakeChangeLogSet(build, Collections.<EntryImpl>emptyList());
}
}

public static class FakeChangeLogSet extends ChangeLogSet<EntryImpl> {
public static class FakeChangeLogSet extends ChangeLogSet<EntryImpl> implements Serializable {
private List<EntryImpl> entries;

public FakeChangeLogSet(AbstractBuild<?, ?> build, List<EntryImpl> entries) {
super(build);
public FakeChangeLogSet(Run<?, ?> build, List<EntryImpl> entries) {
super(build, null);
this.entries = entries;
}

Expand All @@ -117,9 +126,11 @@ public boolean isEmptySet() {
public Iterator<EntryImpl> iterator() {
return entries.iterator();
}

private static final long serialVersionUID = 1L;
}

public static class EntryImpl extends Entry {
public static class EntryImpl extends Entry implements Serializable {
private String msg = "some commit message";
private String author = "someone";

Expand Down Expand Up @@ -147,5 +158,9 @@ public User getAuthor() {
public Collection<String> getAffectedPaths() {
return Collections.singleton("path");
}

private static final long serialVersionUID = 1L;
}

private static final long serialVersionUID = 1L;
}

0 comments on commit 564ffeb

Please sign in to comment.