forked from jenkinsci/bitbucket-branch-source-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-48737 Taking checkout strategy into account.
- Loading branch information
1 parent
3bac95e
commit faf745e
Showing
4 changed files
with
143 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMFileTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.cloudbees.jenkins.plugins.bitbucket; | ||
|
||
import jenkins.scm.api.SCMFile; | ||
import jenkins.scm.api.SCMHead; | ||
import jenkins.scm.api.SCMRevision; | ||
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy; | ||
import jenkins.scm.impl.mock.MockSCMRevision; | ||
import com.cloudbees.jenkins.plugins.bitbucket.filesystem.BitbucketSCMFile; | ||
import com.cloudbees.jenkins.plugins.bitbucket.filesystem.BitbucketSCMFileSystem; | ||
import com.cloudbees.jenkins.plugins.bitbucket.mock.MockBitbucketSCMFileSystem; | ||
|
||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Tests the class {@link BitbucketSCMFile}. | ||
* | ||
* @author Benjamin Fuchs | ||
*/ | ||
public class BitbucketSCMFileTest { | ||
|
||
@Test | ||
public void testGetRefSimple() throws Exception { | ||
BitbucketSCMFile dir = new BitbucketSCMFile(null, null, "master", null); | ||
assertEquals("master", dir.getRef()); | ||
} | ||
|
||
@Test | ||
public void testGetRefForPullRequestForMergeStrategy() throws Exception { | ||
PullRequestSCMHead head = new PullRequestSCMHead("foo", "", "", "", "", null, null, | ||
ChangeRequestCheckoutStrategy.MERGE); | ||
MockSCMRevision rev = new MockSCMRevision(head, null); | ||
BitbucketSCMFileSystem fileSystem = new MockBitbucketSCMFileSystem(null, null, (SCMRevision) rev); | ||
BitbucketSCMFile dir = new BitbucketSCMFile(fileSystem, null, "PR-123", null); | ||
assertEquals("refs/pull-requests/123/merge", dir.getRef()); | ||
} | ||
|
||
@Test | ||
public void testGetRefForPullRequestForHeadStrategy() throws Exception { | ||
PullRequestSCMHead head = new PullRequestSCMHead("foo", "", "", "", "", null, null, | ||
ChangeRequestCheckoutStrategy.HEAD); | ||
MockSCMRevision rev = new MockSCMRevision(head, null); | ||
BitbucketSCMFileSystem fileSystem = new MockBitbucketSCMFileSystem(null, null, (SCMRevision) rev); | ||
BitbucketSCMFile dir = new BitbucketSCMFile(fileSystem, null, "PR-123", null); | ||
assertEquals("refs/pull-requests/123/from", dir.getRef()); | ||
} | ||
|
||
@Test | ||
public void testGetRefForPullRequestWithFile() throws Exception { | ||
PullRequestSCMHead head = new PullRequestSCMHead("foo", "", "", "", "", null, null, | ||
ChangeRequestCheckoutStrategy.HEAD); | ||
MockSCMRevision rev = new MockSCMRevision(head, null); | ||
BitbucketSCMFileSystem fileSystem = new MockBitbucketSCMFileSystem(null, null, (SCMRevision) rev); | ||
BitbucketSCMFile dir = new BitbucketSCMFile(fileSystem, null, "PR-123", null); | ||
BitbucketSCMFile file = new BitbucketSCMFile(dir, "Jenkinsfile", SCMFile.Type.REGULAR_FILE, null); | ||
assertEquals("refs/pull-requests/123/from", file.getRef()); | ||
} | ||
|
||
@Test(expected = UnsupportedOperationException.class) | ||
public void testGetRefForPullRequestFailsWithError() throws Exception { | ||
SCMHead head = new SCMHead("foo"); | ||
MockSCMRevision rev = new MockSCMRevision(head, null); | ||
BitbucketSCMFileSystem fileSystem = new MockBitbucketSCMFileSystem(null, null, (SCMRevision) rev); | ||
BitbucketSCMFile dir = new BitbucketSCMFile(fileSystem, null, "PR-123", null); | ||
dir.getRef(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/test/java/com/cloudbees/jenkins/plugins/bitbucket/mock/MockBitbucketSCMFileSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.cloudbees.jenkins.plugins.bitbucket.mock; | ||
|
||
import java.io.IOException; | ||
|
||
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketApi; | ||
import com.cloudbees.jenkins.plugins.bitbucket.filesystem.BitbucketSCMFileSystem; | ||
|
||
import jenkins.scm.api.SCMRevision; | ||
|
||
public class MockBitbucketSCMFileSystem extends BitbucketSCMFileSystem { | ||
|
||
public MockBitbucketSCMFileSystem(BitbucketApi api, String ref, SCMRevision rev) throws IOException { | ||
super(api, ref, rev); | ||
} | ||
} |