Additional aspects module test cleanup

This commit is contained in:
Nicki Watt
2014-02-23 17:29:07 +00:00
parent 7152ce6783
commit 97ea4c236b
8 changed files with 100 additions and 309 deletions

View File

@@ -0,0 +1,30 @@
/**
* 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;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.NodeEntity;
import javax.validation.constraints.NotNull;
@NodeEntity
public class NonNullNamed {
@GraphId
private Long graphId;
@NotNull
private String name;
}

View File

@@ -16,6 +16,7 @@
package org.springframework.data.neo4j.illegal.aspects.index1;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -30,8 +31,6 @@ import static org.junit.Assert.fail;
public class IllegalIndex1Tests extends EntityTestBase {
private static final String NAME_VALUE = "aName";
@NodeEntity
static class InvalidIndexed {
@@ -90,28 +89,13 @@ public class IllegalIndex1Tests extends EntityTestBase {
// requirements) this would only blow up when actually
// attempting to do something illegal - now everything blows up on startup
verifyAppCtxBlowsUpOnStartup(InvalidSpatialIndexed1.class);
createAppCtxAndPropagateRootExceptionIfThrown(InvalidSpatialIndexed1.class);
//InvalidSpatialIndexed1 invalidIndexed = persist(new InvalidSpatialIndexed1());
//String latlon = "POINT (55 15)";
//invalidIndexed.setWkt(latlon);
}
private void verifyAppCtxBlowsUpOnStartup(Class entityUnderTest) throws Throwable {
try {
// This no longer blows up at access time, but rather at startup
ClassPathXmlApplicationContext appCtx = new ClassPathXmlApplicationContext();
appCtx.setConfigLocation("org/springframework/data/neo4j/aspects/support/illegal-index1-tests-context.xml");
appCtx.getEnvironment().setActiveProfiles( entityUnderTest.getSimpleName() );
appCtx.refresh();
} catch (BeanCreationException bce) {
// Throw the underlying cause ....
throw bce.getCause();
}
}
@Test(expected = IllegalStateException.class)
@Transactional
public void indexAccessWithDefaultSpatialIndexNameShouldFail() throws Throwable{
@@ -120,7 +104,7 @@ public class IllegalIndex1Tests extends EntityTestBase {
// requirements) this would only blow up when actually
// attempting to do something illegal - now everything blows up on startup
verifyAppCtxBlowsUpOnStartup(InvalidSpatialIndexed2.class);
createAppCtxAndPropagateRootExceptionIfThrown(InvalidSpatialIndexed2.class);
//InvalidSpatialIndexed2 invalidIndexed = persist(new InvalidSpatialIndexed2());
//String latlon = "POINT (55 15)";
@@ -136,11 +120,33 @@ public class IllegalIndex1Tests extends EntityTestBase {
// requirements) this would only blow up when actually
// attempting to do something illegal - now everything blows up on startup
verifyAppCtxBlowsUpOnStartup(InvalidIndexed.class);
createAppCtxAndPropagateRootExceptionIfThrown(InvalidIndexed.class);
//InvalidIndexed invalidIndexed = persist(new InvalidIndexed());
//invalidIndexed.setFulltextNoIndexName(NAME_VALUE);
}
/**
* As the first illegal entity detected will blow up the application context - we need a way
* to ensure only the illegal entity under test it loaded to assert that we fail
* for the correct reason and in an appropriate way. This method will create and application
* context ensuring that only the illegal entity under test (passed in as an argument), is
* detected by the context. This is currently done by wrapping each Illegal Entity bootstrap
* logic in a Spring profile against its same name
*
* @param entityUnderTest Class which should be detected by SDN for the purposes of testing
* @throws Throwable
*/
private void createAppCtxAndPropagateRootExceptionIfThrown(Class entityUnderTest) throws Throwable {
try {
ClassPathXmlApplicationContext appCtx = new ClassPathXmlApplicationContext();
appCtx.setConfigLocation("org/springframework/data/neo4j/aspects/support/illegal-index1-tests-context.xml");
appCtx.getEnvironment().setActiveProfiles( entityUnderTest.getSimpleName() );
appCtx.refresh();
} catch (BeanCreationException bce) {
throw ExceptionUtils.getRootCause(bce);
}
}
}

View File

@@ -16,12 +16,12 @@
package org.springframework.data.neo4j.illegal.aspects.index2;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.aspects.support.EntityTestBase;
import org.springframework.data.neo4j.support.index.IndexType;
import org.springframework.transaction.annotation.Transactional;
@@ -44,25 +44,39 @@ public class IllegalIndex2Tests {
}
}
@Test
@Test(expected = IllegalStateException.class)
@Transactional
public void indexAccessWithFullAndNoIndexNameShouldFail() {
public void indexAccessWithFullAndNoIndexNameShouldFail() throws Throwable {
try {
// This no longer blows up at access time, but rather at startup
ClassPathXmlApplicationContext appCtx = new ClassPathXmlApplicationContext(
"org/springframework/data/neo4j/aspects/support/illegal-index2-tests-context.xml");
} catch (BeanCreationException bce) {
Throwable t = bce.getCause().getCause().getCause().getCause();
assertEquals("unexpected underlying cause",
IllegalStateException.class, t.getClass());
return;
}
createAppCtxAndPropagateRootExceptionIfThrown(InvalidIndexed.class);
fail("Should never get here ...");
//InvalidIndexed invalidIndexed = persist(new InvalidIndexed());
//invalidIndexed.setFulltextNoIndexName(NAME_VALUE);
}
/**
* As the first illegal entity detected will blow up the application context - we need a way
* to ensure only the illegal entity under test it loaded to assert that we fail
* for the correct reason and in an appropriate way. This method will create and application
* context ensuring that only the illegal entity under test (passed in as an argument), is
* detected by the context. This is currently done by wrapping each Illegal Entity bootstrap
* logic in a Spring profile against its same name
*
* @param entityUnderTest Class which should be detected by SDN for the purposes of testing
* @throws Throwable
*/
private void createAppCtxAndPropagateRootExceptionIfThrown(Class entityUnderTest) throws Throwable {
try {
ClassPathXmlApplicationContext appCtx = new ClassPathXmlApplicationContext();
appCtx.setConfigLocation("org/springframework/data/neo4j/aspects/support/illegal-index2-tests-context.xml");
appCtx.getEnvironment().setActiveProfiles( entityUnderTest.getSimpleName() );
appCtx.refresh();
} catch (BeanCreationException bce) {
throw ExceptionUtils.getRootCause(bce);
}
}
}

View File

@@ -9,8 +9,6 @@
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:annotation-config/>
<!-- Base Package is mandatory for using label based indexing -->
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.aspects.support.domain"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>

View File

@@ -1,131 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>
<context:component-scan base-package="org.springframework.data.neo4j.aspects.support" />
<bean id="neo4jNodeBacking" class="org.springframework.data.neo4j.aspects.support.node.Neo4jNodeBacking" factory-method="aspectOf">
<property name="template" ref="template"/>
<property name="nodeEntityStateFactory" ref="nodeEntityStateFactory"/>
</bean>
<bean class="org.springframework.data.neo4j.aspects.support.relationship.Neo4jRelationshipBacking" factory-method="aspectOf">
<property name="template" ref="template"/>
<property name="relationshipEntityStateFactory" ref="relationshipEntityStateFactory"/>
</bean>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown" scope="singleton"/>
<bean id="conversionService" class="org.springframework.data.neo4j.fieldaccess.Neo4jConversionServiceFactoryBean"/>
<bean id="indexCreationMappingEventListener" class="org.springframework.data.neo4j.support.mapping.EntityIndexCreator">
<constructor-arg ref="indexProvider" />
<constructor-arg ref="schemaIndexProvider" />
<constructor-arg ref="nodeTypeRepresentationStrategy" />
</bean>
<bean id="mappingInfrastructure" class="org.springframework.data.neo4j.support.MappingInfrastructureFactoryBean">
<property name="graphDatabaseService" ref="graphDatabaseService"/>
<property name="conversionService" ref="conversionService"/>
<property name="mappingContext" ref="mappingContext"/>
<property name="entityStateHandler" ref="entityStateHandler"/>
<property name="nodeTypeRepresentationStrategy" ref="nodeTypeRepresentationStrategy"/>
<property name="nodeEntityStateFactory" ref="nodeEntityStateFactory"/>
<property name="nodeEntityInstantiator" ref="graphEntityInstantiator"/>
<property name="relationshipTypeRepresentationStrategy" ref="relationshipTypeRepresentationStrategy"/>
<property name="relationshipEntityStateFactory" ref="relationshipEntityStateFactory"/>
<property name="relationshipEntityInstantiator" ref="relationshipEntityInstantiator"/>
<property name="validator">
<bean class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
</property>
</bean>
<bean id="template" class="org.springframework.data.neo4j.support.Neo4jTemplate">
<constructor-arg name="infrastructure" ref="mappingInfrastructure"/>
</bean>
<bean id="indexProvider" class="org.springframework.data.neo4j.support.index.IndexProviderImpl">
<constructor-arg ref="graphDatabase" />
</bean>
<bean id="schemaIndexProvider" class="org.springframework.data.neo4j.support.schema.SchemaIndexProvider">
<constructor-arg ref="graphDatabase" />
</bean>
<bean id="entityStateHandler" class="org.springframework.data.neo4j.support.mapping.EntityStateHandler">
<constructor-arg ref="mappingContext"/>
<constructor-arg ref="graphDatabase"/>
</bean>
<bean id="graphDatabase" class="org.springframework.data.neo4j.support.DelegatingGraphDatabase">
<constructor-arg ref="graphDatabaseService"/>
</bean>
<bean id="relationshipEntityInstantiator" class="org.springframework.data.neo4j.support.relationship.RelationshipEntityInstantiator">
<constructor-arg ref="entityStateHandler"/>
</bean>
<bean id="graphEntityInstantiator" class="org.springframework.data.neo4j.support.node.NodeEntityInstantiator">
<constructor-arg ref="entityStateHandler"/>
</bean>
<bean id="typeRepresentationStrategyFactory" class="org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory">
<constructor-arg ref="graphDatabase"/>
</bean>
<bean id="nodeTypeRepresentationStrategy" factory-bean="typeRepresentationStrategyFactory" factory-method="getNodeTypeRepresentationStrategy" />
<bean id="relationshipTypeRepresentationStrategy" factory-bean="typeRepresentationStrategyFactory" factory-method="getRelationshipTypeRepresentationStrategy"/>
<bean id="nodeEntityStateFactory" class="org.springframework.data.neo4j.support.node.NodeEntityStateFactory">
<constructor-arg ref="mappingContext"/>
<constructor-arg>
<bean class="org.springframework.data.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory$Factory"/>
</constructor-arg>
</bean>
<bean id="mappingContext" class="org.springframework.data.neo4j.support.mapping.Neo4jMappingContext">
<!-- NW-ISSUE01 Possibility for getting around some of the schema vs data tx issues
is to set the initialEntitySet upfront, however its a pain to do this
manually would probably be better if we could detect all the entities
at startup rather than requiring them to be explicitly set here ... -->
<property name="initialEntitySet" >
<set>
<value>org.springframework.data.neo4j.aspects.support.domain.TypeAliasedThing</value>
<value>org.springframework.data.neo4j.aspects.support.domain.TypeAliasedSubThing</value>
<value>org.springframework.data.neo4j.aspects.support.domain.TypeAliasedSubSubThing</value>
</set>
</property>
</bean>
<bean id="relationshipEntityStateFactory" class="org.springframework.data.neo4j.support.relationship.RelationshipEntityStateFactory">
<constructor-arg ref="mappingContext"/>
<constructor-arg>
<bean class="org.springframework.data.neo4j.fieldaccess.RelationshipDelegatingFieldAccessorFactory$Factory"/>
</constructor-arg>
</bean>
<bean id="transactionManager" class="org.springframework.data.neo4j.config.JtaTransactionManagerFactoryBean">
<constructor-arg ref="graphDatabaseService"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<!-- Adds dependency checks for setters annotated with @Required -->
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" />
<bean class="org.springframework.data.neo4j.support.Neo4jExceptionTranslator"/>
</beans>

View File

@@ -8,6 +8,17 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- TODO : Simplify to get to something like below
<context:annotation-config/>
<neo4j:repositories base-package="org.springframework.data.neo4j.aspects" />
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.aspects"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
<bean id="template" class="org.springframework.data.neo4j.support.Neo4jTemplate">
<constructor-arg name="infrastructure" ref="mappingInfrastructure"/>
</bean-->
<context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>
<context:component-scan base-package="org.springframework.data.neo4j.aspects">

View File

@@ -4,6 +4,5 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="noopNodeStrategy" class="org.springframework.data.neo4j.support.typerepresentation.NoopNodeTypeRepresentationStrategy" />
<bean id="noopRelationshipStrategy" class="org.springframework.data.neo4j.support.typerepresentation.NoopRelationshipTypeRepresentationStrategy" />
</beans>

View File

@@ -8,145 +8,9 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>
<context:annotation-config/>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.illegal.aspects.index2" />
<neo4j:repositories base-package="org.springframework.data.neo4j.aspects"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
<context:component-scan base-package="org.springframework.data.neo4j.aspects">
<context:exclude-filter expression=".*_Roo_.*" type="regex"/>
<context:exclude-filter expression="org.springframework.context.annotation.Configuration" type="annotation"/>
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
<bean id="neo4jNodeBacking" class="org.springframework.data.neo4j.aspects.support.node.Neo4jNodeBacking" factory-method="aspectOf">
<property name="template" ref="template"/>
<property name="nodeEntityStateFactory" ref="nodeEntityStateFactory"/>
</bean>
<bean class="org.springframework.data.neo4j.aspects.support.relationship.Neo4jRelationshipBacking" factory-method="aspectOf">
<property name="template" ref="template"/>
<property name="relationshipEntityStateFactory" ref="relationshipEntityStateFactory"/>
</bean>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown" scope="singleton"/>
<bean id="conversionService" class="org.springframework.data.neo4j.fieldaccess.Neo4jConversionServiceFactoryBean"/>
<bean id="indexCreationMappingEventListener" class="org.springframework.data.neo4j.support.mapping.EntityIndexCreator">
<constructor-arg ref="indexProvider" />
<constructor-arg ref="schemaIndexProvider" />
</bean>
<bean id="mappingInfrastructure" class="org.springframework.data.neo4j.support.MappingInfrastructureFactoryBean">
<property name="graphDatabaseService" ref="graphDatabaseService"/>
<property name="conversionService" ref="conversionService"/>
<property name="mappingContext" ref="mappingContext"/>
<property name="entityStateHandler" ref="entityStateHandler"/>
<property name="nodeTypeRepresentationStrategy" ref="nodeTypeRepresentationStrategy"/>
<property name="nodeEntityStateFactory" ref="nodeEntityStateFactory"/>
<property name="nodeEntityInstantiator" ref="graphEntityInstantiator"/>
<property name="relationshipTypeRepresentationStrategy" ref="relationshipTypeRepresentationStrategy"/>
<property name="relationshipEntityStateFactory" ref="relationshipEntityStateFactory"/>
<property name="relationshipEntityInstantiator" ref="relationshipEntityInstantiator"/>
<property name="validator">
<bean class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
</property>
</bean>
<bean id="template" class="org.springframework.data.neo4j.support.Neo4jTemplate">
<constructor-arg name="infrastructure" ref="mappingInfrastructure"/>
</bean>
<bean id="indexProvider" class="org.springframework.data.neo4j.support.index.IndexProviderImpl">
<constructor-arg ref="graphDatabase" />
</bean>
<bean id="schemaIndexProvider" class="org.springframework.data.neo4j.support.schema.SchemaIndexProvider">
<constructor-arg ref="graphDatabase" />
</bean>
<bean id="entityStateHandler" class="org.springframework.data.neo4j.support.mapping.EntityStateHandler">
<constructor-arg ref="mappingContext"/>
<constructor-arg ref="graphDatabase"/>
</bean>
<bean id="graphDatabase" class="org.springframework.data.neo4j.support.DelegatingGraphDatabase">
<constructor-arg ref="graphDatabaseService"/>
</bean>
<bean id="relationshipEntityInstantiator" class="org.springframework.data.neo4j.support.relationship.RelationshipEntityInstantiator">
<constructor-arg ref="entityStateHandler"/>
</bean>
<bean id="graphEntityInstantiator" class="org.springframework.data.neo4j.support.node.NodeEntityInstantiator">
<constructor-arg ref="entityStateHandler"/>
</bean>
<bean id="typeRepresentationStrategyFactory" class="org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory">
<constructor-arg ref="graphDatabase"/>
</bean>
<bean id="nodeTypeRepresentationStrategy" factory-bean="typeRepresentationStrategyFactory" factory-method="getNodeTypeRepresentationStrategy" />
<bean id="relationshipTypeRepresentationStrategy" factory-bean="typeRepresentationStrategyFactory" factory-method="getRelationshipTypeRepresentationStrategy"/>
<bean id="nodeEntityStateFactory" class="org.springframework.data.neo4j.support.node.NodeEntityStateFactory">
<constructor-arg ref="mappingContext"/>
<constructor-arg>
<bean class="org.springframework.data.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory$Factory"/>
</constructor-arg>
</bean>
<!--bean class="org.springframework.data.neo4j.aspects.config.Neo4jAspectConfiguration">
<property name="basePackage" value="org.springframework.data.neo4j.aspects"/>
</bean-->
<bean id="mappingContext" class="org.springframework.data.neo4j.support.mapping.Neo4jMappingContext">
<property name="initialEntitySet">
<set>
<value>org.springframework.data.neo4j.illegal.aspects.index2.IllegalIndex2Tests$InvalidIndexed</value>
</set>
</property>
<property name="entityIndexCreator" ref="indexCreationMappingEventListener" />
</bean>
<bean id="relationshipEntityStateFactory" class="org.springframework.data.neo4j.support.relationship.RelationshipEntityStateFactory">
<constructor-arg ref="mappingContext"/>
<constructor-arg>
<bean class="org.springframework.data.neo4j.fieldaccess.RelationshipDelegatingFieldAccessorFactory$Factory"/>
</constructor-arg>
</bean>
<bean id="transactionManager" class="org.springframework.data.neo4j.config.JtaTransactionManagerFactoryBean">
<constructor-arg ref="graphDatabaseService"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<bean id="personRepository" class="org.springframework.data.neo4j.repository.GraphRepositoryFactoryBean">
<property name="repositoryInterface" value="org.springframework.data.neo4j.aspects.PersonRepository" />
<property name="neo4jTemplate" ref="template"/>
<property name="namedQueries">
<bean class="org.springframework.data.repository.core.support.PropertiesBasedNamedQueries">
<constructor-arg>
<props><prop key="Person.findTeam">start p=node({p_person}) match (p)&lt;-[:persons]-(group) return group</prop></props>
</constructor-arg>
</bean>
</property>
</bean>
<bean id="groupRepository" class="org.springframework.data.neo4j.repository.GraphRepositoryFactoryBean">
<property name="repositoryInterface" value="org.springframework.data.neo4j.aspects.GroupRepository" />
<property name="neo4jTemplate" ref="template"/>
</bean>
<bean id="friendshipRepository" class="org.springframework.data.neo4j.repository.GraphRepositoryFactoryBean">
<property name="repositoryInterface" value="org.springframework.data.neo4j.aspects.FriendshipRepository" />
<property name="neo4jTemplate" ref="template"/>
</bean>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<!-- Adds dependency checks for setters annotated with @Required -->
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" />
<bean class="org.springframework.data.neo4j.support.Neo4jExceptionTranslator"/>
</beans>
</beans>