diff --git a/pom.xml b/pom.xml index f5d07710e3..1ade39698d 100644 --- a/pom.xml +++ b/pom.xml @@ -156,7 +156,6 @@ examples spring-data-neo4j-examples/hello-worlds - spring-data-neo4j-examples/hello-worlds-aspects spring-data-neo4j-examples/imdb spring-data-neo4j-examples/cineasts spring-data-neo4j-examples/cineasts-aspects diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/.gitignore b/spring-data-neo4j-examples/hello-worlds-aspects/.gitignore deleted file mode 100644 index f092f6270e..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -lib -.ivy -.gradle -target -*.ipr -*.iml -*.iws -.classpath -.project -.settings - diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/README.md b/spring-data-neo4j-examples/hello-worlds-aspects/README.md deleted file mode 100644 index 70d44f7590..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/README.md +++ /dev/null @@ -1,14 +0,0 @@ -Hello Worlds -============ - -A simple Spring Data Neo4j example with just enough code to -do something that works. - -This version of the project takes advantage of the niceties -provided by spring-data-neo4j-aspects, which enhances the -Plain Old Java Objects into Deluxe Aspect Java Objects. - -Build and Run -------------- - -`mvn clean package exec:java` diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/build.gradle b/spring-data-neo4j-examples/hello-worlds-aspects/build.gradle deleted file mode 100644 index 7ffdbf9b75..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/build.gradle +++ /dev/null @@ -1,27 +0,0 @@ -sourceCompatibility = 1.6 -targetCompatibility = 1.6 - -apply plugin: 'idea' -apply plugin: 'eclipse' - - -springVersion = "3.0.7.RELEASE" -springDataNeo4jVersion = "2.0.0.RELEASE" -aspectjVersion = "1.6.12" - -apply from:'https://github.com/SpringSource/spring-data-neo4j/raw/master/build/gradle/springdataneo4j.gradle' - -configurations { - runtime - testCompile -} -repositories { - mavenCentral() - mavenLocal() - mavenRepo urls: "http://maven.springframework.org/release" -} - - -dependencies{ - testCompile group:"junit", name: "junit", version: "4.8" -} diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/build.xml b/spring-data-neo4j-examples/hello-worlds-aspects/build.xml deleted file mode 100644 index 60a0d7f3dd..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/build.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/pom.xml b/spring-data-neo4j-examples/hello-worlds-aspects/pom.xml deleted file mode 100644 index a4808f42a2..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/pom.xml +++ /dev/null @@ -1,210 +0,0 @@ - - 4.0.0 - - org.springframework.data.examples - spring-data-neo4j-hello-worlds-aspects - 2.1.0.BUILD-SNAPSHOT - jar - - Spring Data Neo4j hello-worlds Aspects - - - UTF-8 - 3.0.7.RELEASE - 1.6.12 - 1.6.1 - ${project.version} - - - - - spring-maven-release - Spring Maven Release Repository - http://maven.springframework.org/release - - - spring-maven-snapshot - Spring Maven Snapshot Repository - - true - - http://maven.springframework.org/snapshot - - - spring-maven-milestone - Spring Maven Milestone Repository - http://maven.springframework.org/milestone - - - neo4j-release-repository - Neo4j Maven 2 release repository - http://m2.neo4j.org/releases - - true - - - false - - - - neo4j-snapshot-repository - Neo4j Maven 2 snapshot repository - http://m2.neo4j.org/snapshots - - true - - - false - - - - - - - spring-maven-release - Spring Maven Release Repository - http://maven.springframework.org/release - - - spring-maven-milestone - Spring Maven Milestone Repository - http://maven.springframework.org/milestone - - - - - - junit - junit - 4.8.1 - test - - - org.springframework - spring-test - ${spring.version} - test - - - commons-logging - commons-logging - - - - - org.springframework.data - spring-data-neo4j-aspects - ${spring-data-neo4j.version} - - - cglib - cglib-nodep - 2.2 - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.1 - - 1.6 - 1.6 - - - - - - org.codehaus.mojo - aspectj-maven-plugin - 1.2 - - true - - - org.springframework - spring-aspects - - - org.springframework.data - spring-data-neo4j-aspects - - - 1.6 - 1.6 - - - - - compile - test-compile - - - - - - org.aspectj - aspectjrt - ${aspectj.version} - - - org.aspectj - aspectjtools - ${aspectj.version} - - - - - - - org.apache.maven.plugins - maven-eclipse-plugin - 2.8 - - - 1.5 - - org.eclipse.ajdt.ui.ajnature - org.eclipse.jdt.core.javanature - org.springframework.ide.eclipse.core.springnature - - - - - - - org.apache.maven.plugins - maven-idea-plugin - 2.2 - - true - true - - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.2 - - - - exec - - - - - org.springframework.data.neo4j.examples.hellograph.App - - - - - - diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/settings/install-ivy.xml b/spring-data-neo4j-examples/hello-worlds-aspects/settings/install-ivy.xml deleted file mode 100644 index 314d20d9a8..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/settings/install-ivy.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/settings/ivy.xml b/spring-data-neo4j-examples/hello-worlds-aspects/settings/ivy.xml deleted file mode 100644 index 5fb5f95e13..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/settings/ivy.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/settings/ivysettings.xml b/spring-data-neo4j-examples/hello-worlds-aspects/settings/ivysettings.xml deleted file mode 100644 index 704bb0fbc8..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/settings/ivysettings.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/settings/path.xml b/spring-data-neo4j-examples/hello-worlds-aspects/settings/path.xml deleted file mode 100644 index 3d49c706bc..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/settings/path.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/App.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/App.java deleted file mode 100644 index 16f3f34499..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/App.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -/** - * Hello world(s)! - *

- * An example application for exploring Spring Data Neo4j. - */ -public class App -{ - - public static void main( String[] args ) - { - - ConfigurableApplicationContext applicationContext = - new ClassPathXmlApplicationContext( "/spring/helloWorldContext.xml"); - - WorldRepositoryImpl galaxy = applicationContext.getBean(WorldRepositoryImpl.class); - - Iterable worlds = galaxy.makeSomeWorlds(); - - World homeWorld = worlds.iterator().next(); - System.out.println("At home on: " + homeWorld); - - World foundHomeWorld = galaxy.findWorldNamed( homeWorld.getName() ); - System.out.println( "found home world: " + foundHomeWorld ); - - Iterable worldsBeyond = galaxy.exploreWorldsBeyond( homeWorld ); - for (World world : worldsBeyond) { - System.out.println( "found worlds beyond: " + world ); - } - - applicationContext.close(); - - } - -} diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/MyWorldRepository.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/MyWorldRepository.java deleted file mode 100644 index ead3954a65..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/MyWorldRepository.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.springframework.transaction.annotation.Transactional; - -import java.util.Collection; - -/** - * @author mh - * @since 01.04.11 - */ -public interface MyWorldRepository { - @Transactional - Collection makeSomeWorlds(); - - @Transactional - World world(String name, int moons); - - World findWorldNamed(String name); - - Iterable findWorldsWithMoons(int moonCount); - - Iterable exploreWorldsBeyond(World homeWorld); -} diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/RelationshipTypes.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/RelationshipTypes.java deleted file mode 100644 index 6f66f5f376..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/RelationshipTypes.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -public abstract class RelationshipTypes -{ - public static final String REACHABLE_BY_ROCKET = "REACHABLE_BY_ROCKET"; -} diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java deleted file mode 100644 index 7f34379e59..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - - -import org.neo4j.graphdb.Direction; -import org.springframework.data.neo4j.annotation.Indexed; -import org.springframework.data.neo4j.annotation.NodeEntity; -import org.springframework.data.neo4j.annotation.RelatedTo; - -import java.util.Set; - -/** - * A Spring Data Neo4j enhanced World entity. - *

- * This is the initial POJO in the Universe. - */ -@NodeEntity -public class World -{ - @Indexed - private String name; - - @Indexed(indexName = "moon-index") - private int moons; - - @RelatedTo(type = "REACHABLE_BY_ROCKET", elementClass = World.class, direction = Direction.BOTH) - private Set reachableByRocket; - - public World( String name, int moons ) - { - this.name = name; - this.moons = moons; - } - - public World() - { - } - - public String getName() - { - return name; - } - - public int getMoons() - { - return moons; - } - - @Override - public String toString() - { - return String.format("World{name='%s, moons=%d}", name, moons); - } - - public void addRocketRouteTo( World otherWorld ) - { - relateTo( otherWorld, RelationshipTypes.REACHABLE_BY_ROCKET ); - } - - public boolean canBeReachedFrom( World otherWorld ) - { - return reachableByRocket.contains( otherWorld ); - } -} diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldCounter.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldCounter.java deleted file mode 100644 index 7ff6e2e914..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldCounter.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author mh - * @since 17.02.11 - */ -public class WorldCounter { - - public Map countMoons(Iterable worlds) { - Map moons = new HashMap(); - for (World world : worlds) { - moons.put(world.getName(), world.getMoons()); - } - return moons; - } - -} diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepository.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepository.java deleted file mode 100644 index f529c4d671..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.springframework.data.neo4j.repository.GraphRepository; -import org.springframework.data.neo4j.repository.NamedIndexRepository; - -/** - * @author mh - * @since 01.04.11 - */ -public interface WorldRepository extends MyWorldRepository, GraphRepository, NamedIndexRepository { -} diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryImpl.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryImpl.java deleted file mode 100644 index 286db03466..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.neo4j.graphdb.Direction; -import org.neo4j.graphdb.traversal.TraversalDescription; -import org.neo4j.kernel.Traversal; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; - -import java.util.ArrayList; -import java.util.Collection; - -import static org.neo4j.graphdb.DynamicRelationshipType.withName; -import static org.springframework.data.neo4j.examples.hellograph.RelationshipTypes.REACHABLE_BY_ROCKET; - -/** - * Spring Data Neo4j backed application context for Worlds. - */ -public class WorldRepositoryImpl implements MyWorldRepository { - - @Autowired private WorldRepository worldRepository; - - @Override - @Transactional - public Collection makeSomeWorlds() { - ArrayList newWorlds = new ArrayList(); - - // solar worlds - newWorlds.add(world("Mercury", 0)); - newWorlds.add(world("Venus", 0)); - World earth = world("Earth", 1); - newWorlds.add(earth); - World mars = world("Mars", 2); - mars.addRocketRouteTo(earth); - newWorlds.add(mars); - newWorlds.add(world("Jupiter", 63)); - newWorlds.add(world("Saturn", 62)); - newWorlds.add(world("Uranus", 27)); - newWorlds.add(world("Neptune", 13)); - - // Norse worlds - newWorlds.add(world("Alfheimr", 0)); - newWorlds.add(world("Midgard", 1)); - newWorlds.add(world("Muspellheim", 2)); - newWorlds.add(world("Asgard", 63)); - newWorlds.add(world("Hel", 62)); - - return newWorlds; - } - - - @Override - @Transactional - public World world(String name, int moons) { - World createdWorld = findWorldNamed(name); - if (createdWorld == null) { - createdWorld = new World(name, moons).persist(); - } - return createdWorld; - } - - @Override - public World findWorldNamed(String name) { - return worldRepository.findByPropertyValue("name", name); - } - - @Override - public Iterable findWorldsWithMoons(int moonCount) { - return worldRepository.findAllByPropertyValue("moon-index", "moons", moonCount); - } - - @Override - public Iterable exploreWorldsBeyond(World homeWorld) { - TraversalDescription traversal = Traversal.description().relationships(withName(REACHABLE_BY_ROCKET), Direction.OUTGOING); - return worldRepository.findAllByTraversal(homeWorld, traversal); - } - -} diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/resources/log4j.properties b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/resources/log4j.properties deleted file mode 100644 index beb86feab7..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout - -# Print the date in ISO 8601 format -log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n - -log4j.rootLogger=ERROR, stdout diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldCounterTest.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldCounterTest.java deleted file mode 100644 index 8b2ddf6ad3..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldCounterTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.junit.Test; -import org.junit.runner.RunWith; -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.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.transaction.BeforeTransaction; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Map; - -import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; - -/** - * @author mh - * @since 17.02.11 - * Added to check for some aspectj-snapshot build errors. - */ -@ContextConfiguration(locations = "classpath:spring/helloWorldContext.xml") -@RunWith(SpringJUnit4ClassRunner.class) -@Transactional -public class WorldCounterTest { - - @Autowired - private Neo4jTemplate template; - - @Rollback(false) - @BeforeTransaction - public void clearDatabase() - { - Neo4jHelper.cleanDb(template); - } - - @Test - public void testCountMoons() throws Exception { - WorldCounter counter = new WorldCounter(); - Map result = counter.countMoons(asList(new World("earth", 1))); - assertEquals("earth has one moon",(Integer)1,result.get("earth")); - } -} diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryTest.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryTest.java deleted file mode 100644 index 55b70bfc5d..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryTest.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.neo4j.aspects.core.NodeBacked; -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.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; - -import static junit.framework.Assert.assertEquals; -import static org.hamcrest.CoreMatchers.anyOf; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; -import static org.junit.internal.matchers.StringContains.containsString; - -/** - * Exploratory testing of Spring Data Neo4j using - * the WorldRepositoryImpl. - */ -@ContextConfiguration(locations = "classpath:spring/helloWorldContext.xml") -@RunWith(SpringJUnit4ClassRunner.class) -@Transactional -public class WorldRepositoryTest -{ - - @Autowired - private WorldRepository galaxy; - - @Autowired - private Neo4jTemplate template; - - @Rollback(false) - @BeforeTransaction - public void clearDatabase() - { - Neo4jHelper.cleanDb(template); - } - - @Test - public void shouldAllowDirectWorldCreation() - { - assertEquals(0, (long) galaxy.count()); - World myWorld = new World( "mine", 0 ).persist(); - assertEquals(1, (long) galaxy.count()); - Iterable foundWorlds = galaxy.findAll(); - World mine = foundWorlds.iterator().next(); - assertEquals(myWorld.getName(), mine.getName()); - } - - @Test - public void shouldPopulateGalaxyWithWorlds() - { - Iterable worlds = galaxy.makeSomeWorlds(); - assertNotNull( worlds ); - } - - - @Test - public void shouldHaveCorrectNumberOfWorlds() - { - galaxy.makeSomeWorlds(); - assertEquals(13, (long) galaxy.count()); - } - - @Test - public void shouldFindWorldsById() - { - for ( World w : galaxy.makeSomeWorlds() ) - { - assertNotNull(galaxy.findOne(((NodeBacked) w).getNodeId())); - } - } - - @Test - public void shouldFindAllWorlds() - { - Collection madeWorlds = galaxy.makeSomeWorlds(); - Iterable foundWorlds = galaxy.findAll(); - - int countOfFoundWorlds = 0; - for ( World foundWorld : foundWorlds ) - { - assertTrue( madeWorlds.contains( foundWorld ) ); - countOfFoundWorlds++; - } - - assertEquals( madeWorlds.size(), countOfFoundWorlds ); - } - - @Test - public void shouldFindWorldsByName() - { - for ( World w : galaxy.makeSomeWorlds() ) - { - assertNotNull( galaxy.findWorldNamed( w.getName() ) ); - } - } - - @SuppressWarnings("unchecked") - @Test - public void shouldFindWorldsWith1Moon() - { - galaxy.makeSomeWorlds(); - for ( World worldWithOneMoon : galaxy.findWorldsWithMoons( 1 ) ) - { - assertThat( worldWithOneMoon.getName(), is( anyOf( containsString( "Earth" ), containsString( "Midgard" ) ) ) ); - } - } - - @Test - public void shouldReachMarsFromEarth() - { - galaxy.makeSomeWorlds(); - - World earth = galaxy.findWorldNamed( "Earth" ); - World mars = galaxy.findWorldNamed( "Mars" ); - - assertTrue( mars.canBeReachedFrom( earth ) ); - assertTrue( earth.canBeReachedFrom( mars ) ); - } - -} diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldTest.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldTest.java deleted file mode 100644 index 571cfd42a9..0000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.junit.Test; -import org.junit.runner.RunWith; -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.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.assertNull; - -/** - * Exploratory unit-tests for the Spring Data Neo4j annotated World entity. - * - * Since the World is a @NodeEntity, the SpringDataGraph must - * be setup before you can even create instances of the POJO. - */ -@ContextConfiguration(locations = "classpath:spring/helloWorldContext.xml") -@RunWith(SpringJUnit4ClassRunner.class) -@Transactional -public class WorldTest -{ - - @Autowired - private Neo4jTemplate template; - - @Rollback(false) - @BeforeTransaction - public void clearDatabase() - { - Neo4jHelper.cleanDb(template); - } - - @Test - public void shouldBeSimpleToCreateNewEntities() - { - @SuppressWarnings("unused") - World w = new World(); - } - - @Test - public void shouldHaveNullNameUsingDefaultConstructor() - { - World w = new World(); - assertNull(w.getName()); - } -} diff --git a/spring-data-neo4j-examples/hello-worlds/pom.xml b/spring-data-neo4j-examples/hello-worlds/pom.xml index 2b7d289f0b..ec02a14e18 100644 --- a/spring-data-neo4j-examples/hello-worlds/pom.xml +++ b/spring-data-neo4j-examples/hello-worlds/pom.xml @@ -1,178 +1,300 @@ - 4.0.0 - - org.springframework.data.examples - spring-data-neo4j-hello-worlds - 2.1.0.BUILD-SNAPSHOT - jar - - Spring Data Neo4j hello-worlds - - - UTF-8 - 3.0.7.RELEASE - 1.6.12 - 1.6.1 - ${project.version} - - - - - spring-maven-release - Spring Maven Release Repository - http://maven.springframework.org/release - - - spring-maven-snapshot - Spring Maven Snapshot Repository - - true - - http://maven.springframework.org/snapshot - - - spring-maven-milestone - Spring Maven Milestone Repository - http://maven.springframework.org/milestone - - - neo4j-release-repository - Neo4j Maven 2 release repository - http://m2.neo4j.org/releases - - true - - - false - - - - neo4j-snapshot-repository - Neo4j Maven 2 snapshot repository - http://m2.neo4j.org/snapshots - - true - - - false - - - - - - - spring-maven-release - Spring Maven Release Repository - http://maven.springframework.org/release - - - spring-maven-milestone - Spring Maven Milestone Repository - http://maven.springframework.org/milestone - - - - - - junit - junit - 4.8.1 - test - - - org.springframework - spring-test - ${spring.version} - test - - - commons-logging - commons-logging - - - - - org.springframework.data - spring-data-neo4j - ${spring-data-neo4j.version} - - - cglib - cglib-nodep - 2.2 - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.1 - - 1.6 - 1.6 - - - - - - org.apache.maven.plugins - maven-idea-plugin - 2.2 - - true - true - - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.2 - - - - exec - - - - - org.springframework.data.neo4j.examples.hellograph.App - - - - - maven-assembly-plugin - - hello-worlds-${project.version} - false - false - - - org.springframework.data.neo4j.examples.hellograph.App - - - - jar-with-dependencies - - - - - make-assembly - package - - single - - - - - - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + org.springframework.data.examples + spring-data-neo4j-hello-worlds + 2.1.0.BUILD-SNAPSHOT + jar + + Spring Data Neo4j hello-worlds + + + UTF-8 + 3.0.7.RELEASE + 1.6.12 + 1.6.1 + ${project.version} + + + + + spring-maven-release + Spring Maven Release Repository + http://maven.springframework.org/release + + + spring-maven-snapshot + Spring Maven Snapshot Repository + + true + + http://maven.springframework.org/snapshot + + + spring-maven-milestone + Spring Maven Milestone Repository + http://maven.springframework.org/milestone + + + neo4j-release-repository + Neo4j Maven 2 release repository + http://m2.neo4j.org/releases + + true + + + false + + + + neo4j-snapshot-repository + Neo4j Maven 2 snapshot repository + http://m2.neo4j.org/snapshots + + true + + + false + + + + + + + spring-maven-release + Spring Maven Release Repository + http://maven.springframework.org/release + + + spring-maven-milestone + Spring Maven Milestone Repository + http://maven.springframework.org/milestone + + + + + + junit + junit + 4.8.1 + test + + + org.springframework + spring-test + ${spring.version} + test + + + commons-logging + commons-logging + + + + + cglib + cglib-nodep + 2.2 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.1 + + 1.6 + 1.6 + + + + + + org.apache.maven.plugins + maven-idea-plugin + 2.2 + + true + true + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2 + + + + exec + + + + + org.springframework.data.neo4j.examples.hellograph.App + + + + + maven-assembly-plugin + + hello-worlds-${project.version} + false + false + + + org.springframework.data.neo4j.examples.hellograph.App + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + maven-resources-plugin + + + initialize + + resources + + + + + + + + + + + plain + + + org.springframework.data + spring-data-neo4j + ${spring-data-neo4j.version} + + + + + + + ${project.basedir}/src/main/resources/spring/plain + ${project.build.directory}/classes/spring + true + + helloWorldContext.xml + + + + + + + aspects + + true + + + + + org.springframework.data + spring-data-neo4j-aspects + ${spring-data-neo4j.version} + + + + + + + + org.codehaus.mojo + aspectj-maven-plugin + 1.2 + + true + + + org.springframework + spring-aspects + + + org.springframework.data + spring-data-neo4j-aspects + + + 1.6 + 1.6 + + + + + compile + test-compile + + + + + + org.aspectj + aspectjrt + ${aspectj.version} + + + org.aspectj + aspectjtools + ${aspectj.version} + + + + + + + org.apache.maven.plugins + maven-eclipse-plugin + 2.8 + + + 1.5 + + org.eclipse.ajdt.ui.ajnature + org.eclipse.jdt.core.javanature + org.springframework.ide.eclipse.core.springnature + + + + + + + ${project.basedir}/src/main/resources/spring/aspects + ${project.build.directory}/classes/spring + true + + helloWorldContext.xml + + + + + + diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/App.java b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/App.java deleted file mode 100644 index 064d864bdb..0000000000 --- a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/App.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -/** - * Hello world(s)! - *

- * An example application for exploring Spring Data Neo4j. - */ -public class App -{ - - public static void main( String[] args ) - { - - ConfigurableApplicationContext applicationContext = - new ClassPathXmlApplicationContext( "/spring/helloWorldContext.xml"); - - WorldRepositoryImpl galaxy = applicationContext.getBean(WorldRepositoryImpl.class); - - galaxy.makeSomeWorlds(); - - World homeWorld = galaxy.findWorldNamed( "Earth" ); - System.out.println( "At home on: " + homeWorld ); - - Iterable worldsBeyond = galaxy.exploreWorldsBeyond( homeWorld ); - for (World world : worldsBeyond) { - System.out.println( "found worlds beyond: " + world ); - } - - applicationContext.close(); - - } - -} diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/GalaxyService.java b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/GalaxyService.java new file mode 100644 index 0000000000..41f9cf7e39 --- /dev/null +++ b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/GalaxyService.java @@ -0,0 +1,68 @@ +package org.springframework.data.neo4j.examples.hellograph; + +import java.util.ArrayList; +import java.util.Collection; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class GalaxyService { + + @Autowired + private WorldRepository worldRepository; + + public long getNumberOfWorlds() { + return worldRepository.count(); + } + + public World createWorld(String name, int moons) { + return worldRepository.save(new World(name, moons)); + } + + public Iterable getAllWorlds() { + return worldRepository.findAll(); + } + + public World findWorldById(Long id) { + return worldRepository.findOne(id); + } + + public World findWorldByName(String name) { + return worldRepository.findByPropertyValue("name", name); + } + + public Iterable findAllByNumberOfMoons(int numberOfMoons) { + return worldRepository.findAllByPropertyValue("moons", numberOfMoons); + } + + public Collection makeSomeWorlds() { + Collection worlds = new ArrayList(); + + // Solar worlds + worlds.add(createWorld("Mercury", 0)); + worlds.add(createWorld("Venus", 0)); + + World earth = createWorld("Earth", 1); + World mars = createWorld("Mars", 2); + mars.addRocketRouteTo(earth); + worldRepository.save(mars); + worlds.add(earth); + worlds.add(mars); + + worlds.add(createWorld("Jupiter", 63)); + worlds.add(createWorld("Saturn", 62)); + worlds.add(createWorld("Uranus", 27)); + worlds.add(createWorld("Neptune", 13)); + + // Norse worlds + worlds.add(createWorld("Alfheimr", 0)); + worlds.add(createWorld("Midgard", 1)); + worlds.add(createWorld("Muspellheim", 2)); + worlds.add(createWorld("Asgard", 63)); + worlds.add(createWorld("Hel", 62)); + + return worlds; + } + +} diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/MyWorldRepository.java b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/MyWorldRepository.java deleted file mode 100644 index ead3954a65..0000000000 --- a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/MyWorldRepository.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.springframework.transaction.annotation.Transactional; - -import java.util.Collection; - -/** - * @author mh - * @since 01.04.11 - */ -public interface MyWorldRepository { - @Transactional - Collection makeSomeWorlds(); - - @Transactional - World world(String name, int moons); - - World findWorldNamed(String name); - - Iterable findWorldsWithMoons(int moonCount); - - Iterable exploreWorldsBeyond(World homeWorld); -} diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/RelationshipTypes.java b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/RelationshipTypes.java deleted file mode 100644 index 6f66f5f376..0000000000 --- a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/RelationshipTypes.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -public abstract class RelationshipTypes -{ - public static final String REACHABLE_BY_ROCKET = "REACHABLE_BY_ROCKET"; -} diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java index 6e02e1b008..a4554a2c99 100644 --- a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java +++ b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java @@ -1,27 +1,19 @@ package org.springframework.data.neo4j.examples.hellograph; - import org.neo4j.graphdb.Direction; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.neo4j.annotation.Fetch; import org.springframework.data.neo4j.annotation.GraphId; import org.springframework.data.neo4j.annotation.Indexed; import org.springframework.data.neo4j.annotation.NodeEntity; import org.springframework.data.neo4j.annotation.RelatedTo; -import org.springframework.data.neo4j.support.Neo4jTemplate; - -import java.util.HashSet; import java.util.Set; -/** - * A Spring Data Neo4j enhanced World entity. - *

- * This is the initial POJO in the Universe. - */ @NodeEntity -public class World -{ - @GraphId Long id; +public class World { + private final static String REACHABLE_BY_ROCKET = "REACHABLE_BY_ROCKET"; + + @GraphId + private Long id; @Indexed private String name; @@ -30,43 +22,35 @@ public class World private int moons; @Fetch - @RelatedTo(type = "REACHABLE_BY_ROCKET", direction = Direction.BOTH) - Set reachableByRocket = new HashSet(); + @RelatedTo(type = REACHABLE_BY_ROCKET, direction = Direction.BOTH) + private Set reachableByRocket; - public World( String name, int moons ) - { + public World(String name, int moons) { this.name = name; this.moons = moons; } - public World() - { + public World() { } - public String getName() - { + public Long getId() { + return id; + } + + public String getName() { return name; } - public int getMoons() - { + public int getMoons() { return moons; - } + } - @Override - public String toString() - { - return String.format("World{name='%s, moons=%d}", name, moons); - } - - public void addRocketRouteTo( World otherWorld ) - { + public void addRocketRouteTo(World otherWorld) { reachableByRocket.add(otherWorld); } - - public boolean canBeReachedFrom( World otherWorld ) - { - return reachableByRocket.contains( otherWorld ); + + public boolean canBeReachedFrom(World otherWorld) { + return reachableByRocket.contains(otherWorld); } @Override @@ -83,4 +67,9 @@ public boolean equals(Object obj) { if (id == null) return other.id == null; return id.equals(other.id); } + + @Override + public String toString() { + return String.format("World{name='%s', moons=%d}", name, moons); + } } diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldCounter.java b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldCounter.java deleted file mode 100644 index 7ff6e2e914..0000000000 --- a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldCounter.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author mh - * @since 17.02.11 - */ -public class WorldCounter { - - public Map countMoons(Iterable worlds) { - Map moons = new HashMap(); - for (World world : worlds) { - moons.put(world.getName(), world.getMoons()); - } - return moons; - } - -} diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepository.java b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepository.java index f529c4d671..350acbf345 100644 --- a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepository.java +++ b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepository.java @@ -1,11 +1,5 @@ package org.springframework.data.neo4j.examples.hellograph; import org.springframework.data.neo4j.repository.GraphRepository; -import org.springframework.data.neo4j.repository.NamedIndexRepository; -/** - * @author mh - * @since 01.04.11 - */ -public interface WorldRepository extends MyWorldRepository, GraphRepository, NamedIndexRepository { -} +public interface WorldRepository extends GraphRepository {} diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryImpl.java b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryImpl.java deleted file mode 100644 index 1abe82a033..0000000000 --- a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.neo4j.graphdb.Direction; -import org.neo4j.graphdb.traversal.TraversalDescription; -import org.neo4j.kernel.Traversal; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; - -import java.util.ArrayList; -import java.util.Collection; - -import static org.neo4j.graphdb.DynamicRelationshipType.withName; -import static org.springframework.data.neo4j.examples.hellograph.RelationshipTypes.REACHABLE_BY_ROCKET; - -/** - * Spring Data Neo4j backed application context for Worlds. - */ -public class WorldRepositoryImpl implements MyWorldRepository { - - @Autowired private WorldRepository worldRepository; - - @Override - @Transactional - public Collection makeSomeWorlds() { - ArrayList newWorlds = new ArrayList(); - - // solar worlds - newWorlds.add(world("Mercury", 0)); - newWorlds.add(world("Venus", 0)); - World earth = world("Earth", 1); - newWorlds.add(earth); - - World mars = world("Mars", 2); - earth.addRocketRouteTo(mars); - worldRepository.save(earth); - - newWorlds.add(mars); - newWorlds.add(world("Jupiter", 63)); - newWorlds.add(world("Saturn", 62)); - newWorlds.add(world("Uranus", 27)); - newWorlds.add(world("Neptune", 13)); - - // Norse worlds - newWorlds.add(world("Alfheimr", 0)); - newWorlds.add(world("Midgard", 1)); - newWorlds.add(world("Muspellheim", 2)); - newWorlds.add(world("Asgard", 63)); - newWorlds.add(world("Hel", 62)); - - return newWorlds; - } - - - @Override - @Transactional - public World world(String name, int moons) { - - World createdWorld = findWorldNamed(name); - if (createdWorld == null) { - createdWorld = new World(name, moons); - worldRepository.save(createdWorld); - } - return createdWorld; - } - - @Override - public World findWorldNamed(String name) { - return worldRepository.findByPropertyValue("name", name); - } - - @Override - public Iterable findWorldsWithMoons(int moonCount) { - return worldRepository.findAllByPropertyValue("moon-index", "moons", moonCount); - } - - @Override - public Iterable exploreWorldsBeyond(World homeWorld) { - TraversalDescription traversal = Traversal.description().relationships(withName(REACHABLE_BY_ROCKET), Direction.OUTGOING); - return worldRepository.findAllByTraversal(homeWorld, traversal); - } - -} diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/resources/spring/helloWorldContext.xml b/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/aspects/helloWorldContext.xml similarity index 51% rename from spring-data-neo4j-examples/hello-worlds-aspects/src/main/resources/spring/helloWorldContext.xml rename to spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/aspects/helloWorldContext.xml index d925ed2bd9..f4d652b9bf 100644 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/resources/spring/helloWorldContext.xml +++ b/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/aspects/helloWorldContext.xml @@ -1,16 +1,22 @@ - + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-3.0.xsd + http://www.springframework.org/schema/data/neo4j + http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd + http://www.springframework.org/schema/tx + http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> + diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/helloWorldContext.xml b/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/helloWorldContext.xml deleted file mode 100644 index e442c40a55..0000000000 --- a/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/helloWorldContext.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/plain/helloWorldContext.xml b/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/plain/helloWorldContext.xml new file mode 100644 index 0000000000..20647b2996 --- /dev/null +++ b/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/plain/helloWorldContext.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + diff --git a/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/GalaxyServiceTest.java b/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/GalaxyServiceTest.java new file mode 100644 index 0000000000..76cce92ffb --- /dev/null +++ b/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/GalaxyServiceTest.java @@ -0,0 +1,119 @@ +package org.springframework.data.neo4j.examples.hellograph; + +import static org.hamcrest.CoreMatchers.anyOf; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.*; +import static org.junit.internal.matchers.StringContains.containsString; + +import java.util.Collection; + +import org.junit.Test; +import org.junit.runner.RunWith; +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.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.transaction.BeforeTransaction; +import org.springframework.transaction.annotation.Transactional; + +@ContextConfiguration(locations = "classpath:/spring/helloWorldContext.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@Transactional +public class GalaxyServiceTest { + + @Autowired + private GalaxyService galaxyService; + + @Autowired + private Neo4jTemplate template; + + @Rollback(false) + @BeforeTransaction + public void cleanUpGraph() { + Neo4jHelper.cleanDb(template); + } + + @Test + public void shouldAllowDirectWorldCreation() { + assertEquals(0, galaxyService.getNumberOfWorlds()); + World myWorld = galaxyService.createWorld("mine", 0); + assertEquals(1, galaxyService.getNumberOfWorlds()); + + Iterable foundWorlds = galaxyService.getAllWorlds(); + World mine = foundWorlds.iterator().next(); + assertEquals(myWorld.getName(), mine.getName()); + } + + @Test + public void shouldHaveCorrectNumberOfWorlds() { + galaxyService.makeSomeWorlds(); + assertEquals(13, galaxyService.getNumberOfWorlds()); + } + + @Test + public void shouldFindWorldsById() { + galaxyService.makeSomeWorlds(); + + for(World world : galaxyService.getAllWorlds()) { + World foundWorld = galaxyService.findWorldById(world.getId()); + assertNotNull(foundWorld); + } + } + + @Test + public void shouldFindWorldsByName() { + galaxyService.makeSomeWorlds(); + + for(World world : galaxyService.getAllWorlds()) { + World foundWorld = galaxyService.findWorldByName(world.getName()); + assertNotNull(foundWorld); + } + } + + @Test + public void shouldReachMarsFromEarth() { + galaxyService.makeSomeWorlds(); + + World earth = galaxyService.findWorldByName("Earth"); + World mars = galaxyService.findWorldByName("Mars"); + + assertTrue(mars.canBeReachedFrom(earth)); + assertTrue(earth.canBeReachedFrom(mars)); + } + + @Test + public void shouldFindAllWorlds() { + Collection madeWorlds = galaxyService.makeSomeWorlds(); + Iterable foundWorlds = galaxyService.getAllWorlds(); + + int countOfFoundWorlds = 0; + for(World foundWorld : foundWorlds) { + assertTrue(madeWorlds.contains(foundWorld)); + countOfFoundWorlds++; + } + + assertEquals(madeWorlds.size(), countOfFoundWorlds); + } + + @SuppressWarnings("unchecked") + @Test + public void shouldFindWorldsWith1Moon() { + galaxyService.makeSomeWorlds(); + + for(World worldWithOneMoon : galaxyService.findAllByNumberOfMoons(1)) { + assertThat( + worldWithOneMoon.getName(), + is(anyOf(containsString("Earth"), containsString("Midgard")))); + } + } + + @Test + public void shouldNotFindKrypton() { + galaxyService.makeSomeWorlds(); + World krypton = galaxyService.findWorldByName("Krypton"); + assertNull(krypton); + } + +} diff --git a/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldCounterTest.java b/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldCounterTest.java deleted file mode 100644 index 61d0d35b15..0000000000 --- a/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldCounterTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -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.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.transaction.BeforeTransaction; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Map; - -import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; - -/** - * @author mh - * @since 17.02.11 - * Added to check for some aspectj-snapshot build errors. - */ -@ContextConfiguration(locations = "classpath:spring/helloWorldContext.xml") -@RunWith(SpringJUnit4ClassRunner.class) -@Transactional -@Ignore("TODO ABK") -public class WorldCounterTest { - - @Autowired - private Neo4jTemplate template; - - @Rollback(false) - @BeforeTransaction - public void clearDatabase() - { - Neo4jHelper.cleanDb(template); - } - - @Test - public void testCountMoons() throws Exception { - WorldCounter counter = new WorldCounter(); - Map result = counter.countMoons(asList(new World("earth", 1))); - assertEquals("earth has one moon",(Integer)1,result.get("earth")); - } -} diff --git a/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryTest.java b/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryTest.java deleted file mode 100644 index e9d0c88839..0000000000 --- a/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryTest.java +++ /dev/null @@ -1,121 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -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.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; - -import static junit.framework.Assert.assertEquals; -import static org.hamcrest.CoreMatchers.anyOf; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; -import static org.junit.internal.matchers.StringContains.containsString; - -/** - * Exploratory testing of Spring Data Neo4j using - * the WorldRepositoryImpl. - */ -@ContextConfiguration(locations = "classpath:spring/helloWorldContext.xml") -@RunWith(SpringJUnit4ClassRunner.class) -@Transactional -public class WorldRepositoryTest -{ - - @Autowired - private WorldRepository galaxy; - - @Autowired - private Neo4jTemplate template; - - @Rollback(false) - @BeforeTransaction - public void clearDatabase() - { - Neo4jHelper.cleanDb(template); - } - - @Test - public void shouldAllowDirectWorldCreation() - { - assertEquals(0, (long) template.count(World.class)); - World myWorld = galaxy.save(new World( "mine", 0 )); - assertEquals(1, (long) template.count(World.class)); - World foundWorld = galaxy.findOne(myWorld.id); - assertEquals(myWorld.getName(), foundWorld.getName()); - } - - @Test - public void shouldPopulateGalaxyWithWorlds() - { - Iterable worlds = galaxy.makeSomeWorlds(); - assertNotNull( worlds ); - } - - - @Test - public void shouldHaveCorrectNumberOfWorlds() - { - galaxy.makeSomeWorlds(); - assertEquals(13, (long) galaxy.count()); - } - - @Test - public void shouldFindAllWorlds() - { - Collection madeWorlds = galaxy.makeSomeWorlds(); - Iterable foundWorlds = galaxy.findAll(); - - int countOfFoundWorlds = 0; - for ( World foundWorld : foundWorlds ) - { - assertTrue( madeWorlds.contains( foundWorld ) ); - countOfFoundWorlds++; - } - - assertEquals( madeWorlds.size(), countOfFoundWorlds ); - } - - @Test - public void shouldFindWorldsByName() - { - for ( World w : galaxy.makeSomeWorlds() ) - { - assertNotNull( galaxy.findWorldNamed( w.getName() ) ); - } - } - - @SuppressWarnings("unchecked") - @Test - public void shouldFindWorldsWith1Moon() - { - galaxy.makeSomeWorlds(); - for ( World worldWithOneMoon : galaxy.findWorldsWithMoons( 1 ) ) - { - assertThat( worldWithOneMoon.getName(), is( anyOf( containsString( "Earth" ), containsString( "Midgard" ) ) ) ); - } - } - - @Test - public void shouldReachMarsFromEarth() - { - galaxy.makeSomeWorlds(); - - World earth = galaxy.findWorldNamed( "Earth" ); - World mars = galaxy.findWorldNamed( "Mars" ); - System.err.println(earth.reachableByRocket); - System.err.println(mars.reachableByRocket); - - assertTrue("mars can be reached from earth", mars.canBeReachedFrom( earth ) ); - assertTrue("earth can be reached from mars", earth.canBeReachedFrom( mars ) ); - } - -} diff --git a/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldTest.java b/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldTest.java deleted file mode 100644 index 3c4a856b80..0000000000 --- a/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -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.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.assertNull; - -/** - * Exploratory unit-tests for the Spring Data Neo4j annotated World entity. - * - * Since the World is a @NodeEntity, the SpringDataGraph must - * be setup before you can even create instances of the POJO. - */ -@ContextConfiguration(locations = "classpath:spring/helloWorldContext.xml") -@RunWith(SpringJUnit4ClassRunner.class) -@Transactional -@Ignore("TODO ABK") -public class WorldTest -{ - - @Autowired - private Neo4jTemplate template; - - @Rollback(false) - @BeforeTransaction - public void clearDatabase() - { - Neo4jHelper.cleanDb(template); - } - - @Test - public void shouldBeSimpleToCreateNewEntities() - { - @SuppressWarnings("unused") - World w = new World(); - } - - @Test - public void shouldHaveNullNameUsingDefaultConstructor() - { - World w = new World(); - assertNull(w.getName()); - } -}