Example #1
0
        public virtual void ExecuteMultipleStatements()
        {
            // Document
            ResponseEntity response = GenConflict.get().expectedStatus(200).payload(QuotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' }, " + "{ 'statement': 'CREATE (n {props}) RETURN n', " + "'parameters': { 'props': { 'name': 'My Node' } } } ] }")).post(DataUri + "transaction/commit");

            // Then
            IDictionary <string, object> result = jsonToMap(response.Entity());

            AssertNoErrors(result);
            int?id = ResultCell(result, 0, 0);

            assertThat(GET(getNodeUri(id)).status(), @is(200));
            assertThat(response.Entity(), containsString("My Node"));
        }
Example #2
0
        public virtual void ShouldGet200WhenRetrievingNodeCompact()
        {
            string         uri    = _nodeUri.ToString();
            ResponseEntity entity = GenConflict.get().expectedType(CompactJsonFormat.MEDIA_TYPE).expectedStatus(200).get(uri);

            assertTrue(entity.Entity().Contains("self"));
        }
Example #3
0
        public virtual void BeginATransaction()
        {
            // Document
            ResponseEntity response = GenConflict.get().expectedStatus(201).payload(QuotedJson("{ 'statements': [ { 'statement': 'CREATE (n {props}) RETURN n', " + "'parameters': { 'props': { 'name': 'My Node' } } } ] }")).post(DataUri + "transaction");

            // Then
            IDictionary <string, object> result = jsonToMap(response.Entity());

            AssertNoErrors(result);
            IDictionary <string, object> node = ResultCell(result, 0, 0);

            assertThat(node["name"], equalTo("My Node"));
        }
Example #4
0
        public virtual void ErrorsInOpenTransaction()
        {
            // Given
            string location = POST(DataUri + "transaction").location();

            // Document
            ResponseEntity response = GenConflict.get().expectedStatus(200).payload(QuotedJson("{ 'statements': [ { 'statement': 'This is not a valid Cypher Statement.' } ] }")).post(location);

            // Then
            IDictionary <string, object> result = jsonToMap(response.Entity());

            assertThat(result, not(hasKey("transaction")));
        }
Example #5
0
        public virtual void HandlingErrors()
        {
            // Given
            string location = POST(DataUri + "transaction").location();

            // Document
            ResponseEntity response = GenConflict.get().expectedStatus(200).payload(QuotedJson("{ 'statements': [ { 'statement': 'This is not a valid Cypher Statement.' } ] }")).post(location + "/commit");

            // Then
            IDictionary <string, object> result = jsonToMap(response.Entity());

            AssertErrors(result, Org.Neo4j.Kernel.Api.Exceptions.Status_Statement.SyntaxError);
        }
Example #6
0
        public virtual void ExecuteStatementsInAnOpenTransaction()
        {
            // Given
            string location = POST(DataUri + "transaction").location();

            // Document
            ResponseEntity response = GenConflict.get().expectedStatus(200).payload(QuotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN n' } ] }")).post(location);

            // Then
            IDictionary <string, object> result = jsonToMap(response.Entity());

            assertThat(result, hasKey("transaction"));
            AssertNoErrors(result);
        }
Example #7
0
        public virtual void BeginAndCommitATransactionInOneRequest()
        {
            // Document
            ResponseEntity response = GenConflict.get().expectedStatus(200).payload(QuotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' } ] }")).post(DataUri + "transaction/commit");

            // Then
            IDictionary <string, object> result = jsonToMap(response.Entity());

            AssertNoErrors(result);

            int?id = ResultCell(result, 0, 0);

            assertThat(GET(getNodeUri(id)).status(), @is(200));
        }
Example #8
0
        public virtual void CreateAUniqueRelationshipOrReturnFail__Create()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String index = indexes.newInstance();
            string index = _indexes.newInstance();
            string key   = "name";
            string value = "Tobias";

            _helper.createRelationshipIndex(index);
            ResponseEntity response = GenConflict.get().expectedStatus(201).payloadType(MediaType.APPLICATION_JSON_TYPE).payload("{\"key\": \"" + key + "\", \"value\": \"" + value + "\", \"start\": \"" + _functionalTestHelper.nodeUri(_helper.createNode()) + "\", \"end\": \"" + _functionalTestHelper.nodeUri(_helper.createNode()) + "\", \"type\":\"" + MyRelationshipTypes.Knows + "\"}").post(_functionalTestHelper.relationshipIndexUri() + index + "?uniqueness=create_or_fail");
            MultivaluedMap <string, string> headers = response.Response().Headers;
            IDictionary <string, object>    result  = JsonHelper.jsonToMap(response.Entity());

            assertEquals(result["indexed"], headers.getFirst("Location"));
        }
Example #9
0
        public virtual void ReturnResultsInGraphFormat()
        {
            // Document
            ResponseEntity response = GenConflict.get().expectedStatus(200).payload(QuotedJson("{'statements':[{'statement':" + "'CREATE ( bike:Bike { weight: 10 } ) " + "CREATE ( frontWheel:Wheel { spokes: 3 } ) " + "CREATE ( backWheel:Wheel { spokes: 32 } ) " + "CREATE p1 = (bike)-[:HAS { position: 1 } ]->(frontWheel) " + "CREATE p2 = (bike)-[:HAS { position: 2 } ]->(backWheel) " + "RETURN bike, p1, p2', " + "'resultDataContents': ['row','graph']}] }")).post(DataUri + "transaction/commit");

            // Then
            IDictionary <string, object> result = jsonToMap(response.Entity());

            AssertNoErrors(result);

            IDictionary <string, IList <object> > row = GraphRow(result, 0);

            assertEquals(3, row["nodes"].Count);
            assertEquals(2, row["relationships"].Count);
        }
Example #10
0
        public virtual void IncludeQueryStatistics()
        {
            // Document
            ResponseEntity response = GenConflict.get().expectedStatus(200).payload(QuotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)', 'includeStats': true } ] }")).post(DataUri + "transaction/commit");

            // Then
            IDictionary <string, object> entity = jsonToMap(response.Entity());

            AssertNoErrors(entity);
            IDictionary <string, object> firstResult = ((IList <IDictionary <string, object> >)entity["results"])[0];

            assertThat(firstResult, hasKey("stats"));
            IDictionary <string, object> stats = (IDictionary <string, object>)firstResult["stats"];

            assertThat(stats["nodes_created"], equalTo(1));
        }
Example #11
0
        public virtual void ExecuteStatementsInAnOpenTransactionUsingREST()
        {
            // Given
            string location = POST(DataUri + "transaction").location();

            // Document
            ResponseEntity response = GenConflict.get().expectedStatus(200).payload(QuotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN n','resultDataContents':['REST'] } ] }")).post(location);

            // Then
            IDictionary <string, object> result = jsonToMap(response.Entity());
            List <object> rest    = (List <object>)((System.Collections.IDictionary)((List <object>)((System.Collections.IDictionary)((List <object>)result["results"])[0])["data"])[0])["rest"];
            string        selfUri = ( string )((System.Collections.IDictionary)rest[0])["self"];

            assertTrue(selfUri.StartsWith(DatabaseUri, StringComparison.Ordinal));
            AssertNoErrors(result);
        }
Example #12
0
        public virtual void Streaming()
        {
            Data.get();
            ResponseEntity responseEntity = Gen().withHeader(Org.Neo4j.Server.rest.repr.StreamingFormat_Fields.STREAM_HEADER, "true").expectedType(APPLICATION_JSON_TYPE).expectedStatus(200).get(DataUri);
            JaxRsResponse  response       = responseEntity.Response();
            // this gets the full media type, including things like
            // ; stream=true at the end
            string foundMediaType    = response.Type.ToString();
            string expectedMediaType = Org.Neo4j.Server.rest.repr.StreamingFormat_Fields.MediaType.ToString();

            assertEquals(expectedMediaType, foundMediaType);

            string body = responseEntity.Entity();
            IDictionary <string, object> map = JsonHelper.jsonToMap(body);

            assertEquals(DataUri + "node", map["node"]);
        }
Example #13
0
        public virtual void RollbackAnOpenTransaction()
        {
            // Given
            HTTP.Response firstReq = POST(DataUri + "transaction", HTTP.RawPayload.quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' } ] }"));
            string        location = firstReq.Location();

            // Document
            ResponseEntity response = GenConflict.get().expectedStatus(200).delete(location);

            // Then
            IDictionary <string, object> result = jsonToMap(response.Entity());

            AssertNoErrors(result);

            int?id = ResultCell(firstReq, 0, 0);

            assertThat(GET(getNodeUri(id)).status(), @is(404));
        }
Example #14
0
        public virtual void ResetTransactionTimeoutOfAnOpenTransaction()
        {
            // Given
            HTTP.Response initialResponse       = POST(DataUri + "transaction");
            string        location              = initialResponse.Location();
            long          initialExpirationTime = ExpirationTime(jsonToMap(initialResponse.RawContent()));

            // This generous wait time is necessary to compensate for limited resolution of RFC 1123 timestamps
            // and the fact that the system clock is allowed to run "backwards" between threads
            // (cf. http://stackoverflow.com/questions/2978598)
            //
            Thread.Sleep(3000);

            // Document
            ResponseEntity response = GenConflict.get().expectedStatus(200).payload(QuotedJson("{ 'statements': [ ] }")).post(location);

            // Then
            IDictionary <string, object> result = jsonToMap(response.Entity());

            AssertNoErrors(result);
            long newExpirationTime = ExpirationTime(result);

            assertTrue("Expiration time was not increased", newExpirationTime > initialExpirationTime);
        }