예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldExit0WhenEverythingWorks()
        internal virtual void ShouldExit0WhenEverythingWorks()
        {
            OutsideWorld outsideWorld = mock(typeof(OutsideWorld));

            (new AdminTool(new CannedLocator(new NullCommandProvider()), new NullBlockerLocator(), outsideWorld, false)).Execute(null, null, "null");
            verify(outsideWorld).exit(STATUS_SUCCESS);
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAcceptOnlyUsernameOrPasswordFromEnvVar() throws java.io.IOException, org.neo4j.commandline.admin.CommandFailed
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAcceptOnlyUsernameOrPasswordFromEnvVar()
        {
            // given
            Copier targetCommunicator = MockedTargetCommunicator();
            string username           = "******";

            char[]             password     = new char[] { 'a', 'b', 'c' };
            OutsideWorld       outsideWorld = (new ControlledOutsideWorld(new DefaultFileSystemAbstraction())).withPromptResponse(username).withPasswordResponse(password);
            PushToCloudCommand command      = command().copier(targetCommunicator).OutsideWorld(outsideWorld).build();

            // when
            try
            {
                EnvironmentVariables.set("NEO4J_USERNAME", "neo4j");
                EnvironmentVariables.set("NEO4J_PASSWORD", null);
                command.Execute(array(Arg(ARG_DUMP, CreateSimpleDatabaseDump().ToString()), Arg(ARG_BOLT_URI, SOME_EXAMPLE_BOLT_URI)));
                fail("Should have failed");
            }
            catch (IncorrectUsage)
            {
                // then good
            }

            try
            {
                EnvironmentVariables.set("NEO4J_USERNAME", null);
                EnvironmentVariables.set("NEO4J_PASSWORD", "pass");
                command.Execute(array(Arg(ARG_DUMP, CreateSimpleDatabaseDump().ToString()), Arg(ARG_BOLT_URI, SOME_EXAMPLE_BOLT_URI)));
                fail("Should have failed");
            }
            catch (IncorrectUsage)
            {
                // then good
            }
        }
예제 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldAddTheHelpCommandToThoseProvidedByTheLocator()
        internal virtual void ShouldAddTheHelpCommandToThoseProvidedByTheLocator()
        {
            OutsideWorld outsideWorld = mock(typeof(OutsideWorld));

            (new AdminTool(new NullCommandLocator(), new NullBlockerLocator(), outsideWorld, false)).Execute(null, null, "help");
            verify(outsideWorld).stdOutLine("    help");
        }
예제 #4
0
 internal BackupStrategyCoordinator(ConsistencyCheckService consistencyCheckService, OutsideWorld outsideWorld, LogProvider logProvider, ProgressMonitorFactory progressMonitorFactory, IList <BackupStrategyWrapper> strategies)
 {
     this._consistencyCheckService = consistencyCheckService;
     this._outsideWorld            = outsideWorld;
     this._logProvider             = logProvider;
     this._progressMonitorFactory  = progressMonitorFactory;
     this._strategies = strategies;
 }
예제 #5
0
 internal DiagnosticsReportCommand(Path homeDir, Path configDir, OutsideWorld outsideWorld)
 {
     this._homeDir   = homeDir;
     this._configDir = configDir;
     this._fs        = outsideWorld.FileSystem();
     this.@out       = outsideWorld.OutStream();
     _err            = outsideWorld.ErrorStream();
 }
예제 #6
0
 public AdminTool(CommandLocator commandLocator, BlockerLocator blockerLocator, OutsideWorld outsideWorld, bool debug)
 {
     this._commandLocator = CommandLocator.withAdditionalCommand(Help(), commandLocator);
     this._blockerLocator = blockerLocator;
     this._outsideWorld   = outsideWorld;
     this._debug          = debug;
     this._usage          = new Usage(SCRIPT_NAME, this._commandLocator);
 }
예제 #7
0
        internal BackupStrategyCoordinatorFactory(BackupModule backupModule)
        {
            this._logProvider  = backupModule.LogProvider;
            this._outsideWorld = backupModule.OutsideWorld;

            this._consistencyCheckService = new ConsistencyCheckService();
            this._addressResolver         = new AddressResolver();
        }
예제 #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProvideFeedbackWhenNoCommandIsProvided()
        internal virtual void ShouldProvideFeedbackWhenNoCommandIsProvided()
        {
            OutsideWorld outsideWorld = mock(typeof(OutsideWorld));

            (new AdminTool(new NullCommandLocator(), new NullBlockerLocator(), outsideWorld, false)).Execute(null, null);
            verify(outsideWorld).stdErrLine("you must provide a command");
            verify(outsideWorld).stdErrLine("usage: neo4j-admin <command>");
            verify(outsideWorld).exit(STATUS_ERROR);
        }
예제 #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            File graphDir = new File(GraphDatabaseSettings.DEFAULT_DATABASE_NAME);

            _confDir = new File(graphDir, "conf");
            _homeDir = new File(graphDir, "home");
            @out     = mock(typeof(OutsideWorld));
            ResetOutsideWorldMock();
            _tool = new AdminTool(CommandLocator.fromServiceLocator(), BlockerLocator.fromServiceLocator(), @out, true);
        }
예제 #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            _fileSystem = _fileSystemRule.get();
            OutsideWorld mock = mock(typeof(OutsideWorld));

            when(mock.FileSystem()).thenReturn(_fileSystem);
            _setPasswordCommand = new SetInitialPasswordCommand(_testDir.directory("home").toPath(), _testDir.directory("conf").toPath(), mock);
            _authInitFile       = CommunitySecurityModule.getInitialUserRepositoryFile(_setPasswordCommand.loadNeo4jConfig());
            CommunitySecurityModule.getUserRepositoryFile(_setPasswordCommand.loadNeo4jConfig());
        }
예제 #11
0
 protected internal BackupSupportingClassesFactory(BackupModule backupModule)
 {
     this.LogProvider                  = backupModule.LogProvider;
     this.Clock                        = backupModule.Clock;
     this.Monitors                     = backupModule.Monitors;
     this.FileSystemAbstraction        = backupModule.FileSystemAbstraction;
     this.TransactionLogCatchUpFactory = backupModule.TransactionLogCatchUpFactory;
     this._jobScheduler                = backupModule.JobScheduler();
     this.LogDestination               = backupModule.OutsideWorld.outStream();
     this.OutsideWorld                 = backupModule.OutsideWorld;
 }
예제 #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void versionArgumentPrintsVersionEvenWithCommand()
        internal virtual void VersionArgumentPrintsVersionEvenWithCommand()
        {
            AdminCommand command      = mock(typeof(AdminCommand));
            OutsideWorld outsideWorld = mock(typeof(OutsideWorld));

            (new AdminTool(CannedCommand("command", command), new NullBlockerLocator(), outsideWorld, false)).execute(null, null, "command", "--version");

            verifyNoMoreInteractions(command);
            verify(outsideWorld).stdOutLine("neo4j-admin " + neo4jVersion());
            verify(outsideWorld).exit(STATUS_SUCCESS);
        }
예제 #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProvideFeedbackIfTheCommandFails()
        internal virtual void ShouldProvideFeedbackIfTheCommandFails()
        {
            OutsideWorld outsideWorld = mock(typeof(OutsideWorld));
            AdminCommand command      = args =>
            {
                throw new CommandFailed("the-failure-message");
            };

            (new AdminTool(CannedCommand("exception", command), new NullBlockerLocator(), outsideWorld, false)).execute(null, null, "exception");
            verify(outsideWorld).stdErrLine("command failed: the-failure-message");
            verify(outsideWorld).exit(STATUS_ERROR);
        }
예제 #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldPrintTheStacktraceWhenTheCommandThrowsARuntimeExceptionIfTheDebugFlagIsSet()
        internal virtual void ShouldPrintTheStacktraceWhenTheCommandThrowsARuntimeExceptionIfTheDebugFlagIsSet()
        {
            OutsideWorld outsideWorld = mock(typeof(OutsideWorld));
            Exception    exception    = new Exception("");
            AdminCommand command      = args =>
            {
                throw exception;
            };

            (new AdminTool(CannedCommand("exception", command), new NullBlockerLocator(), outsideWorld, true)).execute(null, null, "exception");
            verify(outsideWorld).printStacktrace(exception);
        }
예제 #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProvideFeedbackIfTheCommandThrowsARuntimeException()
        internal virtual void ShouldProvideFeedbackIfTheCommandThrowsARuntimeException()
        {
            OutsideWorld outsideWorld = mock(typeof(OutsideWorld));
            AdminCommand command      = args =>
            {
                throw new Exception("the-exception-message");
            };

            (new AdminTool(CannedCommand("exception", command), new NullBlockerLocator(), outsideWorld, false)).execute(null, null, "exception");
            verify(outsideWorld).stdErrLine("unexpected error: the-exception-message");
            verify(outsideWorld).exit(STATUS_ERROR);
        }
예제 #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNotPrintTheStacktraceWhenTheCommandFailsIfTheDebugFlagIsNotSet()
        internal virtual void ShouldNotPrintTheStacktraceWhenTheCommandFailsIfTheDebugFlagIsNotSet()
        {
            OutsideWorld  outsideWorld = mock(typeof(OutsideWorld));
            CommandFailed exception    = new CommandFailed("");
            AdminCommand  command      = args =>
            {
                throw exception;
            };

            (new AdminTool(CannedCommand("exception", command), new NullBlockerLocator(), outsideWorld, false)).execute(null, null, "exception");
            verify(outsideWorld, never()).printStacktrace(exception);
        }
예제 #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void helpArgumentPrintsHelpForCommand()
        internal virtual void HelpArgumentPrintsHelpForCommand()
        {
            AdminCommand command      = mock(typeof(AdminCommand));
            OutsideWorld outsideWorld = mock(typeof(OutsideWorld));

            (new AdminTool(CannedCommand("command", command), new NullBlockerLocator(), outsideWorld, false)).execute(null, null, "command", "--help");

            verifyNoMoreInteractions(command);
            verify(outsideWorld).stdErrLine("unknown argument: --help");
            verify(outsideWorld).stdErrLine("usage: neo4j-admin command ");
            verify(outsideWorld).exit(STATUS_ERROR);
        }
예제 #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws java.io.IOException, org.neo4j.kernel.api.exceptions.InvalidArgumentsException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Setup()
        {
            OutsideWorld mock = mock(typeof(OutsideWorld));

            when(mock.FileSystem()).thenReturn(_fileSystem);
            _setDefaultAdmin = new SetDefaultAdminCommand(TestDir.directory("home").toPath(), TestDir.directory("conf").toPath(), mock);
            _config          = _setDefaultAdmin.loadNeo4jConfig();
            UserRepository users = CommunitySecurityModule.getUserRepository(_config, NullLogProvider.Instance, _fileSystem);

            users.create(new User.Builder("jake", LegacyCredential.forPassword("123"))
                         .withRequiredPasswordChange(false).build());
            _adminIniFile = new File(CommunitySecurityModule.getUserRepositoryFile(_config).ParentFile, "admin.ini");
        }
예제 #19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProvideFeedbackIfTheCommandReportsAUsageProblem()
        internal virtual void ShouldProvideFeedbackIfTheCommandReportsAUsageProblem()
        {
            OutsideWorld outsideWorld = mock(typeof(OutsideWorld));
            AdminCommand command      = args =>
            {
                throw new IncorrectUsage("the-usage-message");
            };

            (new AdminTool(CannedCommand("exception", command), new NullBlockerLocator(), outsideWorld, false)).execute(null, null, "exception");
            InOrder inOrder = inOrder(outsideWorld);

            inOrder.verify(outsideWorld).stdErrLine("the-usage-message");
            verify(outsideWorld).exit(STATUS_ERROR);
        }
예제 #20
0
        private static OnlineBackupCommand NewOnlineBackupCommand(OutsideWorld outsideWorld, OnlineBackupContext onlineBackupContext, BackupSupportingClassesFactory backupSupportingClassesFactory, BackupStrategyCoordinatorFactory backupStrategyCoordinatorFactory)
        {
            OnlineBackupContextFactory contextBuilder = mock(typeof(OnlineBackupContextFactory));

            try
            {
                when(contextBuilder.CreateContext(any())).thenReturn(onlineBackupContext);
            }
            catch (Exception e) when(e is IncorrectUsage || e is CommandFailed)
            {
                throw new Exception("Shouldn't happen", e);
            }

            return(new OnlineBackupCommand(outsideWorld, contextBuilder, backupSupportingClassesFactory, backupStrategyCoordinatorFactory));
        }
예제 #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void listShouldDisplayAllClassifiers() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ListShouldDisplayAllClassifiers()
        {
            using (MemoryStream baos = new MemoryStream())
            {
                PrintStream  ps           = new PrintStream(baos);
                string[]     args         = new string[] { "--list" };
                OutsideWorld outsideWorld = mock(typeof(OutsideWorld));
                when(outsideWorld.FileSystem()).thenReturn(_fs);
                when(outsideWorld.OutStream()).thenReturn(ps);

                DiagnosticsReportCommand diagnosticsReportCommand = new DiagnosticsReportCommand(_homeDir, _configDir, outsideWorld);
                diagnosticsReportCommand.Execute(args);

                assertThat(baos.ToString(), @is(string.Format("Finding running instance of neo4j%n" + "No running instance of neo4j was found. Online reports will be omitted.%n" + "If neo4j is running but not detected, you can supply the process id of the running instance with --pid%n" + "All available classifiers:%n" + "  config     include configuration file%n" + "  logs       include log files%n" + "  plugins    include a view of the plugin directory%n" + "  ps         include a list of running processes%n" + "  tree       include a view of the tree structure of the data directory%n" + "  tx         include transaction logs%n")));
            }
        }
예제 #22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReadUsernameAndPasswordFromUserInput() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReadUsernameAndPasswordFromUserInput()
        {
            // given
            Copier targetCommunicator = MockedTargetCommunicator();
            string username           = "******";

            char[]             password     = new char[] { 'a', 'b', 'c' };
            OutsideWorld       outsideWorld = (new ControlledOutsideWorld(new DefaultFileSystemAbstraction())).withPromptResponse(username).withPasswordResponse(password);
            PushToCloudCommand command      = command().copier(targetCommunicator).OutsideWorld(outsideWorld).build();

            // when
            command.Execute(array(Arg(ARG_DUMP, CreateSimpleDatabaseDump().ToString()), Arg(ARG_BOLT_URI, SOME_EXAMPLE_BOLT_URI)));

            // then
            verify(targetCommunicator).authenticate(anyBoolean(), any(), eq(username), eq(password), anyBoolean());
            verify(targetCommunicator).copy(anyBoolean(), any(), any(), any());
        }
예제 #23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBlockDumpIfABlockerSaysSo()
        internal virtual void ShouldBlockDumpIfABlockerSaysSo()
        {
            OutsideWorld outsideWorld = mock(typeof(OutsideWorld));
            AdminCommand command      = mock(typeof(AdminCommand));

            AdminCommand_Blocker blocker = mock(typeof(AdminCommand_Blocker));

            when(blocker.DoesBlock(any(), any())).thenReturn(true);
            when(blocker.Commands()).thenReturn(Collections.singleton("command"));
            when(blocker.Explanation()).thenReturn("the explanation");

            BlockerLocator blockerLocator = mock(typeof(BlockerLocator));

            when(blockerLocator.FindBlockers("command")).thenReturn(Collections.singletonList(blocker));

            (new AdminTool(CannedCommand("command", command), blockerLocator, outsideWorld, false)).execute(null, null, "command");

            verify(outsideWorld).stdErrLine("command failed: the explanation");
            verify(outsideWorld).exit(STATUS_ERROR);
        }
예제 #24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBlockDumpIfOneBlockerOutOfManySaysSo()
        internal virtual void ShouldBlockDumpIfOneBlockerOutOfManySaysSo()
        {
            OutsideWorld outsideWorld = mock(typeof(OutsideWorld));
            AdminCommand command      = mock(typeof(AdminCommand));

            AdminCommand_Blocker trueBlocker = mock(typeof(AdminCommand_Blocker));

            when(trueBlocker.DoesBlock(any(), any())).thenReturn(true);
            when(trueBlocker.Explanation()).thenReturn("trueBlocker explanation");

            AdminCommand_Blocker falseBlocker = mock(typeof(AdminCommand_Blocker));

            when(falseBlocker.DoesBlock(any(), any())).thenReturn(false);
            when(falseBlocker.Explanation()).thenReturn("falseBlocker explanation");

            BlockerLocator blockerLocator = mock(typeof(BlockerLocator));

            when(blockerLocator.FindBlockers("command")).thenReturn(Arrays.asList(falseBlocker, trueBlocker, falseBlocker));

            (new AdminTool(CannedCommand("command", command), blockerLocator, outsideWorld, false)).execute(null, null, "command");

            verify(outsideWorld).stdErrLine("command failed: trueBlocker explanation");
            verify(outsideWorld).exit(STATUS_ERROR);
        }
예제 #25
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: CsvImporter(org.neo4j.helpers.Args args, org.neo4j.kernel.configuration.Config databaseConfig, org.neo4j.commandline.admin.OutsideWorld outsideWorld) throws org.neo4j.commandline.admin.IncorrectUsage
        internal CsvImporter(Args args, Config databaseConfig, OutsideWorld outsideWorld)
        {
            this._args              = args;
            this._outsideWorld      = outsideWorld;
            _nodesFiles             = extractInputFiles(args, "nodes", outsideWorld.ErrorStream());
            _relationshipsFiles     = extractInputFiles(args, "relationships", outsideWorld.ErrorStream());
            _reportFileName         = args.InterpretOption("report-file", withDefault(ImportCommand.DEFAULT_REPORT_FILE_NAME), s => s);
            _ignoreExtraColumns     = args.GetBoolean("ignore-extra-columns", false).Value;
            _ignoreDuplicateNodes   = args.GetBoolean("ignore-duplicate-nodes", false).Value;
            _ignoreBadRelationships = args.GetBoolean("ignore-missing-nodes", false).Value;
            try
            {
                validateInputFiles(_nodesFiles, _relationshipsFiles);
            }
            catch (System.ArgumentException e)
            {
                throw new IncorrectUsage(e.Message);
            }

            _idType              = args.InterpretOption("id-type", withDefault(IdType.STRING), from => IdType.valueOf(from.ToUpper()));
            _inputEncoding       = Charset.forName(args.Get("input-encoding", defaultCharset().name()));
            _highIO              = args.GetBoolean("high-io", null, true);    // intentionally left as null if not specified
            this._databaseConfig = databaseConfig;
        }
예제 #26
0
 internal MemoryRecommendationsCommand(Path homeDir, Path configDir, OutsideWorld outsideWorld)
 {
     this._homeDir      = homeDir;
     this._outsideWorld = outsideWorld;
     this._configDir    = configDir;
 }
예제 #27
0
 internal SetDefaultAdminCommand(Path homeDir, Path configDir, OutsideWorld outsideWorld)
 {
     this._homeDir      = homeDir;
     this._configDir    = configDir;
     this._outsideWorld = outsideWorld;
 }
예제 #28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Override @Nonnull public AdminCommand create(java.nio.file.Path homeDir, java.nio.file.Path configDir, OutsideWorld outsideWorld)
        public override AdminCommand Create(Path homeDir, Path configDir, OutsideWorld outsideWorld)
        {
            return(new HelpCommand(_usage, outsideWorld.stdOutLine, CommandLocator.fromServiceLocator()));
        }
예제 #29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Override @Nonnull public org.neo4j.commandline.admin.AdminCommand create(java.nio.file.Path homeDir, java.nio.file.Path configDir, org.neo4j.commandline.admin.OutsideWorld outsideWorld)
        public override AdminCommand Create(Path homeDir, Path configDir, OutsideWorld outsideWorld)
        {
            return(new SetInitialPasswordCommand(homeDir, configDir, outsideWorld));
        }
예제 #30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Override @Nonnull public org.neo4j.commandline.admin.AdminCommand create(java.nio.file.Path homeDir, java.nio.file.Path configDir, org.neo4j.commandline.admin.OutsideWorld outsideWorld)
        public override AdminCommand Create(Path homeDir, Path configDir, OutsideWorld outsideWorld)
        {
            return(new SetDefaultAdminCommand(homeDir, configDir, outsideWorld));
        }