DATAGRAPH-450 Updated HelloWorld (maven based) examples to work against 3.0.2-SNAPSHOT (split into separate plain vs aspectj based modules)
This commit is contained in:
committed by
Michael Hunger
parent
bd1fb266c4
commit
9058c42d5b
11
spring-data-neo4j-examples/hello-worlds-aspects/.gitignore
vendored
Normal file
11
spring-data-neo4j-examples/hello-worlds-aspects/.gitignore
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
lib
|
||||
.ivy
|
||||
.gradle
|
||||
target
|
||||
*.ipr
|
||||
*.iml
|
||||
*.iws
|
||||
.classpath
|
||||
.project
|
||||
.settings
|
||||
|
||||
12
spring-data-neo4j-examples/hello-worlds-aspects/README.md
Normal file
12
spring-data-neo4j-examples/hello-worlds-aspects/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
Hello Worlds (Using Advanced Mode - AspectJ)
|
||||
============
|
||||
|
||||
A simple Spring Data Neo4j example with just enough code to do something that works using aspectj.
|
||||
|
||||
See https://github.com/SpringSource/spring-data-neo4j/blob/master/spring-data-neo4j-examples/hello-worlds-aspects/src/test/java/org/springframework/data/neo4j/examples/hellograph/GalaxyServiceTest.java for example code.
|
||||
|
||||
Build and Run
|
||||
-------------
|
||||
|
||||
`mvn clean test`
|
||||
|
||||
24
spring-data-neo4j-examples/hello-worlds-aspects/build.gradle
Normal file
24
spring-data-neo4j-examples/hello-worlds-aspects/build.gradle
Normal file
@@ -0,0 +1,24 @@
|
||||
sourceCompatibility = 1.7
|
||||
targetCompatibility = 1.7
|
||||
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'eclipse'
|
||||
|
||||
|
||||
springVersion = "3.2.8.RELEASE"
|
||||
springDataNeo4jVersion = "3.0.2-SNAPSHOT"
|
||||
|
||||
configurations {
|
||||
runtime
|
||||
testCompile
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
mavenRepo urls: "http://maven.springframework.org/release"
|
||||
}
|
||||
|
||||
|
||||
dependencies{
|
||||
testCompile group:"junit", name: "junit", version: "4.11"
|
||||
}
|
||||
61
spring-data-neo4j-examples/hello-worlds-aspects/build.xml
Normal file
61
spring-data-neo4j-examples/hello-worlds-aspects/build.xml
Normal file
@@ -0,0 +1,61 @@
|
||||
<project name="spring-data-neo4j-example" default="test" xmlns:ivy="antlib:org.apache.ivy.ant" basedir=".">
|
||||
<property name="settings.dir" location="settings" />
|
||||
<property name="lib.dir" location="lib" />
|
||||
|
||||
<import file="${settings.dir}/path.xml" />
|
||||
|
||||
<import file="${settings.dir}/install-ivy.xml" />
|
||||
<import file="${settings.dir}/path.xml" />
|
||||
|
||||
<target name="lib.retrieve" depends="install-ivy">
|
||||
<mkdir dir="${lib.dir}" />
|
||||
<ivy:settings file="${settings.dir}/ivysettings.xml" />
|
||||
<ivy:resolve file="${settings.dir}/ivy.xml" />
|
||||
<ivy:retrieve type="jar" pattern="${lib.dir}/[artifact].[ext]" changing="true"/>
|
||||
<ivy:retrieve type="bundle" pattern="${lib.dir}/[artifact].[ext]" changing="true"/>
|
||||
</target>
|
||||
|
||||
<target name="lib.clean">
|
||||
<delete dir="${lib.dir}" />
|
||||
</target>
|
||||
|
||||
<target name="clean" description="Removes the build directory, but not any cached ivy dependencies">
|
||||
<delete dir="target" />
|
||||
<delete dir="build" />
|
||||
</target>
|
||||
|
||||
<target name="compile" description="Compile production classes" depends="lib.retrieve">
|
||||
<mkdir dir="${main.target}" />
|
||||
|
||||
<javac sourcepath="${main.src}" destDir="${main.target}" classpathref="path.libs" source="1.7">
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="compile-tests" description="Compile unit test classes" depends="compile">
|
||||
<mkdir dir="${test.target}" />
|
||||
<copy todir="${main.target}" failonerror="false">
|
||||
<fileset dir="${main.resources}"/>
|
||||
</copy>
|
||||
<javac sourcepath="${test.src}" destDir="${test.target}" classpathref="path.testing" source="1.7">
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="test" depends="clean, compile, compile-tests">
|
||||
<mkdir dir="${test.reports}"/>
|
||||
<copy todir="${test.target}" failonerror="false">
|
||||
<fileset dir="${test.resources}" includes="**/*"/>
|
||||
</copy>
|
||||
|
||||
<fileset id="unittest.source.files" dir="${test.src}">
|
||||
<include name="**/*Test.java" />
|
||||
</fileset>
|
||||
|
||||
<junit printsummary="yes" showoutput="true" dir="." outputtoformatters="false">
|
||||
<classpath refid="path.testing"/>
|
||||
<formatter type="plain" />
|
||||
<batchtest fork="no" todir="${test.reports}">
|
||||
<fileset refid="unittest.source.files"/>
|
||||
</batchtest>
|
||||
</junit>
|
||||
</target>
|
||||
</project>
|
||||
206
spring-data-neo4j-examples/hello-worlds-aspects/pom.xml
Normal file
206
spring-data-neo4j-examples/hello-worlds-aspects/pom.xml
Normal file
@@ -0,0 +1,206 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.springframework.data.examples</groupId>
|
||||
<artifactId>spring-data-neo4j-hello-worlds-aspects</artifactId>
|
||||
<version>3.0.2.BUILD-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Spring Data Neo4j hello-worlds</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring.version>3.2.8.RELEASE</spring.version>
|
||||
<aspectj.version>1.7.4</aspectj.version>
|
||||
<slf4j.version>1.7.5</slf4j.version>
|
||||
<spring-data-neo4j.version>${project.version}</spring-data-neo4j.version>
|
||||
<neo4j.version>2.0.1</neo4j.version>
|
||||
<junit.version>4.11</junit.version>
|
||||
<log4j.version>1.2.17</log4j.version>
|
||||
<hibernate-validator.version>4.2.0.Final</hibernate-validator.version>
|
||||
<hibernate-jpa.version>1.0.0.Final</hibernate-jpa.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-maven-release</id>
|
||||
<name>Spring Maven Release Repository</name>
|
||||
<url>http://maven.springframework.org/release</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-maven-snapshot</id>
|
||||
<name>Spring Maven Snapshot Repository</name>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<url>http://maven.springframework.org/snapshot</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-maven-milestone</id>
|
||||
<name>Spring Maven Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>neo4j-release-repository</id>
|
||||
<name>Neo4j Maven 2 release repository</name>
|
||||
<url>http://m2.neo4j.org/releases</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>neo4j-snapshot-repository</id>
|
||||
<name>Neo4j Maven 2 snapshot repository</name>
|
||||
<url>http://m2.neo4j.org/snapshots</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-maven-release</id>
|
||||
<name>Spring Maven Release Repository</name>
|
||||
<url>http://maven.springframework.org/release</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-maven-milestone</id>
|
||||
<name>Spring Maven Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<dependencies>
|
||||
<!-- SDN for simple mapping mode -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j-aspects</artifactId>
|
||||
<version>${spring-data-neo4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Hibernate implementation of the JSR-303 Bean Validation Spec API.
|
||||
(SDN makes use of the javax.validation:validation-api dependency and
|
||||
hibernate provides a concrete implementation -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>${hibernate-validator.version}</version>
|
||||
</dependency>
|
||||
<!-- JPA annotations for spring-aspects compilation which uses @Transactional -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate.javax.persistence</groupId>
|
||||
<artifactId>hibernate-jpa-2.0-api</artifactId>
|
||||
<version>${hibernate-jpa.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging Related dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- TEST dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.neo4j</groupId>
|
||||
<artifactId>neo4j-kernel</artifactId>
|
||||
<version>${neo4j.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<!-- Must use java 1.5 or higher for annotations -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<!-- required to resolve aspectj-enhanced class features -->
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>aspectj-maven-plugin</artifactId>
|
||||
<version>1.4</version>
|
||||
<configuration>
|
||||
<outxml>true</outxml>
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aspects</artifactId>
|
||||
</aspectLibrary>
|
||||
<aspectLibrary>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j-aspects</artifactId>
|
||||
</aspectLibrary>
|
||||
</aspectLibraries>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjtools</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,29 @@
|
||||
<project xmlns:ivy="antlib:org.apache.ivy.ant" basedir="..">
|
||||
|
||||
<property name="ivy.install.version" value="2.2.0" />
|
||||
<property name="ivy.jar.dir" location="${basedir}/.ivy" />
|
||||
<property name="ivy.jar.file" location="${ivy.jar.dir}/ivy.jar" />
|
||||
<property name="ivy.cache.dir" location="${basedir}/.ivy/cache" />
|
||||
|
||||
<target name="download-ivy" unless="skip.download">
|
||||
<mkdir dir="${ivy.jar.dir}"/>
|
||||
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
|
||||
dest="${ivy.jar.file}" usetimestamp="true"/>
|
||||
</target>
|
||||
|
||||
<target name="install-ivy" depends="download-ivy">
|
||||
<path id="ivy.lib.path">
|
||||
<fileset dir="${ivy.jar.dir}" includes="*.jar"/>
|
||||
</path>
|
||||
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
|
||||
</target>
|
||||
|
||||
<target name="clean-ivy">
|
||||
<delete dir="${ivy.jar.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="clean-ivy-cache" depends="install-ivy">
|
||||
<ivy:cleancache />
|
||||
</target>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,12 @@
|
||||
<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
|
||||
<info organisation="org.springframework.data.neo4j.examples" module="hello-worlds"/>
|
||||
<dependencies>
|
||||
<dependency org="org.springframework.data" name="spring-data-neo4j" rev="3.0.1.RELEASE">
|
||||
<exclude module="jms"/>
|
||||
<exclude module="jmxtools"/>
|
||||
<exclude module="jmxri"/>
|
||||
</dependency>
|
||||
<dependency org="org.neo4j" name="neo4j-community" rev="2.0.1"/>
|
||||
<dependency org="junit" name="junit" rev="4.9.11"/>
|
||||
</dependencies>
|
||||
</ivy-module>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0"?>
|
||||
<ivysettings>
|
||||
<settings defaultResolver="chained"/>
|
||||
<property name="local-maven2-pattern"
|
||||
value="${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]"
|
||||
override="false" />
|
||||
|
||||
<resolvers>
|
||||
<chain name="chained" returnFirst="false">
|
||||
<filesystem name="local-maven2" m2compatible="true" >
|
||||
<ivy pattern="${local-maven2-pattern}"/>
|
||||
<artifact pattern="${local-maven2-pattern}"/>
|
||||
</filesystem>
|
||||
<ibiblio name="neo4j" root="http://m2.neo4j.org/releases" m2compatible="true"/>
|
||||
<ibiblio name="maven_central" root="http://repo2.maven.org/maven2/" m2compatible="true"/>
|
||||
<ibiblio name="jboss" root="http://repository.jboss.org/nexus/content/groups/public/" m2compatible="true"/>
|
||||
<ibiblio name="springframework" root="http://maven.springframework.org/release" m2compatible="true"/>
|
||||
</chain>
|
||||
</resolvers>
|
||||
<caches>
|
||||
<cache name="default-cache" basedir="${ivy.cache.dir}" />
|
||||
</caches>
|
||||
</ivysettings>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" ?>
|
||||
|
||||
<project name="path" default="donothingToMakeAValidAntFile"
|
||||
basedir=".">
|
||||
|
||||
<property name="main.src" location="src/main/java" />
|
||||
<property name="main.resources" location="src/main/resources" />
|
||||
<property name="main.target" location="target/main/classes" />
|
||||
|
||||
<property name="test.src" location="src/test/java" />
|
||||
<property name="test.target" location="target/test/classes" />
|
||||
<property name="test.reports" location="target/test/reports" />
|
||||
<property name="test.resources" location="src/test/resources" />
|
||||
|
||||
<target name="donothingToMakeAValidAntFile" />
|
||||
|
||||
<path id="path.libs">
|
||||
<fileset dir="lib" />
|
||||
</path>
|
||||
|
||||
<path id="path.compile">
|
||||
<path refid="path.libs" />
|
||||
<dirset dir="${main.target}" />
|
||||
</path>
|
||||
|
||||
<path id="path.testing">
|
||||
<path refid="path.compile" />
|
||||
<dirset dir="${test.target}"/>
|
||||
</path>
|
||||
</project>
|
||||
@@ -0,0 +1,79 @@
|
||||
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.data.neo4j.aspects.core.NodeBacked;
|
||||
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) {
|
||||
// The lin below is just as valid within you code (it assumes)
|
||||
// the aspectj compilcation has occured, however the cast to
|
||||
// the NodeBacked class is being used here as its helpful to
|
||||
// IDE's which struggle with aspectj stuff
|
||||
//
|
||||
// return new World(name, moons).persist();
|
||||
|
||||
World world = new World(name, moons);
|
||||
((NodeBacked)world).persist();
|
||||
return world;
|
||||
}
|
||||
|
||||
public Iterable<World> getAllWorlds() {
|
||||
return worldRepository.findAll();
|
||||
}
|
||||
|
||||
public World findWorldById(Long id) {
|
||||
return worldRepository.findOne(id);
|
||||
}
|
||||
|
||||
public World findWorldByName(String name) {
|
||||
return worldRepository.findBySchemaPropertyValue("name", name);
|
||||
}
|
||||
|
||||
// This is using the legacy index
|
||||
public Iterable<World> findAllByNumberOfMoons(int numberOfMoons) {
|
||||
return worldRepository.findAllByPropertyValue("moons", numberOfMoons);
|
||||
}
|
||||
|
||||
public Collection<World> makeSomeWorlds() {
|
||||
Collection<World> worlds = new ArrayList<World>();
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
import org.neo4j.graphdb.Direction;
|
||||
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.index.IndexType;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@NodeEntity
|
||||
public class World {
|
||||
private final static String REACHABLE_BY_ROCKET = "REACHABLE_BY_ROCKET";
|
||||
|
||||
@GraphId
|
||||
private Long id;
|
||||
|
||||
@Indexed
|
||||
private String name;
|
||||
|
||||
@Indexed(indexType = IndexType.SIMPLE)
|
||||
private int moons;
|
||||
|
||||
@Fetch
|
||||
@RelatedTo(type = REACHABLE_BY_ROCKET, direction = Direction.BOTH)
|
||||
private Set<World> reachableByRocket;
|
||||
|
||||
public World(String name, int moons) {
|
||||
this.name = name;
|
||||
this.moons = moons;
|
||||
}
|
||||
|
||||
public World() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getMoons() {
|
||||
return moons;
|
||||
}
|
||||
|
||||
public void addRocketRouteTo(World otherWorld) {
|
||||
reachableByRocket.add(otherWorld);
|
||||
}
|
||||
|
||||
public boolean canBeReachedFrom(World otherWorld) {
|
||||
return reachableByRocket.contains(otherWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (id == null) ? 0 : id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
World other = (World) 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
import org.springframework.data.neo4j.repository.GraphRepository;
|
||||
|
||||
public interface WorldRepository extends GraphRepository<World> {}
|
||||
@@ -0,0 +1,7 @@
|
||||
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
|
||||
@@ -18,7 +18,7 @@
|
||||
<context:annotation-config/>
|
||||
<context:component-scan base-package="org.springframework.data.neo4j.examples.hellograph" />
|
||||
|
||||
<neo4j:config storeDirectory="target/neo4j-db"/>
|
||||
<neo4j:config storeDirectory="target/neo4j-db-aspect" base-package="org.springframework.data.neo4j.examples.hellograph"/>
|
||||
<neo4j:repositories base-package="org.springframework.data.neo4j.examples.hellograph"/>
|
||||
|
||||
<tx:annotation-driven mode="aspectj"/>
|
||||
@@ -1,12 +1,5 @@
|
||||
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;
|
||||
@@ -18,10 +11,17 @@ 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 org.hamcrest.CoreMatchers.anyOf;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@ContextConfiguration(locations = "classpath:/spring/helloWorldContext.xml")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@Transactional
|
||||
public class GalaxyServiceTests {
|
||||
public class GalaxyServiceTest {
|
||||
|
||||
@Autowired
|
||||
private GalaxyService galaxyService;
|
||||
@@ -1,12 +1,12 @@
|
||||
sourceCompatibility = 1.6
|
||||
targetCompatibility = 1.6
|
||||
sourceCompatibility = 1.7
|
||||
targetCompatibility = 1.7
|
||||
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'eclipse'
|
||||
|
||||
|
||||
springVersion = "3.0.7.RELEASE"
|
||||
springDataNeo4jVersion = "2.0.0.RELEASE"
|
||||
springVersion = "3.2.8.RELEASE"
|
||||
springDataNeo4jVersion = "3.0.2-SNAPSHOT"
|
||||
|
||||
configurations {
|
||||
runtime
|
||||
@@ -20,5 +20,5 @@ repositories {
|
||||
|
||||
|
||||
dependencies{
|
||||
testCompile group:"junit", name: "junit", version: "4.8"
|
||||
testCompile group:"junit", name: "junit", version: "4.11"
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<target name="compile" description="Compile production classes" depends="lib.retrieve">
|
||||
<mkdir dir="${main.target}" />
|
||||
|
||||
<javac sourcepath="${main.src}" destDir="${main.target}" classpathref="path.libs" source="1.6">
|
||||
<javac sourcepath="${main.src}" destDir="${main.target}" classpathref="path.libs" source="1.7">
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<copy todir="${main.target}" failonerror="false">
|
||||
<fileset dir="${main.resources}"/>
|
||||
</copy>
|
||||
<javac sourcepath="${test.src}" destDir="${test.target}" classpathref="path.testing" source="1.6">
|
||||
<javac sourcepath="${test.src}" destDir="${test.target}" classpathref="path.testing" source="1.7">
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
|
||||
@@ -4,17 +4,20 @@
|
||||
|
||||
<groupId>org.springframework.data.examples</groupId>
|
||||
<artifactId>spring-data-neo4j-hello-worlds</artifactId>
|
||||
<version>2.2.0.BUILD-SNAPSHOT</version>
|
||||
<version>3.0.2.BUILD-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Spring Data Neo4j hello-worlds</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring.version>3.0.7.RELEASE</spring.version>
|
||||
<aspectj.version>1.6.12</aspectj.version>
|
||||
<slf4j.version>1.6.1</slf4j.version>
|
||||
<spring.version>3.2.8.RELEASE</spring.version>
|
||||
<slf4j.version>1.7.5</slf4j.version>
|
||||
<spring-data-neo4j.version>${project.version}</spring-data-neo4j.version>
|
||||
<neo4j.version>2.0.1</neo4j.version>
|
||||
<junit.version>4.11</junit.version>
|
||||
<log4j.version>1.2.17</log4j.version>
|
||||
<hibernate-validator.version>4.2.0.Final</hibernate-validator.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
@@ -74,41 +77,59 @@
|
||||
</pluginRepositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
<artifactId>cglib-nodep</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<!-- SDN for simple mapping mode -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate.javax.persistence</groupId>
|
||||
<artifactId>hibernate-jpa-2.0-api</artifactId>
|
||||
<version>1.0.0.Final</version>
|
||||
<optional>true</optional>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>1.0.0.GA</version>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j</artifactId>
|
||||
<version>${spring-data-neo4j.version}</version>
|
||||
</dependency>
|
||||
<!-- Hibernate implementation of the JSR-303 Bean Validation Spec API.
|
||||
(SDN makes use of the javax.validation:validation-api dependency and
|
||||
hibernate provides a concrete implementation -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>${hibernate-validator.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging Related dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- TEST dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.neo4j</groupId>
|
||||
<artifactId>neo4j-kernel</artifactId>
|
||||
<version>${neo4j.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
@@ -119,196 +140,14 @@
|
||||
<!-- Must use java 1.5 or higher for annotations -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.1</version>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<!-- IntelliJ Idea Support -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-idea-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<downloadSources>true</downloadSources>
|
||||
<dependenciesAsLibraries>true</dependenciesAsLibraries>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<!-- Execute the main class -->
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<mainClass>org.springframework.data.neo4j.examples.hellograph.App</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<finalName>hello-worlds-${project.version}</finalName>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
<attach>false</attach>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.springframework.data.neo4j.examples.hellograph.App</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
||||
<phase>package</phase> <!-- bind to the packaging phase -->
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>initialize</phase>
|
||||
<goals>
|
||||
<goal>resources</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>plain</id>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j</artifactId>
|
||||
<version>${spring-data-neo4j.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.basedir}/src/main/resources/spring/plain</directory>
|
||||
<targetPath>${project.build.directory}/classes/spring</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>helloWorldContext.xml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>aspects</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j-aspects</artifactId>
|
||||
<version>${spring-data-neo4j.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<!-- required to resolve aspectj-enhanced class features -->
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>aspectj-maven-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<configuration>
|
||||
<outxml>true</outxml>
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aspects</artifactId>
|
||||
</aspectLibrary>
|
||||
<aspectLibrary>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j-aspects</artifactId>
|
||||
</aspectLibrary>
|
||||
</aspectLibraries>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjtools</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
||||
<!-- the eclipse plugin interacts with the aspectj-maven-plugin BUT
|
||||
ONLY if the ajdtVersion config value is set (remove it and it won't) -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<version>2.8</version>
|
||||
<configuration>
|
||||
<!-- The ajdtVersion configuration parameter is optional. The valid
|
||||
values are none, 1.4, and 1.5. none indicates that AJDT should not be enabled
|
||||
even though Aspectj is enabled in maven. 1.4 generates the org.eclipse.ajdt.ui.prefs
|
||||
file in the .settings directory. 1.5 (or later) includes the configuration
|
||||
into the .classpath file and is the default value. -->
|
||||
<ajdtVersion>1.5</ajdtVersion>
|
||||
<additionalProjectnatures>
|
||||
<projectnature>org.eclipse.ajdt.ui.ajnature</projectnature>
|
||||
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
|
||||
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
|
||||
</additionalProjectnatures>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.basedir}/src/main/resources/spring/aspects</directory>
|
||||
<targetPath>${project.build.directory}/classes/spring</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>helloWorldContext.xml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
|
||||
<info organisation="org.springframework.data.neo4j.examples" module="hello-worlds"/>
|
||||
<dependencies>
|
||||
<dependency org="org.springframework.data" name="spring-data-neo4j" rev="2.0.1.RELEASE">
|
||||
<dependency org="org.springframework.data" name="spring-data-neo4j" rev="3.0.2-SNAPSHOT">
|
||||
<exclude module="jms"/>
|
||||
<exclude module="jmxtools"/>
|
||||
<exclude module="jmxri"/>
|
||||
</dependency>
|
||||
<dependency org="org.neo4j" name="neo4j-community" rev="1.6"/>
|
||||
<dependency org="junit" name="junit" rev="4.8.1"/>
|
||||
<dependency org="org.neo4j" name="neo4j-community" rev="2.0.1"/>
|
||||
<dependency org="junit" name="junit" rev="4.9.11"/>
|
||||
</dependencies>
|
||||
</ivy-module>
|
||||
|
||||
@@ -29,9 +29,10 @@ public class GalaxyService {
|
||||
}
|
||||
|
||||
public World findWorldByName(String name) {
|
||||
return worldRepository.findByPropertyValue("name", name);
|
||||
return worldRepository.findBySchemaPropertyValue("name", name);
|
||||
}
|
||||
|
||||
|
||||
// This is using the legacy index
|
||||
public Iterable<World> findAllByNumberOfMoons(int numberOfMoons) {
|
||||
return worldRepository.findAllByPropertyValue("moons", numberOfMoons);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ 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.index.IndexType;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@NodeEntity
|
||||
@@ -18,7 +20,7 @@ public class World {
|
||||
@Indexed
|
||||
private String name;
|
||||
|
||||
@Indexed(indexName = "moon-index")
|
||||
@Indexed(indexType = IndexType.SIMPLE)
|
||||
private int moons;
|
||||
|
||||
@Fetch
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<context:annotation-config/>
|
||||
<context:component-scan base-package="org.springframework.data.neo4j.examples.hellograph" />
|
||||
|
||||
<neo4j:config storeDirectory="target/neo4j-db"/>
|
||||
<neo4j:config storeDirectory="target/neo4j-db-plain" base-package="org.springframework.data.neo4j.examples.hellograph"/>
|
||||
<neo4j:repositories base-package="org.springframework.data.neo4j.examples.hellograph"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,119 @@
|
||||
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.Collection;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.anyOf;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@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<World> 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<World> madeWorlds = galaxyService.makeSomeWorlds();
|
||||
Iterable<World> 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user