DATAGRAPH-408 - Upgrade to latest Spring Data Build, fixed issues with AspectJ Test Cleanup

This commit is contained in:
Michael Hunger
2013-11-15 18:01:15 +01:00
committed by Oliver Gierke
parent 0031cc37fa
commit 881c91f7e7
9 changed files with 149 additions and 20 deletions

View File

@@ -0,0 +1,103 @@
/**
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.aspects.support;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.index.Index;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.aspects.Friendship;
import org.springframework.data.neo4j.aspects.Group;
import org.springframework.data.neo4j.aspects.Person;
import org.springframework.data.neo4j.aspects.SubGroup;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.neo4j.support.index.IndexType;
import org.springframework.test.annotation.DirtiesContext;
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 static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
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})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD, hierarchyMode = DirtiesContext.HierarchyMode.EXHAUSTIVE)
public class FailingIndexTests extends EntityTestBase {
private static final String NAME_VALUE = "aName";
private static final String NAME_VALUE2 = "aSecondName";
@Test
@Transactional
public void testFindGroupByInstanceIndex() {
Group group = persist(new SubGroup());
group.setIndexLevelName("indexLevelNameValue");
Index<Node> subGroupIndex = neo4jTemplate.getIndex(SubGroup.class);
final Node found = subGroupIndex.get("indexLevelName", "indexLevelNameValue").getSingle();
final SubGroup foundEntity = neo4jTemplate.createEntityFromState(found, SubGroup.class, neo4jTemplate.getMappingPolicy(SubGroup.class));
assertEquals(group, foundEntity);
}
@NodeEntity
static class InvalidIndexed {
@Indexed(indexType=IndexType.FULLTEXT)
String fulltextNoIndexName;
public void setFulltextNoIndexName(String fulltextNoIndexName) {
this.fulltextNoIndexName = fulltextNoIndexName;
}
}
@Test(expected = IllegalStateException.class)
@Transactional
public void indexAccessWithFullAndNoIndexNameShouldFail() {
InvalidIndexed invalidIndexed = persist(new InvalidIndexed());
invalidIndexed.setFulltextNoIndexName(NAME_VALUE);
}
@Test
@Transactional
public void testDontFindGroupByNonIndexedFieldWithAnnotation() {
Group group = persist(new Group());
group.setUnindexedName("value-unindexedName");
final Group found = this.groupRepository.findByPropertyValue("unindexedName", "value-unindexedName");
assertNull(found);
}
@Test
@Transactional
public void testCanIndexIntFieldsOnRelationshipEntities() {
Person p = persistedPerson(NAME_VALUE, 35);
Person p2 = persistedPerson(NAME_VALUE2, 25);
Friendship friendship = p.knows(p2);
friendship.setYears(1);
GraphRepository<Friendship> friendshipFinder = neo4jTemplate.repositoryFor(Friendship.class);
assertEquals(friendship, friendshipFinder.findByPropertyValue("Friendship.years", 1));
}
}

View File

@@ -25,6 +25,7 @@ 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.test.annotation.DirtiesContext;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

View File

@@ -17,6 +17,7 @@
package org.springframework.data.neo4j.aspects.support;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.graphdb.DynamicRelationshipType;
@@ -55,8 +56,9 @@ import static org.springframework.data.neo4j.aspects.Person.persistedPerson;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTests-context.xml"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
//@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD, hierarchyMode = DirtiesContext.HierarchyMode.EXHAUSTIVE)
public class IndexTests extends EntityTestBase {
private static final String NAME = "name";
@@ -66,6 +68,7 @@ public class IndexTests extends EntityTestBase {
@Test
@Transactional
@Ignore
public void testCanIndexIntFieldsOnRelationshipEntities() {
Person p = persistedPerson(NAME_VALUE, 35);
Person p2 = persistedPerson(NAME_VALUE2, 25);
@@ -132,6 +135,7 @@ public class IndexTests extends EntityTestBase {
@Test
@Transactional
@Ignore
public void testFindGroupByInstanceIndex() {
Group group = persist(new SubGroup());
group.setIndexLevelName("indexLevelNameValue");
@@ -226,6 +230,7 @@ public class IndexTests extends EntityTestBase {
@Test(expected = IllegalStateException.class)
@Transactional
@Ignore
public void indexAccessWithFullAndNoIndexNameShouldFail() {
InvalidIndexed invalidIndexed = persist(new InvalidIndexed());
invalidIndexed.setFulltextNoIndexName(NAME_VALUE);
@@ -241,6 +246,7 @@ public class IndexTests extends EntityTestBase {
@Test
@Transactional
@Ignore
public void testDontFindGroupByNonIndexedFieldWithAnnotation() {
Group group = persist(new Group());
group.setUnindexedName("value-unindexedName");

View File

@@ -22,8 +22,12 @@ import org.junit.runner.RunWith;
import org.neo4j.helpers.collection.IteratorUtil;
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.Collection;
@@ -41,6 +45,7 @@ import static org.hamcrest.Matchers.*;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTests-context.xml"})
@Transactional
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
public class NodeEntityQueryTests extends EntityTestBase {
private TestTeam testTeam;
private Person michael;

View File

@@ -26,8 +26,12 @@ import org.springframework.data.neo4j.aspects.Friendship;
import org.springframework.data.neo4j.aspects.Group;
import org.springframework.data.neo4j.aspects.Mentorship;
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.Arrays;
@@ -46,6 +50,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 NodeEntityRelationshipTests extends EntityTestBase {

View File

@@ -25,8 +25,12 @@ import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.neo4j.aspects.Attribute;
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 javax.validation.ValidationException;
@@ -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 NodeEntityTests extends EntityTestBase {

View File

@@ -38,8 +38,12 @@ import org.springframework.data.neo4j.support.DelegatingGraphDatabase;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.conversion.EntityResultConverter;
import org.springframework.data.neo4j.support.query.QueryEngine;
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.Collection;
@@ -58,6 +62,7 @@ import static org.neo4j.helpers.collection.MapUtil.map;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTests-context.xml"})
@Transactional
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
public class QueryEngineTests extends EntityTestBase {
@Autowired
protected ConversionService conversionService;

View File

@@ -34,6 +34,7 @@ import org.springframework.data.neo4j.model.*;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.conversion.NoSuchColumnFoundException;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

View File

@@ -16,28 +16,26 @@
package org.springframework.test.context;
import java.lang.reflect.Field;
import java.util.Map;
import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.support.AbstractTestExecutionListener;
public class CleanContextCacheTestExecutionListener extends AbstractTestExecutionListener {
@Override
@Override
public void beforeTestClass(TestContext testContext) throws Exception {
super.beforeTestClass(testContext);
testContext.markApplicationContextDirty(DirtiesContext.HierarchyMode.EXHAUSTIVE);
}
// @Override
// public void afterTestMethod(TestContext testContext) throws Exception {
// testContext.markApplicationContextDirty(DirtiesContext.HierarchyMode.EXHAUSTIVE);
// super.afterTestMethod(testContext);
// }
@Override
public void afterTestClass(TestContext testContext) throws Exception {
Field cacheField = TestContext.class.getDeclaredField("contextCache");
cacheField.setAccessible(true);
ContextCache cache = (ContextCache) cacheField.get(testContext);
Field cacheMapField = ContextCache.class.getDeclaredField("contextMap");
cacheMapField.setAccessible(true);
@SuppressWarnings("unchecked")
Map<MergedContextConfiguration, ApplicationContext> cacheMap = (Map<MergedContextConfiguration, ApplicationContext>) cacheMapField
.get(cache);
for (MergedContextConfiguration key : cacheMap.keySet()) {
cache.setDirty(key);
}
testContext.markApplicationContextDirty(DirtiesContext.HierarchyMode.EXHAUSTIVE);
super.afterTestClass(testContext);
}
}