DefaultStellarShellExecutor implements StellarShellExecutor { @Override public StellarResult execute(String expression) { expression = StringUtils.trimToEmpty(expression); if(StringUtils.isBlank(expression)) { return noop(); } for(SpecialCommand command : specials) { if(command.getMatcher().apply(expression)) { return command.execute(expression, this); } } return executeStellar(expression); } DefaultStellarShellExecutor(
          FunctionResolver functionResolver,
          Properties properties,
          Optional<String> zookeeperUrl,
          List<SpecialCommand> specials);  DefaultStellarShellExecutor(
          FunctionResolver functionResolver,
          Properties properties,
          Optional<String> zookeeperUrl);  DefaultStellarShellExecutor(
          Properties properties,
          Optional<String> zookeeperUrl); static List<SpecialCommand> defaultSpecials(); @Override void init(); @Override void addFunctionListener(FunctionDefinedListener listener); @Override void addVariableListener(VariableDefinedListener listener); @Override void addSpecialListener(SpecialDefinedListener listener); @Override StellarResult execute(String expression); @Override @SuppressWarnings("unchecked") Map<String, Object> getGlobalConfig(); @Override void assign(String variableName, Object value, Optional<String> expression); @Override FunctionResolver getFunctionResolver(); @Override @SuppressWarnings("unchecked") Map<String, VariableResult> getState(); Map<String, Object> getVariables(); @Override Context getContext(); static final String SHELL_VARIABLES; }
@Test public void testBadAssignment() { StellarResult result = executor.execute("x := 2 + "); assertTrue(result.isError()); assertTrue(result.getException().isPresent()); }
@Test public void testExpression() { StellarResult result = executor.execute("2 + 2"); assertTrue(result.isSuccess()); assertTrue(result.getValue().isPresent()); assertEquals(4, result.getValue().get()); }
@Test public void testExpressionWithOddWhitespace() { StellarResult result = executor.execute(" 2 + 2"); assertTrue(result.isSuccess()); assertTrue(result.getValue().isPresent()); assertEquals(4, result.getValue().get()); }
@Test public void testBadExpression() { StellarResult result = executor.execute("2 + "); assertTrue(result.isError()); assertTrue(result.getException().isPresent()); }
@Test public void testMagicCommand() { executor.execute("x := 2 + 2"); StellarResult result = executor.execute("%vars"); assertTrue(result.isSuccess()); assertTrue(result.getValue().isPresent()); assertNotNull(result.getValue().get()); }
@Test public void testBadMagicCommand() { StellarResult result = executor.execute("%invalid"); assertTrue(result.isError()); assertTrue(result.getException().isPresent()); }
@Test public void testDocCommand() { StellarResult result = executor.execute("?TO_STRING"); assertTrue(result.isSuccess()); assertTrue(result.getValue().isPresent()); assertNotNull(result.getValue().get()); }
@Test public void testBadDocCommand() { StellarResult result = executor.execute("?INVALID"); assertTrue(result.isError()); assertTrue(result.getException().isPresent()); }
@Test public void testQuit() { StellarResult result = executor.execute("quit"); assertTrue(result.isTerminate()); }
@Test public void testEmptyInput() { StellarResult result = executor.execute(""); assertTrue(result.isSuccess()); assertTrue(result.getValue().isPresent()); assertEquals("", result.getValue().get()); }
@Test public void testComment() { StellarResult result = executor.execute("# this is a comment"); assertTrue(result.isSuccess()); assertTrue(result.getValue().isPresent()); assertEquals("", result.getValue().get()); }