Skip to content
Permalink
Browse files

[JENKINS-43507] Bump structs to 1.8 and fix tests

  • Loading branch information...
stephenc committed Jun 15, 2017
1 parent 07ba4b5 commit dd3e427593857367cbec598c693155f05bb6fb0b
@@ -143,6 +143,11 @@
<version>1.15</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git-client</artifactId>
@@ -258,6 +258,9 @@ private RefSpecsSCMSourceTrait asRefSpecsSCMSourceTrait(String rawRefSpecs, Stri
if (!defaults.contains(rawRefSpecs.trim())) {
List<String> templates = new ArrayList<>();
for (String rawRefSpec : rawRefSpecs.split(" ")) {
if (StringUtils.isBlank(rawRefSpec)) {
continue;
}
if (defaults.contains(rawRefSpec)) {
templates.add(AbstractGitSCMSource.REF_SPEC_DEFAULT);
} else {
@@ -60,7 +60,7 @@
/**
* Constructor.
*
* @param includeTags
* @param includeTags {@code true} to request fetching tags.
*/
public GitSCMSourceDefaults(boolean includeTags) {
this.includeTags = includeTags;
@@ -21,13 +21,15 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import jenkins.plugins.git.traits.IgnoreOnPushNotificationTrait;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import static org.hamcrest.Matchers.*;

import jenkins.scm.api.SCMSourceOwner;
import jenkins.scm.api.metadata.PrimaryInstanceMetadataAction;
import jenkins.scm.api.trait.SCMSourceTrait;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.Rule;
@@ -253,13 +255,20 @@ public void testSpecificRevisionBuildChooser() throws Exception {
sampleRepo.git("commit", "--message=master-branch-commit-message");

/* Fetch from sampleRepo */
GitSCMSource source = new GitSCMSource(null, sampleRepo.toString(), "", "*", "", true);
GitSCMSource source = new GitSCMSource(sampleRepo.toString());
source.setTraits(Collections.<SCMSourceTrait>singletonList(new IgnoreOnPushNotificationTrait()));
List<GitSCMExtension> extensions = new ArrayList<GitSCMExtension>();
assertThat(source.getExtensions(), is(empty()));
LocalBranch localBranchExtension = new LocalBranch("**");
extensions.add(localBranchExtension);
source.setExtensions(extensions);
assertEquals(source.getExtensions(), extensions);
assertThat(source.getExtensions(), contains(
allOf(
instanceOf(LocalBranch.class),
hasProperty("localBranch", is("**")
)
)
));

SCMHead head = new SCMHead("master");
SCMRevision revision = new AbstractGitSCMSource.SCMRevisionImpl(head, "beaded4deed2bed4feed2deaf78933d0f97a5a34");
@@ -269,26 +278,28 @@ public void testSpecificRevisionBuildChooser() throws Exception {

/* Check that BuildChooserSetting not added to extensions by build() */
GitSCM scm = (GitSCM) source.build(head);
List<GitSCMExtension> scmExtensions = scm.getExtensions();
assertThat(scmExtensions, Matchers.<List<GitSCMExtension>>allOf(
not(Matchers.<GitSCMExtension>hasItem(instanceOf(BuildChooserSetting.class))),
containsInAnyOrder(extensions.toArray(new GitSCMExtension[extensions.size()]))
assertThat(scm.getExtensions(), containsInAnyOrder(
allOf(
instanceOf(LocalBranch.class),
hasProperty("localBranch", is("**")
)
),
// no BuildChooserSetting
instanceOf(IgnoreNotifyCommit.class),
instanceOf(GitSCMSourceDefaults.class)
));


/* Check that BuildChooserSetting has been added to extensions by build() */
GitSCM scmRevision = (GitSCM) source.build(head, revision);
scmExtensions = scmRevision.getExtensions();
for (GitSCMExtension e: scmExtensions) {
if (e instanceof BuildChooserSetting) {
extensions.add(e);
break;
}
}
assertThat(scmExtensions, Matchers.<List<GitSCMExtension>>allOf(
Matchers.<GitSCMExtension>hasSize(3),
containsInAnyOrder(extensions.toArray(new GitSCMExtension[extensions.size()])),
Matchers.<GitSCMExtension>hasItem(instanceOf(BuildChooserSetting.class))
assertThat(scmRevision.getExtensions(), containsInAnyOrder(
allOf(
instanceOf(LocalBranch.class),
hasProperty("localBranch", is("**")
)
),
instanceOf(BuildChooserSetting.class),
instanceOf(IgnoreNotifyCommit.class),
instanceOf(GitSCMSourceDefaults.class)
));
}

@@ -311,19 +322,15 @@ public void testCustomRemoteName() throws Exception {
public void testCustomRefSpecs() throws Exception {
sampleRepo.init();

GitSCMSource source = new GitSCMSource(null, sampleRepo.toString(), "", null, "+refs/heads/*:refs/remotes/origin/* +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*", "*", "", true);
GitSCMSource source = new GitSCMSource(null, sampleRepo.toString(), "", null, "+refs/heads/*:refs/remotes/origin/* +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*", "*", "", true);
SCMHead head = new SCMHead("master");
GitSCM scm = (GitSCM) source.build(head);
List<UserRemoteConfig> configs = scm.getUserRemoteConfigs();

assertEquals(2, configs.size());
assertEquals(1, configs.size());

UserRemoteConfig config = configs.get(0);
assertEquals("origin", config.getName());
assertEquals("+refs/heads/*:refs/remotes/origin/*", config.getRefspec());

config = configs.get(1);
assertEquals("origin", config.getName());
assertEquals("+refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*", config.getRefspec());
assertEquals("+refs/heads/*:refs/remotes/origin/* +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*", config.getRefspec());
}
}

0 comments on commit dd3e427

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