Added unmanaged extension injectable tests
This commit is contained in:
@@ -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++;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.neo4j.rest.graphdb.SpringPluginInitializerTest
|
||||
@@ -0,0 +1,19 @@
|
||||
<?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="testObject" class="org.neo4j.rest.graphdb.SpringPluginInitializerTest" scope="singleton">
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,2 @@
|
||||
org.neo4j.server.database.location=target/test-db
|
||||
org.neo4j.server.thirdparty_jaxrs_classes=org.neo4j.rest.graphdb=/test
|
||||
Reference in New Issue
Block a user