db cleanup in tests is now run before the transactions
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
<org.slf4j.version>1.5.10</org.slf4j.version>
|
||||
<org.springframework.version>3.0.5.RELEASE</org.springframework.version>
|
||||
<data.commons.version>1.0.0.M3</data.commons.version>
|
||||
<neo4j.version>1.3.M02</neo4j.version>
|
||||
<neo4j.version>1.3.M03</neo4j.version>
|
||||
<aspectj.version>1.6.11.M2</aspectj.version>
|
||||
</properties>
|
||||
<profiles>
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
|
||||
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -43,9 +44,14 @@ public class Neo4jEntityManagerTest {
|
||||
Person person;
|
||||
private Node node;
|
||||
|
||||
@Before
|
||||
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
person = new Person("Michael",35);
|
||||
node = person.getUnderlyingState();
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
<bean class="org.springframework.persistence.graph.Neo4jSimpleNodePropertyStorageForeignStoreKeyManager"/>
|
||||
-->
|
||||
|
||||
<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase"
|
||||
<bean id="graphDatabaseService" class="org.neo4j.kernel.ImpermanentGraphDatabase"
|
||||
destroy-method="shutdown" scope="singleton">
|
||||
<constructor-arg index="0" value="target/data/emtest" />
|
||||
</bean>
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.neo4j.graphdb.*;
|
||||
import org.neo4j.graphdb.index.Index;
|
||||
import org.neo4j.graphdb.index.IndexManager;
|
||||
import org.neo4j.kernel.EmbeddedGraphDatabase;
|
||||
import org.neo4j.kernel.AbstractGraphDatabase;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.graph.core.GraphBacked;
|
||||
import org.springframework.data.graph.core.NodeBacked;
|
||||
@@ -296,7 +296,7 @@ public class GraphDatabaseContext {
|
||||
*/
|
||||
public TransactionManager getTxManager() {
|
||||
|
||||
return ((EmbeddedGraphDatabase) graphDatabaseService).getConfig().getTxModule().getTxManager();
|
||||
return ((AbstractGraphDatabase) graphDatabaseService).getConfig().getTxModule().getTxManager();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,31 +16,50 @@
|
||||
|
||||
package org.springframework.data.graph.neo4j.support.node;
|
||||
|
||||
import org.neo4j.graphdb.GraphDatabaseService;
|
||||
import org.neo4j.graphdb.Node;
|
||||
import org.neo4j.graphdb.Relationship;
|
||||
import org.neo4j.graphdb.Transaction;
|
||||
import org.neo4j.graphdb.index.IndexManager;
|
||||
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
|
||||
|
||||
public abstract class Neo4jHelper {
|
||||
|
||||
public static void cleanDb(GraphDatabaseContext graphDatabaseContext, String... indexFieldsToRemove) {
|
||||
Transaction tx = graphDatabaseContext.beginTx();
|
||||
public static void cleanDb(GraphDatabaseContext graphDatabaseContext) {
|
||||
cleanDb(graphDatabaseContext.getGraphDatabaseService());
|
||||
}
|
||||
|
||||
public static void cleanDb(GraphDatabaseService graphDatabaseService) {
|
||||
|
||||
Transaction tx = graphDatabaseService.beginTx();
|
||||
try {
|
||||
Node refNode = graphDatabaseContext.getReferenceNode();
|
||||
for (Node node : graphDatabaseContext.getAllNodes()) {
|
||||
for (Relationship rel : node.getRelationships()) {
|
||||
rel.delete();
|
||||
}
|
||||
if (!refNode.equals(node)) {
|
||||
node.delete();
|
||||
}
|
||||
}
|
||||
for (String indexField : indexFieldsToRemove) {
|
||||
graphDatabaseContext.getNodeIndex("node").remove(null, indexField, null);
|
||||
}
|
||||
removeNodes(graphDatabaseService);
|
||||
clearIndex(graphDatabaseService);
|
||||
tx.success();
|
||||
} finally {
|
||||
tx.finish();
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeNodes(GraphDatabaseService graphDatabaseService) {
|
||||
Node refNode = graphDatabaseService.getReferenceNode();
|
||||
for (Node node : graphDatabaseService.getAllNodes()) {
|
||||
for (Relationship rel : node.getRelationships()) {
|
||||
rel.delete();
|
||||
}
|
||||
if (!refNode.equals(node)) {
|
||||
node.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void clearIndex(GraphDatabaseService gds) {
|
||||
IndexManager indexManager = gds.index();
|
||||
for (String ix : indexManager.nodeIndexNames()) {
|
||||
indexManager.forNodes(ix).delete();
|
||||
}
|
||||
for (String ix : indexManager.relationshipIndexNames()) {
|
||||
indexManager.forRelationships(ix).delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -41,7 +42,7 @@ public class RecommendationTest {
|
||||
@Autowired
|
||||
DataSource dataSource;
|
||||
|
||||
@Before
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@@ -2,29 +2,19 @@ package org.springframework.data.graph.neo4j.support;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.graphdb.Direction;
|
||||
import org.neo4j.graphdb.DynamicRelationshipType;
|
||||
import org.neo4j.graphdb.Node;
|
||||
import org.neo4j.graphdb.Relationship;
|
||||
import org.neo4j.helpers.collection.IteratorUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.graph.neo4j.Friendship;
|
||||
import org.springframework.data.graph.neo4j.Group;
|
||||
import org.springframework.data.graph.neo4j.Person;
|
||||
import org.springframework.data.graph.neo4j.finder.FinderFactory;
|
||||
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.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.validation.ValidationException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -38,7 +28,7 @@ public class EntityPropertyValidationTest {
|
||||
@Autowired
|
||||
private GraphDatabaseContext graphDatabaseContext;
|
||||
|
||||
@Before
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.graphdb.NotFoundException;
|
||||
import org.neo4j.graphdb.Transaction;
|
||||
import org.neo4j.helpers.collection.IteratorUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.graph.neo4j.Group;
|
||||
@@ -18,6 +16,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.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -39,10 +38,11 @@ public class FinderTest {
|
||||
@Autowired
|
||||
private FinderFactory finderFactory;
|
||||
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testFinderFindAll() {
|
||||
|
||||
@@ -2,7 +2,6 @@ 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;
|
||||
@@ -23,6 +22,7 @@ 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.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -50,31 +50,11 @@ public class IndexTest {
|
||||
@Autowired
|
||||
private FinderFactory finderFactory;
|
||||
|
||||
@Before
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
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() {
|
||||
|
||||
@@ -15,7 +15,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.transaction.annotation.Transactional;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.graph.neo4j.support.HasRelationshipMatcher.hasRelationship;
|
||||
@@ -35,9 +35,8 @@ public class ModificationOutsideOfTransactionTest
|
||||
private FinderFactory finderFactory;
|
||||
|
||||
@Before
|
||||
public void cleanDb()
|
||||
{
|
||||
Neo4jHelper.cleanDb( graphDatabaseContext );
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -14,11 +14,11 @@ import org.springframework.data.graph.neo4j.Friendship;
|
||||
import org.springframework.data.graph.neo4j.Group;
|
||||
import org.springframework.data.graph.neo4j.Person;
|
||||
import org.springframework.data.graph.neo4j.finder.FinderFactory;
|
||||
import org.springframework.data.graph.neo4j.finder.NodeFinder;
|
||||
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.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
@@ -38,9 +38,9 @@ public class NodeEntityRelationshipTest {
|
||||
@Autowired
|
||||
private FinderFactory finderFactory;
|
||||
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -4,29 +4,21 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.graphdb.*;
|
||||
import org.neo4j.graphdb.traversal.TraversalDescription;
|
||||
import org.neo4j.helpers.collection.IteratorUtil;
|
||||
import org.neo4j.kernel.Traversal;
|
||||
import org.neo4j.kernel.impl.traversal.TraversalDescriptionImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.graph.neo4j.*;
|
||||
import org.springframework.data.graph.neo4j.finder.FinderFactory;
|
||||
import org.springframework.data.graph.neo4j.finder.NodeFinder;
|
||||
import org.springframework.data.graph.neo4j.finder.RelationshipFinder;
|
||||
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
@@ -43,9 +35,9 @@ import static org.junit.Assert.assertNull;
|
||||
@Autowired
|
||||
private FinderFactory finderFactory;
|
||||
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -5,26 +5,18 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.graphdb.DynamicRelationshipType;
|
||||
import org.neo4j.graphdb.traversal.TraversalDescription;
|
||||
import org.neo4j.kernel.Traversal;
|
||||
import org.neo4j.kernel.impl.traversal.TraversalDescriptionImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.graph.neo4j.Group;
|
||||
import org.springframework.data.graph.neo4j.Named;
|
||||
import org.springframework.data.graph.neo4j.Person;
|
||||
import org.springframework.data.graph.neo4j.finder.FinderFactory;
|
||||
import org.springframework.data.graph.neo4j.finder.NodeFinder;
|
||||
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@@ -40,10 +32,11 @@ public class ProjectionTest {
|
||||
@Autowired
|
||||
private FinderFactory finderFactory;
|
||||
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testProjectGroupToNamed() {
|
||||
|
||||
@@ -6,28 +6,21 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.graphdb.DynamicRelationshipType;
|
||||
import org.neo4j.graphdb.NotFoundException;
|
||||
import org.neo4j.graphdb.traversal.TraversalDescription;
|
||||
import org.neo4j.kernel.Traversal;
|
||||
import org.neo4j.kernel.impl.traversal.TraversalDescriptionImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.graph.neo4j.Friendship;
|
||||
import org.springframework.data.graph.neo4j.Group;
|
||||
import org.springframework.data.graph.neo4j.Person;
|
||||
import org.springframework.data.graph.neo4j.Personality;
|
||||
import org.springframework.data.graph.neo4j.finder.FinderFactory;
|
||||
import org.springframework.data.graph.neo4j.finder.NodeFinder;
|
||||
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -44,9 +37,9 @@ public class PropertyTest {
|
||||
@Autowired
|
||||
private FinderFactory finderFactory;
|
||||
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
@Test
|
||||
@Transactional
|
||||
|
||||
@@ -2,21 +2,19 @@ package org.springframework.data.graph.neo4j.support;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.graphdb.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.graph.neo4j.Friendship;
|
||||
import org.springframework.data.graph.neo4j.Group;
|
||||
import org.springframework.data.graph.neo4j.Person;
|
||||
import org.springframework.data.graph.neo4j.finder.FinderFactory;
|
||||
import org.springframework.data.graph.neo4j.finder.NodeFinder;
|
||||
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.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -34,9 +32,9 @@ public class RelationshipEntityTest {
|
||||
@Autowired
|
||||
private FinderFactory finderFactory;
|
||||
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -25,6 +25,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.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -51,9 +52,14 @@ public class SubReferenceNodeTypeStrategyTest {
|
||||
private Node thingNode;
|
||||
private Thing thing;
|
||||
|
||||
@Before
|
||||
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
nodeTypeStrategy = graphDatabaseContext.getNodeTypeStrategy();
|
||||
thingNode = createThing();
|
||||
}
|
||||
|
||||
@@ -2,13 +2,11 @@ package org.springframework.data.graph.neo4j.support;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.graphdb.DynamicRelationshipType;
|
||||
import org.neo4j.graphdb.traversal.TraversalDescription;
|
||||
import org.neo4j.helpers.collection.IteratorUtil;
|
||||
import org.neo4j.kernel.Traversal;
|
||||
import org.neo4j.kernel.impl.traversal.TraversalDescriptionImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -21,10 +19,9 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
||||
@@ -43,10 +40,11 @@ public class TraversalTest {
|
||||
@Autowired
|
||||
private FinderFactory finderFactory;
|
||||
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testTraverseFromGroupToPeople() {
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.neo4j.kernel.Config;
|
||||
import org.neo4j.kernel.EmbeddedGraphDatabase;
|
||||
import org.objectweb.jotm.Current;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
|
||||
import org.springframework.transaction.jta.JtaTransactionManager;
|
||||
import org.springframework.transaction.jta.ManagedTransactionAdapter;
|
||||
|
||||
@@ -37,38 +38,13 @@ public class JOTMIntegrationTest {
|
||||
public void setUp() throws Exception {
|
||||
ctx = new ClassPathXmlApplicationContext("classpath:spring-tx-text-context.xml");
|
||||
gds = ctx.getBean(GraphDatabaseService.class);
|
||||
Neo4jHelper.cleanDb(gds);
|
||||
}
|
||||
|
||||
@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 {
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
<bean class="org.springframework.persistence.graph.Neo4jSimpleNodePropertyStorageForeignStoreKeyManager"/>
|
||||
-->
|
||||
|
||||
<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase"
|
||||
<bean id="graphDatabaseService" class="org.neo4j.kernel.ImpermanentGraphDatabase"
|
||||
destroy-method="shutdown" scope="singleton">
|
||||
<constructor-arg index="0" value="target/data/recommendation" />
|
||||
</bean>
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
<property name="relationshipEntityStateAccessorsFactory" ref="relationshipEntityStateAccessorsFactory"/>
|
||||
</bean>
|
||||
|
||||
<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase"
|
||||
<bean id="graphDatabaseService" class="org.neo4j.kernel.ImpermanentGraphDatabase"
|
||||
destroy-method="shutdown" scope="singleton">
|
||||
<constructor-arg index="0" value="${neo4j.databaseDirectory}" />
|
||||
</bean>
|
||||
|
||||
Reference in New Issue
Block a user