-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
115 additions
and
101 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
@@ -26,34 +27,43 @@ | |
@ExtendWith(MockitoExtension.class) | ||
public class BitBucketPPRTriggerTest { | ||
|
||
@Test | ||
public void testTriggerUrlOverridesBaseUrl() { | ||
try (MockedStatic<BitBucketPPRPluginConfig> config = Mockito.mockStatic( | ||
BitBucketPPRPluginConfig.class)) { | ||
BitBucketPPRPluginConfig c = mock(BitBucketPPRPluginConfig.class); | ||
config.when(BitBucketPPRPluginConfig::getInstance).thenReturn(c); | ||
when(c.getPropagationUrl()).thenReturn("https://example.org/scm/some-namespace/some-repo.git"); | ||
|
||
BitBucketPPRPayload payloadMock = mock(BitBucketPPRPayload.class, RETURNS_DEEP_STUBS); | ||
List<BitBucketPPRServerClone> clones = new ArrayList<>(); | ||
BitBucketPPRServerClone mockServerClone = mock(BitBucketPPRServerClone.class); | ||
when(mockServerClone.getName()).thenReturn("ssh"); | ||
when(mockServerClone.getHref()).thenReturn("ssh://[email protected]/some-namespace/some-repo.git"); | ||
clones.add(mockServerClone); | ||
when(payloadMock.getServerRepository().getLinks().getCloneProperty()).thenReturn(clones); | ||
BitBucketPPRPullRequestServerAction bitBucketPPRServerRepositoryAction = new BitBucketPPRPullRequestServerAction(payloadMock); | ||
BitBucketPPRTriggerFilter bitBucketPPRTriggerFilter = mock(BitBucketPPRTriggerFilter.class); | ||
BitBucketPPRTrigger bitBucketPPRTrigger = new BitBucketPPRTrigger(List.of(bitBucketPPRTriggerFilter)); | ||
bitBucketPPRTrigger.setPropagationUrl("https://example2.org/scm/some-namespace/some-repo2.git"); | ||
BitBucketPPRHookEvent bitBucketHookEvent = mock(BitBucketPPRHookEvent.class); | ||
|
||
SCM scmTrigger = mock(SCM.class); | ||
BitBucketPPRObservable observable = mock(BitBucketPPRObservable.class); | ||
bitBucketPPRTrigger.onPost(bitBucketHookEvent, bitBucketPPRServerRepositoryAction, scmTrigger, observable); | ||
assertEquals("https://example2.org:-1", bitBucketPPRServerRepositoryAction.getCommitLink().split("/rest/build-status/1.0/commits/")[0]); | ||
|
||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
@Test | ||
public void testTriggerUrlOverridesBaseUrl() { | ||
try (MockedStatic<BitBucketPPRPluginConfig> config = | ||
Mockito.mockStatic(BitBucketPPRPluginConfig.class)) { | ||
BitBucketPPRPluginConfig c = mock(BitBucketPPRPluginConfig.class); | ||
config.when(BitBucketPPRPluginConfig::getInstance).thenReturn(c); | ||
when(c.getPropagationUrl()) | ||
.thenReturn(new URL("https://example.org/scm/some-namespace/some-repo.git")); | ||
|
||
BitBucketPPRPayload payloadMock = mock(BitBucketPPRPayload.class, RETURNS_DEEP_STUBS); | ||
List<BitBucketPPRServerClone> clones = new ArrayList<>(); | ||
BitBucketPPRServerClone mockServerClone = mock(BitBucketPPRServerClone.class); | ||
when(mockServerClone.getName()).thenReturn("ssh"); | ||
when(mockServerClone.getHref()) | ||
.thenReturn("ssh://[email protected]/some-namespace/some-repo.git"); | ||
clones.add(mockServerClone); | ||
when(payloadMock.getServerRepository().getLinks().getCloneProperty()).thenReturn(clones); | ||
BitBucketPPRPullRequestServerAction bitBucketPPRServerRepositoryAction = | ||
new BitBucketPPRPullRequestServerAction(payloadMock); | ||
BitBucketPPRTriggerFilter bitBucketPPRTriggerFilter = mock(BitBucketPPRTriggerFilter.class); | ||
BitBucketPPRTrigger bitBucketPPRTrigger = | ||
new BitBucketPPRTrigger(List.of(bitBucketPPRTriggerFilter)); | ||
bitBucketPPRTrigger.setPropagationUrl( | ||
"https://example2.org/scm/some-namespace/some-repo2.git"); | ||
BitBucketPPRHookEvent bitBucketHookEvent = mock(BitBucketPPRHookEvent.class); | ||
|
||
SCM scmTrigger = mock(SCM.class); | ||
BitBucketPPRObservable observable = mock(BitBucketPPRObservable.class); | ||
bitBucketPPRTrigger.onPost( | ||
bitBucketHookEvent, bitBucketPPRServerRepositoryAction, scmTrigger, observable); | ||
assertEquals( | ||
"https://example2.org:-1", | ||
bitBucketPPRServerRepositoryAction.getCommitLink() | ||
.split("/rest/build-status/1.0/commits/")[0]); | ||
|
||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,39 +8,44 @@ | |
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class BitBucketPPRPullRequestServerActionTest { | ||
@Test | ||
public void testBaseUrlSet() { | ||
try (MockedStatic<BitBucketPPRPluginConfig> config = Mockito.mockStatic( | ||
BitBucketPPRPluginConfig.class)) { | ||
BitBucketPPRPluginConfig c = mock(BitBucketPPRPluginConfig.class); | ||
config.when(BitBucketPPRPluginConfig::getInstance).thenReturn(c); | ||
when(c.getPropagationUrl()).thenReturn("https://example.org/scm/some-namespace/some-repo.git"); | ||
@Test | ||
public void testBaseUrlSet() { | ||
try (MockedStatic<BitBucketPPRPluginConfig> config = | ||
Mockito.mockStatic(BitBucketPPRPluginConfig.class)) { | ||
BitBucketPPRPluginConfig c = mock(BitBucketPPRPluginConfig.class); | ||
config.when(BitBucketPPRPluginConfig::getInstance).thenReturn(c); | ||
when(c.getPropagationUrl()) | ||
.thenReturn(new URL("https://example.org/scm/some-namespace/some-repo.git")); | ||
|
||
BitBucketPPRPayload payloadMock = mock(BitBucketPPRPayload.class, RETURNS_DEEP_STUBS); | ||
List<BitBucketPPRServerClone> clones = new ArrayList<>(); | ||
BitBucketPPRServerClone mockServerClone = mock(BitBucketPPRServerClone.class); | ||
when(mockServerClone.getName()).thenReturn("ssh"); | ||
when(mockServerClone.getHref()).thenReturn("ssh://[email protected]/some-namespace/some-repo.git"); | ||
clones.add(mockServerClone); | ||
when(payloadMock.getServerRepository().getLinks().getCloneProperty()).thenReturn(clones); | ||
BitBucketPPRPullRequestServerAction bitBucketPPRPullRequestServerAction; | ||
try { | ||
bitBucketPPRPullRequestServerAction = new BitBucketPPRPullRequestServerAction(payloadMock); | ||
assertDoesNotThrow(() -> { | ||
bitBucketPPRPullRequestServerAction.getCommitLink(); | ||
}); | ||
} catch (BitBucketPPRPayloadPropertyNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
BitBucketPPRPayload payloadMock = mock(BitBucketPPRPayload.class, RETURNS_DEEP_STUBS); | ||
List<BitBucketPPRServerClone> clones = new ArrayList<>(); | ||
BitBucketPPRServerClone mockServerClone = mock(BitBucketPPRServerClone.class); | ||
when(mockServerClone.getName()).thenReturn("ssh"); | ||
when(mockServerClone.getHref()) | ||
.thenReturn("ssh://[email protected]/some-namespace/some-repo.git"); | ||
clones.add(mockServerClone); | ||
when(payloadMock.getServerRepository().getLinks().getCloneProperty()).thenReturn(clones); | ||
BitBucketPPRPullRequestServerAction bitBucketPPRPullRequestServerAction; | ||
try { | ||
bitBucketPPRPullRequestServerAction = new BitBucketPPRPullRequestServerAction(payloadMock); | ||
assertDoesNotThrow( | ||
() -> { | ||
bitBucketPPRPullRequestServerAction.getCommitLink(); | ||
}); | ||
} catch (BitBucketPPRPayloadPropertyNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
} catch (MalformedURLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
|
||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package io.jenkins.plugins.bitbucketpushandpullrequest.action; | ||
|
||
|
||
import io.jenkins.plugins.bitbucketpushandpullrequest.config.BitBucketPPRPluginConfig; | ||
import io.jenkins.plugins.bitbucketpushandpullrequest.model.BitBucketPPRPayload; | ||
import io.jenkins.plugins.bitbucketpushandpullrequest.model.server.BitBucketPPRServerClone; | ||
|
@@ -10,6 +9,8 @@ | |
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
@@ -19,31 +20,32 @@ | |
@ExtendWith(MockitoExtension.class) | ||
public class BitBucketPPRServerRepositoryActionTest { | ||
|
||
|
||
@Test | ||
public void testBaseUrlSet() { | ||
try (MockedStatic<BitBucketPPRPluginConfig> config = Mockito.mockStatic( | ||
BitBucketPPRPluginConfig.class)) { | ||
BitBucketPPRPluginConfig c = mock(BitBucketPPRPluginConfig.class); | ||
config.when(BitBucketPPRPluginConfig::getInstance).thenReturn(c); | ||
when(c.getPropagationUrl()).thenReturn("https://example.org/scm/some-namespace/some-repo.git"); | ||
|
||
BitBucketPPRPayload payloadMock = mock(BitBucketPPRPayload.class, RETURNS_DEEP_STUBS); | ||
List<BitBucketPPRServerClone> clones = new ArrayList<>(); | ||
BitBucketPPRServerClone mockServerClone = mock(BitBucketPPRServerClone.class); | ||
when(mockServerClone.getName()).thenReturn("ssh"); | ||
when(mockServerClone.getHref()).thenReturn("ssh://[email protected]/some-namespace/some-repo.git"); | ||
clones.add(mockServerClone); | ||
when(payloadMock.getServerRepository().getLinks().getCloneProperty()).thenReturn(clones); | ||
BitBucketPPRServerRepositoryAction bitBucketPPRServerRepositoryAction = new BitBucketPPRServerRepositoryAction(payloadMock); | ||
|
||
assertDoesNotThrow(() -> { | ||
bitBucketPPRServerRepositoryAction.getCommitLinks(); | ||
}); | ||
} | ||
|
||
|
||
@Test | ||
public void testBaseUrlSet() { | ||
try (MockedStatic<BitBucketPPRPluginConfig> config = | ||
Mockito.mockStatic(BitBucketPPRPluginConfig.class)) { | ||
BitBucketPPRPluginConfig c = mock(BitBucketPPRPluginConfig.class); | ||
config.when(BitBucketPPRPluginConfig::getInstance).thenReturn(c); | ||
when(c.getPropagationUrl()) | ||
.thenReturn(new URL("https://example.org/scm/some-namespace/some-repo.git")); | ||
|
||
BitBucketPPRPayload payloadMock = mock(BitBucketPPRPayload.class, RETURNS_DEEP_STUBS); | ||
List<BitBucketPPRServerClone> clones = new ArrayList<>(); | ||
BitBucketPPRServerClone mockServerClone = mock(BitBucketPPRServerClone.class); | ||
when(mockServerClone.getName()).thenReturn("ssh"); | ||
when(mockServerClone.getHref()) | ||
.thenReturn("ssh://[email protected]/some-namespace/some-repo.git"); | ||
clones.add(mockServerClone); | ||
when(payloadMock.getServerRepository().getLinks().getCloneProperty()).thenReturn(clones); | ||
BitBucketPPRServerRepositoryAction bitBucketPPRServerRepositoryAction = | ||
new BitBucketPPRServerRepositoryAction(payloadMock); | ||
|
||
assertDoesNotThrow( | ||
() -> { | ||
bitBucketPPRServerRepositoryAction.getCommitLinks(); | ||
}); | ||
} catch (MalformedURLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
|
||
} | ||
} |
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