// Copyright 2023 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source // License, and you may not use this file except in compliance with the Business Source License. // // As of the Change Date specified in that file, in accordance with // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. #pragma once #include #include #include "query/v2/common.hpp" #include "query/v2/context.hpp" #include "query/v2/plan/operator.hpp" #include "query/v2/request_router.hpp" namespace memgraph::query::v2::tests { class MockedRequestRouter : public RequestRouterInterface { public: MOCK_METHOD(std::vector, ScanVertices, (std::optional label)); MOCK_METHOD(std::vector, CreateVertices, (std::vector)); MOCK_METHOD(std::vector, ExpandOne, (msgs::ExpandOneRequest)); MOCK_METHOD(std::vector, CreateExpand, (std::vector)); MOCK_METHOD(std::vector, GetProperties, (msgs::GetPropertiesRequest)); MOCK_METHOD(void, StartTransaction, ()); MOCK_METHOD(void, Commit, ()); MOCK_METHOD(storage::v3::EdgeTypeId, NameToEdgeType, (const std::string &), (const)); MOCK_METHOD(storage::v3::PropertyId, NameToProperty, (const std::string &), (const)); MOCK_METHOD(storage::v3::LabelId, NameToLabel, (const std::string &), (const)); MOCK_METHOD(storage::v3::LabelId, LabelToName, (const std::string &), (const)); MOCK_METHOD(const std::string &, PropertyToName, (storage::v3::PropertyId), (const)); MOCK_METHOD(const std::string &, LabelToName, (storage::v3::LabelId label), (const)); MOCK_METHOD(const std::string &, EdgeTypeToName, (storage::v3::EdgeTypeId type), (const)); MOCK_METHOD(std::optional, MaybeNameToProperty, (const std::string &), (const)); MOCK_METHOD(std::optional, MaybeNameToEdgeType, (const std::string &), (const)); MOCK_METHOD(std::optional, MaybeNameToLabel, (const std::string &), (const)); MOCK_METHOD(bool, IsPrimaryLabel, (storage::v3::LabelId), (const)); MOCK_METHOD(bool, IsPrimaryProperty, (storage::v3::LabelId, storage::v3::PropertyId), (const)); MOCK_METHOD((std::optional>), AllocateInitialEdgeIds, (io::Address)); MOCK_METHOD(void, InstallSimulatorTicker, (std::function)); MOCK_METHOD(const std::vector &, GetSchemaForLabel, (storage::v3::LabelId), (const)); }; class MockedLogicalOperator : public plan::LogicalOperator { public: MOCK_METHOD(plan::UniqueCursorPtr, MakeCursor, (utils::MemoryResource *), (const)); MOCK_METHOD(std::vector, ModifiedSymbols, (const expr::SymbolTable &), (const)); MOCK_METHOD(bool, HasSingleInput, (), (const)); MOCK_METHOD(std::shared_ptr, input, (), (const)); MOCK_METHOD(void, set_input, (std::shared_ptr)); MOCK_METHOD(std::unique_ptr, Clone, (AstStorage * storage), (const)); MOCK_METHOD(bool, Accept, (plan::HierarchicalLogicalOperatorVisitor & visitor)); }; class MockedCursor : public plan::Cursor { public: MOCK_METHOD(bool, Pull, (Frame &, expr::ExecutionContext &)); MOCK_METHOD(bool, PullMultiple, (MultiFrame &, expr::ExecutionContext &)); MOCK_METHOD(void, Reset, ()); MOCK_METHOD(void, Shutdown, ()); }; inline expr::ExecutionContext MakeContext(const expr::AstStorage &storage, const expr::SymbolTable &symbol_table, RequestRouterInterface *router, IdAllocator *id_alloc) { expr::ExecutionContext context; context.symbol_table = symbol_table; context.evaluation_context.properties = NamesToProperties(storage.properties_, router); context.evaluation_context.labels = NamesToLabels(storage.labels_, router); context.edge_ids_alloc = id_alloc; context.request_router = router; return context; } inline MockedLogicalOperator &BaseToMock(plan::LogicalOperator &op) { return dynamic_cast(op); } inline MockedCursor &BaseToMock(plan::Cursor &cursor) { return dynamic_cast(cursor); } } // namespace memgraph::query::v2::tests