use of picocli.CommandLine 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());
}
use of picocli.CommandLine 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());
}
use of picocli.CommandLine in project neo4j by neo4j.
the class PushToCloudCommandTest method shouldNotAcceptBothDumpAndDatabaseNameAsSource.
@Test
public void shouldNotAcceptBothDumpAndDatabaseNameAsSource() throws IOException, CommandFailedException {
// given
PushToCloudCommand command = command().copier(mockedTargetCommunicator()).build();
// when
String[] args = { "--dump", directory.file("some-dump-file").toString(), "--database", DBNAME, "--bolt-uri", SOME_EXAMPLE_BOLT_URI };
int returnValue = new CommandLine(command).execute(args);
assertNotEquals(0, returnValue, "Expected command to fail");
}
use of picocli.CommandLine 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());
}
use of picocli.CommandLine in project neo4j by neo4j.
the class RealDumpCreator method dumpDatabase.
@Override
public Path dumpDatabase(String database, Path targetDumpFile) throws CommandFailedException {
String[] args = array("--database", database, "--to", targetDumpFile.toString());
new CommandLine(new DumpCommandProvider().createCommand(ctx)).execute(args);
ctx.out().printf("Dumped contents of database '%s' into '%s'%n", database, targetDumpFile);
return targetDumpFile;
}
Aggregations