Search in sources :

Example 16 with Copier

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

the class PushToCloudCommandTest method shouldAcceptPasswordViaEnvAndPromptForUsername.

@Test
public void shouldAcceptPasswordViaEnvAndPromptForUsername() throws Exception {
    // given
    Copier targetCommunicator = mockedTargetCommunicator();
    String username = "neo4j";
    PushToCloudCommand command = command().copier(targetCommunicator).console(PushToCloudConsole.fakeConsole(username, "tomte")).build();
    Path dump = this.dump;
    // when
    String[] args = { "--dump", dump.toString(), "--bolt-uri", SOME_EXAMPLE_BOLT_URI };
    var environment = Map.of("NEO4J_USERNAME", "", "NEO4J_PASSWORD", "pass");
    new CommandLine(command).setResourceBundle(new MapResourceBundle(environment)).execute(args);
    verify(targetCommunicator).authenticate(anyBoolean(), anyString(), eq("neo4j"), eq("pass".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 17 with Copier

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

the class PushToCloudCommandTest method shouldAcceptDumpAsSource.

@Test
void shouldAcceptDumpAsSource() throws Exception {
    // given
    Copier targetCommunicator = mockedTargetCommunicator();
    PushToCloudCommand command = command().copier(targetCommunicator).build();
    // when
    PushToCloudCommand.Uploader uploader = command.makeDumpUploader(this.dump);
    String[] args = { "--dump", dump.toString(), "--bolt-uri", SOME_EXAMPLE_BOLT_URI };
    new CommandLine(command).execute(args);
    // then
    verify(targetCommunicator).checkSize(anyBoolean(), any(), anyLong(), any());
    verify(targetCommunicator).copy(anyBoolean(), any(), any(), eq(uploader.source), 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 18 with Copier

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

the class PushToCloudCommandTest method shouldUseNeo4jAsDefaultUsernameIfUserHitsEnter.

@Test
public void shouldUseNeo4jAsDefaultUsernameIfUserHitsEnter() throws Exception {
    // given
    Copier targetCommunicator = mockedTargetCommunicator();
    PushToCloudConsole console = mock(PushToCloudConsole.class);
    when(console.readLine(anyString(), anyString())).thenReturn("");
    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(console).readLine("%s", format("Neo4j aura username (default: %s):", defaultUsername));
    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)

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