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

Commit f4c4954

Browse files
authored
Merge pull request #162 from sherfert/fix-its
Adapt integration tests to work with both 3.X and 4.X series.
2 parents b9ecf0e + b92fa65 commit f4c4954

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
package org.neo4j.shell.commands;
22

3-
43
import org.junit.Before;
54
import org.junit.Rule;
65
import org.junit.Test;
76
import org.junit.rules.ExpectedException;
87
import org.neo4j.driver.v1.exceptions.AuthenticationException;
9-
import org.neo4j.shell.ConnectionConfig;
108
import org.neo4j.shell.CypherShell;
119
import org.neo4j.shell.StringLinePrinter;
1210
import org.neo4j.shell.cli.Format;
1311
import org.neo4j.shell.exception.CommandException;
1412
import org.neo4j.shell.prettyprint.PrettyConfig;
1513

16-
public class CypherShellFailureIntegrationTest {
14+
public class CypherShellFailureIntegrationTest extends CypherShellIntegrationTest {
1715
@Rule
1816
public final ExpectedException thrown = ExpectedException.none();
1917

2018
private StringLinePrinter linePrinter = new StringLinePrinter();
21-
private CypherShell shell;
2219

2320
@Before
24-
public void setUp() throws Exception {
21+
public void setUp() {
2522
linePrinter.clear();
2623
shell = new CypherShell(linePrinter, new PrettyConfig(Format.VERBOSE, true, 1000));
2724
}
@@ -31,6 +28,6 @@ public void cypherWithNoPasswordShouldReturnValidError() throws CommandException
3128
thrown.expect( AuthenticationException.class );
3229
thrown.expectMessage("The client is unauthorized due to authentication failure.");
3330

34-
shell.connect(new ConnectionConfig("bolt://", "localhost", 7687, "neo4j", "", true));
31+
connect("");
3532
}
3633
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.neo4j.shell.commands;
2+
3+
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
4+
import org.neo4j.shell.ConnectionConfig;
5+
import org.neo4j.shell.CypherShell;
6+
import org.neo4j.shell.exception.CommandException;
7+
8+
abstract class CypherShellIntegrationTest
9+
{
10+
CypherShell shell;
11+
12+
void connect(String password) throws CommandException {
13+
// Try with encryption first, which is the default for 3.X
14+
try
15+
{
16+
shell.connect( new ConnectionConfig( "bolt://", "localhost", 7687, "neo4j", password, true ) );
17+
}
18+
catch ( ServiceUnavailableException e )
19+
{
20+
// This means we are probablyin 4.X, let's retry with encryption off
21+
shell.connect( new ConnectionConfig( "bolt://", "localhost", 7687, "neo4j", password, false ) );
22+
}
23+
}
24+
}

cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellPlainIntegrationTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@
1717
import static org.hamcrest.MatcherAssert.assertThat;
1818
import static org.neo4j.shell.prettyprint.OutputFormatter.NEWLINE;
1919

20-
public class CypherShellPlainIntegrationTest {
20+
public class CypherShellPlainIntegrationTest extends CypherShellIntegrationTest {
2121
@Rule
2222
public final ExpectedException thrown = ExpectedException.none();
2323

2424
private StringLinePrinter linePrinter = new StringLinePrinter();
25-
private CypherShell shell;
2625

2726
@Before
2827
public void setUp() throws Exception {
2928
linePrinter.clear();
3029
shell = new CypherShell(linePrinter, new PrettyConfig(Format.PLAIN, true, 1000));
31-
shell.connect(new ConnectionConfig("bolt://", "localhost", 7687, "neo4j", "neo", true));
30+
connect( "neo" );
3231
}
3332

3433
@After

cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellVerboseIntegrationTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@
2020
import static org.neo4j.shell.Versions.majorVersion;
2121
import static org.neo4j.shell.Versions.minorVersion;
2222

23-
public class CypherShellVerboseIntegrationTest {
23+
public class CypherShellVerboseIntegrationTest extends CypherShellIntegrationTest {
2424
@Rule
2525
public final ExpectedException thrown = ExpectedException.none();
2626

2727
private StringLinePrinter linePrinter = new StringLinePrinter();
2828
private Command rollbackCommand;
2929
private Command commitCommand;
3030
private Command beginCommand;
31-
private CypherShell shell;
3231

3332
@Before
3433
public void setUp() throws Exception {
@@ -38,7 +37,7 @@ public void setUp() throws Exception {
3837
commitCommand = new Commit(shell);
3938
beginCommand = new Begin(shell);
4039

41-
shell.connect(new ConnectionConfig("bolt://", "localhost", 7687, "neo4j", "neo", true));
40+
connect( "neo" );
4241
}
4342

4443
@After
@@ -72,9 +71,8 @@ public void connectTwiceThrows() throws CommandException {
7271
thrown.expect(CommandException.class);
7372
thrown.expectMessage("Already connected");
7473

75-
ConnectionConfig config = new ConnectionConfig("bolt://", "localhost", 7687, "neo4j", "neo", true);
7674
assertTrue("Shell should already be connected", shell.isConnected());
77-
shell.connect(config);
75+
connect( "neo" );
7876
}
7977

8078
@Test
@@ -193,6 +191,7 @@ public void cypherWithOrder() throws CommandException {
193191
assumeTrue(minorVersion(serverVersion) == 6 || majorVersion(serverVersion) == 4);
194192

195193
shell.execute( "CREATE INDEX ON :Person(age)" );
194+
shell.execute( "CALL db.awaitIndexes()" );
196195

197196
//when
198197
shell.execute("CYPHER RUNTIME=INTERPRETED EXPLAIN MATCH (n:Person) WHERE n.age >= 18 RETURN n.name, n.age");

tyrekicking.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ function prepare-bundle {
1111
}
1212

1313
function testscript {
14-
if cypher-shell/cypher-shell -u neo4j -p neo "RETURN 1;"; then
14+
# first try with encryption on (3.X series), if that fails with encryption of (4.X series)
15+
if cypher-shell/cypher-shell -u neo4j -p neo --encryption true "RETURN 1;"; then
16+
echo "$1 Success!"
17+
elif cypher-shell/cypher-shell -u neo4j -p neo --encryption false "RETURN 1;"; then
1518
echo "$1 Success!"
1619
else
1720
echo "$1 Failure!"

0 commit comments

Comments
 (0)