@Override public StatementExecutorInterface getStatementExecutor() { StatementExecutorInterface statementExecutor = new StatementExecutor(new SlimExecutionContext(interaction)); if (timeout != null) { statementExecutor = StatementTimeoutExecutor.decorate(statementExecutor, timeout); } return statementExecutor; }
@Override public void addPath(String path) throws SlimException { context.addPath(path); }
@Override public Object getInstance(String instanceName) { return context.getInstance(instanceName); }
private void addToInstancesOrLibrary(String instanceName, Object instance) { if (isLibrary(instanceName)) { libraries.add(new Library(instanceName, instance)); } else { setInstance(instanceName, instance); } }
public void create(String instanceName, String className, Object[] args) throws SlimError, IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException { Object potentialActor = variables.getStored(className); if (potentialActor != null && !(potentialActor instanceof String)) { addToInstancesOrLibrary(instanceName, potentialActor); } else { String replacedClassName = variables .replaceSymbolsInString(className); Object instance = interaction.createInstance(paths, replacedClassName, replaceSymbols(args)); addToInstancesOrLibrary(instanceName, instance); } }
@Override public void create(String instanceName, String className, Object... args) throws SlimException { try { context.create(instanceName, className, args); // TODO Hack for supporting SlimHelperLibrary, please remove. Object newInstance = context.getInstance(instanceName); if (newInstance instanceof StatementExecutorConsumer) { ((StatementExecutorConsumer) newInstance).setStatementExecutor(this); } } catch (SlimError e) { throw new SlimException(format("%s[%d]", className, args.length), e, SlimServer.COULD_NOT_INVOKE_CONSTRUCTOR, true); } catch (IllegalArgumentException e) { throw new SlimException(format("%s[%d]", className, args.length), e, SlimServer.COULD_NOT_INVOKE_CONSTRUCTOR, true); } catch (InvocationTargetException e) { checkExceptionForStop(e.getTargetException()); throw new SlimException(e.getTargetException(), true); } catch (Throwable e) { // NOSONAR checkExceptionForStop(e); throw new SlimException(e); } }
@Override public Object getSymbol(String symbolName) { MethodExecutionResult result = context.getVariable(symbolName); if (result == null) { return null; } return result.returnValue(); }
private void addSlimHelperLibraryToLibraries() { SlimHelperLibrary slimHelperLibrary = new SlimHelperLibrary(); slimHelperLibrary.setStatementExecutor(this); context.addLibrary(new Library(SLIM_HELPER_LIBRARY_INSTANCE_NAME, slimHelperLibrary)); }
protected MethodExecutionResult findAndInvoke(String methodName, Object[] args, Object instance) throws Throwable { FixtureInteraction interaction = context.getInteraction(); return interaction.findAndInvoke(methodName, instance, args); } }
@Override public MethodExecutionResult execute(String instanceName, String methodName, Object[] args) throws Throwable { List<Library> libraries = context.getLibraries(); for (int i = (libraries.size() - 1); i >= 0; i--) { MethodExecutionResult result = findAndInvoke(methodName, args, libraries.get(i).instance); if (result.hasResult()) { return result; } } return MethodExecutionResult.NO_METHOD_IN_LIBRARIES; } }
private void addToInstancesOrLibrary(String instanceName, Object instance) { if (isLibrary(instanceName)) { libraries.add(new Library(instanceName, instance)); } else { setInstance(instanceName, instance); } }
public void create(String instanceName, String className, Object[] args) throws SlimError, IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException { Object potentialActor = variables.getStored(className); if (potentialActor != null && !(potentialActor instanceof String)) { addToInstancesOrLibrary(instanceName, potentialActor); } else { String replacedClassName = variables .replaceSymbolsInString(className); Object instance = interaction.createInstance(paths, replacedClassName, replaceSymbols(args)); addToInstancesOrLibrary(instanceName, instance); } }
@Override public void create(String instanceName, String className, Object... args) throws SlimException { try { context.create(instanceName, className, args); // TODO Hack for supporting SlimHelperLibrary, please remove. Object newInstance = context.getInstance(instanceName); if (newInstance instanceof StatementExecutorConsumer) { ((StatementExecutorConsumer) newInstance).setStatementExecutor(this); } } catch (SlimError e) { throw new SlimException(format("%s[%d]", className, args.length), e, SlimServer.COULD_NOT_INVOKE_CONSTRUCTOR, true); } catch (IllegalArgumentException e) { throw new SlimException(format("%s[%d]", className, args.length), e, SlimServer.COULD_NOT_INVOKE_CONSTRUCTOR, true); } catch (InvocationTargetException e) { checkExceptionForStop(e.getTargetException()); throw new SlimException(e.getTargetException(), true); } catch (Throwable e) { // NOSONAR checkExceptionForStop(e); throw new SlimException(e); } }
@Override public Object getSymbol(String symbolName) { MethodExecutionResult result = context.getVariable(symbolName); if (result == null) { return null; } return result.returnValue(); }
private void addSlimHelperLibraryToLibraries() { SlimHelperLibrary slimHelperLibrary = new SlimHelperLibrary(); slimHelperLibrary.setStatementExecutor(this); context.addLibrary(new Library(SLIM_HELPER_LIBRARY_INSTANCE_NAME, slimHelperLibrary)); }
protected MethodExecutionResult findAndInvoke(String methodName, Object[] args, Object instance) throws Throwable { FixtureInteraction interaction = context.getInteraction(); return interaction.findAndInvoke(methodName, instance, args); } }
@Override public MethodExecutionResult execute(String instanceName, String methodName, Object[] args) throws Throwable { List<Library> libraries = context.getLibraries(); for (int i = (libraries.size() - 1); i >= 0; i--) { MethodExecutionResult result = findAndInvoke(methodName, args, libraries.get(i).instance); if (result.hasResult()) { return result; } } return MethodExecutionResult.NO_METHOD_IN_LIBRARIES; } }
@Override public Object getInstance(String instanceName) { return context.getInstance(instanceName); }
@Override public Object getSymbolObject(String symbolName) { MethodExecutionResult result = context.getVariable(symbolName); if (result == null) { return null; } return result.getObject(); }
@Override public StatementExecutorInterface getStatementExecutor() { StatementExecutorInterface statementExecutor = new StatementExecutor(new SlimExecutionContext(interaction)); if (timeout != null) { statementExecutor = StatementTimeoutExecutor.decorate(statementExecutor, timeout); } return statementExecutor; }