use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project SSM by Intel-bigdata.
the class ParagraphTest method returnUnchangedResultsWithDifferentUser.
@Test
public void returnUnchangedResultsWithDifferentUser() throws Throwable {
InterpreterSettingManager mockInterpreterSettingManager = mock(InterpreterSettingManager.class);
Note mockNote = mock(Note.class);
when(mockNote.getCredentials()).thenReturn(mock(Credentials.class));
Paragraph spyParagraph = spy(new Paragraph("para_1", mockNote, null, null, mockInterpreterSettingManager));
doReturn("spy").when(spyParagraph).getRequiredReplName();
Interpreter mockInterpreter = mock(Interpreter.class);
doReturn(mockInterpreter).when(spyParagraph).getRepl(anyString());
InterpreterGroup mockInterpreterGroup = mock(InterpreterGroup.class);
when(mockInterpreter.getInterpreterGroup()).thenReturn(mockInterpreterGroup);
when(mockInterpreterGroup.getId()).thenReturn("mock_id_1");
when(mockInterpreterGroup.getAngularObjectRegistry()).thenReturn(mock(AngularObjectRegistry.class));
when(mockInterpreterGroup.getResourcePool()).thenReturn(mock(ResourcePool.class));
List<InterpreterSetting> spyInterpreterSettingList = spy(Lists.<InterpreterSetting>newArrayList());
InterpreterSetting mockInterpreterSetting = mock(InterpreterSetting.class);
InterpreterOption mockInterpreterOption = mock(InterpreterOption.class);
when(mockInterpreterSetting.getOption()).thenReturn(mockInterpreterOption);
when(mockInterpreterOption.permissionIsSet()).thenReturn(false);
when(mockInterpreterSetting.getStatus()).thenReturn(Status.READY);
when(mockInterpreterSetting.getId()).thenReturn("mock_id_1");
when(mockInterpreterSetting.getInterpreterGroup(anyString(), anyString())).thenReturn(mockInterpreterGroup);
spyInterpreterSettingList.add(mockInterpreterSetting);
when(mockNote.getId()).thenReturn("any_id");
when(mockInterpreterSettingManager.getInterpreterSettings(anyString())).thenReturn(spyInterpreterSettingList);
doReturn("spy script body").when(spyParagraph).getScriptBody();
when(mockInterpreter.getFormType()).thenReturn(FormType.NONE);
ParagraphJobListener mockJobListener = mock(ParagraphJobListener.class);
doReturn(mockJobListener).when(spyParagraph).getListener();
doNothing().when(mockJobListener).onOutputUpdateAll(Mockito.<Paragraph>any(), Mockito.anyList());
InterpreterResult mockInterpreterResult = mock(InterpreterResult.class);
when(mockInterpreter.interpret(anyString(), Mockito.<InterpreterContext>any())).thenReturn(mockInterpreterResult);
when(mockInterpreterResult.code()).thenReturn(Code.SUCCESS);
// Actual test
List<InterpreterResultMessage> result1 = Lists.newArrayList();
result1.add(new InterpreterResultMessage(Type.TEXT, "result1"));
when(mockInterpreterResult.message()).thenReturn(result1);
AuthenticationInfo user1 = new AuthenticationInfo("user1");
spyParagraph.setAuthenticationInfo(user1);
spyParagraph.jobRun();
Paragraph p1 = spyParagraph.getUserParagraph(user1.getUser());
List<InterpreterResultMessage> result2 = Lists.newArrayList();
result2.add(new InterpreterResultMessage(Type.TEXT, "result2"));
when(mockInterpreterResult.message()).thenReturn(result2);
AuthenticationInfo user2 = new AuthenticationInfo("user2");
spyParagraph.setAuthenticationInfo(user2);
spyParagraph.jobRun();
Paragraph p2 = spyParagraph.getUserParagraph(user2.getUser());
assertNotEquals(p1.getReturn().toString(), p2.getReturn().toString());
assertEquals(p1, spyParagraph.getUserParagraph(user1.getUser()));
}
use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project metron by apache.
the class StellarInterpreterTest method testExecuteWithStellarList.
/**
* Ensure that Stellar lists are displayed correctly in Zeppelin.
*/
@Test
public void testExecuteWithStellarList() {
final String expected = "[1, 2, 3, 4, 5]";
InterpreterResult result = interpreter.interpret("[1,2,3,4,5]", context);
// validate the result
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
// validate the message
InterpreterResultMessage message = result.message().get(0);
assertEquals(expected, message.getData());
assertEquals(InterpreterResult.Type.TEXT, message.getType());
}
use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project metron by apache.
the class StellarInterpreterTest method testExecuteStellarMultipleLines.
/**
* Ensure that we can run Stellar code in the interpreter.
*/
@Test
public void testExecuteStellarMultipleLines() {
// multi-line input
String input = "x := 2 + 2" + System.lineSeparator() + "y := 4 + 4";
InterpreterResult result = interpreter.interpret(input, context);
// expect x == 4 and y == 8
Map<String, VariableResult> vars = interpreter.getExecutor().getState();
assertEquals(4, vars.get("x").getResult());
assertEquals(8, vars.get("y").getResult());
// validate the result
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
// the output is the result of only the 'last' expression
InterpreterResultMessage message = result.message().get(0);
assertEquals("8", message.getData());
assertEquals(InterpreterResult.Type.TEXT, message.getType());
}
use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project metron by apache.
the class StellarInterpreterTest method testExecuteStellar.
/**
* Ensure that we can run Stellar code in the interpreter.
*/
@Test
public void testExecuteStellar() {
InterpreterResult result = interpreter.interpret("2 + 2", context);
// validate the result
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
// validate the message
InterpreterResultMessage message = result.message().get(0);
assertEquals("4", message.getData());
assertEquals(InterpreterResult.Type.TEXT, message.getType());
}
use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project metron by apache.
the class StellarInterpreterTest method testExecuteBadStellar.
/**
* Ensure that 'bad' Stellar code is handled correctly by the interpreter.
*/
@Test
public void testExecuteBadStellar() {
InterpreterResult result = interpreter.interpret("2 + ", context);
// validate the result
assertEquals(InterpreterResult.Code.ERROR, result.code());
assertEquals(1, result.message().size());
// validate the message
InterpreterResultMessage message = result.message().get(0);
assertTrue(message.getData().length() > 0);
assertEquals(InterpreterResult.Type.TEXT, message.getType());
}
Aggregations