2222import static org .junit .Assert .assertNotEquals ;
2323import static org .junit .Assert .assertNotNull ;
2424import static org .mockito .Matchers .any ;
25+ import static org .mockito .Matchers .anyBoolean ;
26+ import static org .mockito .Matchers .anyListOf ;
27+ import static org .mockito .Matchers .anySetOf ;
2528import static org .mockito .Matchers .anyString ;
2629import static org .mockito .Matchers .eq ;
2730import static org .mockito .Mockito .doReturn ;
2831import static org .mockito .Mockito .mock ;
2932import static org .mockito .Mockito .spy ;
33+ import static org .mockito .Mockito .times ;
3034import static org .mockito .Mockito .verify ;
3135import static org .mockito .Mockito .when ;
3236
@@ -351,9 +355,6 @@ public void testCursorPosition() {
351355 }
352356 }
353357
354- //(TODO zjffdu) temporary disable it.
355- //https://github.com/apache/zeppelin/pull/3416
356- @ Ignore
357358 @ Test
358359 public void credentialReplacement () throws Throwable {
359360 Note mockNote = mock (Note .class );
@@ -369,11 +370,16 @@ public void credentialReplacement() throws Throwable {
369370 spyParagraph .setInterpreter (mockInterpreter );
370371 doReturn (mockInterpreter ).when (spyParagraph ).getBindedInterpreter ();
371372
373+ InterpreterSetting mockInterpreterSetting = mock (InterpreterSetting .class );
374+ when (mockInterpreterSetting .getStatus ()).thenReturn (InterpreterSetting .Status .READY );
375+ when (mockInterpreterSetting .isUserAuthorized (anyListOf (String .class ))).thenReturn (true );
376+
372377 ManagedInterpreterGroup mockInterpreterGroup = mock (ManagedInterpreterGroup .class );
373378 when (mockInterpreter .getInterpreterGroup ()).thenReturn (mockInterpreterGroup );
374379 when (mockInterpreterGroup .getId ()).thenReturn ("mock_id_1" );
375380 when (mockInterpreterGroup .getAngularObjectRegistry ()).thenReturn (mock (AngularObjectRegistry .class ));
376381 when (mockInterpreterGroup .getResourcePool ()).thenReturn (mock (ResourcePool .class ));
382+ when (mockInterpreterGroup .getInterpreterSetting ()).thenReturn (mockInterpreterSetting );
377383 when (mockInterpreter .getFormType ()).thenReturn (FormType .NONE );
378384
379385 ParagraphJobListener mockJobListener = mock (ParagraphJobListener .class );
@@ -386,23 +392,23 @@ public void credentialReplacement() throws Throwable {
386392 AuthenticationInfo user1 = new AuthenticationInfo ("user1" );
387393 spyParagraph .setAuthenticationInfo (user1 );
388394
389- spyParagraph .setText ("val x = \" usr={user. ent}&pass={password. ent}\" " );
395+ spyParagraph .setText ("val x = \" usr={ent.user }&pass={ent.password }\" " );
390396
391397 // Credentials should only be injected when it is enabled for an interpreter or when specified in a local property
392398 when (mockInterpreter .getProperty (Constants .INJECT_CREDENTIALS , "false" )).thenReturn ("false" );
393399 spyParagraph .jobRun ();
394- verify (mockInterpreter ).interpret (eq ("val x = \" usr={user. ent}&pass={password. ent}\" " ), any (InterpreterContext .class ));
400+ verify (mockInterpreter ).interpret (eq ("val x = \" usr={ent.user }&pass={ent.password }\" " ), any (InterpreterContext .class ));
395401
396402 when (mockInterpreter .getProperty (Constants .INJECT_CREDENTIALS , "false" )).thenReturn ("true" );
397- mockInterpreter .setProperty (Constants .INJECT_CREDENTIALS , "true " );
403+ mockInterpreter .setProperty (Constants .INJECT_CREDENTIALS , "false " );
398404 spyParagraph .jobRun ();
399405 verify (mockInterpreter ).interpret (eq ("val x = \" usr=user&pass=pwd\" " ), any (InterpreterContext .class ));
400406
401407 // Check if local property override works
402- when (mockInterpreter .getProperty (Constants .INJECT_CREDENTIALS , "false" )).thenReturn ("true " );
408+ when (mockInterpreter .getProperty (Constants .INJECT_CREDENTIALS , "false" )).thenReturn ("false " );
403409 spyParagraph .getLocalProperties ().put (Constants .INJECT_CREDENTIALS , "true" );
404410 spyParagraph .jobRun ();
405- verify (mockInterpreter ).interpret (eq ("val x = \" usr=user&pass=pwd\" " ), any (InterpreterContext .class ));
411+ verify (mockInterpreter , times ( 2 ) ).interpret (eq ("val x = \" usr=user&pass=pwd\" " ), any (InterpreterContext .class ));
406412
407413 }
408414}
0 commit comments