예제 #1
0
        private void SetUpMocks()
        {
            _database             = mock(typeof(Database));
            _databaseFacade       = mock(typeof(GraphDatabaseFacade));
            _resolver             = mock(typeof(DependencyResolver));
            _executionEngine      = mock(typeof(ExecutionEngine));
            _statementBridge      = mock(typeof(ThreadToStatementContextBridge));
            _databaseQueryService = mock(typeof(GraphDatabaseQueryService));
            _kernelTransaction    = mock(typeof(KernelTransaction));
            _statement            = mock(typeof(Statement));
            _request = mock(typeof(HttpServletRequest));

            InternalTransaction transaction = new TopLevelTransaction(_kernelTransaction);

            LoginContext loginContext = AUTH_DISABLED;

            KernelTransaction.Type  type = KernelTransaction.Type.@implicit;
            QueryRegistryOperations registryOperations = mock(typeof(QueryRegistryOperations));

            when(_statement.queryRegistration()).thenReturn(registryOperations);
            when(_statementBridge.get()).thenReturn(_statement);
            when(_kernelTransaction.securityContext()).thenReturn(loginContext.Authorize(s => - 1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME));
            when(_kernelTransaction.transactionType()).thenReturn(type);
            when(_database.Graph).thenReturn(_databaseFacade);
            when(_databaseFacade.DependencyResolver).thenReturn(_resolver);
            when(_resolver.resolveDependency(typeof(QueryExecutionEngine))).thenReturn(_executionEngine);
            when(_resolver.resolveDependency(typeof(ThreadToStatementContextBridge))).thenReturn(_statementBridge);
            when(_resolver.resolveDependency(typeof(GraphDatabaseQueryService))).thenReturn(_databaseQueryService);
            when(_databaseQueryService.beginTransaction(type, loginContext)).thenReturn(transaction);
            when(_databaseQueryService.beginTransaction(type, loginContext, CUSTOM_TRANSACTION_TIMEOUT, TimeUnit.MILLISECONDS)).thenReturn(transaction);
            when(_databaseQueryService.DependencyResolver).thenReturn(_resolver);
            when(_request.Scheme).thenReturn("http");
            when(_request.RemoteAddr).thenReturn("127.0.0.1");
            when(_request.RemotePort).thenReturn(5678);
            when(_request.ServerName).thenReturn("127.0.0.1");
            when(_request.ServerPort).thenReturn(7474);
            when(_request.RequestURI).thenReturn("/");
        }