2626
2727import java .io .File ;
2828import java .util .Properties ;
29+ import java .util .concurrent .TimeUnit ;
2930
3031import javax .servlet .http .HttpServletRequest ;
3132import javax .servlet .http .HttpServletResponse ;
3839import org .apache .directory .server .core .annotations .CreateDS ;
3940import org .apache .directory .server .core .annotations .CreatePartition ;
4041import org .apache .directory .server .core .integ .AbstractLdapTestUnit ;
41- import org .apache .directory .server .core .integ .FrameworkRunner ;
42+ import org .apache .directory .server .core .integ .ApacheDSTestExtension ;
4243import org .apache .hadoop .minikdc .KerberosSecurityTestcase ;
4344import org .apache .hadoop .security .authentication .KerberosTestUtils ;
4445import org .apache .hadoop .security .authentication .client .AuthenticationException ;
45- import org .junit .After ;
46- import org .junit .Assert ;
47- import org .junit .Before ;
48- import org .junit .Test ;
49- import org .junit .runner .RunWith ;
46+ import org .junit .jupiter .api .AfterEach ;
47+ import org .junit .jupiter .api .Assertions ;
48+ import org .junit .jupiter .api .BeforeEach ;
49+ import org .junit .jupiter .api .Test ;
50+ import org .junit .jupiter .api .Timeout ;
51+ import org .junit .jupiter .api .extension .ExtendWith ;
5052import org .mockito .Mockito ;
5153
5254/**
5355 * This unit test verifies the functionality of "multi-scheme" auth handler.
5456 */
55- @ RunWith ( FrameworkRunner .class )
57+ @ ExtendWith ( ApacheDSTestExtension .class )
5658@ CreateLdapServer (
5759 transports =
5860 {
@@ -79,7 +81,7 @@ public class TestMultiSchemeAuthenticationHandler
7981 private KerberosSecurityTestcase krbTest = new KerberosSecurityTestcase ();
8082 private MultiSchemeAuthenticationHandler handler ;
8183
82- @ Before
84+ @ BeforeEach
8385 public void setUp () throws Exception {
8486 krbTest .startMiniKdc ();
8587
@@ -99,7 +101,7 @@ public void setUp() throws Exception {
99101 }
100102 }
101103
102- @ After
104+ @ AfterEach
103105 public void tearDown () throws Exception {
104106 krbTest .stopMiniKdc ();
105107 }
@@ -122,18 +124,20 @@ private Properties getDefaultProperties() {
122124 return p ;
123125 }
124126
125- @ Test (timeout = 60000 )
127+ @ Test
128+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
126129 public void testRequestWithoutAuthorization () throws Exception {
127130 HttpServletRequest request = Mockito .mock (HttpServletRequest .class );
128131 HttpServletResponse response = Mockito .mock (HttpServletResponse .class );
129132
130- Assert .assertNull (handler .authenticate (request , response ));
133+ Assertions .assertNull (handler .authenticate (request , response ));
131134 Mockito .verify (response ).addHeader (WWW_AUTHENTICATE_HEADER , BASIC );
132135 Mockito .verify (response ).addHeader (WWW_AUTHENTICATE_HEADER , NEGOTIATE );
133136 Mockito .verify (response ).setStatus (HttpServletResponse .SC_UNAUTHORIZED );
134137 }
135138
136- @ Test (timeout = 60000 )
139+ @ Test
140+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
137141 public void testRequestWithInvalidAuthorization () throws Exception {
138142 HttpServletRequest request = Mockito .mock (HttpServletRequest .class );
139143 HttpServletResponse response = Mockito .mock (HttpServletResponse .class );
@@ -142,13 +146,14 @@ public void testRequestWithInvalidAuthorization() throws Exception {
142146 String credentials = "bjones:invalidpassword" ;
143147 Mockito .when (request .getHeader (AUTHORIZATION_HEADER ))
144148 .thenReturn (base64 .encodeToString (credentials .getBytes ()));
145- Assert .assertNull (handler .authenticate (request , response ));
149+ Assertions .assertNull (handler .authenticate (request , response ));
146150 Mockito .verify (response ).addHeader (WWW_AUTHENTICATE_HEADER , BASIC );
147151 Mockito .verify (response ).addHeader (WWW_AUTHENTICATE_HEADER , NEGOTIATE );
148152 Mockito .verify (response ).setStatus (HttpServletResponse .SC_UNAUTHORIZED );
149153 }
150154
151- @ Test (timeout = 60000 )
155+ @ Test
156+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
152157 public void testRequestWithLdapAuthorization () throws Exception {
153158 HttpServletRequest request = Mockito .mock (HttpServletRequest .class );
154159 HttpServletResponse response = Mockito .mock (HttpServletResponse .class );
@@ -159,14 +164,15 @@ public void testRequestWithLdapAuthorization() throws Exception {
159164 Mockito .when (request .getHeader (AUTHORIZATION_HEADER ))
160165 .thenReturn (authHeader );
161166 AuthenticationToken token = handler .authenticate (request , response );
162- Assert .assertNotNull (token );
167+ Assertions .assertNotNull (token );
163168 Mockito .verify (response ).setStatus (HttpServletResponse .SC_OK );
164- Assert .assertEquals (TYPE , token .getType ());
165- Assert .assertEquals ("bjones" , token .getUserName ());
166- Assert .assertEquals ("bjones" , token .getName ());
169+ Assertions .assertEquals (TYPE , token .getType ());
170+ Assertions .assertEquals (token .getUserName (), "bjones" );
171+ Assertions .assertEquals (token .getName (), "bjones" );
167172 }
168173
169- @ Test (timeout = 60000 )
174+ @ Test
175+ @ Timeout (value = 60 , unit = TimeUnit .SECONDS )
170176 public void testRequestWithInvalidKerberosAuthorization () throws Exception {
171177 String token = new Base64 (0 ).encodeToString (new byte []{0 , 1 , 2 });
172178
@@ -178,11 +184,11 @@ public void testRequestWithInvalidKerberosAuthorization() throws Exception {
178184
179185 try {
180186 handler .authenticate (request , response );
181- Assert .fail ();
187+ Assertions .fail ();
182188 } catch (AuthenticationException ex ) {
183189 // Expected
184190 } catch (Exception ex ) {
185- Assert .fail ("Wrong exception :" +ex );
191+ Assertions .fail ("Wrong exception :" +ex );
186192 }
187193 }
188194
0 commit comments