diff --git a/spring-data-neo4j-rest/src/test/java/org/neo4j/rest/graphdb/SpringPluginInitializerTest.java b/spring-data-neo4j-rest/src/test/java/org/neo4j/rest/graphdb/SpringPluginInitializerTest.java new file mode 100644 index 000000000..b652ab5a6 --- /dev/null +++ b/spring-data-neo4j-rest/src/test/java/org/neo4j/rest/graphdb/SpringPluginInitializerTest.java @@ -0,0 +1,115 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.neo4j.rest.graphdb; + +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import org.apache.log4j.BasicConfigurator; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.springframework.data.graph.neo4j.server.SpringPluginInitializer; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +@Path( "/" ) +public class SpringPluginInitializerTest extends SpringPluginInitializer implements TestInterface { + private LocalTestServer neoServer; + + public SpringPluginInitializerTest() { + super( new String[]{"ServerTest-context.xml"}, "testObject" ); + } + + private static int touched = 0; + private static final String HOSTNAME = "localhost"; + private static final int PORT = 7473; +// +// @Path( "/testInterface" ) +// @POST +// @Produces( MediaType.APPLICATION_JSON ) +// public void runThis( @Context TestInterface test ) { +// test.thisIsARecording(); +// } + + @Path( "/testConcrete" ) + @POST + @Produces( MediaType.APPLICATION_JSON ) + public void runThis( @Context SpringPluginInitializerTest test ) { + test.thisIsARecording(); + } + + @Path( "/testNoContext" ) + @POST + @Produces( MediaType.APPLICATION_JSON ) + public void runThis() { + } + + @Before + public void setUp() throws Exception { + BasicConfigurator.configure(); + neoServer = new LocalTestServer( HOSTNAME, PORT ).withPropertiesFile( "server-test-db.properties" ); + neoServer.start(); + touched=0; + } + + @After + public void tearDown() throws Exception { + neoServer.stop(); + } + + @Test + public void shouldWorkWithThirdPartyJaxrs() throws Exception { + ClientResponse response = sendRequest( "testNoContext" ); + + Assert.assertEquals( 204, response.getStatus() ); + } + + + @Test + public void shouldInjectConcreteClass() throws Exception { + ClientResponse response = sendRequest( "testConcrete" ); + + Assert.assertEquals( 204, response.getStatus() ); + Assert.assertEquals( 1, touched ); + } + + + @Test + public void shouldInjectInterface() throws Exception { + ClientResponse response = sendRequest( "testInterface" ); + + Assert.assertEquals( 204, response.getStatus() ); + Assert.assertEquals( 1, touched ); + } + + private ClientResponse sendRequest( String method ) { + return Client.create(). + resource( "http://localhost:7473/test/" + method ). + type( MediaType.APPLICATION_JSON ). + accept( MediaType.APPLICATION_JSON ).post( ClientResponse.class ); + } + + @Override + public void thisIsARecording() { + touched++; + } +} diff --git a/spring-data-neo4j-rest/src/test/java/org/neo4j/rest/graphdb/TestInterface.java b/spring-data-neo4j-rest/src/test/java/org/neo4j/rest/graphdb/TestInterface.java new file mode 100644 index 000000000..908aca052 --- /dev/null +++ b/spring-data-neo4j-rest/src/test/java/org/neo4j/rest/graphdb/TestInterface.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.neo4j.rest.graphdb; + +public interface TestInterface { + void thisIsARecording(); +} diff --git a/spring-data-neo4j-rest/src/test/resources/META-INF/services/org.neo4j.server.plugins.PluginLifecycle b/spring-data-neo4j-rest/src/test/resources/META-INF/services/org.neo4j.server.plugins.PluginLifecycle new file mode 100644 index 000000000..1b1b94e19 --- /dev/null +++ b/spring-data-neo4j-rest/src/test/resources/META-INF/services/org.neo4j.server.plugins.PluginLifecycle @@ -0,0 +1 @@ +org.neo4j.rest.graphdb.SpringPluginInitializerTest \ No newline at end of file diff --git a/spring-data-neo4j-rest/src/test/resources/ServerTest-context.xml b/spring-data-neo4j-rest/src/test/resources/ServerTest-context.xml new file mode 100644 index 000000000..4a41276cf --- /dev/null +++ b/spring-data-neo4j-rest/src/test/resources/ServerTest-context.xml @@ -0,0 +1,19 @@ + + + + + + diff --git a/spring-data-neo4j-rest/src/test/resources/server-test-db.properties b/spring-data-neo4j-rest/src/test/resources/server-test-db.properties new file mode 100644 index 000000000..9fcca8e4b --- /dev/null +++ b/spring-data-neo4j-rest/src/test/resources/server-test-db.properties @@ -0,0 +1,2 @@ +org.neo4j.server.database.location=target/test-db +org.neo4j.server.thirdparty_jaxrs_classes=org.neo4j.rest.graphdb=/test