Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.neo4j.shell.cli.CliArgs;
import org.neo4j.shell.log.AnsiLogger;
import org.neo4j.shell.log.Logger;
import org.neo4j.shell.prettyprint.PrettyConfig;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -32,8 +33,7 @@ public void connectInteractivelyPromptsOnWrongAuthentication() throws Exception
cliArgs.setPassword( "", "" );

Logger logger = new AnsiLogger(cliArgs.getDebugMode());
logger.setFormat(cliArgs.getFormat());

PrettyConfig prettyConfig = new PrettyConfig(cliArgs);
ConnectionConfig connectionConfig = new ConnectionConfig(
cliArgs.getScheme(),
cliArgs.getHost(),
Expand All @@ -42,7 +42,7 @@ public void connectInteractivelyPromptsOnWrongAuthentication() throws Exception
cliArgs.getPassword(),
cliArgs.getEncryption());

CypherShell shell = new CypherShell(logger);
CypherShell shell = new CypherShell(logger, prettyConfig);

// when
assertEquals("", connectionConfig.username());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.neo4j.shell;

import org.neo4j.shell.prettyprint.LinePrinter;
import org.neo4j.shell.prettyprint.OutputFormatter;

public class StringLinePrinter implements LinePrinter {

private StringBuilder sb = new StringBuilder();

@Override
public void printOut(String line) {
sb.append(line).append(OutputFormatter.NEWLINE);
}

public void clear() {
sb.setLength(0);
}

public String output() {
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,25 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import org.neo4j.driver.v1.exceptions.AuthenticationException;
import org.neo4j.shell.ConnectionConfig;
import org.neo4j.shell.CypherShell;
import org.neo4j.shell.StringLinePrinter;
import org.neo4j.shell.cli.Format;
import org.neo4j.shell.exception.CommandException;
import org.neo4j.shell.log.Logger;

import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import org.neo4j.shell.prettyprint.PrettyConfig;

public class CypherShellFailureIntegrationTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();

private Logger logger = mock(Logger.class);
private StringLinePrinter linePrinter = new StringLinePrinter();
private CypherShell shell;

@Before
public void setUp() throws Exception {
doReturn(Format.VERBOSE).when(logger).getFormat();

shell = new CypherShell(logger);
linePrinter.clear();
shell = new CypherShell(linePrinter, new PrettyConfig(Format.VERBOSE, true, 1000));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,28 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
import org.neo4j.shell.ConnectionConfig;
import org.neo4j.shell.CypherShell;
import org.neo4j.shell.StringLinePrinter;
import org.neo4j.shell.cli.Format;
import org.neo4j.shell.exception.CommandException;
import org.neo4j.shell.log.Logger;

import java.util.List;
import org.neo4j.shell.prettyprint.PrettyConfig;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.neo4j.shell.prettyprint.OutputFormatter.NEWLINE;

public class CypherShellPlainIntegrationTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();

private Logger logger = mock(Logger.class);
private StringLinePrinter linePrinter = new StringLinePrinter();
private CypherShell shell;

@Before
public void setUp() throws Exception {
doReturn(Format.PLAIN).when(logger).getFormat();
shell = new CypherShell(logger);
linePrinter.clear();
shell = new CypherShell(linePrinter, new PrettyConfig(Format.PLAIN, true, 1000));
shell.connect(new ConnectionConfig("bolt://", "localhost", 7687, "neo4j", "neo", true));
}

Expand All @@ -46,14 +41,11 @@ public void periodicCommitWorks() throws CommandException {
shell.execute("USING PERIODIC COMMIT\n" +
"LOAD CSV FROM 'https://neo4j.com/docs/cypher-refcard/3.2/csv/artists.csv' AS line\n" +
"CREATE (:Artist {name: line[1], year: toInt(line[2])});");
linePrinter.clear();

shell.execute("MATCH (a:Artist) WHERE a.name = 'Europe' RETURN a.name");

ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(logger, times(2)).printOut(captor.capture());

List<String> queryResult = captor.getAllValues();
assertThat(queryResult.get(1), containsString("Europe"));
assertThat(linePrinter.output(), containsString("a.name"+ NEWLINE+"\"Europe\""));
}

@Test
Expand All @@ -62,11 +54,7 @@ public void cypherWithProfileStatements() throws CommandException {
shell.execute("CYPHER RUNTIME=INTERPRETED PROFILE RETURN null");

//then
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(logger, times(1)).printOut(captor.capture());

List<String> result = captor.getAllValues();
String actual = result.get(0);
String actual = linePrinter.output();
// This assertion checks everything except for time and cypher
assertThat(actual, containsString("Plan: \"PROFILE\""));
assertThat(actual, containsString("Statement: \"READ_ONLY\""));
Expand All @@ -84,11 +72,7 @@ public void cypherWithExplainStatements() throws CommandException {
shell.execute("CYPHER RUNTIME=INTERPRETED EXPLAIN RETURN null");

//then
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(logger, times(1)).printOut(captor.capture());

List<String> result = captor.getAllValues();
String actual = result.get(0);
String actual = linePrinter.output();
// This assertion checks everything except for time and cypher
assertThat(actual, containsString("Plan: \"EXPLAIN\""));
assertThat(actual, containsString("Statement: \"READ_ONLY\""));
Expand Down
Loading