From 840c81846cc51cd3b9bbc26362dd1c7de845da1c Mon Sep 17 00:00:00 2001 From: Michael Hunger Date: Mon, 28 Mar 2011 13:58:54 +0200 Subject: [PATCH] added first REST test --- spring-data-neo4j-rest/pom.xml | 23 ++++++++- .../org/neo4j/rest/graphdb/RestTestBase.java | 5 +- .../graph/neo4j/rest/RestNodeEntityTest.java | 48 +++++++++++++++++++ .../graph/neo4j/support/RestTest-context.xml | 20 ++++++++ spring-data-neo4j/pom.xml | 13 ++++- ...leanContextCacheTestExecutionListener.java | 24 ++-------- 6 files changed, 107 insertions(+), 26 deletions(-) create mode 100644 spring-data-neo4j-rest/src/test/java/org/springframework/data/graph/neo4j/rest/RestNodeEntityTest.java create mode 100644 spring-data-neo4j-rest/src/test/resources/org/springframework/data/graph/neo4j/support/RestTest-context.xml diff --git a/spring-data-neo4j-rest/pom.xml b/spring-data-neo4j-rest/pom.xml index 7efd5b256..a16d22487 100644 --- a/spring-data-neo4j-rest/pom.xml +++ b/spring-data-neo4j-rest/pom.xml @@ -7,7 +7,7 @@ 1.0.0.BUILD-SNAPSHOT ../spring-data-graph-parent/pom.xml - org.neo4j + org.springframework.data spring-data-neo4j-rest jar 1.0.0.BUILD-SNAPSHOT @@ -30,6 +30,27 @@ + + + org.springframework.data + spring-data-neo4j + 1.0.0.BUILD-SNAPSHOT + test + test-jar + + + org.springframework.data + spring-data-neo4j + 1.0.0.BUILD-SNAPSHOT + test + + + org.hibernate + hibernate-validator + 4.0.2.GA + test + + junit junit diff --git a/spring-data-neo4j-rest/src/test/java/org/neo4j/rest/graphdb/RestTestBase.java b/spring-data-neo4j-rest/src/test/java/org/neo4j/rest/graphdb/RestTestBase.java index 3a129e724..03851bc5f 100644 --- a/spring-data-neo4j-rest/src/test/java/org/neo4j/rest/graphdb/RestTestBase.java +++ b/spring-data-neo4j-rest/src/test/java/org/neo4j/rest/graphdb/RestTestBase.java @@ -27,10 +27,9 @@ public class RestTestBase { protected GraphDatabaseService graphDb; private static final String HOSTNAME = "localhost"; - private static final int PORT = 7474; + private static final int PORT = 7473; private static LocalTestServer neoServer = new LocalTestServer(HOSTNAME,PORT).withPropertiesFile("test-db.properties"); private static final String SERVER_ROOT_URI = "http://" + HOSTNAME + ":" + PORT + "/db/data/"; - private static final String SERVER_CLEANDB_URI = "http://" + HOSTNAME + ":" + PORT + "/cleandb/secret-key"; @BeforeClass public static void startDb() throws Exception { @@ -44,7 +43,7 @@ public class RestTestBase { graphDb = new RestGraphDatabase(new URI(SERVER_ROOT_URI)); } - private void cleanDb() { + public static void cleanDb() { neoServer.cleanDb(); } diff --git a/spring-data-neo4j-rest/src/test/java/org/springframework/data/graph/neo4j/rest/RestNodeEntityTest.java b/spring-data-neo4j-rest/src/test/java/org/springframework/data/graph/neo4j/rest/RestNodeEntityTest.java new file mode 100644 index 000000000..966b12b46 --- /dev/null +++ b/spring-data-neo4j-rest/src/test/java/org/springframework/data/graph/neo4j/rest/RestNodeEntityTest.java @@ -0,0 +1,48 @@ +package org.springframework.data.graph.neo4j.rest; + +import org.apache.log4j.BasicConfigurator; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.neo4j.rest.graphdb.RestGraphDatabase; +import org.neo4j.rest.graphdb.RestTestBase; +import org.springframework.data.graph.neo4j.support.NodeEntityTest; +import org.springframework.test.context.CleanContextCacheTestExecutionListener; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestExecutionListeners; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; +import org.springframework.test.context.transaction.TransactionalTestExecutionListener; + +import java.net.URI; +import java.net.URISyntaxException; + +/** +* @author mh +* @since 28.03.11 +*/ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = {"classpath:org/springframework/data/graph/neo4j/support/Neo4jGraphPersistenceTest-context.xml", + "classpath:org/springframework/data/graph/neo4j/rest/RestTest-context.xml"}) +@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class}) +public class RestNodeEntityTest extends NodeEntityTest { + + @BeforeClass + public static void startDb() throws Exception { + RestTestBase.startDb(); + } + + @Before + public void cleanDb() { + RestTestBase.cleanDb(); + } + + @AfterClass + public static void shutdownDb() { + RestTestBase.shutdownDb(); + + } + +} diff --git a/spring-data-neo4j-rest/src/test/resources/org/springframework/data/graph/neo4j/support/RestTest-context.xml b/spring-data-neo4j-rest/src/test/resources/org/springframework/data/graph/neo4j/support/RestTest-context.xml new file mode 100644 index 000000000..59dcb4650 --- /dev/null +++ b/spring-data-neo4j-rest/src/test/resources/org/springframework/data/graph/neo4j/support/RestTest-context.xml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/spring-data-neo4j/pom.xml b/spring-data-neo4j/pom.xml index c1876dc39..586f47b8b 100644 --- a/spring-data-neo4j/pom.xml +++ b/spring-data-neo4j/pom.xml @@ -11,7 +11,6 @@ jar Spring Data Neo4J Support - org.springframework @@ -239,6 +238,18 @@ 1.6 + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + + + + test-jar + + + + diff --git a/spring-data-neo4j/src/test/java/org/springframework/test/context/CleanContextCacheTestExecutionListener.java b/spring-data-neo4j/src/test/java/org/springframework/test/context/CleanContextCacheTestExecutionListener.java index 45b245453..7c0ddc0af 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/test/context/CleanContextCacheTestExecutionListener.java +++ b/spring-data-neo4j/src/test/java/org/springframework/test/context/CleanContextCacheTestExecutionListener.java @@ -1,10 +1,12 @@ package org.springframework.test.context; +import org.springframework.test.context.support.AbstractTestExecutionListener; + import java.applet.AppletContext; import java.lang.reflect.Field; import java.util.Map; -public class CleanContextCacheTestExecutionListener implements TestExecutionListener { +public class CleanContextCacheTestExecutionListener extends AbstractTestExecutionListener { @Override public void afterTestClass(TestContext testContext) throws Exception { @@ -20,24 +22,4 @@ public class CleanContextCacheTestExecutionListener implements TestExecutionList cache.setDirty(key); } } - - @Override - public void beforeTestClass(TestContext testContext) throws Exception { - - } - - @Override - public void prepareTestInstance(TestContext testContext) throws Exception { - - } - - @Override - public void beforeTestMethod(TestContext testContext) throws Exception { - - } - - @Override - public void afterTestMethod(TestContext testContext) throws Exception { - - } }