Skip to content

Commit

Permalink
Make sure properties are cleared between tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Mar 1, 2018
1 parent 76eb142 commit 09bfddc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
Expand Up @@ -21,8 +21,6 @@


import org.junit.Test; import org.junit.Test;


import org.neo4j.graphdb.PropertyContainer;

import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
Expand All @@ -33,6 +31,7 @@
@SuppressWarnings( "Duplicates" ) @SuppressWarnings( "Duplicates" )
public abstract class GraphPropertiesTestBase<G extends KernelAPIWriteTestSupport> extends KernelAPIWriteTestBase<G> public abstract class GraphPropertiesTestBase<G extends KernelAPIWriteTestSupport> extends KernelAPIWriteTestBase<G>
{ {

@Test @Test
public void shouldBeAbleToWriteNewGraphProperty() throws Exception public void shouldBeAbleToWriteNewGraphProperty() throws Exception
{ {
Expand All @@ -46,7 +45,7 @@ public void shouldBeAbleToWriteNewGraphProperty() throws Exception


try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
{ {
assertThat( graphProperties().getProperty( "prop" ), equalTo( "hello" ) ); assertThat( testSupport.graphProperties().getProperty( "prop" ), equalTo( "hello" ) );
} }
} }


Expand All @@ -69,7 +68,7 @@ public void shouldBeAbleToReplaceExistingGraphProperty() throws Exception


try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
{ {
assertThat( graphProperties().getProperty( "prop" ), equalTo( "good bye" ) ); assertThat( testSupport.graphProperties().getProperty( "prop" ), equalTo( "good bye" ) );
} }
} }


Expand All @@ -92,7 +91,7 @@ public void shouldBeAbleToRemoveExistingGraphProperty() throws Exception


try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
{ {
assertFalse( graphProperties().hasProperty( "prop" ) ); assertFalse( testSupport.graphProperties().hasProperty( "prop" ) );
} }
} }


Expand Down Expand Up @@ -193,6 +192,4 @@ public void shouldNotSeeURemovedGraphPropertyInTransaction() throws Exception
assertFalse( cursor.next() ); assertFalse( cursor.next() );
} }
} }

protected abstract PropertyContainer graphProperties();
} }
Expand Up @@ -20,9 +20,9 @@
package org.neo4j.internal.kernel.api; package org.neo4j.internal.kernel.api;


import java.io.File; import java.io.File;
import java.io.IOException;


import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.PropertyContainer;




/** /**
Expand All @@ -34,7 +34,6 @@ public interface KernelAPIWriteTestSupport
/** /**
* Create the Kernel to test in the provided directory. * Create the Kernel to test in the provided directory.
* @param storeDir The directory to hold the database * @param storeDir The directory to hold the database
* @throws IOException Thrown on IO failure during database creation
*/ */
void setup( File storeDir ); void setup( File storeDir );


Expand All @@ -57,4 +56,10 @@ public interface KernelAPIWriteTestSupport
* Clean up resources and close the database. Executed after all tests are completed. * Clean up resources and close the database. Executed after all tests are completed.
*/ */
void tearDown(); void tearDown();

/**
* Retrieves all properties associated with the graph
* @return The properties associated with the graph
*/
PropertyContainer graphProperties();
} }
Expand Up @@ -20,15 +20,16 @@
package org.neo4j.kernel.impl.newapi; package org.neo4j.kernel.impl.newapi;


import java.io.File; import java.io.File;
import java.io.IOException;


import org.neo4j.graphdb.DependencyResolver; import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
import org.neo4j.internal.kernel.api.Kernel; import org.neo4j.internal.kernel.api.Kernel;
import org.neo4j.internal.kernel.api.KernelAPIWriteTestSupport; import org.neo4j.internal.kernel.api.KernelAPIWriteTestSupport;
import org.neo4j.kernel.impl.core.EmbeddedProxySPI;
import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.test.TestGraphDatabaseFactory; import org.neo4j.test.TestGraphDatabaseFactory;


Expand Down Expand Up @@ -58,10 +59,25 @@ public void clearGraph()
node.delete(); node.delete();
} }


PropertyContainer graphProperties = graphProperties();
for ( String key : graphProperties.getPropertyKeys() )
{
graphProperties.removeProperty( key );
}

tx.success(); tx.success();
} }
} }


@Override
public PropertyContainer graphProperties()
{
return ((GraphDatabaseAPI) db)
.getDependencyResolver()
.resolveDependency( EmbeddedProxySPI.class )
.newGraphPropertiesProxy();
}

@Override @Override
public Kernel kernelToTest() public Kernel kernelToTest()
{ {
Expand Down
Expand Up @@ -19,10 +19,7 @@
*/ */
package org.neo4j.kernel.impl.newapi; package org.neo4j.kernel.impl.newapi;


import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.internal.kernel.api.GraphPropertiesTestBase; import org.neo4j.internal.kernel.api.GraphPropertiesTestBase;
import org.neo4j.kernel.impl.core.EmbeddedProxySPI;
import org.neo4j.kernel.internal.GraphDatabaseAPI;


public class GraphPropertiesTest extends GraphPropertiesTestBase<WriteTestSupport> public class GraphPropertiesTest extends GraphPropertiesTestBase<WriteTestSupport>
{ {
Expand All @@ -32,12 +29,4 @@ public WriteTestSupport newTestSupport()
return new WriteTestSupport(); return new WriteTestSupport();
} }


@Override
protected PropertyContainer graphProperties()
{
return ((GraphDatabaseAPI) graphDb)
.getDependencyResolver()
.resolveDependency( EmbeddedProxySPI.class )
.newGraphPropertiesProxy();
}
} }

0 comments on commit 09bfddc

Please sign in to comment.