Skip to content
Permalink
Browse files

[JENKINS-48035] Add a test

  • Loading branch information
rsandell committed Dec 12, 2017
1 parent 93cc3f4 commit 945bd9842f98446123c4156fcf23962eabbc3b11
Showing with 32 additions and 0 deletions.
  1. +32 −0 src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceTest.java
@@ -25,6 +25,8 @@

package org.jenkinsci.plugins.github_branch_source;

import com.cloudbees.jenkins.GitHubRepositoryName;
import com.cloudbees.jenkins.GitHubRepositoryNameContributor;
import com.github.tomakehurst.wiremock.common.FileSource;
import com.github.tomakehurst.wiremock.common.SingleRootFileSource;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
@@ -34,6 +36,7 @@
import com.github.tomakehurst.wiremock.http.Response;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.ExtensionList;
import hudson.model.Action;
import hudson.model.Item;
import hudson.model.TaskListener;
@@ -45,8 +48,13 @@
import hudson.util.LogTaskListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import jenkins.branch.BranchSource;
import jenkins.branch.MultiBranchProject;
import jenkins.model.Jenkins;
import jenkins.plugins.git.GitSCMSource;
@@ -67,14 +75,19 @@
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockAuthorizationStrategy;
import org.jvnet.hudson.test.MockFolder;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
@@ -146,6 +159,25 @@ public void prepareMockGitHub() throws Exception {
source = new GitHubSCMSource(null, "http://localhost:" + githubApi.port(), GitHubSCMSource.DescriptorImpl.SAME, null, "cloudbeers", "yolo");
}

@Test
@Issue("JENKINS-48035")
public void testGitHubRepositoryNameContributor() throws IOException {
WorkflowMultiBranchProject job = r.createProject(WorkflowMultiBranchProject.class);
job.setSourcesList(Arrays.asList(new BranchSource(source)));
Collection<GitHubRepositoryName> names = GitHubRepositoryNameContributor.parseAssociatedNames(job);
assertThat(names, contains(allOf(
hasProperty("userName", equalTo("cloudbeers")),
hasProperty("repositoryName", equalTo("yolo"))
)));
//And specifically...
names = new ArrayList<>();
ExtensionList.lookup(GitHubRepositoryNameContributor.class).get(GitHubSCMSourceRepositoryNameContributor.class).parseAssociatedNames(job, names);
assertThat(names, contains(allOf(
hasProperty("userName", equalTo("cloudbeers")),
hasProperty("repositoryName", equalTo("yolo"))
)));
}

@Test
public void fetchSmokes() throws Exception {
SCMHeadObserver.Collector collector = SCMHeadObserver.collect();

0 comments on commit 945bd98

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