Databases Reference
In-Depth Information
// then
assertEquals ( "4" , distance );
}
Because the extension's constructor accepts a GraphDatabaseService instance, we can
inject a test instance (an ImpermanentGraphDatabase instance), and then call its meth‐
ods as per any other object.
If, however, we wanted to test the extension running inside a server, we have a little
more setup to do:
public class SocialNetworkExtensionTest
{
private static CommunityNeoServer server ;
@BeforeClass
public static void init () throws IOException
{
server = ServerBuilder . server ()
. withThirdPartyJaxRsPackage (
"org.neo4j.graphdatabases.queries.server" ,
"/socnet" )
. build ();
server . start ();
populateDatabase ( server . getDatabase (). getGraph () );
}
@AfterClass
public static void teardown ()
{
server . stop ();
}
@Test
public void serverShouldReturnDistance () throws Exception
{
ClientConfig config = new DefaultClientConfig ();
Client client = Client . create ( config );
WebResource resource = client
. resource ( "http://localhost:7474/socnet/distance/Ben/Mike" );
ClientResponse response = resource
. accept ( MediaType . TEXT_PLAIN )
. get ( ClientResponse . class );
assertEquals ( 200 , response . getStatus () );
assertEquals ( "text/plain" ,
response . getHeaders (). get ( "Content-Type" ). get ( 0 ) );
assertEquals ( "4" , response . getEntity ( String . class ) );
}
Search WWH ::




Custom Search