DATAGRAPH-408 - Fixing more tests for different test behavior in Spring Framework 3.2.5.

This commit is contained in:
Michael Hunger
2013-11-15 22:33:20 +01:00
committed by Oliver Gierke
parent 881c91f7e7
commit d9b4402f95
5 changed files with 83 additions and 7 deletions

View File

@@ -26,8 +26,12 @@ import org.springframework.data.domain.PageRequest;
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.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.TransactionalTestExecutionListener;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
@@ -41,6 +45,7 @@ import static org.springframework.data.neo4j.aspects.Person.persistedPerson;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTests-context.xml"})
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
public class FinderTests extends EntityTestBase {
@Test

View File

@@ -15,16 +15,86 @@
*/
package org.springframework.data.neo4j.partial;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.support.Neo4jTemplate;
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.PlatformTransactionManager;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.sql.DataSource;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:org/springframework/data/neo4j/partial/Neo4jGraphRecommendationTest-context-config.xml"})
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
public class RecommendationConfigTests extends RecommendationTests {
public class RecommendationConfigTests {
protected final Logger log = LoggerFactory.getLogger(getClass());
@Autowired
PlatformTransactionManager transactionManager;
@Autowired
private Neo4jTemplate template;
@PersistenceContext
EntityManager em;
@Autowired
DataSource dataSource;
@BeforeTransaction
public void cleanDb() {
Neo4jHelper.cleanDb(template);
}
@Test
@Transactional
public void jpaUserHasNodeAndId() {
User user = user("John");
Assert.assertNotNull("jpa-id", user.getId());
Assert.assertNotNull("node",user.getPersistentState());
}
@Test
@Transactional
public void jpaUserCanHaveGraphProperties() {
User user = user("John");
Assert.assertNotNull("jpa-id",user.getId());
Assert.assertNotNull("node",user.getPersistentState());
Assert.assertNotNull("nickname in entity",user.getNickname());
Assert.assertEquals("nickname in graph","John",user.getPersistentState().getProperty("nickname"));
}
private User user(final String name) {
User user = new User();
user.setAge(35);
user.setNickname(name);
em.persist(user);
em.flush();
return user.persist();
}
@Test
@Transactional
public void jpaUserCanHaveGraphRelationships() {
User user = user("John");
Assert.assertNotNull("jpa-id",user.getId());
Assert.assertNotNull("node",user.getPersistentState());
User user2 = user("Jane");
user.getFriends().add(user2);
//user.knows(user2);
Assert.assertEquals(user2, user.getFriends().iterator().next());
}
}

View File

@@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

View File

@@ -27,7 +27,7 @@
<property name="password" value="${database.password}"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<tx:annotation-driven mode="aspectj" transaction-manager="neo4jTransactionManager"/>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="dataSource" ref="dataSource"/>

View File

@@ -27,11 +27,11 @@ public class CleanContextCacheTestExecutionListener extends AbstractTestExecutio
testContext.markApplicationContextDirty(DirtiesContext.HierarchyMode.EXHAUSTIVE);
}
// @Override
// public void afterTestMethod(TestContext testContext) throws Exception {
// testContext.markApplicationContextDirty(DirtiesContext.HierarchyMode.EXHAUSTIVE);
// super.afterTestMethod(testContext);
// }
@Override
public void afterTestMethod(TestContext testContext) throws Exception {
testContext.markApplicationContextDirty(DirtiesContext.HierarchyMode.EXHAUSTIVE);
super.afterTestMethod(testContext);
}
@Override
public void afterTestClass(TestContext testContext) throws Exception {