2929import com .cloudbees .plugins .credentials .impl .UsernamePasswordCredentialsImpl ;
3030import hudson .model .FreeStyleBuild ;
3131import hudson .model .FreeStyleProject ;
32+ import jenkins .scm .impl .subversion .SubversionSampleRepoExtension ;
33+ import org .junit .jupiter .api .BeforeEach ;
34+ import org .junit .jupiter .api .Test ;
35+ import org .junit .jupiter .api .extension .RegisterExtension ;
36+ import org .jvnet .hudson .test .Issue ;
37+ import org .jvnet .hudson .test .JenkinsRule ;
38+ import org .jvnet .hudson .test .junit .jupiter .BuildWatcherExtension ;
39+ import org .jvnet .hudson .test .junit .jupiter .WithJenkins ;
40+
3241import java .net .ServerSocket ;
3342import java .util .Arrays ;
3443import java .util .Collections ;
3544import java .util .Set ;
3645import java .util .TreeSet ;
37- import jenkins .scm .impl .subversion .SubversionSampleRepoRule ;
38- import org .junit .ClassRule ;
39- import org .junit .Test ;
40- import static org .junit .Assert .*;
41- import org .junit .Rule ;
42- import org .jvnet .hudson .test .BuildWatcher ;
43- import org .jvnet .hudson .test .Issue ;
44- import org .jvnet .hudson .test .JenkinsRule ;
4546
46- public class CredentialsExternalsTest {
47+ import static org .junit .jupiter .api .Assertions .assertEquals ;
48+
49+ @ WithJenkins
50+ class CredentialsExternalsTest {
4751
48- @ ClassRule
49- public static BuildWatcher buildWatcher = new BuildWatcher ();
52+ @ SuppressWarnings ("unused" )
53+ @ RegisterExtension
54+ private static final BuildWatcherExtension BUILD_WATCHER = new BuildWatcherExtension ();
5055
51- @ Rule
52- public JenkinsRule r = new JenkinsRule ();
56+ private JenkinsRule r ;
5357
54- @ Rule
55- public SubversionSampleRepoRule main = new SubversionSampleRepoRule ();
58+ @ RegisterExtension
59+ private final SubversionSampleRepoExtension main = new SubversionSampleRepoExtension ();
5660
57- @ Rule
58- public SubversionSampleRepoRule ext = new SubversionSampleRepoRule ();
61+ @ RegisterExtension
62+ private final SubversionSampleRepoExtension ext = new SubversionSampleRepoExtension ();
63+
64+ @ BeforeEach
65+ void beforeEach (JenkinsRule rule ) {
66+ r = rule ;
67+ }
5968
6069 @ Issue ("JENKINS-32167" )
6170 @ Test
62- public void smokes () throws Exception {
71+ void smokes () throws Exception {
6372 main .init ();
6473 main .writeConf ("svnserve.conf" ,
65- "[general]\n " +
66- "password-db = passwd\n " +
67- "authz-db = authz\n " +
68- "anon-access = none\n " ); // https://bugzilla.redhat.com/show_bug.cgi?id=556712
74+ """
75+ [general]
76+ password-db = passwd
77+ authz-db = authz
78+ anon-access = none
79+ """ ); // https://bugzilla.redhat.com/show_bug.cgi?id=556712
6980 main .writeConf ("passwd" ,
70- "[users]\n " +
71- "alice = alice\n " );
81+ """
82+ [users]
83+ alice = alice
84+ """ );
7285 main .writeConf ("authz" ,
73- "[/]\n " +
74- "alice = rw\n " );
86+ """
87+ [/]
88+ alice = rw
89+ """ );
7590 // Adapted from AbstractSubversionTest.runSvnServe:
7691 int mainPort ;
7792 ServerSocket serverSocket = new ServerSocket (0 );
@@ -86,16 +101,22 @@ public void smokes() throws Exception {
86101 System .err .println ("Running svnserve on <svn://localhost:" + mainPort + "> " + main .uuid ());
87102 ext .init ();
88103 ext .writeConf ("svnserve.conf" ,
89- "[general]\n " +
90- "password-db = passwd\n " +
91- "authz-db = authz\n " +
92- "anon-access = none\n " );
104+ """
105+ [general]
106+ password-db = passwd
107+ authz-db = authz
108+ anon-access = none
109+ """ );
93110 ext .writeConf ("passwd" ,
94- "[users]\n " +
95- "bob = bob\n " );
111+ """
112+ [users]
113+ bob = bob
114+ """ );
96115 ext .writeConf ("authz" ,
97- "[/]\n " +
98- "bob = rw\n " );
116+ """
117+ [/]
118+ bob = rw
119+ """ );
99120 int extPort ;
100121 serverSocket = new ServerSocket (0 );
101122 try {
@@ -111,12 +132,12 @@ public void smokes() throws Exception {
111132 main .svnkit ("commit" , "--message=externals" , main .wc ());
112133 FreeStyleProject p = r .createFreeStyleProject ("p" );
113134 SystemCredentialsProvider .getInstance ().setDomainCredentialsMap (Collections .singletonMap (Domain .global (), Arrays .asList (
114- new UsernamePasswordCredentialsImpl (CredentialsScope .GLOBAL , "main-creds" , null , "alice" , "alice" ),
115- new UsernamePasswordCredentialsImpl (CredentialsScope .GLOBAL , "ext-creds" , null , "bob" , "bob" ))));
135+ new UsernamePasswordCredentialsImpl (CredentialsScope .GLOBAL , "main-creds" , null , "alice" , "alice" ),
136+ new UsernamePasswordCredentialsImpl (CredentialsScope .GLOBAL , "ext-creds" , null , "bob" , "bob" ))));
116137 p .setScm (new SubversionSCM (
117- Collections .singletonList (new SubversionSCM .ModuleLocation ("svn://localhost:" + mainPort + "/prj/trunk" , "main-creds" , "." , "" , false )),
118- null , null , null , null , null , null , null , false , false , // WTF was all that?
119- Collections .singletonList (new SubversionSCM .AdditionalCredentials ("<svn://localhost:" + extPort + "> " + ext .uuid (), "ext-creds" ))));
138+ Collections .singletonList (new SubversionSCM .ModuleLocation ("svn://localhost:" + mainPort + "/prj/trunk" , "main-creds" , "." , "" , false )),
139+ null , null , null , null , null , null , null , false , false , // WTF was all that?
140+ Collections .singletonList (new SubversionSCM .AdditionalCredentials ("<svn://localhost:" + extPort + "> " + ext .uuid (), "ext-creds" ))));
120141 FreeStyleBuild b = r .buildAndAssertSuccess (p );
121142 assertEquals ("" , b .getWorkspace ().child ("file" ).readToString ());
122143 assertEquals ("" , b .getWorkspace ().child ("ext/file" ).readToString ());
0 commit comments