changed tests to not use all of the mixed in methods
This commit is contained in:
@@ -44,6 +44,11 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j</artifactId>
|
||||
<type>test-jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
</dependency>
|
||||
@@ -235,6 +240,8 @@
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<weaveDependencies>
|
||||
</weaveDependencies>
|
||||
<outxml>true</outxml>
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
|
||||
@@ -16,21 +16,17 @@
|
||||
|
||||
package org.springframework.data.neo4j.aspects.support;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.helpers.collection.IteratorUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.neo4j.aspects.*;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
import org.springframework.data.neo4j.support.node.Neo4jHelper;
|
||||
import org.springframework.data.neo4j.aspects.Friendship;
|
||||
import org.springframework.data.neo4j.aspects.Group;
|
||||
import org.springframework.data.neo4j.aspects.Person;
|
||||
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.*;
|
||||
@@ -47,23 +43,6 @@ import static org.springframework.data.neo4j.aspects.Person.persistedPerson;
|
||||
@ContextConfiguration(locations = {"classpath:org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTest-context.xml"})
|
||||
public class FinderTest extends EntityTestBase {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
@Autowired
|
||||
private GraphDatabaseContext graphDatabaseContext;
|
||||
|
||||
@Autowired
|
||||
private PersonRepository personRepository;
|
||||
@Autowired
|
||||
private GroupRepository groupRepository;
|
||||
@Autowired
|
||||
private FriendshipRepository friendshipRepository;
|
||||
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testFinderFindAll() {
|
||||
@@ -76,7 +55,6 @@ public class FinderTest extends EntityTestBase {
|
||||
@Test
|
||||
@Transactional
|
||||
public void testFindIterableOfPersonWithQueryAnnotation() {
|
||||
final TestTeam testTeam = new TestTeam();
|
||||
testTeam.createSDGTeam();
|
||||
Iterable<Person> teamMembers = personRepository.findAllTeamMembers(testTeam.sdg);
|
||||
assertThat(asCollection(teamMembers), hasItems(testTeam.michael,testTeam.david,testTeam.emil));
|
||||
@@ -85,7 +63,6 @@ public class FinderTest extends EntityTestBase {
|
||||
@Test
|
||||
@Transactional
|
||||
public void testFindPersonWithQueryAnnotation() {
|
||||
final TestTeam testTeam = new TestTeam();
|
||||
testTeam.createSDGTeam();
|
||||
Person boss = personRepository.findBoss(testTeam.michael);
|
||||
assertThat(boss, is(testTeam.emil));
|
||||
@@ -94,7 +71,7 @@ public class FinderTest extends EntityTestBase {
|
||||
@Test
|
||||
@Transactional
|
||||
public void testFindIterableMapsWithQueryAnnotation() {
|
||||
final TestTeam testTeam = new TestTeam();
|
||||
final TestTeam testTeam = new TestTeam(graphDatabaseContext);
|
||||
testTeam.createSDGTeam();
|
||||
Iterable<Map<String,Object>> teamMembers = personRepository.findAllTeamMemberData(testTeam.sdg);
|
||||
assertThat(asCollection(teamMembers), hasItems(testTeam.simpleRowFor(testTeam.michael,"member"),testTeam.simpleRowFor(testTeam.david,"member"),testTeam.simpleRowFor(testTeam.emil,"member")));
|
||||
@@ -103,7 +80,7 @@ public class FinderTest extends EntityTestBase {
|
||||
@Test
|
||||
@Transactional
|
||||
public void testFindByNamedQuery() {
|
||||
final TestTeam testTeam = new TestTeam();
|
||||
final TestTeam testTeam = new TestTeam(graphDatabaseContext);
|
||||
testTeam.createSDGTeam();
|
||||
Group team = personRepository.findTeam(testTeam.michael);
|
||||
assertThat(team, is(testTeam.sdg));
|
||||
|
||||
@@ -16,26 +16,19 @@
|
||||
|
||||
package org.springframework.data.neo4j.aspects.support;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.neo4j.aspects.Group;
|
||||
import org.springframework.data.neo4j.aspects.Person;
|
||||
import org.springframework.data.neo4j.aspects.PersonRepository;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
import org.springframework.data.neo4j.support.node.Neo4jHelper;
|
||||
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -56,22 +49,8 @@ import static org.neo4j.helpers.collection.IteratorUtil.asCollection;
|
||||
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
|
||||
public class GraphRepositoryTest extends EntityTestBase {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
@Autowired
|
||||
private GraphDatabaseContext graphDatabaseContext;
|
||||
|
||||
@Autowired
|
||||
private PersonRepository personRepository;
|
||||
private TestTeam testTeam;
|
||||
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
testTeam = new TestTeam();
|
||||
testTeam.createSDGTeam();
|
||||
}
|
||||
|
||||
@@ -94,6 +73,7 @@ public class GraphRepositoryTest extends EntityTestBase {
|
||||
Person boss = personRepository.findBoss(testTeam.michael);
|
||||
assertThat(boss, is(testTeam.emil));
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@Transactional
|
||||
public void testFindIterableMapsWithQueryAnnotation() {
|
||||
@@ -116,6 +96,7 @@ public class GraphRepositoryTest extends EntityTestBase {
|
||||
assertEquals(asList(testTeam.michael, testTeam.emil), asCollection(teamMemberPage1));
|
||||
assertThat(teamMemberPage1.isFirstPage(), is(true));
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@Transactional
|
||||
public void testFindPagedNull() {
|
||||
|
||||
@@ -20,9 +20,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.helpers.collection.IteratorUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.neo4j.aspects.Person;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -42,18 +40,17 @@ import static org.junit.internal.matchers.IsCollectionContaining.hasItems;
|
||||
@ContextConfiguration(locations = {"classpath:org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTest-context.xml"})
|
||||
@Transactional
|
||||
public class NodeEntityQueryTest extends EntityTestBase {
|
||||
@Autowired
|
||||
GraphDatabaseContext graphDatabaseContext;
|
||||
private TestTeam testTeam;
|
||||
private Person michael;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
testTeam = new TestTeam();
|
||||
testTeam = new TestTeam(graphDatabaseContext);
|
||||
testTeam.createSDGTeam();
|
||||
michael = testTeam.michael;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@Transactional
|
||||
public void testQueryVariableRelationshipSingleResult() throws Exception {
|
||||
|
||||
@@ -252,9 +252,9 @@ public class NodeEntityRelationshipTest extends EntityTestBase {
|
||||
public void multipleRelationshipsOfSameTypeBetweenTwoEntities() {
|
||||
Person michael = persistedPerson("Michael", 35);
|
||||
Person david = persistedPerson("David", 25);
|
||||
Friendship friendship1 = michael.relateTo(david, Friendship.class, "knows", true);
|
||||
Friendship friendship1 = graphDatabaseContext.relateTo(michael,david, Friendship.class, "knows", true);
|
||||
friendship1.setYears(1);
|
||||
Friendship friendship2 = michael.relateTo(david, Friendship.class, "knows",true);
|
||||
Friendship friendship2 = graphDatabaseContext.relateTo(michael,david, Friendship.class, "knows",true);
|
||||
friendship2.setYears(2);
|
||||
assertTrue("two different relationships", friendship1 != friendship2);
|
||||
assertTrue("two different relationships", getRelationshipState(friendship1) != getRelationshipState(friendship2));
|
||||
|
||||
@@ -16,24 +16,16 @@
|
||||
|
||||
package org.springframework.data.neo4j.aspects.support;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.graphdb.NotFoundException;
|
||||
import org.neo4j.graphdb.Transaction;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.neo4j.aspects.Attribute;
|
||||
import org.springframework.data.neo4j.aspects.Group;
|
||||
import org.springframework.data.neo4j.aspects.Person;
|
||||
import org.springframework.data.neo4j.aspects.PersonRepository;
|
||||
import org.springframework.data.neo4j.repository.DirectGraphRepositoryFactory;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
import org.springframework.data.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 static org.junit.Assert.assertEquals;
|
||||
@@ -42,20 +34,7 @@ import static org.springframework.data.neo4j.aspects.Person.persistedPerson;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = {"classpath:org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTest-context.xml"})
|
||||
|
||||
public class NodeEntityTest extends EntityTestBase {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
@Autowired
|
||||
private DirectGraphRepositoryFactory graphRepositoryFactory;
|
||||
|
||||
@Autowired
|
||||
private PersonRepository personRepository;
|
||||
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
super.cleanDb();
|
||||
}
|
||||
public class NodeEntityTest extends EntityTestBase {
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@@ -123,7 +102,7 @@ import static org.springframework.data.neo4j.aspects.Person.persistedPerson;
|
||||
Person spouse = persistedPerson("Tina", 36);
|
||||
p.setSpouse(spouse);
|
||||
long id = spouse.getId();
|
||||
spouse.remove();
|
||||
graphDatabaseContext.remove(spouse);
|
||||
tx.success();
|
||||
tx.finish();
|
||||
Assert.assertNull("spouse removed " + p.getSpouse(), p.getSpouse());
|
||||
|
||||
@@ -16,19 +16,12 @@
|
||||
|
||||
package org.springframework.data.neo4j.aspects.support;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.neo4j.aspects.Group;
|
||||
import org.springframework.data.neo4j.aspects.Named;
|
||||
import org.springframework.data.neo4j.repository.DirectGraphRepositoryFactory;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
import org.springframework.data.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 static org.junit.Assert.assertEquals;
|
||||
@@ -38,26 +31,13 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ProjectionTest extends EntityTestBase {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
@Autowired
|
||||
private GraphDatabaseContext graphDatabaseContext;
|
||||
|
||||
@Autowired
|
||||
private DirectGraphRepositoryFactory graphRepositoryFactory;
|
||||
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testProjectGroupToNamed() {
|
||||
Group group = persist(new Group());
|
||||
group.setName("developers");
|
||||
|
||||
Named named = (Named)group.projectTo(Named.class);
|
||||
Named named = graphDatabaseContext.projectTo(group,Named.class);
|
||||
assertEquals("named.name","developers", named.getName());
|
||||
assertEquals("nameds node name property","developers", getNodeState(named).getProperty("name"));
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class RelationshipEntityTest extends EntityTestBase {
|
||||
Person p = persistedPerson("Michael", 35);
|
||||
Person p2 = persistedPerson("David", 25);
|
||||
Friendship f = p.knows(p2);
|
||||
assertEquals(f,p.getRelationshipTo(p2, Friendship.class, "knows"));
|
||||
assertEquals(f,graphDatabaseContext.getRelationshipTo(p,p2, Friendship.class, "knows"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,7 +140,7 @@ public class RelationshipEntityTest extends EntityTestBase {
|
||||
Transaction tx2 = graphDatabaseService.beginTx();
|
||||
try
|
||||
{
|
||||
f.remove();
|
||||
graphDatabaseContext.removeRelationshipEntity(f);
|
||||
tx2.success();
|
||||
}
|
||||
finally
|
||||
@@ -169,7 +169,7 @@ public class RelationshipEntityTest extends EntityTestBase {
|
||||
Transaction tx2 = graphDatabaseService.beginTx();
|
||||
try
|
||||
{
|
||||
p.remove();
|
||||
graphDatabaseContext.removeNodeEntity(p);
|
||||
tx2.success();
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.neo4j.helpers.collection.MapUtil;
|
||||
import org.springframework.data.neo4j.aspects.Group;
|
||||
import org.springframework.data.neo4j.aspects.Person;
|
||||
import org.springframework.data.neo4j.aspects.Personality;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -32,8 +33,10 @@ public class TestTeam {
|
||||
public Person emil;
|
||||
public Person david;
|
||||
public Group sdg;
|
||||
private final GraphDatabaseContext graphDatabaseContext;
|
||||
|
||||
public TestTeam() {
|
||||
public TestTeam(GraphDatabaseContext graphDatabaseContext) {
|
||||
this.graphDatabaseContext = graphDatabaseContext;
|
||||
}
|
||||
|
||||
public void createSDGTeam() {
|
||||
@@ -43,17 +46,16 @@ public class TestTeam {
|
||||
michael.setPersonality(Personality.EXTROVERT);
|
||||
david = Person.persistedPerson("David", 25);
|
||||
david.setBoss(emil);
|
||||
sdg = new Group().persist();
|
||||
sdg = graphDatabaseContext.save(new Group());
|
||||
sdg.setName("SDG");
|
||||
sdg.addPerson(michael);
|
||||
sdg.addPerson(emil);
|
||||
sdg.addPerson(david);
|
||||
// todo those should be attached and automatically written through to the db
|
||||
david.persist();
|
||||
emil.persist();
|
||||
michael.persist();
|
||||
sdg.persist();
|
||||
|
||||
graphDatabaseContext.save(david);
|
||||
graphDatabaseContext.save(emil);
|
||||
graphDatabaseContext.save(michael);
|
||||
graphDatabaseContext.save(sdg);
|
||||
}
|
||||
|
||||
public Map<String, Object> simpleRowFor(final Person person, String prefix) {
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.data.neo4j.aspects.support;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.graphdb.Direction;
|
||||
@@ -28,17 +26,12 @@ 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.data.neo4j.aspects.Group;
|
||||
import org.springframework.data.neo4j.aspects.Person;
|
||||
import org.springframework.data.neo4j.core.EntityPath;
|
||||
import org.springframework.data.neo4j.repository.DirectGraphRepositoryFactory;
|
||||
import org.springframework.data.neo4j.repository.GraphRepository;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
import org.springframework.data.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.Collections;
|
||||
@@ -52,12 +45,6 @@ import static org.springframework.data.neo4j.aspects.Person.persistedPerson;
|
||||
|
||||
public class TraversalTest extends EntityTestBase {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
@Autowired
|
||||
private DirectGraphRepositoryFactory graphRepositoryFactory;
|
||||
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testTraverseFromGroupToPeople() {
|
||||
@@ -66,13 +53,14 @@ public class TraversalTest extends EntityTestBase {
|
||||
group.setName("dev");
|
||||
group.addPerson(p);
|
||||
final TraversalDescription traversalDescription = Traversal.description().relationships(DynamicRelationshipType.withName("persons")).evaluator(Evaluators.excludeStartPosition());
|
||||
Iterable<Person> people = (Iterable<Person>) group.findAllByTraversal(Person.class, traversalDescription);
|
||||
Iterable<Person> people = graphDatabaseContext.<Person>findAllByTraversal(group,Person.class, traversalDescription);
|
||||
final HashSet<Person> found = new HashSet<Person>();
|
||||
for (Person person : people) {
|
||||
found.add(person);
|
||||
}
|
||||
assertEquals(Collections.singleton(p),found);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@Transactional
|
||||
public void testTraverseFromGroupToPeoplePaths() {
|
||||
@@ -81,7 +69,7 @@ public class TraversalTest extends EntityTestBase {
|
||||
group.setName("dev");
|
||||
group.addPerson(p);
|
||||
final TraversalDescription traversalDescription = Traversal.description().relationships(DynamicRelationshipType.withName("persons"), Direction.OUTGOING).evaluator(Evaluators.excludeStartPosition());
|
||||
Iterable<EntityPath<Group,Person>> paths = group.<Group,Person>findAllPathsByTraversal(traversalDescription);
|
||||
Iterable<EntityPath<Group,Person>> paths = graphDatabaseContext.<EntityPath<Group,Person>>findAllByTraversal(group, EntityPath.class, traversalDescription);
|
||||
for (EntityPath<Group, Person> path : paths) {
|
||||
assertEquals(group, path.startEntity());
|
||||
assertEquals(p, path.endEntity());
|
||||
|
||||
@@ -21,20 +21,14 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.helpers.collection.IteratorUtil;
|
||||
import org.neo4j.helpers.collection.MapUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.neo4j.annotation.QueryType;
|
||||
import org.springframework.data.neo4j.aspects.Person;
|
||||
import org.springframework.data.neo4j.aspects.support.EntityTestBase;
|
||||
import org.springframework.data.neo4j.aspects.support.TestTeam;
|
||||
import org.springframework.data.neo4j.core.GraphDatabase;
|
||||
import org.springframework.data.neo4j.support.DelegatingGraphDatabase;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
import org.springframework.data.neo4j.support.node.Neo4jHelper;
|
||||
import org.springframework.data.neo4j.support.query.QueryEngine;
|
||||
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,28 +45,17 @@ import static org.junit.Assert.assertEquals;
|
||||
@ContextConfiguration(locations = {"classpath:org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTest-context.xml"})
|
||||
@Transactional
|
||||
public class GremlinQueryEngineTest extends EntityTestBase {
|
||||
@Autowired
|
||||
protected ConversionService conversionService;
|
||||
@Autowired
|
||||
private GraphDatabaseContext graphDatabaseContext;
|
||||
private QueryEngine<Object> queryEngine;
|
||||
private TestTeam testTeam;
|
||||
private Person michael;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
GraphDatabase graphDatabase = createGraphDatabase();
|
||||
testTeam = new TestTeam();
|
||||
testTeam.createSDGTeam();
|
||||
queryEngine = graphDatabase.queryEngineFor(QueryType.Gremlin);
|
||||
michael = testTeam.michael;
|
||||
}
|
||||
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
protected GraphDatabase createGraphDatabase() throws Exception {
|
||||
final DelegatingGraphDatabase graphDatabase = new DelegatingGraphDatabase(graphDatabaseContext.getGraphDatabaseService());
|
||||
graphDatabase.setConversionService(conversionService);
|
||||
|
||||
@@ -28,18 +28,15 @@ import org.springframework.data.neo4j.annotation.QueryType;
|
||||
import org.springframework.data.neo4j.aspects.Person;
|
||||
import org.springframework.data.neo4j.aspects.Personality;
|
||||
import org.springframework.data.neo4j.aspects.support.EntityTestBase;
|
||||
import org.springframework.data.neo4j.aspects.support.TestTeam;
|
||||
import org.springframework.data.neo4j.conversion.QueryResult;
|
||||
import org.springframework.data.neo4j.conversion.ResultConverter;
|
||||
import org.springframework.data.neo4j.core.GraphDatabase;
|
||||
import org.springframework.data.neo4j.support.DelegatingGraphDatabase;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
import org.springframework.data.neo4j.support.conversion.EntityResultConverter;
|
||||
import org.springframework.data.neo4j.support.node.Neo4jHelper;
|
||||
import org.springframework.data.neo4j.support.query.QueryEngine;
|
||||
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;
|
||||
@@ -62,30 +59,23 @@ public class QueryEngineTest extends EntityTestBase {
|
||||
@Autowired
|
||||
private GraphDatabaseContext graphDatabaseContext;
|
||||
private QueryEngine<Map<String,Object>> queryEngine;
|
||||
private TestTeam testTeam;
|
||||
private Person michael;
|
||||
private GraphDatabase graphDatabase;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
graphDatabase = createGraphDatabase();
|
||||
testTeam = new TestTeam();
|
||||
GraphDatabase graphDatabase = createGraphDatabase();
|
||||
testTeam.createSDGTeam();
|
||||
queryEngine = graphDatabase.queryEngineFor(QueryType.Cypher);
|
||||
michael = testTeam.michael;
|
||||
}
|
||||
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
protected GraphDatabase createGraphDatabase() throws Exception {
|
||||
final DelegatingGraphDatabase graphDatabase = new DelegatingGraphDatabase(graphDatabaseContext.getGraphDatabaseService());
|
||||
graphDatabase.setConversionService(conversionService);
|
||||
return graphDatabase;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testQueryList() throws Exception {
|
||||
final String queryString = "start person=node({people}) return person.name, person.age";
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.data.neo4j.aspects.support.typerepresentation;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -33,17 +31,13 @@ import org.springframework.data.neo4j.aspects.Person;
|
||||
import org.springframework.data.neo4j.aspects.Toyota;
|
||||
import org.springframework.data.neo4j.aspects.Volvo;
|
||||
import org.springframework.data.neo4j.aspects.support.EntityTestBase;
|
||||
import org.springframework.data.neo4j.repository.DirectGraphRepositoryFactory;
|
||||
import org.springframework.data.neo4j.repository.GraphRepository;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
import org.springframework.data.neo4j.support.node.Neo4jHelper;
|
||||
import org.springframework.data.neo4j.support.typerepresentation.SubReferenceNodeTypeRepresentationStrategy;
|
||||
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -64,12 +58,6 @@ import static org.springframework.data.neo4j.aspects.Person.persistedPerson;
|
||||
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
|
||||
public class SubReferenceNodeTypeRepresentationStrategyTest extends EntityTestBase {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
@Autowired
|
||||
GraphDatabaseContext graphDatabaseContext;
|
||||
@Autowired
|
||||
private DirectGraphRepositoryFactory graphRepositoryFactory;
|
||||
@Autowired
|
||||
private SubReferenceNodeTypeRepresentationStrategy nodeTypeRepresentationStrategy;
|
||||
private Node thingNode;
|
||||
@@ -77,12 +65,6 @@ public class SubReferenceNodeTypeRepresentationStrategyTest extends EntityTestBa
|
||||
private SubThing subThing;
|
||||
private Node subThingNode;
|
||||
|
||||
|
||||
@BeforeTransaction
|
||||
public void cleanDb() {
|
||||
Neo4jHelper.cleanDb(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
createThing();
|
||||
|
||||
@@ -81,8 +81,6 @@ public class GraphDatabaseContext {
|
||||
private TypeRepresentationStrategies typeRepresentationStrategies;
|
||||
private EntityInstantiator<Relationship> relationshipEntityInstantiator;
|
||||
private EntityInstantiator<Node> nodeEntityInstantiator;
|
||||
private EntityTools<Node> nodeEntityTools;
|
||||
private EntityTools<Relationship> relationshipEntityTools;
|
||||
|
||||
public void setRelationshipEntityInstantiator(EntityInstantiator<Relationship> relationshipEntityInstantiator) {
|
||||
this.relationshipEntityInstantiator = relationshipEntityInstantiator;
|
||||
@@ -169,6 +167,7 @@ public class GraphDatabaseContext {
|
||||
final Traverser traverser = traversalDescription.traverse((Node) state);
|
||||
if (Node.class.isAssignableFrom(targetType)) return (Iterable<T>) traverser.nodes();
|
||||
if (Relationship.class.isAssignableFrom(targetType)) return (Iterable<T>) traverser.relationships();
|
||||
if (EntityPath.class.isAssignableFrom(targetType)) return new EntityPathPathIterableWrapper(traverser,this);
|
||||
if (Path.class.isAssignableFrom(targetType)) return (Iterable<T>) traverser;
|
||||
return (Iterable<T>) convertToGraphEntity(traverser, targetType);
|
||||
}
|
||||
@@ -231,6 +230,18 @@ public class GraphDatabaseContext {
|
||||
typeRepresentationStrategies.postEntityCreation(node, entityClass);
|
||||
}
|
||||
|
||||
public void remove(Object entity) {
|
||||
final Class<?> type = entity.getClass();
|
||||
if (isNodeEntity(type)) {
|
||||
entityRemover.removeNodeEntity(entity);
|
||||
return;
|
||||
}
|
||||
if (isRelationshipEntity(type)) {
|
||||
entityRemover.removeRelationshipEntity(entity);
|
||||
return;
|
||||
}
|
||||
throw new IllegalArgumentException("@NodeEntity or @RelationshipEntity annotation required on domain class"+type);
|
||||
}
|
||||
public void removeNodeEntity(Object entity) {
|
||||
entityRemover.removeNodeEntity(entity);
|
||||
}
|
||||
@@ -289,12 +300,12 @@ public class GraphDatabaseContext {
|
||||
if (nodeEntityInstantiator==null) {
|
||||
nodeEntityInstantiator = new NodeEntityInstantiator(entityStateHandler);
|
||||
}
|
||||
this.nodeEntityTools = new EntityTools<Node>(nodeTypeRepresentationStrategy,nodeEntityStateFactory, nodeEntityInstantiator);
|
||||
EntityTools<Node> nodeEntityTools = new EntityTools<Node>(nodeTypeRepresentationStrategy, nodeEntityStateFactory, nodeEntityInstantiator);
|
||||
if (relationshipEntityInstantiator==null) {
|
||||
relationshipEntityInstantiator = new RelationshipEntityInstantiator(entityStateHandler);
|
||||
}
|
||||
this.relationshipEntityTools = new EntityTools<Relationship>(relationshipTypeRepresentationStrategy, relationshipEntityStateFactory, relationshipEntityInstantiator);
|
||||
this.entityPersister = new Neo4jEntityPersister(conversionService, nodeEntityTools,relationshipEntityTools,mappingContext, entityStateHandler);
|
||||
EntityTools<Relationship> relationshipEntityTools = new EntityTools<Relationship>(relationshipTypeRepresentationStrategy, relationshipEntityStateFactory, relationshipEntityInstantiator);
|
||||
this.entityPersister = new Neo4jEntityPersister(conversionService, nodeEntityTools, relationshipEntityTools,mappingContext, entityStateHandler);
|
||||
this.entityRemover = new EntityRemover(this.entityStateHandler, nodeTypeRepresentationStrategy, relationshipTypeRepresentationStrategy, graphDatabaseService.index());
|
||||
this.indexProvider = new IndexProvider(graphDatabaseService.index(), mappingContext);
|
||||
}
|
||||
@@ -308,8 +319,9 @@ public class GraphDatabaseContext {
|
||||
return targetType.isAnnotationPresent(RelationshipEntity.class);
|
||||
}
|
||||
|
||||
public Object save(Object entity) {
|
||||
return entityPersister.persist(entity);
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T save(T entity) {
|
||||
return (T)entityPersister.persist(entity);
|
||||
}
|
||||
|
||||
public boolean isManaged(Object entity) {
|
||||
|
||||
Reference in New Issue
Block a user