Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit 225d650

Browse files
committed
Support Neo4j Java Driver 1.7.0-rc2 and --driver-version
1 parent 3beb5e3 commit 225d650

File tree

12 files changed

+180
-21
lines changed

12 files changed

+180
-21
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ ext {
7272

7373
argparse4jVersion = '0.7.0'
7474
junitVersion = '4.12'
75-
neo4jJavaVersion = '1.6.1'
75+
neo4jJavaDriverVersion = '1.7.0-rc2'
7676
findbugsVersion = '3.0.0'
7777
jansiVersion = '1.13'
7878
jlineVersion = '2.14.6'

cypher-shell/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ task generateBuildProperties {
77
def propFile = new File(outputDir, "build.properties")
88
def props = new Properties()
99
props.setProperty("version", buildVersion)
10+
props.setProperty("driverVersion", neo4jJavaDriverVersion)
1011
props.store(propFile.newWriter(), null)
1112
}
1213
}
@@ -36,7 +37,7 @@ distributions {
3637

3738
dependencies {
3839
compile "net.sourceforge.argparse4j:argparse4j:$argparse4jVersion"
39-
compile "org.neo4j.driver:neo4j-java-driver:$neo4jJavaVersion"
40+
compile "org.neo4j.driver:neo4j-java-driver:$neo4jJavaDriverVersion"
4041
compileOnly "com.google.code.findbugs:annotations:$findbugsVersion"
4142
compile "org.fusesource.jansi:jansi:$jansiVersion"
4243
compile("jline:jline:$jlineVersion") {

cypher-shell/src/main/java/org/neo4j/shell/Main.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public static void main(String[] args) {
5151
void startShell(@Nonnull CliArgs cliArgs) {
5252
if (cliArgs.getVersion()) {
5353
out.println("Cypher-Shell " + Build.version());
54+
}
55+
if (cliArgs.getDriverVersion()) {
56+
out.println("Neo4j Driver " + Build.driverVersion());
57+
}
58+
if (cliArgs.getVersion() || cliArgs.getDriverVersion()) {
5459
return;
5560
}
5661
Logger logger = instantiateLogger(cliArgs);

cypher-shell/src/main/java/org/neo4j/shell/build/Build.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ private static Properties getProperties() {
2222
if (props == null) {
2323
props = new Properties();
2424
try (InputStream stream = Build.class.getClassLoader().getResourceAsStream("build.properties")) {
25-
props.load(stream);
25+
if (stream == null) {
26+
throw new IllegalStateException("Cannot read build.properties");
27+
} else {
28+
props.load(stream);
29+
}
2630
} catch (IOException e) {
2731
System.err.println("Could not read build properties: " + e.getMessage());
2832
}
@@ -38,4 +42,12 @@ private static Properties getProperties() {
3842
public static String version() {
3943
return getProperties().getProperty("version", "dev");
4044
}
45+
46+
/**
47+
* @return the revision of the Neo4j Driver, or "dev" if no properties file could be read.
48+
*/
49+
@Nonnull
50+
public static String driverVersion() {
51+
return getProperties().getProperty("driverVersion", "dev");
52+
}
4153
}

cypher-shell/src/main/java/org/neo4j/shell/cli/CliArgHelper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public static CliArgs parse(@Nonnull String... args) {
9090

9191
cliArgs.setVersion(ns.getBoolean("version"));
9292

93+
cliArgs.setDriverVersion(ns.getBoolean("driver-version"));
94+
9395
return cliArgs;
9496
}
9597

@@ -169,6 +171,11 @@ private static ArgumentParser setupParser()
169171
.help("print version of cypher-shell and exit")
170172
.action(new StoreTrueArgumentAction());
171173

174+
parser.addArgument("--driver-version")
175+
.help("print version of the Neo4j Driver used and exit")
176+
.dest("driver-version")
177+
.action(new StoreTrueArgumentAction());
178+
172179
parser.addArgument("cypher")
173180
.nargs("?")
174181
.help("an optional string of cypher to execute and then exit");

cypher-shell/src/main/java/org/neo4j/shell/cli/CliArgs.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class CliArgs {
1717
private boolean debugMode;
1818
private boolean nonInteractive = false;
1919
private boolean version = false;
20+
private boolean driverVersion = false;
2021

2122
/**
2223
* Set the scheme to the primary value, or if null, the fallback value.
@@ -155,6 +156,14 @@ public void setVersion(boolean version) {
155156
this.version = version;
156157
}
157158

159+
public boolean getDriverVersion() {
160+
return driverVersion;
161+
}
162+
163+
public void setDriverVersion(boolean version) {
164+
this.driverVersion = version;
165+
}
166+
158167
public boolean isStringShell() {
159168
return cypher.isPresent();
160169
}

cypher-shell/src/test/java/org/neo4j/shell/MainTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public void connectMaybeInteractivelyRepromptsIfUserIsNotProvided() throws Excep
221221
}
222222

223223
@Test
224-
public void printsVersionAndExits() throws Exception {
224+
public void printsVersionAndExits() {
225225
CliArgs args = new CliArgs();
226226
args.setVersion(true);
227227

@@ -235,4 +235,20 @@ public void printsVersionAndExits() throws Exception {
235235
verify(printStream).println(argument.capture());
236236
assertTrue(argument.getValue().matches("Cypher-Shell \\d+\\.\\d+\\.\\d+.*"));
237237
}
238+
239+
@Test
240+
public void printsDriverVersionAndExits() {
241+
CliArgs args = new CliArgs();
242+
args.setDriverVersion(true);
243+
244+
PrintStream printStream = mock(PrintStream.class);
245+
246+
Main main = new Main(System.in, printStream);
247+
main.startShell(args);
248+
249+
ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
250+
251+
verify(printStream).println(argument.capture());
252+
assertTrue(argument.getValue().matches("Neo4j Driver \\d+\\.\\d+\\.\\d+.*"));
253+
}
238254
}

cypher-shell/src/test/java/org/neo4j/shell/build/BuildTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ public class BuildTest {
1010
public void versionIsNumeric() throws Exception {
1111
assertTrue(Build.version().matches("\\d+\\.\\d+\\.\\d+.*"));
1212
}
13+
14+
@Test
15+
public void neo4jDriverVersionIsNumeric() throws Exception {
16+
assertTrue(Build.driverVersion().matches("\\d+\\.\\d+\\.\\d+.*"));
17+
}
1318
}

cypher-shell/src/test/java/org/neo4j/shell/cli/CliArgHelperTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ public void testDebugIsParsed() {
5050
CliArgHelper.parse(asArray("--debug")).getDebugMode());
5151
}
5252

53+
@Test
54+
public void testVersionIsParsed() {
55+
assertTrue("Version should have been parsed to true",
56+
CliArgHelper.parse(asArray("--version")).getVersion());
57+
}
58+
59+
@Test
60+
public void testDriverVersionIsParsed() {
61+
assertTrue("Driver version should have been parsed to true",
62+
CliArgHelper.parse(asArray("--driver-version")).getDriverVersion());
63+
}
64+
5365
@Test
5466
public void testFailFastIsDefault() {
5567
assertEquals("Unexpected fail-behavior", FailBehavior.FAIL_FAST,

cypher-shell/src/test/java/org/neo4j/shell/test/bolt/FakeSession.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ public Transaction beginTransaction() {
1717
return null;
1818
}
1919

20+
@Override
21+
public Transaction beginTransaction( TransactionConfig config )
22+
{
23+
return null;
24+
}
25+
2026
@Override
2127
public Transaction beginTransaction(String bookmark) {
2228
return null;
@@ -27,26 +33,92 @@ public CompletionStage<Transaction> beginTransactionAsync() {
2733
return null;
2834
}
2935

36+
@Override
37+
public CompletionStage<Transaction> beginTransactionAsync( TransactionConfig config )
38+
{
39+
return null;
40+
}
41+
3042
@Override
3143
public <T> T readTransaction(TransactionWork<T> work) {
3244
return null;
3345
}
3446

47+
@Override
48+
public <T> T readTransaction( TransactionWork<T> work, TransactionConfig config )
49+
{
50+
return null;
51+
}
52+
3553
@Override
3654
public <T> CompletionStage<T> readTransactionAsync(TransactionWork<CompletionStage<T>> work) {
3755
return null;
3856
}
3957

58+
@Override
59+
public <T> CompletionStage<T> readTransactionAsync( TransactionWork<CompletionStage<T>> work, TransactionConfig config )
60+
{
61+
return null;
62+
}
63+
4064
@Override
4165
public <T> T writeTransaction(TransactionWork<T> work) {
4266
return null;
4367
}
4468

69+
@Override
70+
public <T> T writeTransaction( TransactionWork<T> work, TransactionConfig config )
71+
{
72+
return null;
73+
}
74+
4575
@Override
4676
public <T> CompletionStage<T> writeTransactionAsync(TransactionWork<CompletionStage<T>> work) {
4777
return null;
4878
}
4979

80+
@Override
81+
public <T> CompletionStage<T> writeTransactionAsync( TransactionWork<CompletionStage<T>> work, TransactionConfig config )
82+
{
83+
return null;
84+
}
85+
86+
@Override
87+
public StatementResult run( String statement, TransactionConfig config )
88+
{
89+
return FakeStatementResult.parseStatement(statement);
90+
}
91+
92+
@Override
93+
public StatementResult run( String statement, Map<String,Object> parameters, TransactionConfig config )
94+
{
95+
return FakeStatementResult.parseStatement(statement);
96+
}
97+
98+
@Override
99+
public StatementResult run( Statement statement, TransactionConfig config )
100+
{
101+
return new FakeStatementResult();
102+
}
103+
104+
@Override
105+
public CompletionStage<StatementResultCursor> runAsync( String statement, TransactionConfig config )
106+
{
107+
return null;
108+
}
109+
110+
@Override
111+
public CompletionStage<StatementResultCursor> runAsync( String statement, Map<String,Object> parameters, TransactionConfig config )
112+
{
113+
return null;
114+
}
115+
116+
@Override
117+
public CompletionStage<StatementResultCursor> runAsync( Statement statement, TransactionConfig config )
118+
{
119+
return null;
120+
}
121+
50122
@Override
51123
public String lastBookmark() {
52124
return null;

0 commit comments

Comments
 (0)