• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 
16 #include <gtest/gtest.h>
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <memory>
21 #include <string>
22 #include <variant>
23 
24 #include "gdb_errors.h"
25 #include "gdb_helper.h"
26 #include "gdb_store.h"
27 #include "grd_adapter_manager.h"
28 
29 using namespace testing::ext;
30 using namespace OHOS::DistributedDataAip;
31 class GdbQueryTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp();
36     void TearDown();
37     void InsertCompany(const std::string &name, const int32_t &founded);
38     void MatchAndVerifyCompany(const std::string &name, const int32_t &founded);
39     void VerifyCompanyInfo(const GraphValue &company, const std::string &name, const int32_t &founded);
40 
41     static const std::string databaseName;
42     static const std::string databasePath;
43     static std::shared_ptr<DBStore> store_;
44     static const std::string createGraphGql;
45     static const std::string createGraphGql2;
46     static const std::shared_ptr<StoreConfig> databaseConfig;
47 };
48 std::shared_ptr<DBStore> GdbQueryTest::store_;
49 const std::string GdbQueryTest::databaseName = "test_gdb";
50 const std::string GdbQueryTest::databasePath = "/data";
51 const std::string GdbQueryTest::createGraphGql = "CREATE GRAPH companyGraph { "
52                                                     "(company:Company {name STRING, founded INT}), "
53                                                     "(department:Department {name STRING}), "
54                                                     "(employee:Employee {name STRING, position STRING}), "
55                                                     "(project:Project {name STRING, budget INT}), "
56                                                     "(company) -[:HAS_DEPARTMENT]-> (department), "
57                                                     "(department) -[:HAS_EMPLOYEE]-> (employee), "
58                                                     "(employee) -[:WORKS_ON]-> (project), "
59                                                     "(department) -[:HAS_PROJECT]-> (project) "
60                                                     "};";
61 const std::string GdbQueryTest::createGraphGql2 = "CREATE GRAPH companyGraph2 {"
62                                                      "(company:Company {name STRING, founded INT}) };";
SetUpTestCase()63 void GdbQueryTest::SetUpTestCase()
64 {
65     if (!IsSupportArkDataDb()) {
66         GTEST_SKIP() << "Current testcase is not compatible from current gdb";
67     }
68     int errCode = E_OK;
69     auto config = StoreConfig(databaseName, databasePath);
70     GDBHelper::DeleteDBStore(config);
71 
72     GdbQueryTest::store_ = GDBHelper::GetDBStore(config, errCode);
73     EXPECT_NE(GdbQueryTest::store_, nullptr);
74     EXPECT_EQ(errCode, E_OK);
75 }
76 
TearDownTestCase()77 void GdbQueryTest::TearDownTestCase()
78 {
79     GDBHelper::DeleteDBStore(StoreConfig(databaseName, databasePath));
80     store_ = nullptr;
81 }
82 
SetUp()83 void GdbQueryTest::SetUp()
84 {
85     if (!IsSupportArkDataDb()) {
86         GTEST_SKIP() << "Current testcase is not compatible from current gdb";
87     }
88     auto result = store_->ExecuteGql(createGraphGql);
89     EXPECT_EQ(result.first, E_OK);
90 }
91 
TearDown()92 void GdbQueryTest::TearDown()
93 {
94     if (store_ != nullptr) {
95         auto result = store_->ExecuteGql("DROP GRAPH companyGraph");
96     }
97 }
98 
99 HWTEST_F(GdbQueryTest, GdbStore_Test_CreateHaveRowId, TestSize.Level1)
100 {
101     ASSERT_NE(store_, nullptr);
102     auto createGql = "CREATE GRAPH companyGraph3 {"
103                      "(company:Company {rowid INT, name STRING, founded INT}) };";
104     auto result = store_->ExecuteGql(createGql);
105     EXPECT_EQ(result.first, E_GRD_OVER_LIMIT);
106 }
107 
108 /**
109  * @tc.name: GdbStore_Test_CreateLimitDb
110  * @tc.desc: Too many graphs can be created for only one graph in a library. Failed to create too many graphs.
111  * @tc.type: FUNC
112  */
113 HWTEST_F(GdbQueryTest, GdbStore_Test_CreateLimitDb, TestSize.Level1)
114 {
115     ASSERT_NE(store_, nullptr);
116     // Too many graphs can be created for only one graph in a library. Failed to create too many graphs.
117     auto result = store_->ExecuteGql(createGraphGql2);
118     EXPECT_EQ(result.first, E_GRD_OVER_LIMIT);
119 }
120 
121 /**
122  * @tc.name: GdbStore_QuertTest_001
123  * @tc.desc: To test the function of querying an employee.
124  * @tc.type: FUNC
125  */
126 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_001, TestSize.Level1)
127 {
128     ASSERT_NE(store_, nullptr);
129     // Insert Employee
130     const std::string insertEmployeeQuery = "INSERT (:Employee {name: 'John Doe11', position: 'Software Engineer'});";
131     auto result = store_->ExecuteGql(insertEmployeeQuery);
132     EXPECT_EQ(result.first, E_OK);
133 
134     // Verifying the Employee Vertex
135     result = store_->QueryGql("MATCH (e:Employee {name: 'John Doe11'}) RETURN e;");
136     ASSERT_EQ(result.first, E_OK);
137     EXPECT_EQ(result.second->GetAllData().size(), 1);
138 
139     GraphValue employee = result.second->GetAllData()[0]["e"];
140     ASSERT_TRUE(std::holds_alternative<std::shared_ptr<Vertex>>(employee));
141     auto employeeVertex = std::get<std::shared_ptr<Vertex>>(employee);
142     EXPECT_EQ(employeeVertex->GetLabel(), "Employee");
143 
144     auto name = employeeVertex->GetProperties().find("name");
145     ASSERT_NE(name, employeeVertex->GetProperties().end());
146     EXPECT_EQ(std::get<std::string>(name->second), "John Doe11");
147 
148     auto position = employeeVertex->GetProperties().find("position");
149     ASSERT_NE(position, employeeVertex->GetProperties().end());
150     EXPECT_EQ(std::get<std::string>(position->second), "Software Engineer");
151 }
152 
153 /**
154  * @tc.name: GdbStore_QuertTest_002
155  * @tc.desc: To test the function of querying an Employee and Project and Relation.
156  * @tc.type: FUNC
157  */
158 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_002, TestSize.Level1)
159 {
160     ASSERT_NE(store_, nullptr);
161     // insert Employee
162     auto result = store_->ExecuteGql("INSERT (:Employee {name: 'John Doe', position: 'Software Engineer'});");
163     EXPECT_EQ(result.first, E_OK);
164     // insert Project
165     result = store_->ExecuteGql("INSERT (:Project {name: 'Project Alpha'});");
166     EXPECT_EQ(result.first, E_OK);
167 
168     // Associating an Employee with a Project, WORKS_ON
169     const std::string insertRelationQuery =
170         "MATCH (e:Employee {name: 'John Doe'}), (p:Project {name: 'Project Alpha'}) "
171         "INSERT (e)-[:WORKS_ON]->(p);";
172     result = store_->ExecuteGql(insertRelationQuery);
173     EXPECT_EQ(result.first, E_OK);
174 
175     // Querying and Verifying the Relationship Existence
176     result = store_->QueryGql("MATCH (e:Employee {name: 'John Doe'})-[r:WORKS_ON]->"
177                               "(p:Project {name: 'Project Alpha'}) RETURN e, r, p;");
178     ASSERT_EQ(result.first, E_OK);
179     ASSERT_NE(result.second, nullptr);
180     EXPECT_EQ(result.second->GetAllData().size(), 1);
181 
182     // Verifying the Employee Vertex
183     GraphValue employee = result.second->GetAllData()[0]["e"];
184     ASSERT_TRUE(std::holds_alternative<std::shared_ptr<Vertex>>(employee));
185     auto employeeVertex = std::get<std::shared_ptr<Vertex>>(employee);
186     EXPECT_EQ(employeeVertex->GetLabel(), "Employee");
187 
188     // Verifying Project Vertex
189     GraphValue project = result.second->GetAllData()[0]["p"];
190     ASSERT_TRUE(std::holds_alternative<std::shared_ptr<Vertex>>(project));
191     auto projectVertex = std::get<std::shared_ptr<Vertex>>(project);
192     EXPECT_EQ(projectVertex->GetLabel(), "Project");
193 
194     // Validate Relationships
195     GraphValue relation = result.second->GetAllData()[0]["r"];
196     ASSERT_TRUE(std::holds_alternative<std::shared_ptr<Edge>>(relation));
197     auto relationship = std::get<std::shared_ptr<Edge>>(relation);
198     EXPECT_EQ(relationship->GetSourceId(), "1");
199     EXPECT_EQ(relationship->GetTargetId(), "2");
200 }
201 
202 /**
203  * @tc.name: MatchAndVerifyCompany
204  * @tc.desc: Match And Verify that company information meets expectations
205  * @tc.type: FUNC
206  */
MatchAndVerifyCompany(const std::string & name,const int32_t & founded)207 void GdbQueryTest::MatchAndVerifyCompany(const std::string &name, const int32_t &founded)
208 {
209     ASSERT_NE(store_, nullptr);
210     auto gql = "MATCH (company:Company {name: '" + name + "'}) RETURN company;";
211     auto result = store_->QueryGql(gql);
212     ASSERT_EQ(result.first, E_OK);
213     ASSERT_NE(result.second, nullptr);
214     EXPECT_EQ(result.second->GetAllData().size(), 1);
215     GraphValue company = result.second->GetAllData()[0]["company"];
216     VerifyCompanyInfo(company, name, founded);
217 }
218 
219 /**
220  * @tc.name: VerifyCompanyInfo
221  * @tc.desc: Verify that company information meets expectations
222  * @tc.type: FUNC
223  */
VerifyCompanyInfo(const GraphValue & company,const std::string & name,const int32_t & founded)224 void GdbQueryTest::VerifyCompanyInfo(const GraphValue &company, const std::string &name, const int32_t &founded)
225 {
226     auto expectSize = 2;
227     ASSERT_TRUE(std::holds_alternative<std::shared_ptr<Vertex>>(company));
228     auto companyVertex = std::get<std::shared_ptr<Vertex>>(company);
229     EXPECT_EQ(companyVertex->GetLabel(), "Company");
230     ASSERT_EQ(companyVertex->GetProperties().size(), expectSize);
231 
232     auto nameDb = companyVertex->GetProperties().find("name");
233     ASSERT_NE(nameDb, companyVertex->GetProperties().end());
234     ASSERT_TRUE(std::holds_alternative<std::string>(nameDb->second));
235     EXPECT_EQ(std::get<std::string>(nameDb->second), name);
236 
237     auto foundedDb = companyVertex->GetProperties().find("founded");
238     ASSERT_NE(foundedDb, companyVertex->GetProperties().end());
239     ASSERT_TRUE(std::holds_alternative<int64_t>(foundedDb->second));
240     EXPECT_EQ(std::get<int64_t>(foundedDb->second), founded);
241 }
242 
243 /**
244  * @tc.name: InsertCompany
245  * @tc.desc: Insert Company Information
246  * @tc.type: FUNC
247  */
InsertCompany(const std::string & name,const int32_t & founded)248 void GdbQueryTest::InsertCompany(const std::string &name, const int32_t &founded)
249 {
250     ASSERT_NE(store_, nullptr);
251     auto result =
252         store_->ExecuteGql("INSERT (:Company {name: '" + name + "', founded: " + std::to_string(founded) + "});");
253     EXPECT_EQ(result.first, E_OK);
254     MatchAndVerifyCompany(name, founded);
255 }
256 
257 /**
258  * @tc.name: GdbStore_QuertTest_WhereInMatch
259  * @tc.desc: Verify the where condition in match.
260  * @tc.type: FUNC
261  */
262 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_WhereInMatch, TestSize.Level1)
263 {
264     ASSERT_NE(store_, nullptr);
265     InsertCompany("myCompany", 1991);
266     InsertCompany("myCompany2", 2001);
267     InsertCompany("myCompany3", 2011);
268     // where condition in match.
269     auto result = store_->QueryGql("MATCH (company:Company where company.founded > 2000) RETURN company;");
270     ASSERT_EQ(result.first, E_OK);
271     EXPECT_EQ(result.second->GetAllData().size(), 2);
272     GraphValue company = result.second->GetAllData()[0]["company"];
273     VerifyCompanyInfo(company, "myCompany2", 2001);
274 
275     GraphValue company1 = result.second->GetAllData()[1]["company"];
276     VerifyCompanyInfo(company1, "myCompany3", 2011);
277 }
278 
279 /**
280  * @tc.name: GdbStore_QuertTest_WhereOutsideMatch
281  * @tc.desc: Validate where condition outside match
282  * @tc.type: FUNC
283  */
284 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_WhereOutsideMatch, TestSize.Level1)
285 {
286     ASSERT_NE(store_, nullptr);
287     InsertCompany("myCompany", 1991);
288     InsertCompany("myCompany2", 2001);
289     InsertCompany("myCompany3", 2011);
290     // where condition outside match
291     auto result = store_->QueryGql("MATCH (company:Company) where company.founded != 2001 RETURN company;");
292     ASSERT_EQ(result.first, E_OK);
293     EXPECT_EQ(result.second->GetAllData().size(), 2);
294     GraphValue company = result.second->GetAllData()[0]["company"];
295     VerifyCompanyInfo(company, "myCompany", 1991);
296 
297     GraphValue company1 = result.second->GetAllData()[1]["company"];
298     VerifyCompanyInfo(company1, "myCompany3", 2011);
299 }
300 
301 /**
302  * @tc.name: GdbStore_QuertTest_WhereAppendAnd
303  * @tc.desc: Verify that the where condition is appended to the AND statement outside the match condition.
304  * @tc.type: FUNC
305  */
306 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_WhereAppendAnd, TestSize.Level1)
307 {
308     ASSERT_NE(store_, nullptr);
309 
310     InsertCompany("myCompany", 1991);
311     InsertCompany("myCompany2", 2001);
312     InsertCompany("myCompany3", 2011);
313     // Verify that the where condition is appended to the AND statement outside the match condition.
314     auto result = store_->QueryGql("MATCH (company:Company) "
315                                    "where company.founded != 2001 and company.name <> 'myCompany3' RETURN company;");
316     ASSERT_EQ(result.first, E_OK);
317     EXPECT_EQ(result.second->GetAllData().size(), 1);
318     GraphValue company = result.second->GetAllData()[0]["company"];
319     VerifyCompanyInfo(company, "myCompany", 1991);
320 }
321 
322 /**
323  * @tc.name: GdbStore_QuertTest_WhereOutsideAndInsideMatch
324  * @tc.desc: Validate where conditions outside and inside match
325  * @tc.type: FUNC
326  */
327 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_WhereOutsideAndInsideMatch, TestSize.Level1)
328 {
329     ASSERT_NE(store_, nullptr);
330 
331     InsertCompany("myCompany", 1991);
332     InsertCompany("myCompany2", 2001);
333     InsertCompany("myCompany3", 2011);
334     // Validate where conditions outside and inside match
335     auto result = store_->QueryGql("MATCH (company:Company where company.founded != 2001 ) "
336                                    " where company.name <> 'myCompany3' RETURN company;");
337     ASSERT_EQ(result.first, E_OK);
338     EXPECT_EQ(result.second->GetAllData().size(), 1);
339     GraphValue company = result.second->GetAllData()[0]["company"];
340     VerifyCompanyInfo(company, "myCompany", 1991);
341 }
342 
343 /**
344  * @tc.name: GdbStore_QuertTest_WhereStartAnd
345  * @tc.desc: The validation condition is outside and inside match, but outside it starts with and, not where.
346  * @tc.type: FUNC
347  */
348 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_WhereStartAnd, TestSize.Level1)
349 {
350     ASSERT_NE(store_, nullptr);
351 
352     InsertCompany("myCompany", 1991);
353     InsertCompany("myCompany2", 2001);
354     InsertCompany("myCompany3", 2011);
355     // The validation condition is outside and inside match, but outside it starts with and, not where.
356     auto result = store_->QueryGql("MATCH (company:Company where company.founded != 2001 ) "
357                                    " AND company.name <> 'myCompany3' RETURN company;");
358     ASSERT_EQ(result.first, E_GRD_SYNTAX_ERROR);
359     EXPECT_EQ(result.second->GetAllData().size(), 0);
360 }
361 
362 /**
363  * @tc.name: GdbStore_QuertTest_WhereByMatch
364  * @tc.desc: Use {} to transfer query conditions in match.
365  * @tc.type: FUNC
366  */
367 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_WhereByMatch, TestSize.Level1)
368 {
369     ASSERT_NE(store_, nullptr);
370 
371     InsertCompany("myCompany", 1991);
372     InsertCompany("myCompany2", 2001);
373     InsertCompany("myCompany3", 2011);
374     // The validation condition is outside and inside match, but outside it starts with and, not where.
375     auto result = store_->QueryGql("MATCH (company:Company {founded: 2001} ) "
376                                    " where company.name = 'myCompany2' RETURN company;");
377     ASSERT_EQ(result.first, E_OK);
378     EXPECT_EQ(result.second->GetAllData().size(), 1);
379     GraphValue company = result.second->GetAllData()[0]["company"];
380     VerifyCompanyInfo(company, "myCompany2", 2001);
381 }
382 
383 /**
384  * @tc.name: GdbStore_QuertTest_WhereOperators
385  * @tc.desc: Verify that operators are supported in the where condition.
386  * @tc.type: FUNC
387  */
388 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_WhereOperators, TestSize.Level1)
389 {
390     ASSERT_NE(store_, nullptr);
391 
392     InsertCompany("myCompany", 1991);
393     InsertCompany("myCompany2", 2001);
394     InsertCompany("myCompany3", 2011);
395     auto result = store_->QueryGql("MATCH (company:Company) "
396                                    "where company.founded >= 2000+1 and company.founded < 2012 -1 RETURN company;");
397     ASSERT_EQ(result.first, E_OK);
398     EXPECT_EQ(result.second->GetAllData().size(), 1);
399     GraphValue company = result.second->GetAllData()[0]["company"];
400     VerifyCompanyInfo(company, "myCompany2", 2001);
401 
402     result = store_->QueryGql("MATCH (company:Company) "
403                               "where company.founded > 2 * 1000 +1 and company.founded < 2 * 1000 +12 RETURN company;");
404     ASSERT_EQ(result.first, E_OK);
405     EXPECT_EQ(result.second->GetAllData().size(), 1);
406     company = result.second->GetAllData()[0]["company"];
407     VerifyCompanyInfo(company, "myCompany3", 2011);
408 }
409 
410 /**
411  * @tc.name: GdbStore_QuertTest_PostLike
412  * @tc.desc: Verify that the matching starts with a fixed character and ends with any number of other characters.
413  * @tc.type: FUNC
414  */
415 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_PostLike, TestSize.Level1)
416 {
417     ASSERT_NE(store_, nullptr);
418 
419     InsertCompany("myCompany", 1991);
420     InsertCompany("myCompany2", 2001);
421     InsertCompany("aimyCompany", 2011);
422     auto result = store_->QueryGql("MATCH (company:Company) "
423                                    "where company.name like 'myCompany%' RETURN company;");
424     ASSERT_EQ(result.first, E_OK);
425     EXPECT_EQ(result.second->GetAllData().size(), 2);
426     GraphValue company = result.second->GetAllData()[0]["company"];
427     VerifyCompanyInfo(company, "myCompany", 1991);
428 
429     company = result.second->GetAllData()[1]["company"];
430     VerifyCompanyInfo(company, "myCompany2", 2001);
431 }
432 
433 /**
434  * @tc.name: GdbStore_QuertTest_WhereLike
435  * @tc.desc: Matches contain specific characters.
436  * @tc.type: FUNC
437  */
438 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_Like, TestSize.Level1)
439 {
440     ASSERT_NE(store_, nullptr);
441 
442     InsertCompany("myCompany", 1991);
443     InsertCompany("myCompany2", 2001);
444     InsertCompany("aimyCompany", 2011);
445     auto result = store_->QueryGql("MATCH (company:Company) "
446                                    "where company.name like '%myCompany%' RETURN company;");
447     ASSERT_EQ(result.first, E_OK);
448     EXPECT_EQ(result.second->GetAllData().size(), 3);
449     GraphValue company = result.second->GetAllData()[0]["company"];
450     VerifyCompanyInfo(company, "myCompany", 1991);
451 
452     company = result.second->GetAllData()[1]["company"];
453     VerifyCompanyInfo(company, "myCompany2", 2001);
454 
455     company = result.second->GetAllData()[2]["company"];
456     VerifyCompanyInfo(company, "aimyCompany", 2011);
457 }
458 
459 /**
460  * @tc.name: GdbStore_QuertTest_BeferLike
461  * @tc.desc: Matches any number of other characters before the end of a fixed character.
462  * @tc.type: FUNC
463  */
464 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_BeferLike, TestSize.Level1)
465 {
466     ASSERT_NE(store_, nullptr);
467     InsertCompany("myCompany", 1991);
468     InsertCompany("myCompany2", 2001);
469     InsertCompany("aimyCompany", 2011);
470     auto result = store_->QueryGql("MATCH (company:Company) "
471                                    "where company.name like '%myCompany' RETURN company;");
472     ASSERT_EQ(result.first, E_OK);
473     EXPECT_EQ(result.second->GetAllData().size(), 2);
474     GraphValue company = result.second->GetAllData()[0]["company"];
475     VerifyCompanyInfo(company, "myCompany", 1991);
476 
477     company = result.second->GetAllData()[1]["company"];
478     VerifyCompanyInfo(company, "aimyCompany", 2011);
479 }
480 
481 /**
482  * @tc.name: GdbStore_QuertTest_MatchesCharacter
483  * @tc.desc: Matches a character
484  * @tc.type: FUNC
485  */
486 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_MatchesCharacter, TestSize.Level1)
487 {
488     ASSERT_NE(store_, nullptr);
489 
490     InsertCompany("myCompany", 1991);
491     InsertCompany("amyCompany", 2001);
492     InsertCompany("amyCompanya", 2002);
493     InsertCompany("abmyCompanyab", 2003);
494     InsertCompany("abmyCompany", 2004);
495     auto result = store_->QueryGql("MATCH (company:Company) "
496                                    "where company.name like '_myCompany' RETURN company;");
497     ASSERT_EQ(result.first, E_OK);
498     EXPECT_EQ(result.second->GetAllData().size(), 1);
499     GraphValue company = result.second->GetAllData()[0]["company"];
500     VerifyCompanyInfo(company, "amyCompany", 2001);
501 }
502 
503 /**
504  * @tc.name: GdbStore_QuertTest_MatchesCharacter02
505  * @tc.desc: Matches a character
506  * @tc.type: FUNC
507  */
508 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_MatchesCharacter02, TestSize.Level1)
509 {
510     ASSERT_NE(store_, nullptr);
511 
512     InsertCompany("myCompany", 1991);
513     InsertCompany("amyCompany", 2001);
514     InsertCompany("amyCompanya", 2002);
515     InsertCompany("abmyCompanyab", 2003);
516     InsertCompany("abmyCompany", 2004);
517     auto result = store_->QueryGql("MATCH (company:Company) "
518                                    "where company.name like '_myCompany_' RETURN company;");
519     ASSERT_EQ(result.first, E_OK);
520     EXPECT_EQ(result.second->GetAllData().size(), 1);
521     GraphValue company = result.second->GetAllData()[0]["company"];
522     VerifyCompanyInfo(company, "amyCompanya", 2002);
523 }
524 
525 /**
526  * @tc.name: GdbStore_QuertTest_MatchesCharacter03
527  * @tc.desc: Matches a character
528  * @tc.type: FUNC
529  */
530 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_MatchesCharacter03, TestSize.Level1)
531 {
532     ASSERT_NE(store_, nullptr);
533     InsertCompany("myCompany", 1991);
534     InsertCompany("myCompanya", 2001);
535     InsertCompany("myCompanyab", 2002);
536     InsertCompany("amyCompanya", 2003);
537     auto result = store_->QueryGql("MATCH (company:Company) "
538                                    "where company.name like 'myCompany_' RETURN company;");
539     ASSERT_EQ(result.first, E_OK);
540     EXPECT_EQ(result.second->GetAllData().size(), 1);
541     GraphValue company = result.second->GetAllData()[0]["company"];
542     VerifyCompanyInfo(company, "myCompanya", 2001);
543 }
544 
545 /**
546  * @tc.name: GdbStore_QuertTest_In
547  * @tc.desc: Match conditions in
548  * @tc.type: FUNC
549  */
550 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_In, TestSize.Level1)
551 {
552     ASSERT_NE(store_, nullptr);
553     InsertCompany("myCompany", 1991);
554     InsertCompany("myCompany1", 2001);
555     InsertCompany("myCompany2", 2002);
556     auto result = store_->QueryGql("MATCH (company:Company) "
557                                    "where company.founded in (2001, 2002, 9999) RETURN company;");
558     ASSERT_EQ(result.first, E_OK);
559     EXPECT_EQ(result.second->GetAllData().size(), 2);
560     GraphValue company = result.second->GetAllData()[0]["company"];
561     VerifyCompanyInfo(company, "myCompany1", 2001);
562 
563     company = result.second->GetAllData()[1]["company"];
564     VerifyCompanyInfo(company, "myCompany2", 2002);
565 }
566 
567 /**
568  * @tc.name: GdbStore_QuertTest_In01
569  * @tc.desc: Match conditions in
570  * @tc.type: FUNC
571  */
572 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_NotIn, TestSize.Level1)
573 {
574     ASSERT_NE(store_, nullptr);
575     InsertCompany("myCompany", 1991);
576     InsertCompany("myCompany1", 2001);
577     InsertCompany("myCompany2", 2002);
578     auto result = store_->QueryGql("MATCH (company:Company) "
579                                    "where company.founded not in (2001, 9999) RETURN company;");
580     ASSERT_EQ(result.first, E_OK);
581     EXPECT_EQ(result.second->GetAllData().size(), 2);
582     GraphValue company = result.second->GetAllData()[0]["company"];
583     VerifyCompanyInfo(company, "myCompany", 1991);
584 
585     company = result.second->GetAllData()[1]["company"];
586     VerifyCompanyInfo(company, "myCompany2", 2002);
587 }
588 
589 /**
590  * @tc.name: GdbStore_QuertTest_IsNull
591  * @tc.desc: Match conditions in
592  * @tc.type: FUNC
593  */
594 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_IsNull, TestSize.Level1)
595 {
596     ASSERT_NE(store_, nullptr);
597 
598     auto result = store_->ExecuteGql("INSERT (:Employee {name: 'zhangsan', position: 'Software'});");
599     EXPECT_EQ(result.first, E_OK);
600     result = store_->ExecuteGql("INSERT (:Employee {name: 'zhangsan1', position: 'Software1'});");
601     EXPECT_EQ(result.first, E_OK);
602     // 寮簊chema涓嬪叾浠栨湭濉瓧娈典负null
603     result = store_->ExecuteGql("MATCH (e:Employee {name: 'zhangsan'}) SET e = {position: 'SoftwareNew'};");
604     EXPECT_EQ(result.first, E_OK);
605     result = store_->QueryGql("MATCH (e:Employee) "
606                               "where e.name IS NULL RETURN e;");
607     ASSERT_EQ(result.first, E_OK);
608     EXPECT_EQ(result.second->GetAllData().size(), 1);
609     GraphValue company = result.second->GetAllData()[0]["e"];
610     ASSERT_TRUE(std::holds_alternative<std::shared_ptr<Vertex>>(company));
611     auto companyVertex = std::get<std::shared_ptr<Vertex>>(company);
612     EXPECT_EQ(companyVertex->GetLabel(), "Employee");
613     ASSERT_EQ(companyVertex->GetProperties().size(), 1);
614 
615     auto nameDb = companyVertex->GetProperties().find("name");
616     EXPECT_EQ(nameDb, companyVertex->GetProperties().end());
617 
618     auto foundedDb = companyVertex->GetProperties().find("position");
619     ASSERT_NE(foundedDb, companyVertex->GetProperties().end());
620     ASSERT_TRUE(std::holds_alternative<std::string>(foundedDb->second));
621     EXPECT_EQ(std::get<std::string>(foundedDb->second), "SoftwareNew");
622 }
623 
624 /**
625  * @tc.name: GdbStore_QuertTest_IsNotNull
626  * @tc.desc: Match conditions in
627  * @tc.type: FUNC
628  */
629 HWTEST_F(GdbQueryTest, GdbStore_QuertTest_IsNotNull, TestSize.Level1)
630 {
631     ASSERT_NE(store_, nullptr);
632 
633     auto result = store_->ExecuteGql("INSERT (:Company {founded: 1991});");
634     EXPECT_EQ(result.first, E_OK);
635     InsertCompany("myCompany1", 2001);
636     InsertCompany("myCompany2", 2002);
637     result = store_->QueryGql("MATCH (company:Company) "
638                               "where company.name IS NOT NULL RETURN company;");
639     ASSERT_EQ(result.first, E_OK);
640     EXPECT_EQ(result.second->GetAllData().size(), 2);
641     GraphValue company = result.second->GetAllData()[0]["company"];
642     VerifyCompanyInfo(company, "myCompany1", 2001);
643 
644     company = result.second->GetAllData()[1]["company"];
645     VerifyCompanyInfo(company, "myCompany2", 2002);
646 }