Search in sources :

Example 6 with CollectingOutput

use of org.neo4j.shell.impl.CollectingOutput in project neo4j by neo4j.

the class FakeShellServer method executeCommand.

public void executeCommand(ShellClient client, String command, String... theseLinesMustExistRegEx) throws Exception {
    CollectingOutput output = new CollectingOutput();
    client.evaluate(command, output);
    for (String lineThatMustExist : theseLinesMustExistRegEx) {
        boolean negative = lineThatMustExist.startsWith("!");
        lineThatMustExist = negative ? lineThatMustExist.substring(1) : lineThatMustExist;
        Pattern pattern = compile(lineThatMustExist);
        boolean found = false;
        for (String line : output) {
            if (pattern.matcher(line).find()) {
                found = true;
                break;
            }
        }
        assertTrue("Was expecting a line matching '" + lineThatMustExist + "', but didn't find any from out of " + Iterables.asCollection(output), found != negative);
    }
}
Also used : Pattern(java.util.regex.Pattern) CollectingOutput(org.neo4j.shell.impl.CollectingOutput)

Example 7 with CollectingOutput

use of org.neo4j.shell.impl.CollectingOutput in project neo4j by neo4j.

the class FakeShellServer method executeCommandExpectingException.

public void executeCommandExpectingException(String command, String errorMessageShouldContain) throws Exception {
    CollectingOutput output = new CollectingOutput();
    try {
        shellClient.evaluate(command, output);
        fail("Was expecting an exception");
    } catch (ShellException e) {
        String errorMessage = e.getMessage();
        if (!errorMessage.toLowerCase().contains(errorMessageShouldContain.toLowerCase())) {
            fail("Error message '" + errorMessage + "' should have contained '" + errorMessageShouldContain + "'");
        }
    }
}
Also used : CollectingOutput(org.neo4j.shell.impl.CollectingOutput)

Example 8 with CollectingOutput

use of org.neo4j.shell.impl.CollectingOutput in project neo4j by neo4j.

the class FakeShellServer method doBefore.

@Before
public void doBefore() throws Exception {
    db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
    shellServer = new FakeShellServer(db);
    shellClient = new SameJvmClient(new HashMap<String, Serializable>(), shellServer, new CollectingOutput());
}
Also used : SameJvmClient(org.neo4j.shell.impl.SameJvmClient) HashMap(java.util.HashMap) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) CollectingOutput(org.neo4j.shell.impl.CollectingOutput) Before(org.junit.Before)

Example 9 with CollectingOutput

use of org.neo4j.shell.impl.CollectingOutput in project neo4j by neo4j.

the class ConfigurationIT method deprecatedConfigName.

@Test
public void deprecatedConfigName() throws Exception {
    CollectingOutput output = new CollectingOutput();
    client.evaluate("pwd", output);
    assertTrue(output.asString().contains("(?)"));
}
Also used : CollectingOutput(org.neo4j.shell.impl.CollectingOutput) Test(org.junit.Test)

Example 10 with CollectingOutput

use of org.neo4j.shell.impl.CollectingOutput in project neo4j by neo4j.

the class CtrlCTest method shouldInstallProvidedHandlerAfterReadingUserInput.

@Test
public void shouldInstallProvidedHandlerAfterReadingUserInput() throws Exception {
    final StubCtrlCHandler handler = new StubCtrlCHandler();
    AbstractClient client = new AbstractClient(new HashMap<String, Serializable>(), handler) {

        @Override
        public ShellServer getServer() {
            try {
                return new FakeShellServer(null);
            } catch (RemoteException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public Output getOutput() {
            try {
                return new CollectingOutput();
            } catch (RemoteException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public String readLine(String ignored) {
            assertFalse("handler installed, expected it to not be there", handler.installed);
            return "CYPHER 2.1 RETURN 42;";
        }

        @Override
        public void evaluate(String output) {
            assertTrue("handler not installed, but expected to be there", handler.installed);
            end();
        }
    };
    client.grabPrompt();
    assertFalse("handler installed, expected it to not be there", handler.installed);
}
Also used : Serializable(java.io.Serializable) AbstractClient(org.neo4j.shell.impl.AbstractClient) CollectingOutput(org.neo4j.shell.impl.CollectingOutput) RemoteException(java.rmi.RemoteException) Test(org.junit.Test)

Aggregations

CollectingOutput (org.neo4j.shell.impl.CollectingOutput)12 Test (org.junit.Test)6 SameJvmClient (org.neo4j.shell.impl.SameJvmClient)6 Serializable (java.io.Serializable)3 Pattern (java.util.regex.Pattern)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2 ShellException (org.neo4j.shell.ShellException)2 GraphDatabaseShellServer (org.neo4j.shell.kernel.GraphDatabaseShellServer)2 URL (java.net.URL)1 RemoteException (java.rmi.RemoteException)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 AbstractClient (org.neo4j.shell.impl.AbstractClient)1 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)1