Search in sources :

Example 11 with CommandLine

use of picocli.CommandLine 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 12 with CommandLine

use of picocli.CommandLine 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)

Example 13 with CommandLine

use of picocli.CommandLine 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 14 with CommandLine

use of picocli.CommandLine in project neo4j by neo4j.

the class PushToCloudCommandTest method shouldAcceptUsernameViaEnvAndPromptForPassword.

@Test
public void shouldAcceptUsernameViaEnvAndPromptForPassword() throws Exception {
    // 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(), "--bolt-uri", SOME_EXAMPLE_BOLT_URI };
    var environment = Map.of("NEO4J_USERNAME", "user", "NEO4J_PASSWORD", "");
    new CommandLine(command).setResourceBundle(new MapResourceBundle(environment)).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 15 with CommandLine

use of picocli.CommandLine in project neo4j by neo4j.

the class PushToCloudCommandTest method shouldRecognizeDatabaseIdFromBoltURI.

@Test
public void shouldRecognizeDatabaseIdFromBoltURI() 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.databases.neo4j.io" };
    new CommandLine(command).execute(args);
    // then
    verify(copier).copy(anyBoolean(), eq("https://console.neo4j.io/v1/databases/mydbid"), eq("bolt+routing://mydbid.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

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