Search in sources :

Example 6 with CommandLine

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());
}
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 7 with CommandLine

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());
}
Also used : CommandLine(picocli.CommandLine) Copier(org.neo4j.pushtocloud.PushToCloudCommand.Copier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 8 with CommandLine

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");
}
Also used : CommandLine(picocli.CommandLine) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 9 with CommandLine

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());
}
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 10 with CommandLine

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;
}
Also used : CommandLine(picocli.CommandLine) DumpCommandProvider(org.neo4j.commandline.dbms.DumpCommandProvider)

Aggregations

CommandLine (picocli.CommandLine)45 Test (org.junit.jupiter.api.Test)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 Copier (org.neo4j.pushtocloud.PushToCloudCommand.Copier)17 Path (java.nio.file.Path)9 DumpCreator (org.neo4j.pushtocloud.PushToCloudCommand.DumpCreator)5 ParseResult (picocli.CommandLine.ParseResult)5 IOException (java.io.IOException)4 PrintWriter (java.io.PrintWriter)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Set (java.util.Set)3 ParameterException (picocli.CommandLine.ParameterException)3 PrintStream (java.io.PrintStream)2 Files (java.nio.file.Files)2 Map (java.util.Map)2 ServiceProvider (com.b2international.snowowl.core.ServiceProvider)1 AuthorizedEventBus (com.b2international.snowowl.core.authorization.AuthorizedEventBus)1 JWTGenerator (com.b2international.snowowl.core.identity.JWTGenerator)1 Environment (com.b2international.snowowl.core.setup.Environment)1