added some cleanup after tests

This commit is contained in:
Thomas Risberg
2011-02-25 17:19:15 -05:00
parent c499f8d40f
commit 69cdcc1b7e
2 changed files with 49 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package org.springframework.data.graph.neo4j.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
@@ -21,6 +22,7 @@ import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.AfterTransaction;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
@@ -53,6 +55,26 @@ public class IndexTest {
Neo4jHelper.cleanDb(graphDatabaseContext);
}
@AfterTransaction
public void tearDown() throws Exception {
GraphDatabaseService gds = graphDatabaseContext.getGraphDatabaseService();
if (gds != null) {
clearIndex(gds);
}
}
private void clearIndex(GraphDatabaseService gds) {
org.neo4j.graphdb.Transaction tx = gds.beginTx();
try {
for (String ix : gds.index().nodeIndexNames()) {
gds.index().forNodes(ix).delete();
}
tx.success();
} finally {
tx.finish();
}
}
@Test
@Transactional
public void testCanIndexIntFieldsOnRelationshipEntities() {

View File

@@ -6,6 +6,7 @@ import org.junit.Test;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotFoundException;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.index.IndexHits;
import org.neo4j.kernel.Config;
import org.neo4j.kernel.EmbeddedGraphDatabase;
@@ -40,8 +41,34 @@ public class JOTMIntegrationTest {
@After
public void tearDown() throws Exception {
if (gds != null) {
clear(gds);
}
if (ctx != null) ctx.close();
}
private void clear(GraphDatabaseService gds) {
org.neo4j.graphdb.Transaction tx = gds.beginTx();
try {
for (String ix : gds.index().nodeIndexNames()) {
gds.index().forNodes(ix).delete();
}
for (Node node : gds.getAllNodes()) {
for (Relationship relationship : node.getRelationships()) {
relationship.delete();
}
}
Node referenceNode = gds.getReferenceNode();
for (Node node : gds.getAllNodes()) {
if (node.equals(referenceNode))
continue;
node.delete();
}
tx.success();
} finally {
tx.finish();
}
}
@Test
public void createdNodeShouldBeFoundAfterCommit() throws Exception {