use of org.apache.metron.stellar.common.shell.StellarResult in project metron by apache.
the class MagicUndefineGlobalTest method testWithNoVariable.
@Test
public void testWithNoVariable() {
// define a global
executor.getGlobalConfig().put("global", 22);
assertEquals(1, executor.getGlobalConfig().size());
// no arg specifying the var to undefine
StellarResult result = magic.execute("%undefine", executor);
// validate the result
assertTrue(result.isError());
assertTrue(result.getException().isPresent());
// ensure that the global variables were not changed
assertEquals(1, executor.getGlobalConfig().size());
}
use of org.apache.metron.stellar.common.shell.StellarResult in project metron by apache.
the class MagicUndefineGlobalTest method testUndefine.
@Test
public void testUndefine() {
// define a global
executor.getGlobalConfig().put("global", 22);
assertEquals(1, executor.getGlobalConfig().size());
// use the magic to undefine the global variable
StellarResult result = magic.execute("%undefine global", executor);
// validate the result
assertTrue(result.isSuccess());
assertTrue(result.getValue().isPresent());
// ensure that the global variable does not exist
assertEquals(0, executor.getGlobalConfig().size());
}
use of org.apache.metron.stellar.common.shell.StellarResult in project metron by apache.
the class StellarInterpreter method interpret.
@Override
public InterpreterResult interpret(final String input, InterpreterContext context) {
InterpreterResult result;
try {
// execute the input
StellarResult stellarResult = executor.execute(input);
if (stellarResult.isSuccess()) {
// on success - if no result, use a blank value
Object value = stellarResult.getValue().orElse("");
String text = value.toString();
result = new InterpreterResult(SUCCESS, TEXT, text);
} else if (stellarResult.isError()) {
// an error occurred
Optional<Throwable> e = stellarResult.getException();
String message = getErrorMessage(e, input);
result = new InterpreterResult(ERROR, TEXT, message);
} else {
// should never happen
throw new IllegalStateException("Unexpected error. result=" + stellarResult);
}
} catch (Throwable t) {
// unexpected exception
String message = getErrorMessage(Optional.of(t), input);
result = new InterpreterResult(ERROR, TEXT, message);
}
return result;
}
Aggregations