use of org.apache.metron.stellar.common.shell.StellarResult in project metron by apache.
the class MagicListGlobalsTest method testWithNoGlobals.
@Test
public void testWithNoGlobals() {
// get all globals
StellarResult result = executor.execute("%globals");
// validate the result
assertTrue(result.isSuccess());
assertTrue(result.getValue().isPresent());
String out = ConversionUtils.convert(result.getValue().get(), String.class);
assertEquals("{}", out);
}
use of org.apache.metron.stellar.common.shell.StellarResult in project metron by apache.
the class MagicListGlobalsTest method test.
@Test
public void test() {
// define some globals
executor.getGlobalConfig().put("x", 2);
// get all globals
StellarResult result = executor.execute("%globals");
// validate the result
assertTrue(result.isSuccess());
assertTrue(result.getValue().isPresent());
String out = ConversionUtils.convert(result.getValue().get(), String.class);
assertEquals("{x=2}", out);
}
use of org.apache.metron.stellar.common.shell.StellarResult in project metron by apache.
the class MagicListVariablesTest method test.
@Test
public void test() {
// define some vars
executor.execute("x := 2 + 2");
StellarResult result = executor.execute("%vars");
// validate the result
assertTrue(result.isSuccess());
assertTrue(result.getValue().isPresent());
// validate the list of vars
String vars = ConversionUtils.convert(result.getValue().get(), String.class);
assertEquals("x = 4 via `2 + 2`", vars);
}
use of org.apache.metron.stellar.common.shell.StellarResult in project metron by apache.
the class MagicListVariablesTest method testWithNoVars.
@Test
public void testWithNoVars() {
// there are no vars defined
StellarResult result = executor.execute("%vars");
// validate the result
assertTrue(result.isSuccess());
assertTrue(result.getValue().isPresent());
// validate the list of vars
String vars = ConversionUtils.convert(result.getValue().get(), String.class);
assertEquals("", vars);
}
use of org.apache.metron.stellar.common.shell.StellarResult in project metron by apache.
the class AssignmentCommand method execute.
/**
* Handles variable assignment.
* @param input The assignment expression to execute.
* @param executor A stellar execution environment.
* @return
*/
@Override
public StellarResult execute(String input, StellarShellExecutor executor) {
assert StellarAssignment.isAssignment(input);
// extract the variable and assignment expression
StellarAssignment assignment = StellarAssignment.from(input);
String varName = assignment.getVariable();
String varExpr = assignment.getStatement();
// execute the stellar expression
StellarResult result = executor.execute(varExpr);
if (result.isSuccess()) {
Object value = null;
if (result.getValue().isPresent()) {
value = result.getValue().get();
} else if (result.isValueNull()) {
value = null;
}
// variable assignment
executor.assign(varName, value, Optional.of(varExpr));
return result;
} else {
return result;
}
}
Aggregations