Search in sources :

Example 1 with Output

use of org.neo4j.shell.Output in project neo4j by neo4j.

the class GshExecutor method runScript.

@Override
protected void runScript(Object groovyScriptEngine, String scriptName, Map<String, Object> properties, String[] paths) throws Exception {
    properties.put("out", new GshOutput((Output) properties.get("out")));
    Object binding = this.newGroovyBinding(properties);
    Method runMethod = groovyScriptEngine.getClass().getMethod("run", String.class, binding.getClass());
    runMethod.invoke(groovyScriptEngine, scriptName + ".groovy", binding);
}
Also used : Output(org.neo4j.shell.Output) Method(java.lang.reflect.Method)

Example 2 with Output

use of org.neo4j.shell.Output in project neo4j by neo4j.

the class JshExecutor method runScript.

@Override
protected void runScript(Object interpreter, String scriptName, Map<String, Object> properties, String[] paths) throws Exception {
    File scriptFile = findScriptFile(scriptName, paths);
    Output out = (Output) properties.remove("out");
    interpreter.getClass().getMethod("setOut", Writer.class).invoke(interpreter, new OutputWriter(out));
    Method setMethod = interpreter.getClass().getMethod("set", String.class, Object.class);
    for (String key : properties.keySet()) {
        setMethod.invoke(interpreter, key, properties.get(key));
    }
    interpreter.getClass().getMethod("execfile", String.class).invoke(interpreter, scriptFile.getAbsolutePath());
}
Also used : Output(org.neo4j.shell.Output) Method(java.lang.reflect.Method) File(java.io.File) Writer(java.io.Writer)

Example 3 with Output

use of org.neo4j.shell.Output in project neo4j by neo4j.

the class ClientIT method shouldExitMultilineModeAfterGettingWarningOrError.

@Test
public void shouldExitMultilineModeAfterGettingWarningOrError() throws ShellException, RemoteException {
    final CollectingOutput output = new CollectingOutput();
    final String message = "Test method called";
    final String prompt = "our test prompt";
    AbstractClient client = new AbstractClient(null, null) {

        @Override
        public ShellServer getServer() {
            ShellServer server = null;
            try {
                server = new GraphDatabaseShellServer(null) {

                    @Override
                    public Response interpretLine(Serializable clientId, String line, Output out) throws ShellException {
                        try {
                            out.println(message);
                        } catch (RemoteException ignored) {
                        }
                        return new Response(prompt, line.endsWith(";") ? Continuation.EXCEPTION_CAUGHT : Continuation.INPUT_INCOMPLETE);
                    }
                };
            } catch (RemoteException ignored) {
            }
            return server;
        }

        @Override
        public Output getOutput() {
            return output;
        }
    };
    client.evaluate("RETURN ");
    assertThat(client.getPrompt(), equalTo("> "));
    client.evaluate("i;");
    Set<String> messages = new HashSet<>();
    for (String s : output) {
        messages.add(s);
    }
    assertThat(messages, contains(message));
    assertThat(client.getPrompt(), equalTo(prompt));
}
Also used : Serializable(java.io.Serializable) ShellException(org.neo4j.shell.ShellException) Response(org.neo4j.shell.Response) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) ShellServer(org.neo4j.shell.ShellServer) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) Output(org.neo4j.shell.Output) RemoteException(java.rmi.RemoteException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with Output

use of org.neo4j.shell.Output in project neo4j by neo4j.

the class ClientIT method shouldHandleNormalInput.

@Test
public void shouldHandleNormalInput() throws ShellException, RemoteException {
    final CollectingOutput output = new CollectingOutput();
    final String message = "Test method called";
    AbstractClient client = new AbstractClient(null, null) {

        @Override
        public ShellServer getServer() {
            ShellServer server = null;
            try {
                server = new GraphDatabaseShellServer(null) {

                    @Override
                    public Response interpretLine(Serializable clientId, String line, Output out) throws ShellException {
                        try {
                            out.println(message);
                        } catch (RemoteException ignored) {
                        }
                        return new Response("", Continuation.INPUT_COMPLETE);
                    }
                };
            } catch (RemoteException ignored) {
            }
            return server;
        }

        @Override
        public Output getOutput() {
            return output;
        }
    };
    client.evaluate("RETURN 1;");
    Set<String> messages = new HashSet<>();
    for (String s : output) {
        messages.add(s);
    }
    assertThat(messages, contains(message));
}
Also used : Serializable(java.io.Serializable) ShellException(org.neo4j.shell.ShellException) Response(org.neo4j.shell.Response) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) ShellServer(org.neo4j.shell.ShellServer) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) Output(org.neo4j.shell.Output) RemoteException(java.rmi.RemoteException) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Output (org.neo4j.shell.Output)4 Serializable (java.io.Serializable)2 Method (java.lang.reflect.Method)2 RemoteException (java.rmi.RemoteException)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 Response (org.neo4j.shell.Response)2 ShellException (org.neo4j.shell.ShellException)2 ShellServer (org.neo4j.shell.ShellServer)2 GraphDatabaseShellServer (org.neo4j.shell.kernel.GraphDatabaseShellServer)2 File (java.io.File)1 Writer (java.io.Writer)1