added first REST test

This commit is contained in:
Michael Hunger
2011-03-28 13:58:54 +02:00
parent 3b09ad16dc
commit 840c81846c
6 changed files with 107 additions and 26 deletions

View File

@@ -7,7 +7,7 @@
<version>1.0.0.BUILD-SNAPSHOT</version>
<relativePath>../spring-data-graph-parent/pom.xml</relativePath>
</parent>
<groupId>org.neo4j</groupId>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j-rest</artifactId>
<packaging>jar</packaging>
<version>1.0.0.BUILD-SNAPSHOT</version>
@@ -30,6 +30,27 @@
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.2.GA</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

View File

@@ -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();
}

View File

@@ -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();
}
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="graphDatabaseService" class="org.neo4j.rest.graphdb.RestGraphDatabase" scope="singleton">
<constructor-arg index="0" value="http://localhost:7475/db/data" />
</bean>
</beans>

View File

@@ -11,7 +11,6 @@
<packaging>jar</packaging>
<name>Spring Data Neo4J Support</name>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
@@ -239,6 +238,18 @@
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -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 {
}
}