8000 HADOOP-19414. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-auth. · apache/hadoop@73f2761 · GitHub
[go: up one dir, main page]

Skip to content

Commit 73f2761

Browse files
committed
HADOOP-19414. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-auth.
1 parent 7d474d3 commit 73f2761

24 files changed

+491
-458
lines changed

hadoop-common-project/hadoop-auth/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@
205205
<artifactId>guava</artifactId>
206206
<scope>test</scope>
207207
</dependency>
208+
<dependency>
209+
<groupId>org.assertj</groupId>
210+
<artifactId>assertj-core</artifactId>
211+
<scope>test</scope>
212+
</dependency>
208213
</dependencies>
209214

210215
<build>

hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/client/AuthenticatorTestCase.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import java.util.EnumSet;
5656
import java.util.Properties;
5757

58-
import org.junit.Assert;
58+
import org.junit.jupiter.api.Assertions;
5959

6060
public class AuthenticatorTestCase {
6161
private Server server;
@@ -170,11 +170,11 @@ protected void _testAuthentication(Authenticator authenticator, boolean doPost)
170170
try {
171171
URL url = new URL(getBaseURL());
172172
AuthenticatedURL.Token token = new AuthenticatedURL.Token();
173-
Assert.assertFalse(token.isSet());
173+
Assertions.assertFalse(token.isSet());
174174
TestConnectionConfigurator connConf = new TestConnectionConfigurator();
175175
AuthenticatedURL aUrl = new AuthenticatedURL(authenticator, connConf);
176176
HttpURLConnection conn = aUrl.openConnection(url, token);
177-
Assert.assertTrue(connConf.invoked);
177+
Assertions.assertTrue(connConf.invoked);
178178
String tokenStr = token.toString();
179179
if (doPost) {
180180
conn.setRequestMethod("POST");
@@ -186,18 +186,18 @@ protected void _testAuthentication(Authenticator authenticator, boolean doPost)
186186
writer.write(POST);
187187
writer.close();
188188
}
189-
Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
189+
Assertions.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
190190
if (doPost) {
191191
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
192192
String echo = reader.readLine();
193-
Assert.assertEquals(POST, echo);
194-
Assert.assertNull(reader.readLine());
193+
Assertions.assertEquals(POST, echo);
194+
Assertions.assertNull(reader.readLine());
195195
}
196196
aUrl = new AuthenticatedURL();
197197
conn = aUrl.openConnection(url, token);
198198
conn.connect();
199-
Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
200-
Assert.assertEquals(tokenStr, token.toString());
199+
Assertions.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
200+
Assertions.assertEquals(tokenStr, token.toString());
201201
} finally {
202202
stop();
203203
}
@@ -233,7 +233,7 @@ private void doHttpClientRequest(HttpClient httpClient, HttpUriRequest request)
233233
try {
234234
response = httpClient.execute(request);
235235
final int httpStatus = response.getStatusLine().getStatusCode();
236-
Assert.assertEquals(HttpURLConnection.HTTP_OK, httpStatus);
236+
Assertions.assertEquals(HttpURLConnection.HTTP_OK, httpStatus);
237237
} finally {
238238
if (response != null) EntityUtils.consumeQuietly(response.getEntity());
239239
}
@@ -255,7 +255,7 @@ protected void _testAuthenticationHttpClient(Authenticator authenticator, boolea
255255
// Important that the entity is not repeatable -- this means if
256256
// we have to renegotiate (e.g. b/c the cookie wasn't handled properly)
257257
// the test will fail.
258-
Assert.assertFalse(entity.isRepeatable());
258+
Assertions.assertFalse(entity.isRepeatable());
259259
post.setEntity(entity);
260260
doHttpClientRequest(httpClient, post);
261261
}

hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/client/TestAuthenticatedURL.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
*/
1414
package org.apache.hadoop.security.authentication.client;
1515

16-
import org.junit.Assert;
17-
import org.junit.Test;
16+
import org.junit.jupiter.api.Assertions;
17+
import org.junit.jupiter.api.Test;
1818
import org.mockito.Mockito;
1919

2020
import java.net.HttpURLConnection;
@@ -29,10 +29,10 @@ public class TestAuthenticatedURL {
2929
@Test
3030
public void testToken() throws Exception {
3131
AuthenticatedURL.Token token = new AuthenticatedURL.Token();
32-
Assert.assertFalse(token.isSet());
32+
Assertions.assertFalse(token.isSet());
3333
token = new AuthenticatedURL.Token("foo");
34-
Assert.assertTrue(token.isSet());
35-
Assert.assertEquals("foo", token.toString());
34+
Assertions.assertTrue(token.isSet());
35+
Assertions.assertEquals("foo", token.toString());
3636
}
3737

3838
@Test
@@ -60,7 +60,7 @@ public void testExtractTokenOK() throws Exception {
6060
AuthenticatedURL.Token token = new AuthenticatedURL.Token();
6161
AuthenticatedURL.extractToken(conn, token);
6262

63-
Assert.assertEquals(tokenStr, token.toString());
63+
Assertions.assertEquals(tokenStr, token.toString());
6464
}
6565

6666
@Test
@@ -80,12 +80,12 @@ public void testExtractTokenFail() throws Exception {
8080
token.set("bar");
8181
try {
8282
AuthenticatedURL.extractToken(conn, token);
83-
Assert.fail();
83+
Assertions.fail();
8484
} catch (AuthenticationException ex) {
8585
// Expected
86-
Assert.assertFalse(token.isSet());
86+
Assertions.assertFalse(token.isSet());
8787
} catch (Exception ex) {
88-
Assert.fail();
88+
Assertions.fail();
8989
}
9090
}
9191

@@ -105,7 +105,7 @@ public void testExtractTokenCookieHeader() throws Exception {
105105
AuthenticatedURL.Token token = new AuthenticatedURL.Token();
106106
AuthenticatedURL.extractToken(conn, token);
107107

108-
Assert.assertTrue(token.isSet());
108+
Assertions.assertTrue(token.isSet());
109109
}
110110

111111
@Test
@@ -124,7 +124,7 @@ public void testExtractTokenLowerCaseCookieHeader() throws Exception {
124124
AuthenticatedURL.Token token = new AuthenticatedURL.Token();
125125
AuthenticatedURL.extractToken(conn, token);
126126

127-
Assert.assertTrue(token.isSet());
127+
Assertions.assertTrue(token.isSet());
128128
}
129129

130130
@Test
@@ -150,7 +150,7 @@ public void testGetAuthenticator() throws Exception {
150150
Authenticator authenticator = Mockito.mock(Authenticator.class);
151151

152152
AuthenticatedURL aURL = new AuthenticatedURL(authenticator);
153-
Assert.assertEquals(authenticator, aURL.getAuthenticator());
153+
Assertions.assertEquals(authenticator, aURL.getAuthenticator());
154154
}
155155

156156
}

hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/client/TestKerberosAuthenticator.java

+47-31
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@
3434
import org.apache.hadoop.security.authentication.server.MultiSchemeAuthenticationHandler;
3535
import org.apache.hadoop.security.authentication.server.PseudoAuthenticationHandler;
3636
import org.apache.hadoop.security.authentication.server.KerberosAuthenticationHandler;
37-
import org.junit.Assert;
38-
import org.junit.Before;
39-
import org.junit.Test;
37+
import org.junit.jupiter.api.Assertions;
38+
import org.junit.jupiter.api.BeforeEach;
39+
import org.junit.jupiter.api.Test;
40+
import org.junit.jupiter.api.Timeout;
4041
import org.mockito.Mockito;
4142

4243
import java.io.File;
@@ -54,7 +55,7 @@ public class TestKerberosAuthenticator extends KerberosSecurityTestcase {
5455
public TestKerberosAuthenticator() {
5556
}
5657

57-
@Before
58+
@BeforeEach
5859
public void setup() throws Exception {
5960
// create keytab
6061
File keytabFile = new File(KerberosTestUtils.getKeytabFile());
@@ -89,7 +90,8 @@ private Properties getMultiAuthHandlerConfiguration() {
8990
return props;
9091
}
9192

92-
@Test(timeout=60000)
93+
@Test
94+
@Timeout(value = 60)
9395
public void testFallbacktoPseudoAuthenticator() throws Exception {
9496
AuthenticatorTestCase auth = new AuthenticatorTestCase();
9597
Properties props = new Properties();
@@ -99,7 +101,8 @@ public void testFallbacktoPseudoAuthenticator() throws Exception {
99101
auth._testAuthentication(new KerberosAuthenticator(), false);
100102
}
101103

102-
@Test(timeout=60000)
104+
@Test
105+
@Timeout(value = 60)
103106
public void testFallbacktoPseudoAuthenticatorAnonymous() throws Exception {
104107
AuthenticatorTestCase auth = new AuthenticatorTestCase();
105108
Properties props = new Properties();
@@ -109,7 +112,8 @@ public void testFallbacktoPseudoAuthenticatorAnonymous() throws Exception {
109112
auth._testAuthentication(new KerberosAuthenticator(), false);
110113
}
111114

112-
@Test(timeout=60000)
115+
@Test
116+
@Timeout(value = 60)
113117
public void testNotAuthenticated() throws Exception {
114118
AuthenticatorTestCase auth = new AuthenticatorTestCase();
115119
AuthenticatorTestCase.setAuthenticationHandlerConfig(getAuthenticationHandlerConfiguration());
@@ -118,14 +122,15 @@ public void testNotAuthenticated() throws Exception {
118122
URL url = new URL(auth.getBaseURL());
119123
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
120124
conn.connect();
121-
Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, conn.getResponseCode());
122-
Assert.assertTrue(conn.getHeaderField(KerberosAuthenticator.WWW_AUTHENTICATE) != null);
125+
Assertions.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, conn.getResponseCode());
126+
Assertions.assertTrue(conn.getHeaderField(KerberosAuthenticator.WWW_AUTHENTICATE) != null);
123127
} finally {
124128
auth 10000 .stop();
125129
}
126130
}
127131

128-
@Test(timeout=60000)
132+
@Test
133+
@Timeout(value = 60)
129134
public void testAuthentication() throws Exception {
130135
final AuthenticatorTestCase auth = new AuthenticatorTestCase();
131136
AuthenticatorTestCase.setAuthenticationHandlerConfig(
@@ -139,7 +144,8 @@ public Void call() throws Exception {
139144
});
140145
}
141146

142-
@Test(timeout=60000)
147+
@Test
148+
@Timeout(value = 60)
143149
public void testAuthenticationPost() throws Exception {
144150
final AuthenticatorTestCase auth = new AuthenticatorTestCase();
145151
AuthenticatorTestCase.setAuthenticationHandlerConfig(
@@ -153,7 +159,8 @@ public Void call() throws Exception {
153159
});
154160
}
155161

156-
@Test(timeout=60000)
162+
@Test
163+
@Timeout(value = 60)
157164
public void testAuthenticationHttpClient() throws Exception {
158165
final AuthenticatorTestCase auth = new AuthenticatorTestCase();
159166
AuthenticatorTestCase.setAuthenticationHandlerConfig(
@@ -167,7 +174,8 @@ public Void call() throws Exception {
167174
});
168175
}
169176

170-
@Test(timeout=60000)
177+
@Test
178+
@Timeout(value = 60)
171179
public void testAuthenticationHttpClientPost() throws Exception {
172180
final AuthenticatorTestCase auth = new AuthenticatorTestCase();
173181
AuthenticatorTestCase.setAuthenticationHandlerConfig(
@@ -181,7 +189,8 @@ public Void call() throws Exception {
181189
});
182190
}
183191

184-
@Test(timeout = 60000)
192+
@Test
193+
@Timeout(value = 60)
185194
public void testNotAuthenticatedWithMultiAuthHandler() throws Exception {
186195
AuthenticatorTestCase auth = new AuthenticatorTestCase();
187196
AuthenticatorTestCase
@@ -191,16 +200,17 @@ public void testNotAuthenticatedWithMultiAuthHandler() throws Exception {
191200
URL url = new URL(auth.getBaseURL());
192201
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
193202
conn.connect();
194-
Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED,
203+
Assertions.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED,
195204
conn.getResponseCode());
196-
Assert.assertTrue(conn
205+
Assertions.assertTrue(conn
197206
.getHeaderField(KerberosAuthenticator.WWW_AUTHENTICATE) != null);
198207
} finally {
199208
auth.stop();
200209
}
201210
}
202211

203-
@Test(timeout = 60000)
212+
@Test
213+
@Timeout(value = 60)
204214
public void testAuthenticationWithMultiAuthHandler() throws Exception {
205215
final AuthenticatorTestCase auth = new AuthenticatorTestCase();
206216
AuthenticatorTestCase
@@ -214,7 +224,8 @@ public Void call() throws Exception {
214224
});
215225
}
216226

217-
@Test(timeout = 60000)
227+
@Test
228+
@Timeout(value = 60)
218229
public void testAuthenticationHttpClientPostWithMultiAuthHandler()
219230
throws Exception {
220231
final AuthenticatorTestCase auth = new AuthenticatorTestCase();
@@ -229,33 +240,35 @@ public Void call() throws Exception {
229240
});
230241
}
231242

232-
@Test(timeout = 60000)
243+
@Test
244+
@Timeout(value = 60)
233245
public void testWrapExceptionWithMessage() {
234246
IOException ex;
235247
ex = new IOException("Induced exception");
236248
ex = KerberosAuthenticator.wrapExceptionWithMessage(ex, "Error while "
237249
+ "authenticating with endpoint: localhost");
238-
Assert.assertEquals("Induced exception", ex.getCause().getMessage());
239-
Assert.assertEquals("Error while authenticating with endpoint: localhost",
250+
Assertions.assertEquals("Induced exception", ex.getCause().getMessage());
251+
Assertions.assertEquals("Error while authenticating with endpoint: localhost",
240252
ex.getMessage());
241253

242254
ex = new AuthenticationException("Auth exception");
243255
ex = KerberosAuthenticator.wrapExceptionWithMessage(ex, "Error while "
244256
+ "authenticating with endpoint: localhost");
245-
Assert.assertEquals("Auth exception", ex.getCause().getMessage());
246-
Assert.assertEquals("Error while authenticating with endpoint: localhost",
257+
Assertions.assertEquals("Auth exception", ex.getCause().getMessage());
258+
Assertions.assertEquals("Error while authenticating with endpoint: localhost",
247259
ex.getMessage());
248260

249261
// Test for Exception with no (String) constructor
250262
// redirect the LOG to and check log message
251263
ex = new CharacterCodingException();
252264
Exception ex2 = KerberosAuthenticator.wrapExceptionWithMessage(ex,
253265
"Error while authenticating with endpoint: localhost");
254-
Assert.assertTrue(ex instanceof CharacterCodingException);
255-
Assert.assertTrue(ex.equals(ex2));
266+
Assertions.assertTrue(ex instanceof CharacterCodingException);
267+
Assertions.assertTrue(ex.equals(ex2));
256268
}
257269

258-
@Test(timeout = 60000)
270+
@Test
271+
@Timeout(value = 60)
259272
public void testNegotiate() throws NoSuchMethodException, InvocationTargetException,
260273
IllegalAccessException, IOException {
261274
KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator();
@@ -269,10 +282,11 @@ public void testNegotiate() throws NoSuchMethodException, InvocationTargetExcept
269282
HttpURLConnection.class);
270283
method.setAccessible(true);
271284

272-
Assert.assertTrue((boolean)method.invoke(kerberosAuthenticator, conn));
285+
Assertions.assertTrue((boolean)method.invoke(kerberosAuthenticator, conn));
273286
}
274287

275-
@Test(timeout = 60000)
288+
@Test
289+
@Timeout(value = 60)
276290
public void testNegotiateLowerCase() throws NoSuchMethodException, InvocationTargetException,
277291
IllegalAccessException, IOException {
278292
KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator();
@@ -286,10 +300,11 @@ public void testNegotiateLowerCase() throws NoSuchMethodException, InvocationTar
286300
HttpURLConnection.class);
287301
method.setAccessible(true);
288302

289-
Assert.assertTrue((boolean)method.invoke(kerberosAuthenticator, conn));
303+
Assertions.assertTrue((boolean)method.invoke(kerberosAuthenticator, conn));
290304
}
291305

292-
@Test(timeout = 60000)
306+
@Test
307+
@Timeout(value = 60)
293308
public void testReadToken() throws NoSuchMethodException, IOException, IllegalAccessException,
294309
InvocationTargetException {
295310
KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator();
@@ -310,7 +325,8 @@ public void testReadToken() throws NoSuchMethodException, IOException, IllegalAc
310325
method.invoke(kerberosAuthenticator, conn); // expecting this not to throw an exception
311326
}
312327

313-
@Test(timeout = 60000)
328+
@Test
329+
@Timeout(value = 60)
314330
public void testReadTokenLowerCase() throws NoSuchMethodException, IOException,
315331
IllegalAccessException, InvocationTargetException {
316332
KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator();

0 commit comments

Comments
 (0)
0