Search in sources :

Example 1 with DumpCreator

use of org.neo4j.pushtocloud.PushToCloudCommand.DumpCreator 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 DumpCreator

use of org.neo4j.pushtocloud.PushToCloudCommand.DumpCreator 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 3 with DumpCreator

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

the class PushToCloudCommandTest method shouldFailOnDatabaseNameAsSourceUsingExistingDumpTarget.

@Test
public void shouldFailOnDatabaseNameAsSourceUsingExistingDumpTarget() throws IOException, CommandFailedException {
    // 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-that-exists");
    Files.write(dumpFile, "some data".getBytes());
    String[] args = { "--database", databaseName, "--dump-to", dumpFile.toString(), "--bolt-uri", SOME_EXAMPLE_BOLT_URI };
    int returnValue = new CommandLine(command).execute(args);
    assertNotEquals(0, returnValue, "Expected command to fail");
}
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 4 with DumpCreator

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

the class PushToCloudCommandTest method mockedDumpCreator.

private DumpCreator mockedDumpCreator() throws CommandFailedException {
    DumpCreator dumpCreator = mock(DumpCreator.class);
    when(dumpCreator.dumpDatabase(anyString(), any())).thenReturn(dump);
    return dumpCreator;
}
Also used : DumpCreator(org.neo4j.pushtocloud.PushToCloudCommand.DumpCreator)

Example 5 with DumpCreator

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

the class PushToCloudCommandTest method shouldAuthenticateBeforeDumping.

@Test
public void shouldAuthenticateBeforeDumping() throws CommandFailedException, IOException {
    // given
    Copier copier = mockedTargetCommunicator();
    DumpCreator dumper = mockedDumpCreator();
    PushToCloudCommand command = command().copier(copier).dumpCreator(dumper).build();
    // when
    String[] args = { "--bolt-uri", "bolt+routing://mydbid.databases.neo4j.io" };
    new CommandLine(command).execute(args);
    // then
    InOrder inOrder = inOrder(copier, dumper);
    inOrder.verify(copier).authenticate(anyBoolean(), anyString(), anyString(), any(), eq(false));
    inOrder.verify(dumper).dumpDatabase(anyString(), any());
    inOrder.verify(copier).copy(anyBoolean(), anyString(), eq("bolt+routing://mydbid.databases.neo4j.io"), any(), eq(true), anyString());
}
Also used : CommandLine(picocli.CommandLine) InOrder(org.mockito.InOrder) DumpCreator(org.neo4j.pushtocloud.PushToCloudCommand.DumpCreator) Copier(org.neo4j.pushtocloud.PushToCloudCommand.Copier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

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