DATAGRAPH-450, DATAGRAPH-449: Updated HelloWorld sample code and references in guide
This commit is contained in:
committed by
Michael Hunger
parent
9058c42d5b
commit
f4bb615b34
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/data/neo4j
|
||||
http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd
|
||||
http://www.springframework.org/schema/tx
|
||||
http://www.springframework.org/schema/tx/spring-tx.xsd">
|
||||
|
||||
<context:spring-configured/>
|
||||
<context:annotation-config/>
|
||||
<context:component-scan base-package="org.springframework.data.neo4j.examples.hellograph" />
|
||||
|
||||
<bean id="typeRepresentationStrategyFactory" class="org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory">
|
||||
<constructor-arg ref="graphDatabase"/>
|
||||
<constructor-arg value="SubRef"/>
|
||||
</bean>
|
||||
|
||||
<neo4j:config storeDirectory="target/neo4j-db-plain-subref" base-package="org.springframework.data.neo4j.examples.hellograph"/>
|
||||
<neo4j:repositories base-package="org.springframework.data.neo4j.examples.hellograph"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -9,6 +9,7 @@ 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.test.context.transaction.TransactionConfiguration;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -21,6 +22,7 @@ import static org.junit.Assert.*;
|
||||
@ContextConfiguration(locations = "classpath:/spring/helloWorldContext.xml")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@Transactional
|
||||
@TransactionConfiguration(defaultRollback = false)
|
||||
public class GalaxyServiceTest {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
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.test.context.transaction.TransactionConfiguration;
|
||||
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-subRef-TRS.xml")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@Transactional
|
||||
@TransactionConfiguration(defaultRollback = false)
|
||||
public class SubRefBasedTRSGalaxyServiceTest {
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
BIN
src/docbkx/reference/helloworlds-labeltrs.png
Normal file
BIN
src/docbkx/reference/helloworlds-labeltrs.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
BIN
src/docbkx/reference/helloworlds-subreftrs.png
Normal file
BIN
src/docbkx/reference/helloworlds-subreftrs.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 199 KiB |
@@ -16,12 +16,14 @@
|
||||
<section id="samples_hello-worlds">
|
||||
<title>Hello Worlds sample application</title>
|
||||
<para>
|
||||
The Hello Worlds sample application is a simple console application. It creates some worlds
|
||||
(node entities) and rocket routes (relationships) between worlds, all in a galaxy (the graph),
|
||||
and then prints them.
|
||||
The Hello Worlds sample application exists merely to provide a client with a way of creating some "worlds"
|
||||
(node entities) and "rocket routes" (relationships) between worlds, all in a galaxy (the graph).
|
||||
There is currently no GUI for this application, rather you can have a look at the associated
|
||||
unit tests for some examples of how to interact with this domain via a dedicated <code>GalaxyService</code>
|
||||
class.
|
||||
</para>
|
||||
<para>
|
||||
The unit tests demonstrate some other features of Spring Data Neo4j as well. The sample comes
|
||||
The unit tests additionally demonstrate some other features of Spring Data Neo4j as well. The sample comes
|
||||
with a minimal configuration for Maven and Spring to get up and running quickly.
|
||||
</para>
|
||||
<para>
|
||||
@@ -29,18 +31,34 @@
|
||||
and for the advanced mapping (<code>hello-world-aspects</code>).
|
||||
</para>
|
||||
<para>
|
||||
Executing the application creates the following graph in the graph database:
|
||||
Running the unit tests create two versions of the world, one based on the default Label based Type
|
||||
Representation Strategy, and another (for comparison purposes) based on the Sub Reference type
|
||||
representation strategy. From the <code>GalaxyService</code> clients perspective, there is no difference,
|
||||
however how the data physically stored in the graph, does differ, and we take this opportunity to show
|
||||
you how using two different type representation strategies can impact how your data is modelled in the
|
||||
graph itself.
|
||||
</para>
|
||||
<para>Hello World Galaxy - Using default "Label" Type Representation Strategy
|
||||
<mediaobject>
|
||||
<imageobject>
|
||||
<imagedata fileref="helloworlds.png" contentwidth="15cm" scalefit="1"/>
|
||||
<imagedata fileref="helloworlds-labeltrs.png" contentwidth="15cm" scalefit="1"/>
|
||||
</imageobject>
|
||||
</mediaobject>
|
||||
</para>
|
||||
<para>Hello World Galaxy - Using "Sub Reference" Type Representation Strategy
|
||||
<mediaobject>
|
||||
<imageobject>
|
||||
<imagedata fileref="helloworlds-subreftrs.png" contentwidth="15cm" scalefit="1"/>
|
||||
</imageobject>
|
||||
</mediaobject>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="samples_imdb">
|
||||
<title>IMDB sample application</title>
|
||||
|
||||
<para>
|
||||
<note><para>This sample application still needs to be upgraded to SDN 3.0.X</para></note>
|
||||
The IMDB sample is a web application that imports datasets from the Internet Movie Database (IMDB)
|
||||
into the graph database. It allows the listing of movies with their actors, and of actors and their
|
||||
roles in different movies. It also uses graph traversal operations to calculate the
|
||||
@@ -68,6 +86,7 @@
|
||||
<section id="samples_myrestaurants-original">
|
||||
<title>MyRestaurants sample application</title>
|
||||
<para>
|
||||
<note><para>This sample application still needs to be upgraded to SDN 3.0.X</para></note>
|
||||
Simple, JPA-based web application for managing users and restaurants, with the ability to add
|
||||
restaurants as favorites to a user. It is basically the foundation for the MyRestaurants-Social
|
||||
application (see<xref linkend="samples:myrestaurants-social" />), and does therefore not use
|
||||
@@ -83,6 +102,7 @@
|
||||
<section id="samples_myrestaurants-social">
|
||||
<title>MyRestaurant-Social sample application</title>
|
||||
<para>
|
||||
<note><para>This sample application still needs to be upgraded to SDN 3.0.X</para></note>
|
||||
This application extends the MyRestaurants sample application, adding social networking
|
||||
functionality to it with cross-store persistence. The web application allows for users to add
|
||||
friends and rate restaurants. A graph traversal provides recommendations based on your friends'
|
||||
@@ -104,6 +124,7 @@
|
||||
</section>
|
||||
<section id="samples_cineasts">
|
||||
<title>Cineasts social movie database</title>
|
||||
<note><para>This sample application still needs to be upgraded to SDN 3.0.X</para></note>
|
||||
<para>
|
||||
The cineasts.net application was introduced extensively in the first part of this guide, the
|
||||
tutorial. The tutorial covers the development of the simple mapping version of cineasts.
|
||||
|
||||
Reference in New Issue
Block a user