GithubHelp home page GithubHelp logo

neo4j-resttest's Introduction

GraphAware Neo4j RestTest - RETIRED

RestTest Has Been Retired

As of April 2020, this module is retiring. This means it will no longer be maintained and released together with new versions of the GraphAware Framework and Neo4j. The last compatible Neo4j version is 3.5.14.

Custom REST APIs on top of Neo4j have been practically replaced by Cypher User Functions and Procedures. If you need functionality similar to what RestTest provided, go ahead and write a procedure that uses GraphUnit.

This repository will remain public.

Introduction

GraphAware RestTest is a simple library for testing code that talks to Neo4j running in standalone server mode.

Getting the Software

You will need the GraphAware Neo4j Framework and GraphAware Neo4j RestTest .jar files (both of which you can download here) dropped into the plugins directory of your Neo4j installation. For the framework to work, you need to adjust your neo4j configuration as described in the framework installation instructions. After Neo4j restart, you will be able to use the RestTest APIs.

Releases are synced to Maven Central repository.

Note on Versioning Scheme

The version number has two parts. The first four numbers indicate compatibility with Neo4j GraphAware Framework. The last number is the version of the RestTest library. For example, version 2.1.2.7.2 is version 2 of RestTest compatible with GraphAware Neo4j Framework 2.1.2.7.

Using GraphAware RestTest

RestTest allows you to assert the state of the database running in server mode and to clear it. It is in a sense equivalent to using GraphUnit in embedded mode.

REST API

When deployed in server mode, there are three URLs that you can issue POST requests to:

  • http://your-server-address:7474/graphaware/resttest/clear to clear your database. No body required.
  • http://your-server-address:7474/graphaware/resttest/assertSameGraph to assert the state of the database. You need to provide a body described shortly.
  • http://your-server-address:7474/graphaware/resttest/assertSubgraph to assert the state of the database. You need to provide a body described shortly.
  • http://your-server-address:7474/graphaware/resttest/assertEmpty to assert the database is empty. You need to provide a body described shortly.

The body where required needs to provide a Cypher CREATE statement, representing the state of the database being asserted, for example:

{
    "cypher": "CREATE (one:Person {name:'One'})-[:FRIEND_OF]->(two:Person {name:'Two'})"
}

The second API call is used to verify that the graph in the database is exactly the same as the graph created by the Cypher CREATE statement provided in the body of the request. This means that the nodes, their properties and labels, relationships, and their properties and labels must be exactly the same. Note that Neo4j internal node/relationship IDs are ignored. In case the graphs aren't identical, the assertion fails and you will get a response with EXPECTATION_FAILED (417) status code. If the test passes, you will get an OK (200).

The third API call is used to verify that the graph created by provided Cypher statement is a subgraph of the graph in the database. Request body options and response codes are same as above.

Finally, the API call that ensures that the database is empty has the body as an optional requirement and, of course, no Cypher is required.

Cypher procedures and functions

This module provides a set of Cypher procedures and functions that allows to call the methods from Cypher.

Cleaning the database stored procedure from Cypher

This procedure allows to clear your database. No parameter required. Example of usage:

CALL ga.resttest.clearDatabase();

Assertion functions from Cypher

This function allows to assert the state of the database. You need to provide a parameter described shortly. Example of usage:

RETURN ga.resttest.assertSameGraph("{ \"cypher\": \"...\"}") AS value;

This function is used to verify that the graph in the database is exactly the same as the graph created by the Cypher CREATE statement provided in the parameter. This means that the nodes, their properties and labels, relationships, and their properties and labels must be exactly the same. Note that Neo4j internal node/relationship IDs are ignored. In case the graphs aren't identical, the assertion fails and you will get false value. If the test passes, you will get a true value.

This function allows to assert a part of the database. You need to provide a parameter described shortly. Example of usage:

RETURN ga.resttest.assertSubgraph("{ \"cypher\": \"...\"}") AS value;

This function is is used to verify that the graph created by provided Cypher statement is a subgraph of the graph in the database. In case if the result of cypher is not identical of any subgraph of the database It will return false value. If it is a subgraph of the database you will get a true value.

This function allows to ensure that the database is empty. You can define a parameter described shortly or use with an empty string. Example of usage:

RETURN ga.resttest.assertEmpty("{ \"node\": \"...\"}") AS value;

If the database is not empty It will return false value. If it empty you will get a true value.

Request body and user function parameter

It is possible to use expressions to include/exclude certain nodes, relationships, and properties thereof from the comparisons. For example, for the purposes of comparison, if we only wanted to include nodes labelled Person, relationships with type FRIEND_OF, and ignore any timestamp properties on both nodes and relationships, the body of the POST request (or the parameter of the function) would look like this:

{
    "cypher": "CREATE (one:Person {name:'One'})-[:FRIEND_OF]->(two:Person {name:'Two'})",
    "node":"hasLabel('Person')",
    "relationship":"isType('FRIEND_OF')",
    "node.property":"key != 'timestamp'",
    "relationship.property":"key != 'timestamp'"
}

License

Copyright (c) 2014-2020 GraphAware

GraphAware is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

neo4j-resttest's People

Contributors

aldrinm avatar bachmanm avatar cebe avatar ikwattro avatar michal-trnka avatar szenyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neo4j-resttest's Issues

v3.5.11 has java.lang.NoClassDefFoundError: org/neo4j/test/TestGraphDatabaseFactory

First of all, thank you for this plugin. I'm trying to integrate your plugin with a PHP application and PHPUnit.

However it seems that neo4j has removed the TestGraphDatabaseFactory class from the public API in recent versions.

There is also a (rather old) discussion on the topic here: neo4j/neo4j#12118

You can see org.neo4j.test.TestGraphDatabaseFactory is imported here but it cannot be found at runtime.

My setup:

neo4j Server
v3.5.11

plugins
Graphaware-Framework: graphaware-server-community-all-3.5.11.54.jar
Graphaware-Resttest: graphaware-resttest-3.5.11.54.20.jar

config

com.graphaware.runtime.stats.disabled=true
com.graphaware.server.stats.disabled=true
dbms.unmanaged_extension_classes=com.graphaware.server=/graphaware

Reproduce with curl

curl -X POST -H "Content-Type: application/json" http://neo4j:7474/graphaware/resttest/assertSubgraph -d '{"cypher": "CREATE (n:Person)"}'

Exception:

neo4j_1 | org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: org/neo4j/test/TestGraphDatabaseFactory
neo4j_1 | at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:982)
neo4j_1 | at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
neo4j_1 | at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
neo4j_1 | at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
neo4j_1 | at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
neo4j_1 | at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
neo4j_1 | at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
neo4j_1 | at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:873)
neo4j_1 | at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1623)
neo4j_1 | at org.neo4j.server.rest.dbms.AuthorizationEnabledFilter.doFilter(AuthorizationEnabledFilter.java:132)
neo4j_1 | at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
neo4j_1 | at com.graphaware.server.tx.LongRunningTransactionFilter.doFilter(LongRunningTransactionFilter.java:88)
neo4j_1 | at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
neo4j_1 | at com.graphaware.server.foundation.bootstrap.GraphAwareBootstrappingFilter.doFilter(GraphAwareBootstrappingFilter.java:100)
neo4j_1 | at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
neo4j_1 | at org.neo4j.server.rest.web.CorsFilter.doFilter(CorsFilter.java:115)
neo4j_1 | at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
neo4j_1 | at org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(CollectUserAgentFilter.java:69)
neo4j_1 | at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
neo4j_1 | at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:540)
neo4j_1 | at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
neo4j_1 | at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1700)
neo4j_1 | at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
neo4j_1 | at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
neo4j_1 | at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
neo4j_1 | at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)
neo4j_1 | at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1667)
neo4j_1 | at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
neo4j_1 | at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
neo4j_1 | at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
neo4j_1 | at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:61)
neo4j_1 | at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
neo4j_1 | at org.eclipse.jetty.server.Server.handle(Server.java:505)
neo4j_1 | at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)
neo4j_1 | at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)
neo4j_1 | at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
neo4j_1 | at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
neo4j_1 | at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
neo4j_1 | at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:786)
neo4j_1 | at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:743)
neo4j_1 | at java.lang.Thread.run(Thread.java:748)
neo4j_1 | Caused by: java.lang.NoClassDefFoundError: org/neo4j/test/TestGraphDatabaseFactory
neo4j_1 | at com.graphaware.test.unit.GraphUnit.createTemporaryDb(GraphUnit.java:793)
neo4j_1 | at com.graphaware.test.unit.GraphUnit.assertSubgraph(GraphUnit.java:215)
neo4j_1 | at com.graphaware.module.resttest.RestTestApi.assertSubgraph(RestTestApi.java:85)
neo4j_1 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
neo4j_1 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
neo4j_1 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
neo4j_1 | at java.lang.reflect.Method.invoke(Method.java:498)
neo4j_1 | at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
neo4j_1 | at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
neo4j_1 | at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
neo4j_1 | at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
neo4j_1 | at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
neo4j_1 | at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
neo4j_1 | at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
neo4j_1 | ... 40 more
neo4j_1 | Caused by: java.lang.ClassNotFoundException: org.neo4j.test.TestGraphDatabaseFactory
neo4j_1 | at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
neo4j_1 | at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
neo4j_1 | at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
neo4j_1 | at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
neo4j_1 | ... 54 more

Clear the labels, indexes ...

Hi guys !

The actual version of the plugin deletes nodes and relationships but doesn't take care of labels, indexes, etc ... Would it be possible to update it so that it does so ?

I am thinking deleting the graph.db file would be very efficient (even though restarting the whole server not so much)

Thanks for the plugin anyway :)

Not working with Neo4j 3.1.0

I'm trying to setup graphaware-resttest-3.1.0.44.15.jar with Neo4j 3.1.0 CE but without success. I've tried different 3.1.* neo4j version but always getting the same error. I've tried also 3.0.7 together with graphaware-resttest-3.0.7.44.15.jar but also no success... Would appreciate your help!

If I start neo4j only with the framework plugin, everything works ok. If both jar files are inside, the error occurs. I have updated the neo4j.conf with dbms.unmanaged_extension_classes=com.graphaware.server=/graphaware

I'm on MacOS using docker images but the same happens when I use the dmg installer.

Starting Neo4j.
2017-03-30 11:49:33.533+0000 INFO  Starting...
2017-03-30 11:49:34.217+0000 INFO  Bolt enabled on 0.0.0.0:7687.
2017-03-30 11:49:36.511+0000 INFO  [c.g.r.b.RuntimeKernelExtension] GraphAware Runtime disabled.
2017-03-30 11:49:47.735+0000 ERROR Failed to start Neo4j: Starting Neo4j failed: Component 'org.neo4j.server.database.LifecycleManagingDatabase@5058a8e2' was successfully initialized, but failed to start. Please see attached cause exception. Starting Neo4j failed: Component 'org.neo4j.server.database.LifecycleManagingDatabase@5058a8e2' was successfully initialized, but failed to start. Please see attached cause exception.
org.neo4j.server.ServerStartupException: Starting Neo4j failed: Component 'org.neo4j.server.database.LifecycleManagingDatabase@5058a8e2' was successfully initialized, but failed to start. Please see attached cause exception.
	at org.neo4j.server.exception.ServerStartupErrors.translateToServerStartupError(ServerStartupErrors.java:68)
	at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:227)
	at org.neo4j.server.ServerBootstrapper.start(ServerBootstrapper.java:91)
	at org.neo4j.server.ServerBootstrapper.start(ServerBootstrapper.java:68)
	at org.neo4j.server.CommunityEntryPoint.main(CommunityEntryPoint.java:28)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.server.database.LifecycleManagingDatabase@5058a8e2' was successfully initialized, but failed to start. Please see attached cause exception.
	at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:443)
	at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107)
	at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:199)
	... 3 more
Caused by: java.lang.RuntimeException: Error starting org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory, /var/lib/neo4j/data/databases/graph.db
	at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.initFacade(GraphDatabaseFacadeFactory.java:199)
	at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:130)
	at org.neo4j.server.CommunityNeoServer.lambda$static$0(CommunityNeoServer.java:57)
	at org.neo4j.server.database.LifecycleManagingDatabase.start(LifecycleManagingDatabase.java:89)
	at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:433)
	... 5 more
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.proc.Procedures@35752757' was successfully initialized, but failed to start. Please see attached cause exception.
	at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:443)
	at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107)
	at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.initFacade(GraphDatabaseFacadeFactory.java:195)
	... 9 more
Caused by: org.neo4j.kernel.api.exceptions.ProcedureException: Conflicting procedure annotation, cannot use PerformsWrites and mode
	at org.neo4j.kernel.impl.proc.ReflectiveProcedureCompiler.compileProcedure(ReflectiveProcedureCompiler.java:168)
	at org.neo4j.kernel.impl.proc.ReflectiveProcedureCompiler.compileProcedure(ReflectiveProcedureCompiler.java:133)
	at org.neo4j.kernel.impl.proc.ProcedureJarLoader.loadProcedures(ProcedureJarLoader.java:92)
	at org.neo4j.kernel.impl.proc.ProcedureJarLoader.loadProceduresFromDir(ProcedureJarLoader.java:80)
	at org.neo4j.kernel.impl.proc.Procedures.start(Procedures.java:208)
	at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:433)
	... 11 more

Component 'org.neo4j.server.database.LifecycleManagingDatabase' was successfully initialized, but failed to start

I was trying to run neo4j database with restest library, but when trying to lunch service I'm getting stuck in neo4j starting loop, it's restarting after getting:
ERROR Failed to start Neo4j: Starting Neo4j failed: Component 'org.neo4j.server.database.LifecycleManagingDatabase@7bd3fafa' was successfully initialized, but failed to start.
I'm trying neo4j version 3.5.1 and 3.5.2 with corresponding framework and resttest libraries. (the same applies on enterprise version of neo4j)

Is there anything additional that is required to run this library?

logs from Ubuntu 18.04:
debug.log
journalctl.log
ll.log

config file used:
neo4j.conf.txt

Thanks,
Witold.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.