|
| 1 | +/** |
| 2 | + * Copyright (c) 2002-2016 "Neo Technology," |
| 3 | + * Network Engine for Objects in Lund AB [http://neotechnology.com] |
| 4 | + * |
| 5 | + * This file is part of Neo4j. |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +var neo4j = require("../../../../lib/v1"); |
| 21 | +var util = require("./util"); |
| 22 | + |
| 23 | +module.exports = function () { |
| 24 | + |
| 25 | + this.Given(/^I have a driver$/, function () { |
| 26 | + }); |
| 27 | + |
| 28 | + this.When(/^I start a `Transaction` through a session$/, function () { |
| 29 | + this.transaction = this.session.beginTransaction() |
| 30 | + }); |
| 31 | + |
| 32 | + this.When(/^`run` a query with that same session without closing the transaction first$/, function (callback) { |
| 33 | + self = this; |
| 34 | + this.session.run("CREATE (:n)").then(function(result) {callback()}).catch(function(err) {self.error = err; callback()}) |
| 35 | + }); |
| 36 | + |
| 37 | + this.Then(/^it throws a `ClientException`$/, function (table) { |
| 38 | + expected = table.rows()[0][0]; |
| 39 | + if (this.error === undefined) { |
| 40 | + throw new Error("Exepcted an error but got none.") |
| 41 | + } |
| 42 | + if (this.error.message.indexOf(expected) != 0) { |
| 43 | + if (!(expected == "Unsupported URI scheme:" || expected == "Unable to connect to" )) |
| 44 | + { |
| 45 | + throw new Error("Error messages do not match. Given: '" + this.error.message + "'. Expected: '" + expected + "'"); |
| 46 | + } |
| 47 | + } |
| 48 | + }); |
| 49 | + |
| 50 | + this.When(/^I start a new `Transaction` with the same session before closing the previous$/, function () { |
| 51 | + try { |
| 52 | + this.session.beginTransaction(); |
| 53 | + } catch (e) { |
| 54 | + this.error = e; |
| 55 | + } |
| 56 | + |
| 57 | + }); |
| 58 | + |
| 59 | + this.When(/^I run a non valid cypher statement$/, function (callback) { |
| 60 | + self = this; |
| 61 | + this.session.run("CRETE (:n)").then(function(result) {callback()}).catch(function(err) {self.error = err.fields[0]; callback()}) |
| 62 | + }); |
| 63 | + |
| 64 | + this.When(/^I set up a driver to an incorrect port$/, function (callback) { |
| 65 | + self = this; |
| 66 | + driver = neo4j.driver("bolt://localhost:7777", neo4j.auth.basic("neo4j", "neo4j")); |
| 67 | + driver.session(); |
| 68 | + driver.onError = function (error) { self.error = error; callback()}; |
| 69 | + }); |
| 70 | + |
| 71 | + this.When(/^I set up a driver with wrong scheme$/, function (callback) { |
| 72 | + self = this; |
| 73 | + driver = neo4j.driver("wrong://localhost:7474", neo4j.auth.basic("neo4j", "neo4j")); |
| 74 | + driver.session(); |
| 75 | + driver.onError = function (error) { self.error = error; callback()}; |
| 76 | + }); |
| 77 | + |
| 78 | +} |
0 commit comments