diff --git a/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/NonNullNamed.java b/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/NonNullNamed.java new file mode 100644 index 000000000..bc2a456db --- /dev/null +++ b/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/NonNullNamed.java @@ -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; +} \ No newline at end of file diff --git a/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/illegal/aspects/index1/IllegalIndex1Tests.java b/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/illegal/aspects/index1/IllegalIndex1Tests.java index 306cb0da3..dd447d562 100644 --- a/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/illegal/aspects/index1/IllegalIndex1Tests.java +++ b/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/illegal/aspects/index1/IllegalIndex1Tests.java @@ -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); + } + } + } diff --git a/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/illegal/aspects/index2/IllegalIndex2Tests.java b/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/illegal/aspects/index2/IllegalIndex2Tests.java index 9228a41a1..408c3a718 100644 --- a/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/illegal/aspects/index2/IllegalIndex2Tests.java +++ b/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/illegal/aspects/index2/IllegalIndex2Tests.java @@ -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); + } + } + + + } diff --git a/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/LabelBasedIndexedPropertyEntityTests-context-basic.xml b/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/LabelBasedIndexedPropertyEntityTests-context-basic.xml index ec18b764d..0a173ad92 100644 --- a/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/LabelBasedIndexedPropertyEntityTests-context-basic.xml +++ b/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/LabelBasedIndexedPropertyEntityTests-context-basic.xml @@ -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"> - - diff --git a/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/LabelBasedIndexedPropertyEntityTests-context-with-initialset.xml b/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/LabelBasedIndexedPropertyEntityTests-context-with-initialset.xml deleted file mode 100644 index 389c8543a..000000000 --- a/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/LabelBasedIndexedPropertyEntityTests-context-with-initialset.xml +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.springframework.data.neo4j.aspects.support.domain.TypeAliasedThing - org.springframework.data.neo4j.aspects.support.domain.TypeAliasedSubThing - org.springframework.data.neo4j.aspects.support.domain.TypeAliasedSubSubThing - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTests-context.xml b/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTests-context.xml index 58051190a..12a504bb8 100644 --- a/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTests-context.xml +++ b/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTests-context.xml @@ -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"> + + + diff --git a/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/NoopTypeRepresentationStrategyOverride-context.xml b/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/NoopTypeRepresentationStrategyOverride-context.xml index abc3a5693..c651fc646 100644 --- a/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/NoopTypeRepresentationStrategyOverride-context.xml +++ b/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/NoopTypeRepresentationStrategyOverride-context.xml @@ -4,6 +4,5 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - \ No newline at end of file diff --git a/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/illegal-index2-tests-context.xml b/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/illegal-index2-tests-context.xml index 31f11f540..8901a681b 100644 --- a/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/illegal-index2-tests-context.xml +++ b/spring-data-neo4j-aspects/src/test/resources/org/springframework/data/neo4j/aspects/support/illegal-index2-tests-context.xml @@ -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"> - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.springframework.data.neo4j.illegal.aspects.index2.IllegalIndex2Tests$InvalidIndexed - - - - - - - - - - - - - - - - - - - - - - - - - start p=node({p_person}) match (p)<-[:persons]-(group) return group - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file