-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect requests to keep failed test directory in TestDirectoryExtens…
…ion(s) Also, verify test extension lifecycle by starting custom junit runs that validate that extension did the right thing on test failure/success.
- Loading branch information
1 parent
eacdd90
commit de47415
Showing
7 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ty/io/src/test/java/org/neo4j/test/extension/DirectoryExtensionLifecycleVerification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.test.extension; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.io.File; | ||
|
||
import org.neo4j.test.rule.TestDirectory; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.neo4j.test.extension.ExecutionSharedContext.FAILED_TEST_FILE_KEY; | ||
import static org.neo4j.test.extension.ExecutionSharedContext.INSTANCE; | ||
import static org.neo4j.test.extension.ExecutionSharedContext.SUCCESSFUL_TEST_FILE_KEY; | ||
|
||
/** | ||
* This test class name should not match default test name pattern since it should not be executed by default test launcher | ||
* Its executed by custom test junit launcher to test extensions lifecycle | ||
*/ | ||
@ExtendWith( {DefaultFileSystemExtension.class, TestDirectoryExtension.class} ) | ||
class DirectoryExtensionLifecycleVerification | ||
{ | ||
@Inject | ||
TestDirectory directory; | ||
|
||
@Test | ||
void executeAndCleanupDirectory() | ||
{ | ||
File file = directory.createFile( "a" ); | ||
assertTrue( file.exists() ); | ||
INSTANCE.setValue( SUCCESSFUL_TEST_FILE_KEY, file ); | ||
} | ||
|
||
@Test | ||
void failAndKeepDirectory() | ||
{ | ||
File file = directory.createFile( "b" ); | ||
INSTANCE.setValue( FAILED_TEST_FILE_KEY, file ); | ||
throw new RuntimeException( "simulate test failure" ); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
community/io/src/test/java/org/neo4j/test/extension/ExecutionSharedContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.test.extension; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class ExecutionSharedContext | ||
{ | ||
public static final String FAILED_TEST_FILE_KEY = "failedFileName"; | ||
public static final String SUCCESSFUL_TEST_FILE_KEY = "successfulFileName"; | ||
private static final ConcurrentHashMap<String,Object> context = new ConcurrentHashMap(); | ||
|
||
public static final ExecutionSharedContext INSTANCE = new ExecutionSharedContext(); | ||
|
||
private ExecutionSharedContext() | ||
{ | ||
} | ||
|
||
public <T> T getValue( String key ) | ||
{ | ||
return (T) context.get( key ); | ||
} | ||
|
||
public void setValue( String key, Object value ) | ||
{ | ||
context.put( key, value ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters