Search in sources :

Example 1 with ConnectionConfig

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

the class CypherShellMultiDatabaseIntegrationTest method switchingToNonExistingDatabaseShouldGiveErrorResponseFromServerInteractive.

@Test
public void switchingToNonExistingDatabaseShouldGiveErrorResponseFromServerInteractive() throws CommandException {
    shell = new CypherShell(linePrinter, new PrettyConfig(Format.PLAIN, true, 1000), true, new ShellParameterMap());
    useCommand = new Use(shell);
    shell.connect(new ConnectionConfig("bolt", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME));
    useCommand.execute(SYSTEM_DB_NAME);
    try {
        useCommand.execute("this_database_name_does_not_exist_in_test_container");
        fail("No ClientException thrown");
    } catch (ClientException e) {
        // In interactive we do not want to switch if the database does not exist
        assertOnSystemDB();
    }
}
Also used : ShellParameterMap(org.neo4j.shell.ShellParameterMap) CypherShell(org.neo4j.shell.CypherShell) ClientException(org.neo4j.driver.exceptions.ClientException) PrettyConfig(org.neo4j.shell.prettyprint.PrettyConfig) ConnectionConfig(org.neo4j.shell.ConnectionConfig) Test(org.junit.Test)

Example 2 with ConnectionConfig

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

the class CypherShellProtocolIntegrationTest method shouldConnectWithBoltSSCProtocol.

@Test
public void shouldConnectWithBoltSSCProtocol() throws Exception {
    CypherShell shell = new CypherShell(new StringLinePrinter(), new PrettyConfig(Format.PLAIN, true, 1000), false, new ShellParameterMap());
    // Given 3.X series where X > 1, where SSC are the default. Hard to test in 4.0 sadly.
    onlyIn3_2to3_6(shell);
    shell.connect(new ConnectionConfig("bolt+ssc", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME));
    assertTrue(shell.isConnected());
}
Also used : ShellParameterMap(org.neo4j.shell.ShellParameterMap) CypherShell(org.neo4j.shell.CypherShell) StringLinePrinter(org.neo4j.shell.StringLinePrinter) PrettyConfig(org.neo4j.shell.prettyprint.PrettyConfig) ConnectionConfig(org.neo4j.shell.ConnectionConfig) Test(org.junit.Test)

Example 3 with ConnectionConfig

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

the class CypherShellProtocolIntegrationTest method shouldConnectWithNeo4jSSCProtocol.

@Test
public void shouldConnectWithNeo4jSSCProtocol() throws Exception {
    CypherShell shell = new CypherShell(new StringLinePrinter(), new PrettyConfig(Format.PLAIN, true, 1000), false, new ShellParameterMap());
    // Given 3.X series where X > 1, where SSC are the default. Hard to test in 4.0 sadly.
    onlyIn3_2to3_6(shell);
    // This should work by falling back to bolt+ssc
    shell.connect(new ConnectionConfig("neo4j+ssc", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME));
    assertTrue(shell.isConnected());
}
Also used : ShellParameterMap(org.neo4j.shell.ShellParameterMap) CypherShell(org.neo4j.shell.CypherShell) StringLinePrinter(org.neo4j.shell.StringLinePrinter) PrettyConfig(org.neo4j.shell.prettyprint.PrettyConfig) ConnectionConfig(org.neo4j.shell.ConnectionConfig) Test(org.junit.Test)

Example 4 with ConnectionConfig

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

the class CypherShellProtocolIntegrationTest method onlyIn3_2to3_6.

// Here should be tests for "neo4j+s" and "bolt+s", but we don't have the infrastructure for those.
private void onlyIn3_2to3_6(CypherShell shell) throws Exception {
    // Default connection settings
    shell.connect(new ConnectionConfig("bolt", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME));
    assumeTrue(majorVersion(shell.getServerVersion()) == 3);
    assumeTrue(minorVersion(shell.getServerVersion()) > 1);
    shell.disconnect();
}
Also used : ConnectionConfig(org.neo4j.shell.ConnectionConfig)

Example 5 with ConnectionConfig

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

the class BoltStateHandlerTest method shouldChangePasswordAndKeepSystemDbBookmark.

@Test
public void shouldChangePasswordAndKeepSystemDbBookmark() throws CommandException {
    // Given
    ConnectionConfig config = new ConnectionConfig("bolt", "", -1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME);
    config.setNewPassword("newPW");
    Bookmark bookmark = InternalBookmark.parse("myBookmark");
    Session sessionMock = mock(Session.class);
    Result resultMock = mock(Result.class);
    Driver driverMock = stubResultSummaryInAnOpenSession(resultMock, sessionMock, "Neo4j/9.4.1-ALPHA", "my_default_db");
    when(sessionMock.run("CALL dbms.security.changePassword($n)", Values.parameters("n", config.newPassword()))).thenReturn(resultMock);
    when(sessionMock.lastBookmark()).thenReturn(bookmark);
    BoltStateHandler handler = new OfflineBoltStateHandler(driverMock);
    // When
    handler.changePassword(config);
    // Then
    assertEquals("newPW", config.password());
    assertNull(config.newPassword());
    assertNull(handler.session);
    // When connecting to system db again
    handler.connect(new ConnectionConfig("bolt", "", -1, "", "", Encryption.DEFAULT, SYSTEM_DB_NAME));
    // Then use bookmark for system DB
    verify(driverMock).session(SessionConfig.builder().withDefaultAccessMode(AccessMode.WRITE).withDatabase(SYSTEM_DB_NAME).withBookmarks(bookmark).build());
}
Also used : InternalBookmark(org.neo4j.driver.internal.InternalBookmark) Bookmark(org.neo4j.driver.Bookmark) Driver(org.neo4j.driver.Driver) FakeDriver(org.neo4j.shell.test.bolt.FakeDriver) ConnectionConfig(org.neo4j.shell.ConnectionConfig) Session(org.neo4j.driver.Session) FakeSession(org.neo4j.shell.test.bolt.FakeSession) Result(org.neo4j.driver.Result) Test(org.junit.Test)

Aggregations

ConnectionConfig (org.neo4j.shell.ConnectionConfig)13 Test (org.junit.Test)8 CypherShell (org.neo4j.shell.CypherShell)6 ShellParameterMap (org.neo4j.shell.ShellParameterMap)6 PrettyConfig (org.neo4j.shell.prettyprint.PrettyConfig)6 StringLinePrinter (org.neo4j.shell.StringLinePrinter)4 ClientException (org.neo4j.driver.exceptions.ClientException)3 FakeDriver (org.neo4j.shell.test.bolt.FakeDriver)3 Before (org.junit.Before)2 AuthToken (org.neo4j.driver.AuthToken)2 Bookmark (org.neo4j.driver.Bookmark)2 Driver (org.neo4j.driver.Driver)2 Result (org.neo4j.driver.Result)2 Session (org.neo4j.driver.Session)2 SessionConfig (org.neo4j.driver.SessionConfig)2 InternalBookmark (org.neo4j.driver.internal.InternalBookmark)2 FakeSession (org.neo4j.shell.test.bolt.FakeSession)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Config (org.neo4j.driver.Config)1