public static void main( String[] args ) throws IOException { Path homeDir = Paths.get( NEO4J_HOME ); Path configDir = Paths.get( NEO4J_CONF ); boolean debug = NEO4J_DEBUG != null; try ( RealOutsideWorld outsideWorld = new RealOutsideWorld() ) { new AdminTool( CommandLocator.fromServiceLocator(), BlockerLocator.fromServiceLocator(), outsideWorld, debug ).execute( homeDir, configDir, args ); } }
@Test void shouldBlockDumpIfABlockerSaysSo() { OutsideWorld outsideWorld = mock( OutsideWorld.class ); AdminCommand command = mock( AdminCommand.class ); AdminCommand.Blocker blocker = mock( AdminCommand.Blocker.class ); when( blocker.doesBlock( any(), any() ) ).thenReturn( true ); when( blocker.commands() ).thenReturn( Collections.singleton( "command" ) ); when( blocker.explanation() ).thenReturn( "the explanation" ); BlockerLocator blockerLocator = mock( BlockerLocator.class ); 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 ); }
@Test void shouldNotBlockIfNoneOfTheBlockersBlock() throws CommandFailed, IncorrectUsage { AdminCommand command = mock( AdminCommand.class ); AdminCommand.Blocker falseBlocker = mock( AdminCommand.Blocker.class ); when( falseBlocker.doesBlock( any(), any() ) ).thenReturn( false ); when( falseBlocker.explanation() ).thenReturn( "falseBlocker explanation" ); BlockerLocator blockerLocator = mock( BlockerLocator.class ); when( blockerLocator.findBlockers( "command" ) ) .thenReturn( Arrays.asList( falseBlocker, falseBlocker, falseBlocker ) ); new AdminTool( cannedCommand( "command", command ), blockerLocator, new NullOutsideWorld(), false ) .execute( null, null, "command", "the", "other", "args" ); verify( command ).execute( new String[]{"the", "other", "args"} ); }
@Test void shouldBlockDumpIfOneBlockerOutOfManySaysSo() { OutsideWorld outsideWorld = mock( OutsideWorld.class ); AdminCommand command = mock( AdminCommand.class ); AdminCommand.Blocker trueBlocker = mock( AdminCommand.Blocker.class ); when( trueBlocker.doesBlock( any(), any() ) ).thenReturn( true ); when( trueBlocker.explanation() ).thenReturn( "trueBlocker explanation" ); AdminCommand.Blocker falseBlocker = mock( AdminCommand.Blocker.class ); when( falseBlocker.doesBlock( any(), any() ) ).thenReturn( false ); when( falseBlocker.explanation() ).thenReturn( "falseBlocker explanation" ); BlockerLocator blockerLocator = mock( BlockerLocator.class ); 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 ); }
@Before public void setup() { File graphDir = new File( GraphDatabaseSettings.DEFAULT_DATABASE_NAME ); confDir = new File( graphDir, "conf" ); homeDir = new File( graphDir, "home" ); out = mock( OutsideWorld.class ); resetOutsideWorldMock(); tool = new AdminTool( CommandLocator.fromServiceLocator(), BlockerLocator.fromServiceLocator(), out, true ); }
for ( AdminCommand.Blocker blocker : blockerLocator.findBlockers( name ) )
@Before public void setup() { File graphDir = new File( GraphDatabaseSettings.DEFAULT_DATABASE_NAME ); confDir = new File( graphDir, "conf" ); homeDir = new File( graphDir, "home" ); out = mock( OutsideWorld.class ); resetOutsideWorldMock(); tool = new AdminTool( CommandLocator.fromServiceLocator(), BlockerLocator.fromServiceLocator(), out, true ); }