Search in sources :

Example 1 with Copier

use of org.neo4j.pushtocloud.PushToCloudCommand.Copier in project neo4j by neo4j.

the class PushToCloudCommandTest method shouldAcceptDatabaseNameAsSourceUsingGivenDumpTarget.

@Test
public void shouldAcceptDatabaseNameAsSourceUsingGivenDumpTarget() throws Exception {
    // given
    Copier targetCommunicator = mockedTargetCommunicator();
    DumpCreator dumpCreator = mockedDumpCreator();
    PushToCloudCommand command = command().copier(targetCommunicator).dumpCreator(dumpCreator).build();
    // when
    String databaseName = DBNAME;
    Path dumpFile = directory.file("some-dump-file");
    String[] args = { "--database", databaseName, "--dump-to", dumpFile.toString(), "--bolt-uri", SOME_EXAMPLE_BOLT_URI };
    new CommandLine(command).execute(args);
    // then
    verify(dumpCreator).dumpDatabase(databaseName, dumpFile);
    verify(targetCommunicator).copy(anyBoolean(), any(), any(), any(), eq(true), any());
}
Also used : Path(java.nio.file.Path) CommandLine(picocli.CommandLine) DumpCreator(org.neo4j.pushtocloud.PushToCloudCommand.DumpCreator) Copier(org.neo4j.pushtocloud.PushToCloudCommand.Copier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 2 with Copier

use of org.neo4j.pushtocloud.PushToCloudCommand.Copier in project neo4j by neo4j.

the class PushToCloudCommandTest method shouldUseNeo4jAsDefaultUsernameIfStdinIndicatesEndOfFile.

@Test
public void shouldUseNeo4jAsDefaultUsernameIfStdinIndicatesEndOfFile() throws Exception {
    // given
    Copier targetCommunicator = mockedTargetCommunicator();
    PushToCloudConsole console = mock(PushToCloudConsole.class);
    when(console.readLine(anyString(), anyString())).thenReturn(null);
    String defaultUsername = "neo4j";
    String password = "super-secret-password";
    PushToCloudCommand command = command().copier(targetCommunicator).console(console).build();
    // when
    String[] args = { "--dump", dump.toString(), "--bolt-uri", SOME_EXAMPLE_BOLT_URI, "--password", password.toString() };
    new CommandLine(command).execute(args);
    // then
    verify(targetCommunicator).authenticate(anyBoolean(), any(), eq(defaultUsername), eq(password.toCharArray()), anyBoolean());
    verify(targetCommunicator).copy(anyBoolean(), any(), any(), any(), eq(false), any());
}
Also used : CommandLine(picocli.CommandLine) Copier(org.neo4j.pushtocloud.PushToCloudCommand.Copier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 3 with Copier

use of org.neo4j.pushtocloud.PushToCloudCommand.Copier in project neo4j by neo4j.

the class PushToCloudCommandTest method shouldChooseToDumpDefaultDatabaseIfNeitherDumpNorDatabaseIsGiven.

@Test
public void shouldChooseToDumpDefaultDatabaseIfNeitherDumpNorDatabaseIsGiven() throws IOException, CommandFailedException {
    // given
    DumpCreator dumpCreator = mockedDumpCreator();
    Copier copier = mock(Copier.class);
    PushToCloudCommand command = command().dumpCreator(dumpCreator).copier(copier).build();
    // when
    String[] args = { "--bolt-uri", SOME_EXAMPLE_BOLT_URI };
    new CommandLine(command).execute(args);
    // then
    verify(dumpCreator).dumpDatabase(eq(DEFAULT_DATABASE_NAME), any());
    verify(copier).copy(anyBoolean(), any(), any(), any(), eq(true), any());
}
Also used : CommandLine(picocli.CommandLine) DumpCreator(org.neo4j.pushtocloud.PushToCloudCommand.DumpCreator) Copier(org.neo4j.pushtocloud.PushToCloudCommand.Copier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 4 with Copier

use of org.neo4j.pushtocloud.PushToCloudCommand.Copier in project neo4j by neo4j.

the class PushToCloudCommandTest method shouldAcceptUsernameViaArgAndPromptForPassword.

@Test
public void shouldAcceptUsernameViaArgAndPromptForPassword() throws IOException, CommandFailedException {
    // given
    Copier targetCommunicator = mockedTargetCommunicator();
    String username = "neo4j";
    String password = "abc";
    PushToCloudCommand command = command().copier(targetCommunicator).console(PushToCloudConsole.fakeConsole(username, password)).build();
    Path dump = this.dump;
    // when
    String[] args = { "--dump", dump.toString(), "--username", "user", "--bolt-uri", SOME_EXAMPLE_BOLT_URI };
    new CommandLine(command).execute(args);
    assertTrue(Files.exists(dump));
    verify(targetCommunicator).authenticate(anyBoolean(), anyString(), eq("user"), eq("abc".toCharArray()), anyBoolean());
}
Also used : Path(java.nio.file.Path) CommandLine(picocli.CommandLine) Copier(org.neo4j.pushtocloud.PushToCloudCommand.Copier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 5 with Copier

use of org.neo4j.pushtocloud.PushToCloudCommand.Copier in project neo4j by neo4j.

the class PushToCloudCommandTest method shouldRecognizeBothEnvironmentAndDatabaseIdFromBoltURI.

// TODO: 2019-08-07 shouldFailOnDumpPointingToInvalidDumpFile
@Test
public void shouldRecognizeBothEnvironmentAndDatabaseIdFromBoltURI() throws IOException, CommandFailedException {
    // given
    Copier copier = mock(Copier.class);
    PushToCloudCommand command = command().copier(copier).build();
    // when
    String[] args = { "--dump", dump.toString(), "--bolt-uri", "bolt+routing://mydbid-testenvironment.databases.neo4j.io" };
    new CommandLine(command).execute(args);
    // then
    verify(copier).copy(anyBoolean(), eq("https://console-testenvironment.neo4j.io/v1/databases/mydbid"), eq("bolt+routing://mydbid-testenvironment.databases.neo4j.io"), any(), eq(false), any());
}
Also used : CommandLine(picocli.CommandLine) Copier(org.neo4j.pushtocloud.PushToCloudCommand.Copier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

Copier (org.neo4j.pushtocloud.PushToCloudCommand.Copier)18 Test (org.junit.jupiter.api.Test)17 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)17 CommandLine (picocli.CommandLine)17 Path (java.nio.file.Path)6 DumpCreator (org.neo4j.pushtocloud.PushToCloudCommand.DumpCreator)5 InOrder (org.mockito.InOrder)1