Esempio n. 1
0
        public void GraphClientFactoryUseCase()
        {
            const string queryText = @"MATCH (d) RETURN d";

            var cypherQuery = new CypherQuery(queryText, null, CypherResultMode.Set, CypherResultFormat.Rest);
            var cypherApiQuery = new CypherApiQuery(cypherQuery);

            using (var testHarness = new RestTestHarness
            {
                { MockRequest.Get("/"), MockResponse.NeoRoot() },
                { MockRequest.PostObjectAsJson("/cypher", cypherApiQuery), new MockResponse { StatusCode = HttpStatusCode.OK } }
            })
            {
                var httpClient = testHarness.GenerateHttpClient(testHarness.BaseUri);

                var executeConfiguration = new ExecutionConfiguration
                {
                    HttpClient = httpClient,
                    UserAgent =
                        string.Format("Neo4jClient/{0}", typeof(NeoServerConfiguration).Assembly.GetName().Version),
                    UseJsonStreaming = true,
                    JsonConverters = GraphClient.DefaultJsonConverters
                };

                var configuration = NeoServerConfiguration.GetConfiguration(new Uri(testHarness.BaseUri), null, null, executeConfiguration);

                var factory = new GraphClientFactory(configuration);

                using (var client = factory.Create(httpClient))
                {
                    client.Cypher.Match("(d)").Return<object>("d").ExecuteWithoutResults();
                }
            }
        }
 public void UserCanSetResourceManagerId()
 {
     var resourceManagerId = Guid.NewGuid();
     var configuration = new ExecutionConfiguration {ResourceManagerId = resourceManagerId};
     var executionEnvironment = new TransactionExecutionEnvironment(configuration);
     Assert.AreEqual(resourceManagerId, executionEnvironment.ResourceManagerId);
 }
 public RequestWithPendingContentBuilder(HttpMethod httpMethod, Uri endpoint, ExecutionConfiguration executionConfiguration, NameValueCollection customHeaders, int?maxExecutionTime)
 {
     this.httpMethod             = httpMethod;
     this.endpoint               = endpoint;
     this.executionConfiguration = executionConfiguration;
     this.customHeaders          = customHeaders;
     this.maxExecutionTime       = maxExecutionTime;
 }
 public RequestWithPendingContentBuilder(HttpMethod httpMethod, Uri endpoint, ExecutionConfiguration executionConfiguration, NameValueCollection customHeaders, int? maxExecutionTime)
 {
     _httpMethod = httpMethod;
     _endpoint = endpoint;
     _executionConfiguration = executionConfiguration;
     _customHeaders = customHeaders;
     _maxExecutionTime = maxExecutionTime;
 }
Esempio n. 5
0
 public ResponseBuilder(HttpRequestMessage request, ISet <HttpStatusCode> expectedStatusCodes,
                        ExecutionConfiguration executionConfiguration, IList <ErrorGenerator> errorGenerators)
 {
     _request                = request;
     _expectedStatusCodes    = expectedStatusCodes;
     _executionConfiguration = executionConfiguration;
     _errorGenerators        = errorGenerators;
 }
 public TransactionExecutionEnvironment(ExecutionConfiguration executionConfiguration)
 {
     UserAgent = executionConfiguration.UserAgent;
     UseJsonStreaming = executionConfiguration.UseJsonStreaming;
     Username = executionConfiguration.Username;
     Password = executionConfiguration.Password;
     JsonConverters = executionConfiguration.JsonConverters;
 }
Esempio n. 7
0
 public ResponseBuilder(HttpRequestMessage request, ISet <HttpStatusCode> expectedStatusCodes,
                        ExecutionConfiguration executionConfiguration, IList <ErrorGenerator> errorGenerators, NameValueCollection customHeaders, int?maxExecutionTime = null)
 {
     _request                = request;
     _expectedStatusCodes    = expectedStatusCodes;
     _executionConfiguration = executionConfiguration;
     _errorGenerators        = errorGenerators;
     _customHeaders          = customHeaders;
     _maxExecutionTime       = maxExecutionTime;
 }
Esempio n. 8
0
 public ResponseFailBuilder(HttpRequestMessage request, ISet <HttpStatusCode> expectedStatusCodes,
                            ExecutionConfiguration executionConfiguration, IList <ErrorGenerator> errorGenerators,
                            Func <HttpResponseMessage, bool> condition)
 {
     _request                = request;
     _expectedStatusCodes    = expectedStatusCodes;
     _executionConfiguration = executionConfiguration;
     _errorGenerators        = errorGenerators;
     _errorCondition         = condition;
 }
Esempio n. 9
0
 public ResponseFailBuilder(HttpRequestMessage request, ISet<HttpStatusCode> expectedStatusCodes,
     ExecutionConfiguration executionConfiguration, IList<ErrorGenerator> errorGenerators,
     Func<HttpResponseMessage, bool> errorCondition)
 {
     _request = request;
     _expectedStatusCodes = expectedStatusCodes;
     _executionConfiguration = executionConfiguration;
     _errorGenerators = errorGenerators;
     _errorCondition = errorCondition;
 }
 public ResponseFailBuilder(HttpRequestMessage request, ISet <HttpStatusCode> expectedStatusCodes,
                            ExecutionConfiguration executionConfiguration, IList <ErrorGenerator> errorGenerators,
                            Func <HttpResponseMessage, bool> errorCondition, NameValueCollection customHeaders)
 {
     _request                = request;
     _expectedStatusCodes    = expectedStatusCodes;
     _executionConfiguration = executionConfiguration;
     _errorGenerators        = errorGenerators;
     _errorCondition         = errorCondition;
     _customHeaders          = customHeaders;
 }
Esempio n. 11
0
        public void ShouldThrowExceptionIfRootApiIsNotDefined()
        {
            using (var testHarness = new RestTestHarness
            {
                { MockRequest.Get("/"), new MockResponse { StatusCode = HttpStatusCode.OK } }
            })
            {
                var httpClient = testHarness.GenerateHttpClient(testHarness.BaseUri);

                var executeConfiguration = new ExecutionConfiguration
                {
                    HttpClient = httpClient,
                    UserAgent =
                        string.Format("Neo4jClient/{0}", typeof(NeoServerConfiguration).Assembly.GetName().Version),
                    UseJsonStreaming = true,
                    JsonConverters = GraphClient.DefaultJsonConverters
                };

                NeoServerConfiguration.GetConfiguration(new Uri(testHarness.BaseUri), null, null, executeConfiguration);
            }
        }
Esempio n. 12
0
 private static void DoCommit(Uri commitUri, ExecutionConfiguration executionConfiguration, ISerializer serializer)
 {
     Request.With(executionConfiguration)
        .Post(commitUri.AddPath("commit"))
        .WithJsonContent(serializer.Serialize(new CypherStatementList()))
        .WithExpectedStatusCodes(HttpStatusCode.OK)
        .Execute();
 }
Esempio n. 13
0
 public static IRequestTypeBuilder With(ExecutionConfiguration configuration, NameValueCollection customerHeaders = null, int?maxExecutionTime = null)
 {
     return(new RequestTypeBuilder(configuration, customerHeaders, maxExecutionTime));
 }
        internal static NeoServerConfiguration GetConfiguration(Uri rootUri, string username, string password, ExecutionConfiguration executionConfiguration)
        {
            if (executionConfiguration == null)
            {
                var httpClient = new HttpClientWrapper(username, password);

                executionConfiguration = new ExecutionConfiguration
                {
                    HttpClient = httpClient,
                    UserAgent =
                        string.Format("Neo4jClient/{0}", typeof (NeoServerConfiguration).Assembly.GetName().Version),
                    UseJsonStreaming = true,
                    JsonConverters = GraphClient.DefaultJsonConverters,
                    Username = username,
                    Password = password
                };
            }

            if (!rootUri.AbsoluteUri.EndsWith("/"))
                rootUri = new Uri(rootUri.AbsoluteUri + "/");

            rootUri = new Uri(rootUri, "");

            var result = Request.With(executionConfiguration)
                .Get(rootUri)
                .WithExpectedStatusCodes(HttpStatusCode.OK)
                .ParseAs<RootApiResponse>()
                .Execute();

            if (result == null)
            {
                throw new ApplicationException("Couldn't obtain server Root API configuration.");
            }

            var rootUriWithoutUserInfo = rootUri;
            if (!string.IsNullOrEmpty(rootUriWithoutUserInfo.UserInfo))
            {
                rootUriWithoutUserInfo = new UriBuilder(rootUri.AbsoluteUri)
                {
                    UserName = "",
                    Password = ""
                }.Uri;
            }

            var baseUriLengthToTrim = rootUriWithoutUserInfo.AbsoluteUri.Length - 1;

            result.Batch = result.Batch.Substring(baseUriLengthToTrim);
            result.Node = result.Node.Substring(baseUriLengthToTrim);
            result.NodeIndex = result.NodeIndex.Substring(baseUriLengthToTrim);
            result.Relationship = "/relationship"; //Doesn't come in on the Service Root
            result.RelationshipIndex = result.RelationshipIndex.Substring(baseUriLengthToTrim);
            result.ExtensionsInfo = result.ExtensionsInfo.Substring(baseUriLengthToTrim);

            if (!string.IsNullOrEmpty(result.Transaction))
            {
                result.Transaction = result.Transaction.Substring(baseUriLengthToTrim);
            }

            if (result.Extensions != null && result.Extensions.GremlinPlugin != null)
            {
                result.Extensions.GremlinPlugin.ExecuteScript =
                    result.Extensions.GremlinPlugin.ExecuteScript.Substring(baseUriLengthToTrim);
            }

            if (result.Cypher != null)
            {
                result.Cypher = result.Cypher.Substring(baseUriLengthToTrim);
            }

            return new NeoServerConfiguration(result)
            {
                RootUri = rootUri,
                Username = username,
                Password = password
            };
        }
Esempio n. 15
0
 public RequestTypeBuilder(ExecutionConfiguration executionConfiguration)
 {
     _executionConfiguration = executionConfiguration;
 }
Esempio n. 16
0
 public ResponseBuilder(HttpRequestMessage request, ExecutionConfiguration executionConfiguration, NameValueCollection nameValueCollection, int?maxExecutionTime = null)
     : this(request, new HashSet <HttpStatusCode>(), executionConfiguration, new List <ErrorGenerator>(), nameValueCollection, maxExecutionTime)
 {
 }
 public void ResourceManagerIdDefaultValueIsSet()
 {
     var configuration = new ExecutionConfiguration();
     var executionEnvironment = new TransactionExecutionEnvironment(configuration);
     Assert.AreEqual(configuration.ResourceManagerId, executionEnvironment.ResourceManagerId);
 }
Esempio n. 18
0
 public ResponseBuilder(HttpRequestMessage request, ExecutionConfiguration executionConfiguration)
     : this(request, new HashSet <HttpStatusCode>(), executionConfiguration)
 {
 }
 public RequestWithPendingContentBuilder(HttpMethod httpMethod, Uri endpoint, ExecutionConfiguration executionConfiguration)
 {
     _httpMethod = httpMethod;
     _endpoint = endpoint;
     _executionConfiguration = executionConfiguration;
 }
Esempio n. 20
0
 public RequestTypeBuilder(ExecutionConfiguration executionConfiguration)
 {
     _executionConfiguration = executionConfiguration;
 }
Esempio n. 21
0
 public RequestWithPendingContentBuilder(HttpMethod httpMethod, Uri endpoint, ExecutionConfiguration executionConfiguration)
 {
     _httpMethod             = httpMethod;
     _endpoint               = endpoint;
     _executionConfiguration = executionConfiguration;
 }
 private string GetAuthorizationHeaderValue(ExecutionConfiguration executionConfig)
 {
     byte[] encoded =
         Encoding.ASCII.GetBytes(string.Format("{0}:{1}", executionConfig.Username, executionConfig.Password));
     return new AuthenticationHeaderValue("Basic", Convert.ToBase64String(encoded)).ToString();
 }
 public ResponseBuilder(HttpRequestMessage request, ISet <HttpStatusCode> expectedStatusCodes,
                        ExecutionConfiguration executionConfiguration)
     : this(request, expectedStatusCodes, executionConfiguration, new List <ErrorGenerator>())
 {
 }
 public RequestTypeBuilder(ExecutionConfiguration executionConfiguration, NameValueCollection customHeaders, int? maxExecutionTime)
 {
     _executionConfiguration = executionConfiguration;
     _customHeaders = customHeaders;
     _maxExecutionTime = maxExecutionTime;
 }
 public RequestTypeBuilder(ExecutionConfiguration executionConfiguration, NameValueCollection customHeaders, int?maxExecutionTime)
 {
     _executionConfiguration = executionConfiguration;
     _customHeaders          = customHeaders;
     _maxExecutionTime       = maxExecutionTime;
 }
 public ResponseBuilder(HttpRequestMessage request, ISet <HttpStatusCode> expectedStatusCodes,
                        ExecutionConfiguration executionConfiguration, IList <ErrorGenerator> errorGenerators)
     : base(request, expectedStatusCodes, executionConfiguration, errorGenerators, null)
 {
 }
Esempio n. 27
0
        private static Uri DoKeepAlive(
            Uri keepAliveUri,
            ExecutionConfiguration executionConfiguration,
            ISerializer serializer,
            bool newTransaction = false)
        {
            var partialRequest = Request.With(executionConfiguration)
                .Post(keepAliveUri)
                .WithJsonContent(serializer.Serialize(new CypherStatementList()));

            var response = newTransaction ?
                partialRequest.WithExpectedStatusCodes(HttpStatusCode.OK, HttpStatusCode.Created).Execute() :
                partialRequest.WithExpectedStatusCodes(HttpStatusCode.OK).Execute();

            return response.Headers.Location;
        }
Esempio n. 28
0
 public static IRequestTypeBuilder With(ExecutionConfiguration configuration, NameValueCollection customerHeaders = null, int? maxExecutionTime = null)
 {
     return new RequestTypeBuilder(configuration, customerHeaders, maxExecutionTime);
 }
Esempio n. 29
0
 private static void DoRollback(Uri rollbackUri, ExecutionConfiguration executionConfiguration)
 {
     // not found is ok because it means our transaction either was committed or the timeout was expired
     // and it was rolled back for us
     Request.With(executionConfiguration)
         .Delete(rollbackUri)
         .WithExpectedStatusCodes(HttpStatusCode.OK, HttpStatusCode.NotFound)
         .Execute();
 }