11package com .nirima .jenkins .plugins .docker ;
22
33import static com .cloudbees .plugins .credentials .CredentialsScope .SYSTEM ;
4+ import static org .junit .jupiter .api .Assertions .assertEquals ;
5+ import static org .junit .jupiter .api .Assertions .assertNull ;
46
57import com .cloudbees .plugins .credentials .CredentialsProvider ;
68import com .cloudbees .plugins .credentials .CredentialsStore ;
1719import java .util .List ;
1820import java .util .Map ;
1921import java .util .Set ;
20- import java .util .logging .Level ;
2122import org .jenkinsci .plugins .docker .commons .credentials .DockerServerCredentials ;
2223import org .jenkinsci .plugins .docker .commons .credentials .DockerServerEndpoint ;
23- import org .junit .Assert ;
24- import org .junit .Rule ;
25- import org .junit .Test ;
24+ import org .junit .jupiter .api .Test ;
2625import org .jvnet .hudson .test .Issue ;
2726import org .jvnet .hudson .test .JenkinsRule ;
28- import org .jvnet .hudson .test .LoggerRule ;
27+ import org .jvnet .hudson .test .junit . jupiter . WithJenkins ;
2928
3029/**
3130 * @author Kanstantsin Shautsou
3231 */
33- public class DockerCloudTest {
32+ @ WithJenkins
33+ class DockerCloudTest {
3434
35- @ Rule
36- public JenkinsRule jenkins = new JenkinsRule ();
37-
38- @ Rule
39- public LoggerRule lr = new LoggerRule ();
40-
41- @ SuppressWarnings ("unused" )
35+ @ SuppressWarnings ("deprecation" )
4236 @ Test
43- public void testConstructor_0_10_2 () {
37+ void testConstructor_0_10_2 (@ SuppressWarnings ( "unused" ) JenkinsRule jenkins ) {
4438 new DockerCloud (
4539 "name" ,
4640 List .of (), // templates
@@ -53,25 +47,22 @@ public void testConstructor_0_10_2() {
5347 null ); // dockerHostname
5448 }
5549
56- private static final String LOG_MESSAGE = "Docker cloud requires a non-blank name after Jenkins 2.402" ;
57-
5850 @ Issue ("JENKINS-70729" ) // Handle null or empty cloud name
5951 @ Test
60- public void testCopyConstructor () {
61- lr .record (DockerCloud .class .getName (), Level .ALL ).capture (16 );
52+ void testCopyConstructor (@ SuppressWarnings ("unused" ) JenkinsRule jenkins ) {
6253 DockerCloud cloud =
6354 new DockerCloud ("tmp" , new DockerAPI (new DockerServerEndpoint ("uri" , "credentialsId" )), List .of ());
6455 cloud .name = null ;
65- Assert . assertEquals (cloud .getDisplayName (), null );
56+ assertNull (cloud .getDisplayName ());
6657 String newName = "docker-cloud-" + Integer .toHexString (cloud .hashCode ());
6758 DockerCloud copy = new DockerCloud (newName , cloud );
68- Assert . assertEquals (cloud .getDockerApi (), copy .getDockerApi ());
69- Assert . assertEquals (cloud .getTemplates ().hashCode (), copy .getTemplates ().hashCode ());
70- Assert . assertEquals (newName , copy .getDisplayName ());
59+ assertEquals (cloud .getDockerApi (), copy .getDockerApi ());
60+ assertEquals (cloud .getTemplates ().hashCode (), copy .getTemplates ().hashCode ());
61+ assertEquals (newName , copy .getDisplayName ());
7162 }
7263
7364 @ Test
74- public void globalConfigRoundtrip () throws Exception {
65+ void globalConfigRoundtrip (@ SuppressWarnings ( "unused" ) JenkinsRule jenkins ) throws Exception {
7566
7667 // Create fake credentials, so they are selectable on configuration for during configuration roundtrip
7768 final CredentialsStore store = CredentialsProvider .lookupStores (jenkins .getInstance ())
@@ -128,22 +119,22 @@ public void globalConfigRoundtrip() throws Exception {
128119
129120 jenkins .configRoundtrip ();
130121
131- Assert . assertEquals (cloud , jenkins .getInstance ().clouds .get (0 ));
122+ assertEquals (cloud , jenkins .getInstance ().clouds .get (0 ));
132123 }
133124
134125 @ Test
135- public void keepTrackOfContainersInProgress () {
126+ void keepTrackOfContainersInProgress (@ SuppressWarnings ( "unused" ) JenkinsRule jenkins ) {
136127 final DockerTemplate i1 = new DockerTemplate (new DockerTemplateBase ("image1" ), null , null , null , null );
137128 final DockerTemplate i2 = new DockerTemplate (new DockerTemplateBase ("image2" ), null , null , null , null );
138129 final String uniqueId = Integer .toString (hashCode (), 36 );
139130 final DockerCloud c1 = new DockerCloud ("cloud1." + uniqueId , null , null );
140131 final DockerCloud c2 = new DockerCloud ("cloud2." + uniqueId , null , null );
141132
142133 assertCount (c1 , c2 , i1 , i2 , 0 , 0 , 0 , 0 );
143- Assert .assertEquals (
144- "DockerCloud.CONTAINERS_IN_PROGRESS is empty to start with" ,
134+ assertEquals (
145135 DockerCloud .CONTAINERS_IN_PROGRESS ,
146- Map .of ());
136+ Map .of (),
137+ "DockerCloud.CONTAINERS_IN_PROGRESS is empty to start with" );
147138
148139 c1 .incrementContainersInProgress (i1 );
149140 assertCount (c1 , c2 , i1 , i2 , 1 , 0 , 0 , 0 );
@@ -162,8 +153,8 @@ public void keepTrackOfContainersInProgress() {
162153 assertCount (c1 , c2 , i1 , i2 , 0 , 0 , 1 , 0 );
163154 c2 .decrementContainersInProgress (i1 );
164155 assertCount (c1 , c2 , i1 , i2 , 0 , 0 , 0 , 0 );
165- Assert . assertEquals (
166- "DockerCloud.CONTAINERS_IN_PROGRESS is empty afterwards" , DockerCloud . CONTAINERS_IN_PROGRESS , Map . of () );
156+ assertEquals (
157+ DockerCloud . CONTAINERS_IN_PROGRESS , Map . of (), "DockerCloud.CONTAINERS_IN_PROGRESS is empty afterwards" );
167158 }
168159
169160 private static void assertCount (
@@ -178,16 +169,16 @@ private static void assertCount(
178169 final int c1All = c1i1 + c1i2 ;
179170 final int c2All = c2i1 + c2i2 ;
180171 final String state = "when c1(" + c1i1 + "," + c1i2 + "), c2(" + c2i1 + "," + c2i2 + "), " ;
181- Assert . assertEquals (state + " c1.countContainersInProgress()" , c1All , c1 .countContainersInProgress ());
182- Assert . assertEquals (state + " c2.countContainersInProgress()" , c2All , c2 .countContainersInProgress ());
183- Assert . assertEquals (state + " c1.countContainersInProgress(i1)" , c1i1 , c1 .countContainersInProgress (i1 ));
184- Assert . assertEquals (state + " c1.countContainersInProgress(i2)" , c1i2 , c1 .countContainersInProgress (i2 ));
185- Assert . assertEquals (state + " c2.countContainersInProgress(i1)" , c2i1 , c2 .countContainersInProgress (i1 ));
186- Assert . assertEquals (state + " c2.countContainersInProgress(i2)" , c2i2 , c2 .countContainersInProgress (i2 ));
172+ assertEquals (c1All , c1 .countContainersInProgress (), state + " c1.countContainersInProgress()" );
173+ assertEquals (c2All , c2 .countContainersInProgress (), state + " c2.countContainersInProgress()" );
174+ assertEquals (c1i1 , c1 .countContainersInProgress (i1 ), state + " c1.countContainersInProgress(i1)" );
175+ assertEquals (c1i2 , c1 .countContainersInProgress (i2 ), state + " c1.countContainersInProgress(i2)" );
176+ assertEquals (c2i1 , c2 .countContainersInProgress (i1 ), state + " c2.countContainersInProgress(i1)" );
177+ assertEquals (c2i2 , c2 .countContainersInProgress (i2 ), state + " c2.countContainersInProgress(i2)" );
187178 }
188179
189180 @ Test
190- public void testRegistryCredentials () throws Exception {
181+ void testRegistryCredentials (JenkinsRule jenkins ) throws Exception {
191182
192183 final CredentialsStore store = CredentialsProvider .lookupStores (jenkins .getInstance ())
193184 .iterator ()
@@ -201,61 +192,61 @@ public void testRegistryCredentials() throws Exception {
201192 dtb1 .setPullCredentialsId (rc .getId ());
202193 AuthConfig authConfig = DockerCloud .getAuthConfig (
203194 dtb1 .getRegistry (), jenkins .getInstance ().getItemGroup ());
204- Assert . assertEquals ("test" , authConfig .getUsername ());
205- Assert . assertEquals ("secret" , authConfig .getPassword ());
206- Assert . assertEquals (AuthConfig .DEFAULT_SERVER_ADDRESS , authConfig .getRegistryAddress ());
195+ assertEquals ("test" , authConfig .getUsername ());
196+ assertEquals ("secret" , authConfig .getPassword ());
197+ assertEquals (AuthConfig .DEFAULT_SERVER_ADDRESS , authConfig .getRegistryAddress ());
207198
208199 // Test default registry / tag
209200 dtb1 = new DockerTemplateBase ("user/image1:tag" );
210201 dtb1 .setPullCredentialsId (rc .getId ());
211202 authConfig = DockerCloud .getAuthConfig (
212203 dtb1 .getRegistry (), jenkins .getInstance ().getItemGroup ());
213- Assert . assertEquals ("test" , authConfig .getUsername ());
214- Assert . assertEquals ("secret" , authConfig .getPassword ());
215- Assert . assertEquals (AuthConfig .DEFAULT_SERVER_ADDRESS , authConfig .getRegistryAddress ());
204+ assertEquals ("test" , authConfig .getUsername ());
205+ assertEquals ("secret" , authConfig .getPassword ());
206+ assertEquals (AuthConfig .DEFAULT_SERVER_ADDRESS , authConfig .getRegistryAddress ());
216207
217208 // Test custom registry / tag
218209 dtb1 = new DockerTemplateBase ("my.docker.registry/repo/image1:tag" );
219210 dtb1 .setPullCredentialsId (rc .getId ());
220211 authConfig = DockerCloud .getAuthConfig (
221212 dtb1 .getRegistry (), jenkins .getInstance ().getItemGroup ());
222- Assert . assertEquals ("test" , authConfig .getUsername ());
223- Assert . assertEquals ("secret" , authConfig .getPassword ());
224- Assert . assertEquals ("https://my.docker.registry" , authConfig .getRegistryAddress ());
213+ assertEquals ("test" , authConfig .getUsername ());
214+ assertEquals ("secret" , authConfig .getPassword ());
215+ assertEquals ("https://my.docker.registry" , authConfig .getRegistryAddress ());
225216
226217 // Test custom registry / port / tag
227218 dtb1 = new DockerTemplateBase ("my.docker.registry:12345/repo/image1:tag" );
228219 dtb1 .setPullCredentialsId (rc .getId ());
229220 authConfig = DockerCloud .getAuthConfig (
230221 dtb1 .getRegistry (), jenkins .getInstance ().getItemGroup ());
231- Assert . assertEquals ("test" , authConfig .getUsername ());
232- Assert . assertEquals ("secret" , authConfig .getPassword ());
233- Assert . assertEquals ("https://my.docker.registry:12345" , authConfig .getRegistryAddress ());
222+ assertEquals ("test" , authConfig .getUsername ());
223+ assertEquals ("secret" , authConfig .getPassword ());
224+ assertEquals ("https://my.docker.registry:12345" , authConfig .getRegistryAddress ());
234225
235226 // Test custom registry / port / tag / sha
236227 dtb1 = new DockerTemplateBase ("my.docker.registry:12345/repo/image@sha256:sha256" );
237228 dtb1 .setPullCredentialsId (rc .getId ());
238229 authConfig = DockerCloud .getAuthConfig (
239230 dtb1 .getRegistry (), jenkins .getInstance ().getItemGroup ());
240- Assert . assertEquals ("test" , authConfig .getUsername ());
241- Assert . assertEquals ("secret" , authConfig .getPassword ());
242- Assert . assertEquals ("https://my.docker.registry:12345" , authConfig .getRegistryAddress ());
231+ assertEquals ("test" , authConfig .getUsername ());
232+ assertEquals ("secret" , authConfig .getPassword ());
233+ assertEquals ("https://my.docker.registry:12345" , authConfig .getRegistryAddress ());
243234
244235 // Test V2
245236 dtb1 = new DockerTemplateBase ("my.docker.registry:12345/namespace/repo/image1:tag" );
246237 dtb1 .setPullCredentialsId (rc .getId ());
247238 authConfig = DockerCloud .getAuthConfig (
248239 dtb1 .getRegistry (), jenkins .getInstance ().getItemGroup ());
249- Assert . assertEquals ("test" , authConfig .getUsername ());
250- Assert . assertEquals ("secret" , authConfig .getPassword ());
251- Assert . assertEquals ("https://my.docker.registry:12345" , authConfig .getRegistryAddress ());
240+ assertEquals ("test" , authConfig .getUsername ());
241+ assertEquals ("secret" , authConfig .getPassword ());
242+ assertEquals ("https://my.docker.registry:12345" , authConfig .getRegistryAddress ());
252243
253244 dtb1 = new DockerTemplateBase ("my.docker.registry:12345/namespace/repo/image@sha256:sha256" );
254245 dtb1 .setPullCredentialsId (rc .getId ());
255246 authConfig = DockerCloud .getAuthConfig (
256247 dtb1 .getRegistry (), jenkins .getInstance ().getItemGroup ());
257- Assert . assertEquals ("test" , authConfig .getUsername ());
258- Assert . assertEquals ("secret" , authConfig .getPassword ());
259- Assert . assertEquals ("https://my.docker.registry:12345" , authConfig .getRegistryAddress ());
248+ assertEquals ("test" , authConfig .getUsername ());
249+ assertEquals ("secret" , authConfig .getPassword ());
250+ assertEquals ("https://my.docker.registry:12345" , authConfig .getRegistryAddress ());
260251 }
261252}
0 commit comments