Search in sources :

Example 6 with Copier

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

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

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

Example 9 with Copier

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

the class PushToCloudCommandTest method shouldAcceptOnlyUsernameAndPasswordFromCli.

@Test
public void shouldAcceptOnlyUsernameAndPasswordFromCli() throws IOException, CommandFailedException {
    // given
    Copier targetCommunicator = mockedTargetCommunicator();
    String username = "neo4j";
    String password = "abc";
    PushToCloudCommand command = command().copier(targetCommunicator).console(PushToCloudConsole.fakeConsole(username, password)).build();
    // when
    String[] args = { "--dump", dump.toString(), "--username", "neo4jcli", "--password", "passcli", "--bolt-uri", SOME_EXAMPLE_BOLT_URI };
    new CommandLine(command).execute(args);
    verify(targetCommunicator).authenticate(anyBoolean(), anyString(), eq("neo4jcli"), eq("passcli".toCharArray()), anyBoolean());
}
Also used : CommandLine(picocli.CommandLine) Copier(org.neo4j.pushtocloud.PushToCloudCommand.Copier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 10 with Copier

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

the class PushToCloudCommandTest method shouldAcceptOnlyUsernameAndPasswordFromEnv.

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