4141import hudson .model .Descriptor .FormException ;
4242import hudson .model .Item ;
4343import hudson .plugins .git .GitSCM ;
44- import hudson .plugins .git .UserRemoteConfig ;
4544import hudson .plugins .git .extensions .impl .BuildChooserSetting ;
4645import java .io .ByteArrayOutputStream ;
4746import java .io .IOException ;
48- import java .nio .charset .StandardCharsets ;
4947import java .util .Arrays ;
5048import java .util .List ;
5149import jenkins .plugins .git .AbstractGitSCMSource ;
6563import org .jvnet .hudson .test .junit .jupiter .WithJenkins ;
6664import org .jvnet .hudson .test .recipes .WithTimeout ;
6765
68- import static org .hamcrest .MatcherAssert .assertThat ;
69- import static org .hamcrest .Matchers .containsInAnyOrder ;
70- import static org .hamcrest .Matchers .containsString ;
71- import static org .hamcrest .Matchers .instanceOf ;
72- import static org .hamcrest .Matchers .is ;
66+ import static org .assertj .core .api .Assertions .assertThat ;
7367import static org .mockito .Mockito .mock ;
7468import static org .mockito .Mockito .when ;
7569
7973 */
8074@ WithJenkins
8175@ WithGitSampleRepo
82- public class BitbucketSCMSourceBuildTest {
76+ class BitbucketSCMSourceBuildTest {
8377
8478 private static final String CLOUD_REPO_OWNER = "cloudbeers" ;
8579 private static final String REPO_NAME = "stunning-adventure" ;
8680 private static final String BRANCH_NAME = "master" ;
8781 // Test private key from ssh-credentials test case
8882 // https://github.com/jenkinsci/ssh-credentials-plugin/blob/343.v884f71d78167/src/test/resources/com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKeyTest/readOldCredentials/credentials.xml
89- private static final String PRIVATE_KEY = "-----BEGIN RSA PRIVATE KEY-----\n " +
90- "MIIEpAIBAAKCAQEAu1r+HHzmpybc4iwoP5+44FjvcaMkNEWeGQZlmPwLx70XW8+8\n " +
91- "3d2BMLjhcw1zLsYG3FWpCyn8cB1OmjKiGjvnP5EBoAolvh3qOcWKyWlVGWGgs10B\n " +
92- "0Cgnd3OBXRPQd1cBdiQZmmeCrrH0OjQefYIF2WYN+F8iuNGraAaRsXLgITanjTb1\n " +
93- "6w1dnk+KLpU2J5G6kG1f/Qxl4pgny80S/3TktqoknbOrYDMOSA1Zdww39cpXJHp6\n " +
94- "feEs8tavC93rOsR2O4ZfVUCjTFAF5FtIdRv3LXY3Q5W/AyY1h45Wk6mMVnEluFjB\n " +
95- "aA+gzVAVaHFQfuhwoj4B7jWCmfHsPG1WmyK0YQIDAQABAoIBADt1qlXiMdV0mP9S\n " +
96- "okdm6maQ8xTugKvyODWa+R1vSFHQqhwiNr927+xFkI9SAm8iu8SrjuWTIqF2O57m\n " +
97- "WNnYjxB2dbyT29yVY+OH1P8M5cwTVsv1xYCJbdUUHEcs5akqPLWAyXteRHQq1+as\n " +
98- "6cxNOov/PonHr55WNH7kLtLRMV54jZ68nrEh5pWdabFa0f7d/ByIvYRJm7lpjtSp\n " +
99- "EBp5AseXzSg2EZP3HDPYYPDHK0tMPginz9+YuQCQFoMYAkVZoKFJGsWICktd5Uk7\n " +
100- "wveOJLOfMng1Iww6CEc871GcLn5LbafLWRxjZssK2Z1fC+pZYLLZPeKDMSxoRXm6\n " +
101- "PShUC1ECgYEA623dmwJNYfVRgAgOYhhcxzH4TAXUmUIpadEUjOkAhe3w/abDawFT\n " +
102- "9ianhqfhTjSZGBtUttcN40Vy+P4bsqfQKZ7p6KzrdR2zWjlYcICWhZDZPGmMxpMZ\n " +
103- "mUFhZXsLRVhn8qed8w1t6eju7S+t9satKIMC/KrhNsFzjrgbU9eC+m0CgYEAy7nN\n " +
104- "gMwQeGxAQSJr9H7eKkthnjMe77rLIAZEbDJhcwYVz+Iie/E4hjESQ+IuvXa1VawD\n " +
105- "O6cD0wWdOhH2McNdMNIbM4IOaO/TOaR5jfQwBWmb4iG2BZQWQQE/HUBnoJQWUhqm\n " +
106- "b+D+s4bHh4J+bs+ptgg9Sd9V+VxJBcu2QDmI6UUCgYBTb1pMJyK5hrFdiH1gcnXe\n " +
107- "+myetKpFrlby83AvCBxxWoQ/wKwc7hmNcOGKLVEB4E4pZvY83jZDx0cZyySRyjtR\n " +
108- "pMoM9ct0dBQt84jORiQSLeVvLZEAhv1ZfPxBdLvn1Y7xRkoJ60Z60Vxrnqwueva/\n " +
109- "Fr8mQIEUYLbNa53ztrrqeQKBgQCqOY4k2F3KwWjPA9wAZyFrZaEjdsOavBGNqK7z\n " +
110- "WQVj/umq0eDOfzgjqE0Cu7MiTFYoR5pL9bmUUVSWePuliQANEwH3f+xackmkGHIY\n " +
111- "0rhtTVkbEd/tuVb+6fO6lV4BJrufzvTS9sTbbPq7l6XdIVdE6o2LdDl6Kko5tYWL\n " +
112- "FIf5oQKBgQDLHK/9NTb3VHp+Qriu2Vp8Pnaw6YF6pETfgjyrH2ULSW/R07v+AECC\n " +
113- "sPr+d/hx2MQWp54HglY8lv98rOrRjMiRw1GVoXs+Ut9vkupmrpvzNE7ITl0tzBqD\n " +
114- "sroT/IHW2jKMD0v8kKLUnKCZYzlw0By7+RvJ8lgzHB0D71f6EC1UWg==\n " +
115- "-----END RSA PRIVATE KEY-----\n " ;
116-
117- public static JenkinsRule rule = new JenkinsRule ();
83+ private static final String PRIVATE_KEY = """
84+ -----BEGIN RSA PRIVATE KEY-----
85+ MIIEpAIBAAKCAQEAu1r+HHzmpybc4iwoP5+44FjvcaMkNEWeGQZlmPwLx70XW8+8
86+ 3d2BMLjhcw1zLsYG3FWpCyn8cB1OmjKiGjvnP5EBoAolvh3qOcWKyWlVGWGgs10B
87+ 0Cgnd3OBXRPQd1cBdiQZmmeCrrH0OjQefYIF2WYN+F8iuNGraAaRsXLgITanjTb1
88+ 6w1dnk+KLpU2J5G6kG1f/Qxl4pgny80S/3TktqoknbOrYDMOSA1Zdww39cpXJHp6
89+ feEs8tavC93rOsR2O4ZfVUCjTFAF5FtIdRv3LXY3Q5W/AyY1h45Wk6mMVnEluFjB
90+ aA+gzVAVaHFQfuhwoj4B7jWCmfHsPG1WmyK0YQIDAQABAoIBADt1qlXiMdV0mP9S
91+ okdm6maQ8xTugKvyODWa+R1vSFHQqhwiNr927+xFkI9SAm8iu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2Vp8Pnaw6YF6pETfgjyrH2ULSW/R07v+AECC
108+ sPr+d/hx2MQWp54HglY8lv98rOrRjMiRw1GVoXs+Ut9vkupmrpvzNE7ITl0tzBqD
109+ sroT/IHW2jKMD0v8kKLUnKCZYzlw0By7+RvJ8lgzHB0D71f6EC1UWg==
110+ -----END RSA PRIVATE KEY-----
111+ """ ;
112+
113+ private static JenkinsRule rule ;
118114
119115 @ BeforeAll
120116 static void init (JenkinsRule r ) {
@@ -171,17 +167,19 @@ void buildWhenSetSSHCheckoutTraitThenEmptyAuthenticatorExtension() throws Except
171167 new AbstractGitSCMSource .SCMRevisionImpl (head , sampleRepo .head ());
172168 GitSCM build = (GitSCM ) scmSource .build (head , revision );
173169
174- assertThat (build .getUserRemoteConfigs ().size (), is (1 ));
175- UserRemoteConfig remoteConfig = build .getUserRemoteConfigs ().get (0 );
176- assertThat (remoteConfig .getUrl (), is (String .format ("ssh://user@localhost/%s" , sampleRepo )));
177- assertThat (remoteConfig .getRefspec (), is (String .format ("+refs/heads/%s:refs/remotes/origin/%s" , BRANCH_NAME , BRANCH_NAME )));
178- assertThat (remoteConfig .getCredentialsId (), is (sshCredentials .getId ()));
179- assertThat (build .getExtensions (), containsInAnyOrder (
180- instanceOf (BuildChooserSetting .class ),
181- instanceOf (GitSCMSourceDefaults .class ),
182- instanceOf (GitClientAuthenticatorExtension .class ),
183- instanceOf (BitbucketEnvVarExtension .class ))
184- );
170+ assertThat (build .getUserRemoteConfigs ())
171+ .hasSize (1 )
172+ .element (0 ).satisfies (remoteConfig -> {
173+ assertThat (remoteConfig .getUrl ()).isEqualTo (String .format ("ssh://user@localhost/%s" , sampleRepo ));
174+ assertThat (remoteConfig .getRefspec ()).isEqualTo (String .format ("+refs/heads/%s:refs/remotes/origin/%s" , BRANCH_NAME , BRANCH_NAME ));
175+ assertThat (remoteConfig .getCredentialsId ()).isEqualTo (sshCredentials .getId ());
176+ assertThat (build .getExtensions ()).hasOnlyElementsOfTypes (
177+ BuildChooserSetting .class ,
178+ GitSCMSourceDefaults .class ,
179+ GitClientAuthenticatorExtension .class ,
180+ BitbucketEnvVarExtension .class
181+ );
182+ });
185183
186184 // Create a Pipeline with CpsScmFlowDefinition based of the GitSCM produced
187185 // Then check that the checkout uses GIT_SSH from the git-client logs
@@ -191,7 +189,7 @@ void buildWhenSetSSHCheckoutTraitThenEmptyAuthenticatorExtension() throws Except
191189
192190 ByteArrayOutputStream byteArrayOutStr = new ByteArrayOutputStream ();
193191 run .writeWholeLogTo (byteArrayOutStr );
194- assertThat (byteArrayOutStr . toString ( StandardCharsets . UTF_8 ), containsString ("using GIT_SSH to set credentials" ) );
192+ assertThat (byteArrayOutStr ). asString (). contains ("using GIT_SSH to set credentials" );
195193 }
196194
197195 @ Test
@@ -226,17 +224,19 @@ void buildBasicAuthThenAuthenticatorExtension() throws Exception {
226224 new AbstractGitSCMSource .SCMRevisionImpl (head , sampleRepo .head ());
227225 GitSCM build = (GitSCM ) scmSource .build (head , revision );
228226
229- assertThat (build .getUserRemoteConfigs ().size (), is (1 ));
230- UserRemoteConfig remoteConfig = build .getUserRemoteConfigs ().get (0 );
231- assertThat (remoteConfig .getUrl (), is (sampleRepo .toString ()));
232- assertThat (remoteConfig .getRefspec (), is (String .format ("+refs/heads/%s:refs/remotes/origin/%s" , BRANCH_NAME , BRANCH_NAME )));
233- assertThat (remoteConfig .getCredentialsId (), is (userPassCredentials .getId ()));
234- assertThat (build .getExtensions (), containsInAnyOrder (
235- instanceOf (BuildChooserSetting .class ),
236- instanceOf (GitSCMSourceDefaults .class ),
237- instanceOf (GitClientAuthenticatorExtension .class ),
238- instanceOf (BitbucketEnvVarExtension .class )
239- ));
227+ assertThat (build .getUserRemoteConfigs ())
228+ .hasSize (1 )
229+ .element (0 ).satisfies (remoteConfig -> {
230+ assertThat (remoteConfig .getUrl ()).isEqualTo (sampleRepo .toString ());
231+ assertThat (remoteConfig .getRefspec ()).isEqualTo (String .format ("+refs/heads/%s:refs/remotes/origin/%s" , BRANCH_NAME , BRANCH_NAME ));
232+ assertThat (remoteConfig .getCredentialsId ()).isEqualTo (userPassCredentials .getId ());
233+ assertThat (build .getExtensions ()).hasOnlyElementsOfTypes (
234+ BuildChooserSetting .class ,
235+ GitSCMSourceDefaults .class ,
236+ GitClientAuthenticatorExtension .class ,
237+ BitbucketEnvVarExtension .class
238+ );
239+ });
240240
241241 // Create a Pipeline with CpsScmFlowDefinition based of the GitSCM produced
242242 // Then check that the checkout scm uses GIT_ASKPASS from the git-client logs
@@ -246,7 +246,7 @@ void buildBasicAuthThenAuthenticatorExtension() throws Exception {
246246
247247 ByteArrayOutputStream byteArrayOutStr = new ByteArrayOutputStream ();
248248 run .writeWholeLogTo (byteArrayOutStr );
249- assertThat (byteArrayOutStr . toString ( StandardCharsets . UTF_8 ), containsString ("using GIT_ASKPASS to set credentials" ) );
249+ assertThat (byteArrayOutStr ). asString (). contains ("using GIT_ASKPASS to set credentials" );
250250 }
251251
252252 @ Test
@@ -279,17 +279,19 @@ void verify_ssh_trait_on_data_center_with_disabled_https_protocol() throws Excep
279279 AbstractGitSCMSource .SCMRevisionImpl revision = new AbstractGitSCMSource .SCMRevisionImpl (head , "1dbb02d4c1b99f1e84459c6947e3caa53cadfad1" );
280280 GitSCM build = (GitSCM ) scmSource .build (head , revision );
281281
282- assertThat (build .getUserRemoteConfigs ().size (), is (1 ));
283- UserRemoteConfig remoteConfig = build .getUserRemoteConfigs ().get (0 );
284- assertThat (remoteConfig .getUrl (), is (sshCloneURL ));
285- assertThat (remoteConfig .getRefspec (), is (String .format ("+refs/heads/%s:refs/remotes/origin/%s" , BRANCH_NAME , BRANCH_NAME )));
286- assertThat (remoteConfig .getCredentialsId (), is (sshCredentials .getId ()));
287- assertThat (build .getExtensions (), containsInAnyOrder (
288- instanceOf (BuildChooserSetting .class ),
289- instanceOf (GitSCMSourceDefaults .class ),
290- instanceOf (GitClientAuthenticatorExtension .class ),
291- instanceOf (BitbucketEnvVarExtension .class ))
292- );
282+ assertThat (build .getUserRemoteConfigs ())
283+ .hasSize (1 )
284+ .element (0 ).satisfies (remoteConfig -> {
285+ assertThat (remoteConfig .getUrl ()).isEqualTo (sshCloneURL );
286+ assertThat (remoteConfig .getRefspec ()).isEqualTo (String .format ("+refs/heads/%s:refs/remotes/origin/%s" , BRANCH_NAME , BRANCH_NAME ));
287+ assertThat (remoteConfig .getCredentialsId ()).isEqualTo (sshCredentials .getId ());
288+ assertThat (build .getExtensions ()).hasOnlyElementsOfTypes (
289+ BuildChooserSetting .class ,
290+ GitSCMSourceDefaults .class ,
291+ GitClientAuthenticatorExtension .class ,
292+ BitbucketEnvVarExtension .class
293+ );
294+ });
293295 }
294296
295297 private StandardUsernameCredentials registerSSHCredentials () throws IOException {
0 commit comments