diff --git a/community/consistency-check-legacy/src/main/java/org/neo4j/legacy/consistency/ConsistencyCheckTool.java b/community/consistency-check-legacy/src/main/java/org/neo4j/legacy/consistency/ConsistencyCheckTool.java index e752a6377f202..ff40328697556 100644 --- a/community/consistency-check-legacy/src/main/java/org/neo4j/legacy/consistency/ConsistencyCheckTool.java +++ b/community/consistency-check-legacy/src/main/java/org/neo4j/legacy/consistency/ConsistencyCheckTool.java @@ -52,24 +52,10 @@ public class ConsistencyCheckTool private static final String CONFIG = "config"; private static final String PROP_OWNER = "propowner"; - public interface ExitHandle - { - ExitHandle SYSTEM_EXIT = new ExitHandle() - { - @Override - public void pull() - { - System.exit( 1 ); - } - }; - - void pull(); - } - public static void main( String[] args ) throws IOException { ConsistencyCheckTool tool = new ConsistencyCheckTool( new ConsistencyCheckService(), new GraphDatabaseFactory(), - new DefaultFileSystemAbstraction(), System.err, ExitHandle.SYSTEM_EXIT ); + new DefaultFileSystemAbstraction(), System.err ); try { tool.run( args ); @@ -83,17 +69,15 @@ public static void main( String[] args ) throws IOException private final ConsistencyCheckService consistencyCheckService; private final GraphDatabaseFactory dbFactory; private final PrintStream systemError; - private final ExitHandle exitHandle; private final FileSystemAbstraction fs; public ConsistencyCheckTool( ConsistencyCheckService consistencyCheckService, - GraphDatabaseFactory dbFactory, FileSystemAbstraction fs, PrintStream systemError, ExitHandle exitHandle ) + GraphDatabaseFactory dbFactory, FileSystemAbstraction fs, PrintStream systemError ) { this.consistencyCheckService = consistencyCheckService; this.dbFactory = dbFactory; this.fs = fs; this.systemError = systemError; - this.exitHandle = exitHandle; } public void run( String... args ) throws ToolFailureException, IOException @@ -134,7 +118,7 @@ private void attemptRecoveryOrCheckStateOfLogicalLogs( Args arguments, File stor "Consistency checking will continue, abort if you wish to perform recovery first.", "To perform recovery before checking consistency, use the '--recovery' flag." ) ); - exitHandle.pull(); + exit(); } } catch ( IOException e ) @@ -211,7 +195,12 @@ void exitTool() getCause().printStackTrace( System.err ); } - exitHandle.pull(); + exit(); } } + + private static void exit() + { + System.exit( 1 ); + } } diff --git a/community/consistency-check-legacy/src/test/java/org/neo4j/legacy/consistency/ConsistencyCheckToolTest.java b/community/consistency-check-legacy/src/test/java/org/neo4j/legacy/consistency/ConsistencyCheckToolTest.java index dd0a7d4eaead9..cd23b123530a4 100644 --- a/community/consistency-check-legacy/src/test/java/org/neo4j/legacy/consistency/ConsistencyCheckToolTest.java +++ b/community/consistency-check-legacy/src/test/java/org/neo4j/legacy/consistency/ConsistencyCheckToolTest.java @@ -44,6 +44,7 @@ import org.neo4j.legacy.consistency.checking.full.TaskExecutionOrder; import org.neo4j.logging.LogProvider; import org.neo4j.test.EphemeralFileSystemRule; +import org.neo4j.test.SystemExitRule; import org.neo4j.test.TargetDirectory; import org.neo4j.test.TestGraphDatabaseFactory; @@ -65,6 +66,10 @@ public class ConsistencyCheckToolTest { + + @Rule + public SystemExitRule systemExitRule = SystemExitRule.none(); + @Test public void runsConsistencyCheck() throws Exception { @@ -185,7 +190,7 @@ public void shouldExecuteRecoveryWhenStoreWasNonCleanlyShutdown() throws Excepti monitors.addMonitorListener( listener ); ConsistencyCheckTool consistencyCheckTool = - newConsistencyCheckToolWith( monitors, mock( ConsistencyCheckTool.ExitHandle.class ), fs.get() ); + newConsistencyCheckToolWith( monitors, fs.get() ); // When consistencyCheckTool.run( "-recovery", storeDirectory.graphDbDir().getAbsolutePath() ); @@ -199,6 +204,7 @@ public void shouldExecuteRecoveryWhenStoreWasNonCleanlyShutdown() throws Excepti public void shouldExitWhenRecoveryNeededButRecoveryFalseOptionSpecified() throws Exception { // Given + systemExitRule.expectExit( 1 ); File storeDir = storeDirectory.graphDbDir(); EphemeralFileSystemAbstraction fileSystem = createDataBaseWithStateThatNeedsRecovery( storeDir ); @@ -206,15 +212,13 @@ public void shouldExitWhenRecoveryNeededButRecoveryFalseOptionSpecified() throws PhysicalLogFile.Monitor listener = mock( PhysicalLogFile.Monitor.class ); monitors.addMonitorListener( listener ); - ConsistencyCheckTool.ExitHandle exitHandle = mock( ConsistencyCheckTool.ExitHandle.class ); - ConsistencyCheckTool consistencyCheckTool = newConsistencyCheckToolWith( monitors, exitHandle, fileSystem ); + ConsistencyCheckTool consistencyCheckTool = newConsistencyCheckToolWith( monitors, fileSystem ); // When consistencyCheckTool.run( "-recovery=false", storeDir.getAbsolutePath() ); // Then verifyZeroInteractions( listener ); - verify( exitHandle ).pull(); } private EphemeralFileSystemAbstraction createDataBaseWithStateThatNeedsRecovery( File storeDir ) @@ -252,7 +256,7 @@ private void createGraphDbAndKillIt() } private ConsistencyCheckTool newConsistencyCheckToolWith( Monitors monitors, - ConsistencyCheckTool.ExitHandle exitHandle, FileSystemAbstraction fileSystem ) throws IOException + FileSystemAbstraction fileSystem ) throws IOException { GraphDatabaseFactory graphDbFactory = new TestGraphDatabaseFactory() { @@ -264,14 +268,14 @@ public GraphDatabaseService newEmbeddedDatabase( File storeDir ) }.setFileSystem( fileSystem ).setMonitors( monitors ); return new ConsistencyCheckTool( mock( ConsistencyCheckService.class ), - graphDbFactory, fileSystem, mock( PrintStream.class ), exitHandle ); + graphDbFactory, fileSystem, mock( PrintStream.class ) ); } private ConsistencyCheckTool newConsistencyCheckToolWith ( ConsistencyCheckService consistencyCheckService, PrintStream systemError ) { return new ConsistencyCheckTool( consistencyCheckService, new GraphDatabaseFactory(), - new DefaultFileSystemAbstraction(), systemError, ConsistencyCheckTool.ExitHandle.SYSTEM_EXIT ); + new DefaultFileSystemAbstraction(), systemError ); } @Rule diff --git a/community/consistency-check/src/main/java/org/neo4j/consistency/ConsistencyCheckTool.java b/community/consistency-check/src/main/java/org/neo4j/consistency/ConsistencyCheckTool.java index d6cc5b5560da4..3ad81cd5d15f6 100644 --- a/community/consistency-check/src/main/java/org/neo4j/consistency/ConsistencyCheckTool.java +++ b/community/consistency-check/src/main/java/org/neo4j/consistency/ConsistencyCheckTool.java @@ -39,12 +39,10 @@ import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.impl.pagecache.StandalonePageCacheFactory; import org.neo4j.kernel.impl.recovery.RecoveryRequiredChecker; -import org.neo4j.legacy.consistency.ConsistencyCheckTool.ExitHandle; import org.neo4j.logging.FormattedLogProvider; import org.neo4j.logging.LogProvider; import static java.lang.System.currentTimeMillis; - import static org.neo4j.helpers.Args.jarUsage; import static org.neo4j.helpers.Strings.joinAsLines; import static org.neo4j.helpers.collection.MapUtil.stringMap; @@ -66,7 +64,7 @@ public class ConsistencyCheckTool public static void main( String[] args ) throws IOException { ConsistencyCheckTool tool = new ConsistencyCheckTool( new ConsistencyCheckService(), new GraphDatabaseFactory(), - new DefaultFileSystemAbstraction(), System.err, ExitHandle.SYSTEM_EXIT ); + new DefaultFileSystemAbstraction(), System.err ); try { tool.run( args ); @@ -80,17 +78,15 @@ public static void main( String[] args ) throws IOException private final ConsistencyCheckService consistencyCheckService; private final GraphDatabaseFactory dbFactory; private final PrintStream systemError; - private final ExitHandle exitHandle; private final FileSystemAbstraction fs; ConsistencyCheckTool( ConsistencyCheckService consistencyCheckService, - GraphDatabaseFactory dbFactory, FileSystemAbstraction fs, PrintStream systemError, ExitHandle exitHandle ) + GraphDatabaseFactory dbFactory, FileSystemAbstraction fs, PrintStream systemError ) { this.consistencyCheckService = consistencyCheckService; this.dbFactory = dbFactory; this.fs = fs; this.systemError = systemError; - this.exitHandle = exitHandle; } void run( String... args ) throws ToolFailureException, IOException @@ -131,10 +127,7 @@ private void runLegacyConsistencyChecker( String[] args ) throws ToolFailureExce { org.neo4j.legacy.consistency.ConsistencyCheckTool legacyTool = new org.neo4j.legacy.consistency.ConsistencyCheckTool( new org.neo4j.legacy.consistency.ConsistencyCheckService(), - dbFactory, - fs, - systemError, - exitHandle ); + dbFactory, fs, systemError); legacyTool.run( args ); } catch ( org.neo4j.legacy.consistency.ConsistencyCheckTool.ToolFailureException e ) @@ -182,7 +175,7 @@ private void attemptRecoveryOrCheckStateOfLogicalLogs( Args arguments, File stor "Consistency checking will continue, abort if you wish to perform recovery first.", "To perform recovery before checking consistency, use the '--recovery' flag." ) ); - exitHandle.pull(); + exit(); } } catch ( IOException e ) @@ -264,7 +257,12 @@ void exitTool() getCause().printStackTrace( System.err ); } - exitHandle.pull(); + exit(); } } + + private static void exit() + { + System.exit( 1 ); + } } diff --git a/community/consistency-check/src/test/java/org/neo4j/consistency/ConsistencyCheckToolTest.java b/community/consistency-check/src/test/java/org/neo4j/consistency/ConsistencyCheckToolTest.java index 3d95eba151298..b12fdec94fedd 100644 --- a/community/consistency-check/src/test/java/org/neo4j/consistency/ConsistencyCheckToolTest.java +++ b/community/consistency-check/src/test/java/org/neo4j/consistency/ConsistencyCheckToolTest.java @@ -47,9 +47,9 @@ import org.neo4j.kernel.impl.transaction.log.PhysicalLogFile; import org.neo4j.kernel.monitoring.Monitors; import org.neo4j.kernel.recovery.Recovery; -import org.neo4j.legacy.consistency.ConsistencyCheckTool.ExitHandle; import org.neo4j.logging.LogProvider; import org.neo4j.test.EphemeralFileSystemRule; +import org.neo4j.test.SystemExitRule; import org.neo4j.test.TargetDirectory; import org.neo4j.test.TestGraphDatabaseFactory; @@ -66,7 +66,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; - import static org.neo4j.consistency.ConsistencyCheckTool.EXPERIMENTAL; import static org.neo4j.graphdb.DynamicLabel.label; import static org.neo4j.helpers.ArrayUtil.concat; @@ -77,6 +76,9 @@ public class ConsistencyCheckToolTest { private final boolean experimental; + @Rule + public SystemExitRule systemExitRule = SystemExitRule.none(); + @Parameters( name = "Experimental:{0}" ) public static Collection data() { @@ -217,7 +219,7 @@ public void shouldExecuteRecoveryWhenStoreWasNonCleanlyShutdown() throws Excepti monitors.addMonitorListener( listener ); // When - runConsistencyCheckToolWith( monitors, mock( ExitHandle.class ), fs.get(), + runConsistencyCheckToolWith( monitors, fs.get(), "-recovery", storeDirectory.graphDbDir().getAbsolutePath() ); // Then @@ -229,6 +231,7 @@ public void shouldExecuteRecoveryWhenStoreWasNonCleanlyShutdown() throws Excepti public void shouldExitWhenRecoveryNeededButRecoveryFalseOptionSpecified() throws Exception { // Given + systemExitRule.expectExit( 1 ); File storeDir = storeDirectory.graphDbDir(); EphemeralFileSystemAbstraction fileSystem = createDataBaseWithStateThatNeedsRecovery( storeDir ); @@ -236,15 +239,11 @@ public void shouldExitWhenRecoveryNeededButRecoveryFalseOptionSpecified() throws PhysicalLogFile.Monitor listener = mock( PhysicalLogFile.Monitor.class ); monitors.addMonitorListener( listener ); - ExitHandle exitHandle = mock( ExitHandle.class ); - // When - runConsistencyCheckToolWith( monitors, exitHandle, fileSystem, - "-recovery=false", storeDir.getAbsolutePath() ); + runConsistencyCheckToolWith( monitors, fileSystem, "-recovery=false", storeDir.getAbsolutePath() ); // Then verifyZeroInteractions( listener ); - verify( exitHandle ).pull(); } private EphemeralFileSystemAbstraction createDataBaseWithStateThatNeedsRecovery( File storeDir ) @@ -281,8 +280,7 @@ private void createGraphDbAndKillIt() fs.snapshot( shutdownDbAction( db ) ); } - private void runConsistencyCheckToolWith( Monitors monitors, - ExitHandle exitHandle, FileSystemAbstraction fileSystem, String... args ) + private void runConsistencyCheckToolWith( Monitors monitors, FileSystemAbstraction fileSystem, String... args ) throws IOException, ToolFailureException { GraphDatabaseFactory graphDbFactory = new TestGraphDatabaseFactory() @@ -295,7 +293,7 @@ public GraphDatabaseService newEmbeddedDatabase( File storeDir ) }.setFileSystem( fileSystem ).setMonitors( monitors ); new ConsistencyCheckTool( mock( ConsistencyCheckService.class ), - graphDbFactory, fileSystem, mock( PrintStream.class ), exitHandle ).run( augment( args ) ); + graphDbFactory, fileSystem, mock( PrintStream.class ) ).run( augment( args ) ); } private String[] augment( String[] args ) @@ -307,7 +305,7 @@ private void runConsistencyCheckToolWith ( ConsistencyCheckService consistencyCheckService, PrintStream systemError, String... args ) throws ToolFailureException, IOException { new ConsistencyCheckTool( consistencyCheckService, new GraphDatabaseFactory(), - new DefaultFileSystemAbstraction(), systemError, ExitHandle.SYSTEM_EXIT ) + new DefaultFileSystemAbstraction(), systemError ) .run( augment( args ) ); } diff --git a/community/kernel/pom.xml b/community/kernel/pom.xml index 65edd9e574546..0c43e1b57cc3a 100644 --- a/community/kernel/pom.xml +++ b/community/kernel/pom.xml @@ -336,11 +336,6 @@ the relevant Commercial Agreement. test - - org.powermock - powermock-api-mockito - test - geronimo-spec diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/IntegrityValidatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/IntegrityValidatorTest.java index 03d89b0de4c51..13019a1160194 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/IntegrityValidatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/IntegrityValidatorTest.java @@ -30,9 +30,10 @@ import static org.junit.Assert.fail; import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.neo4j.kernel.impl.store.record.UniquePropertyConstraintRule.uniquenessConstraintRule; -import static org.powermock.api.mockito.PowerMockito.mock; + public class IntegrityValidatorTest { diff --git a/community/kernel/src/test/java/org/neo4j/test/SystemExitError.java b/community/kernel/src/test/java/org/neo4j/test/SystemExitError.java new file mode 100644 index 0000000000000..40a4069387dbe --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/test/SystemExitError.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2002-2015 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.test; + +/** + * Error that used by {@link TestSecurityManager} as notification to {@link SystemExitRule} + * that System.exit call has happened. + * + * Should not be used anywhere except tests. + */ +class SystemExitError extends Error +{ + private int statusCode; + + public SystemExitError( int statusCode ) + { + this.statusCode = statusCode; + } + + public int getStatusCode() + { + return statusCode; + } +} diff --git a/community/kernel/src/test/java/org/neo4j/test/SystemExitRule.java b/community/kernel/src/test/java/org/neo4j/test/SystemExitRule.java new file mode 100644 index 0000000000000..4d44c860645aa --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/test/SystemExitRule.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2002-2015 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.test; + +import org.junit.rules.ExternalResource; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class SystemExitRule extends ExternalResource +{ + private Integer expectedExitStatusCode; + private SecurityManager originalSecurityManager = null; + + public static SystemExitRule none() { + return new SystemExitRule(); + } + + private SystemExitRule() + { + } + + public void expectExit(int statusCode) { + this.expectedExitStatusCode = statusCode; + } + + @Override + protected void before() throws Throwable + { + originalSecurityManager = System.getSecurityManager(); + TestSecurityManager testSecurityManager = new TestSecurityManager( originalSecurityManager ); + System.setSecurityManager( testSecurityManager ); + } + + @Override + public Statement apply( Statement base, Description description ) + { + final Statement externalRuleStatement = super.apply( base, description ); + return new Statement() + { + @Override + public void evaluate() throws Throwable + { + try + { + externalRuleStatement.evaluate(); + if ( exitWasExpected() ) + { + fail( "System exit call was expected, but not invoked." ); + } + } + catch ( SystemExitError e ) + { + int exceptionStatusCode = e.getStatusCode(); + if ( exitWasExpected() ) + { + int expectedCode = expectedExitStatusCode; + assertEquals( String.format( "Expected system exit code:%d but was: %d.", + expectedCode, exceptionStatusCode ), expectedCode, exceptionStatusCode ); + } + else + { + fail( "System exit call was not expected, but was invoked. Exit status code: " + + exceptionStatusCode ); + } + + } + } + }; + } + + @Override + protected void after() + { + System.setSecurityManager( originalSecurityManager ); + } + + private boolean exitWasExpected() + { + return expectedExitStatusCode != null; + } +} diff --git a/community/kernel/src/test/java/org/neo4j/test/TestSecurityManager.java b/community/kernel/src/test/java/org/neo4j/test/TestSecurityManager.java new file mode 100644 index 0000000000000..4fed382ae18a1 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/test/TestSecurityManager.java @@ -0,0 +1,446 @@ +/* + * Copyright (c) 2002-2015 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.test; + +import java.io.FileDescriptor; +import java.net.InetAddress; +import java.security.Permission; + +public class TestSecurityManager extends SecurityManager +{ + + private SecurityManager securityManager; + + public TestSecurityManager( SecurityManager securityManager ) + { + this.securityManager = securityManager; + } + + @Override + public void checkExit( int status ) + { + throw new SystemExitError( status ); + } + + @Override + public boolean getInCheck() + { + return managerExists() ? securityManager.getInCheck() : super.getInCheck(); + } + + @Override + public Object getSecurityContext() + { + return managerExists() ? securityManager.getSecurityContext() : super.getSecurityContext(); + } + + @Override + public void checkPermission( Permission perm ) + { + // if original security manager exists delegate permission check to it + // otherwise silently allow everything + if ( managerExists() ) + { + securityManager.checkPermission( perm ); + } + } + + @Override + public void checkPermission( Permission perm, Object context ) + { + if ( managerExists() ) + { + securityManager.checkPermission( perm, context ); + } + else + { + super.checkPermission( perm, context ); + } + } + + @Override + public void checkCreateClassLoader() + { + if ( managerExists() ) + { + securityManager.checkCreateClassLoader(); + } + else + { + super.checkCreateClassLoader(); + } + } + + @Override + public void checkAccess( Thread t ) + { + if ( managerExists() ) + { + securityManager.checkAccess( t ); + } + else + { + super.checkAccess( t ); + } + } + + @Override + public void checkAccess( ThreadGroup g ) + { + if ( managerExists() ) + { + securityManager.checkAccess( g ); + } + else + { + super.checkAccess( g ); + } + } + + @Override + public void checkExec( String cmd ) + { + if ( managerExists() ) + { + securityManager.checkExec( cmd ); + } + else + { + super.checkExec( cmd ); + } + } + + @Override + public void checkLink( String lib ) + { + if ( managerExists() ) + { + securityManager.checkLink( lib ); + } + else + { + super.checkLink( lib ); + } + } + + @Override + public void checkRead( FileDescriptor fd ) + { + if ( managerExists() ) + { + securityManager.checkRead( fd ); + } + else + { + super.checkRead( fd ); + } + } + + @Override + public void checkRead( String file ) + { + if ( managerExists() ) + { + securityManager.checkRead( file ); + } + else + { + super.checkRead( file ); + } + } + + @Override + public void checkRead( String file, Object context ) + { + if ( managerExists() ) + { + securityManager.checkRead( file, context ); + } + else + { + super.checkRead( file, context ); + } + } + + @Override + public void checkWrite( FileDescriptor fd ) + { + if ( managerExists() ) + { + securityManager.checkWrite( fd ); + } + else + { + super.checkWrite( fd ); + } + } + + @Override + public void checkWrite( String file ) + { + if ( managerExists() ) + { + securityManager.checkWrite( file ); + } + else + { + super.checkWrite( file ); + } + } + + @Override + public void checkDelete( String file ) + { + if ( managerExists() ) + { + securityManager.checkDelete( file ); + } + else + { + super.checkDelete( file ); + } + } + + @Override + public void checkConnect( String host, int port ) + { + if ( managerExists() ) + { + securityManager.checkConnect( host, port ); + } + else + { + super.checkConnect( host, port ); + } + } + + @Override + public void checkConnect( String host, int port, Object context ) + { + if ( managerExists() ) + { + securityManager.checkConnect( host, port, context ); + } + else + { + super.checkConnect( host, port, context ); + } + } + + @Override + public void checkListen( int port ) + { + if ( managerExists() ) + { + securityManager.checkListen( port ); + } + else + { + super.checkListen( port ); + } + } + + @Override + public void checkAccept( String host, int port ) + { + if ( managerExists() ) + { + securityManager.checkAccept( host, port ); + } + else + { + super.checkAccept( host, port ); + } + } + + @Override + public void checkMulticast( InetAddress maddr ) + { + if ( managerExists() ) + { + securityManager.checkMulticast( maddr ); + } + else + { + super.checkMulticast( maddr ); + } + } + + @Override + public void checkMulticast( InetAddress maddr, byte ttl ) + { + if ( managerExists() ) + { + securityManager.checkMulticast( maddr, ttl ); + } + else + { + super.checkMulticast( maddr, ttl ); + } + } + + @Override + public void checkPropertiesAccess() + { + if ( managerExists() ) + { + securityManager.checkPropertiesAccess(); + } + else + { + super.checkPropertiesAccess(); + } + } + + @Override + public void checkPropertyAccess( String key ) + { + if ( managerExists() ) + { + securityManager.checkPropertyAccess( key ); + } + else + { + super.checkPropertyAccess( key ); + } + } + + @Override + public boolean checkTopLevelWindow( Object window ) + { + return managerExists() ? securityManager.checkTopLevelWindow( window ) : super.checkTopLevelWindow( window ); + } + + @Override + public void checkPrintJobAccess() + { + if ( managerExists() ) + { + securityManager.checkPrintJobAccess(); + } + else + { + super.checkPrintJobAccess(); + } + } + + @Override + public void checkSystemClipboardAccess() + { + if ( managerExists() ) + { + securityManager.checkSystemClipboardAccess(); + } + else + { + super.checkSystemClipboardAccess(); + } + } + + @Override + public void checkAwtEventQueueAccess() + { + if ( managerExists() ) + { + securityManager.checkAwtEventQueueAccess(); + } + else + { + super.checkAwtEventQueueAccess(); + } + } + + @Override + public void checkPackageAccess( String pkg ) + { + if ( managerExists() ) + { + securityManager.checkPackageAccess( pkg ); + } + else + { + super.checkPackageAccess( pkg ); + } + } + + @Override + public void checkPackageDefinition( String pkg ) + { + if ( managerExists() ) + { + securityManager.checkPackageDefinition( pkg ); + } + else + { + super.checkPackageDefinition( pkg ); + } + } + + @Override + public void checkSetFactory() + { + if ( managerExists() ) + { + securityManager.checkSetFactory(); + } + else + { + super.checkSetFactory(); + } + } + + @Override + public void checkMemberAccess( Class clazz, int which ) + { + if ( managerExists() ) + { + securityManager.checkMemberAccess( clazz, which ); + } + else + { + super.checkMemberAccess( clazz, which ); + } + } + + @Override + public void checkSecurityAccess( String target ) + { + if ( managerExists() ) + { + securityManager.checkSecurityAccess( target ); + } + else + { + super.checkSecurityAccess( target ); + } + } + + @Override + public ThreadGroup getThreadGroup() + { + return managerExists() ? securityManager.getThreadGroup() : super.getThreadGroup(); + } + + private boolean managerExists() + { + return securityManager != null; + } + +} diff --git a/community/lucene-index/src/test/java/org/neo4j/index/IndexConstraintsTest.java b/community/lucene-index/src/test/java/org/neo4j/index/IndexConstraintsTest.java index 61aa1bace8768..49d838521aa3f 100644 --- a/community/lucene-index/src/test/java/org/neo4j/index/IndexConstraintsTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/index/IndexConstraintsTest.java @@ -19,6 +19,10 @@ */ package org.neo4j.index; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import java.io.IOException; import java.util.UUID; import java.util.concurrent.Callable; @@ -26,10 +30,6 @@ import java.util.concurrent.ExecutorCompletionService; import java.util.concurrent.Executors; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - import org.neo4j.graphdb.DynamicLabel; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Label; @@ -43,7 +43,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; - import static org.neo4j.helpers.collection.Iterables.first; import static org.neo4j.helpers.collection.Iterables.single; diff --git a/community/server/pom.xml b/community/server/pom.xml index 9fd70acf16764..d96cdd2ff0da1 100644 --- a/community/server/pom.xml +++ b/community/server/pom.xml @@ -347,16 +347,7 @@ test - - org.powermock - powermock-module-junit4 - test - - - org.powermock - powermock-api-mockito - test - + com.google.jimfs jimfs diff --git a/community/server/src/test/java/org/neo4j/server/rest/transactional/Neo4jJsonCodecTest.java b/community/server/src/test/java/org/neo4j/server/rest/transactional/Neo4jJsonCodecTest.java index f7382784047f4..45834f9a04cfe 100644 --- a/community/server/src/test/java/org/neo4j/server/rest/transactional/Neo4jJsonCodecTest.java +++ b/community/server/src/test/java/org/neo4j/server/rest/transactional/Neo4jJsonCodecTest.java @@ -19,31 +19,26 @@ */ package org.neo4j.server.rest.transactional; +import org.codehaus.jackson.JsonGenerator; +import org.junit.Before; +import org.junit.Test; + import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import org.codehaus.jackson.JsonGenerator; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - import org.neo4j.graphdb.Path; import org.neo4j.graphdb.PropertyContainer; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.doThrow; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; +import static org.mockito.Mockito.when; -@RunWith(PowerMockRunner.class) -@PrepareForTest(JsonGenerator.class) public class Neo4jJsonCodecTest { diff --git a/enterprise/backup/pom.xml b/enterprise/backup/pom.xml index 12bca17938003..172c403915589 100644 --- a/enterprise/backup/pom.xml +++ b/enterprise/backup/pom.xml @@ -109,16 +109,6 @@ test-jar test - - org.powermock - powermock-module-junit4 - test - - - org.powermock - powermock-api-mockito - test - diff --git a/enterprise/backup/src/test/java/org/neo4j/backup/BackupToolTest.java b/enterprise/backup/src/test/java/org/neo4j/backup/BackupToolTest.java index d8d3b0fe52a94..7192df3b30c8b 100644 --- a/enterprise/backup/src/test/java/org/neo4j/backup/BackupToolTest.java +++ b/enterprise/backup/src/test/java/org/neo4j/backup/BackupToolTest.java @@ -32,6 +32,8 @@ import org.neo4j.consistency.ConsistencyCheckSettings; import org.neo4j.helpers.HostnamePort; import org.neo4j.kernel.configuration.Config; +import org.neo4j.test.SuppressOutput; +import org.neo4j.test.SystemExitRule; import org.neo4j.test.TargetDirectory; import static org.hamcrest.CoreMatchers.containsString; @@ -56,6 +58,26 @@ public class BackupToolTest { + + @Rule + public SuppressOutput suppressOutput = SuppressOutput.suppressAll(); + @Rule + public SystemExitRule systemExitRule = SystemExitRule.none(); + + @Test + public void shouldToolFailureExceptionCauseExitCode() + { + systemExitRule.expectExit( 1 ); + BackupTool.exitFailure( "tool failed" ); + } + + @Test + public void shouldBackupToolMainCauseExitCode() + { + systemExitRule.expectExit( 1 ); + BackupTool.main( new String[]{} ); + } + @Test public void shouldUseIncrementalOrFallbackToFull() throws Exception { diff --git a/enterprise/backup/src/test/java/org/neo4j/backup/ExitCodeTest.java b/enterprise/backup/src/test/java/org/neo4j/backup/ExitCodeTest.java deleted file mode 100644 index 925b5f2b7059d..0000000000000 --- a/enterprise/backup/src/test/java/org/neo4j/backup/ExitCodeTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2002-2015 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.neo4j.backup; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - - -@RunWith(PowerMockRunner.class) -@PrepareForTest(BackupTool.class) -public class ExitCodeTest { - - @Test - public void shouldToolFailureExceptionCauseExitCode() { - - // setup - PowerMockito.mockStatic(System.class); - - // when - BackupTool.exitFailure( "tool failed" ); - - // then - PowerMockito.verifyStatic(); - System.exit(1); - } - - @Test - public void shouldBackupToolMainCauseExitCode() { - - // setup - PowerMockito.mockStatic(System.class); - - // when - BackupTool.main(new String[] {}); - - // then - PowerMockito.verifyStatic(); - System.exit(1); - } - -} diff --git a/pom.xml b/pom.xml index 763a603377e03..6c01f28d59b79 100644 --- a/pom.xml +++ b/pom.xml @@ -495,32 +495,6 @@ test - - org.powermock - powermock-module-junit4 - ${powermock.version} - test - - - org.powermock - powermock-api-mockito - ${powermock.version} - test - - - org.mockito - mockito-all - - - - geronimo-spec geronimo-spec-j2ee