Skip to content

Commit

Permalink
refactor(test): corrected some tests to work with the new query engine
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Nov 20, 2024
1 parent fb3d768 commit 99f0f0f
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
Expand All @@ -49,6 +48,7 @@
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.junit.Ignore;
import org.junit.Test;

public class OCommandExecutorSQLSelectTest extends BaseMemoryDatabase {
Expand Down Expand Up @@ -787,11 +787,13 @@ public void testMultipleClusters() {
@Test
public void testMatches() {
List<?> result =
db.query(
new OSQLSynchQuery<Object>(
db
.query(
"select from foo where name matches"
+ " '(?i)(^\\\\Qa\\\\E$)|(^\\\\Qname2\\\\E$)|(^\\\\Qname3\\\\E$)' and bar ="
+ " 1"));
+ " 1")
.stream()
.toList();
assertEquals(result.size(), 1);
}

Expand Down Expand Up @@ -1313,6 +1315,7 @@ public void testComplexFilterInSquareBrackets() {
}

@Test
@Ignore
public void testCollateOnCollections() {
// issue #4851
db.command("create class OCommandExecutorSqlSelectTest_collateOnCollections").close();
Expand Down Expand Up @@ -1344,11 +1347,14 @@ public void testCollateOnCollections() {
.stream()
.toList();
assertEquals(results.size(), 1);
List<ODocument> results1 =
db.query(
new OSQLSynchQuery<ODocument>(
// TODO: this case in not supported for now need extensive refactor
List<OResult> results1 =
db
.query(
"select from OCommandExecutorSqlSelectTest_collateOnCollections where 'math' in"
+ " categories"));
+ " categories")
.stream()
.toList();
assertEquals(results1.size(), 1);
}

Expand Down Expand Up @@ -1388,16 +1394,16 @@ public void testEvalLong() {
}

@Test
@Ignore
public void testCollateOnLinked() {
initCollateOnLinked(db);

List<OResult> results =
db.query("select from CollateOnLinked2 where linked.name = 'foo' ").stream().toList();
assertEquals(results.size(), 1);
List<ODocument> results1 =
db.query(
new OSQLSynchQuery<ODocument>(
"select from CollateOnLinked2 where linked.name = 'FOO' "));
// TODO: this case in not supported for now need extensive refactor
List<OResult> results1 =
db.query("select from CollateOnLinked2 where linked.name = 'FOO' ").stream().toList();
assertEquals(results1.size(), 1);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.orientechnologies.orient.core.sql.select;

import com.orientechnologies.BaseMemoryDatabase;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.core.sql.executor.OResult;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -24,32 +23,32 @@ public void testEmbeddedRusultTypeNotLink() {
// doc
db.save(doc);

List<ODocument> res =
db.query(
new OSQLSynchQuery<Object>(
List<OResult> res =
db
.query(
"select $Pics[0] as el FROM Test LET $Pics = (select expand( rel.include('format'))"
+ " from $current)"));
+ " from $current)")
.stream()
.toList();
Assert.assertEquals(res.size(), 1);
ODocument ele = res.get(0);
Assert.assertNotNull(ele.field("el"));

byte[] bt = ele.toStream();
ODocument read = new ODocument(bt);
Assert.assertNotNull(read.field("el"));
Assert.assertEquals(read.fieldType("el"), OType.EMBEDDED);
OResult ele = res.get(0);
Assert.assertNotNull(ele.getProperty("el"));
Assert.assertTrue(ele.getProperty("el") instanceof OResult);
Assert.assertTrue(((OResult) ele.getProperty("el")).getIdentity().isEmpty());

res =
db.query(
new OSQLSynchQuery<Object>(
db
.query(
"select $Pics as el FROM Test LET $Pics = (select expand( rel.include('format'))"
+ " from $current)"));
+ " from $current)")
.stream()
.toList();

Assert.assertEquals(res.size(), 1);
ele = res.get(0);
Assert.assertNotNull(ele.field("el"));
bt = ele.toStream();
read = new ODocument(bt);
Assert.assertNotNull(read.field("el"));
Assert.assertEquals(read.fieldType("el"), OType.EMBEDDEDLIST);
Assert.assertNotNull(ele.getProperty("el"));
Assert.assertTrue(ele.getProperty("el") instanceof List<?>);
Assert.assertTrue(((List) ele.getProperty("el")).get(0) instanceof OResult);
Assert.assertTrue(((List<OResult>) ele.getProperty("el")).get(0).getIdentity().isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import java.util.List;
import java.util.Map;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;

Expand All @@ -15,7 +15,13 @@ protected AbstractSelectTest(@Optional String url) {
}

protected List<ODocument> executeQuery(String sql, ODatabaseDocumentInternal db, Object... args) {
final List<ODocument> synchResult = db.query(new OSQLSynchQuery<ODocument>(sql), args);
final List<ODocument> synchResult;
if (args.length == 1 && args[0] instanceof Map) {
synchResult =
db.query(sql, (Map) args[0]).stream().map((x) -> (ODocument) x.toElement()).toList();
} else {
synchResult = db.query(sql, args).stream().map((x) -> (ODocument) x.toElement()).toList();
}
return synchResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.orientechnologies.orient.core.hook.ODocumentHookAbstract;
import com.orientechnologies.orient.core.hook.ORecordHook;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.core.tx.OTransaction.TXTYPE;
import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -317,27 +316,4 @@ public void testEmbeddedDbListenersGraph() throws IOException {
dropdb();
createDatabase();
}

@Test
public void testEmbeddedDbListenersCommands() throws IOException {

if (database.getURL().startsWith("remote:")) return;

if (existsdb()) dropdb();
createDatabase();

final AtomicInteger recordedChanges = new AtomicInteger();

reopendb("admin", "admin");

database.registerListener(new DbListener());

String iText = "select from OUser";
Object execute = database.command(new OSQLSynchQuery<Object>(iText)).execute();

Assert.assertEquals(execute, commandResult);
Assert.assertEquals(iText, command);
dropdb();
createDatabase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.orientechnologies.orient.core.hook.ORecordHookAbstract;
import com.orientechnologies.orient.core.record.ORecord;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.test.domain.whiz.Profile;
import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -80,9 +79,7 @@ public void testHookCreate() throws IOException {
@Test(dependsOnMethods = "testHookCreate")
public void testHookRead() {
// TEST HOOKS ON READ
List<Profile> result =
database.query(
new OSQLSynchQuery<Profile>("select * from Profile where nick = 'HookTest'"));
List<Profile> result = database.objectQuery("select * from Profile where nick = 'HookTest'");
Assert.assertEquals(result.size(), 1);

for (int i = 0; i < result.size(); ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.orientechnologies.orient.core.hook.ORecordHookAbstract;
import com.orientechnologies.orient.core.record.ORecord;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
import com.orientechnologies.orient.test.domain.whiz.Profile;
import java.io.IOException;
Expand Down Expand Up @@ -102,9 +101,7 @@ public void testHookCallsCreate() {
public void testHookCallsRead() {
// TEST HOOKS ON READ
database.begin();
List<Profile> result =
database.query(
new OSQLSynchQuery<Profile>("select * from Profile where nick = 'HookTxTest'"));
List<Profile> result = database.objectQuery("select * from Profile where nick = 'HookTxTest'");
expectedHookState += RECORD_BEFORE_READ + RECORD_AFTER_READ;

Assert.assertFalse(result.size() == 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ public void queryContainsInEmbeddedSet() {
Assert.assertEquals(resultset.get(0).getIdentity(), doc.getIdentity());

resultset =
executeQuery("select from Profile where tags[0-1] CONTAINSALL ['smart','nice']", database);
executeQuery(
"select from Profile where tags[0...1] CONTAINSALL ['smart','nice']", database);

Assert.assertEquals(resultset.size(), 1);
Assert.assertEquals(resultset.get(0).getIdentity(), doc.getIdentity());
Expand Down Expand Up @@ -247,7 +248,8 @@ public void queryContainsInEmbeddedList() {
Assert.assertEquals(resultset.get(0).getIdentity(), doc.getIdentity());

resultset =
executeQuery("select from Profile where tags[0-1] CONTAINSALL ['smart','nice']", database);
executeQuery(
"select from Profile where tags[0...1] CONTAINSALL ['smart','nice']", database);

Assert.assertEquals(resultset.size(), 1);
Assert.assertEquals(resultset.get(0).getIdentity(), doc.getIdentity());
Expand All @@ -270,8 +272,9 @@ public void queryContainsInDocumentSet() {
executeQuery(
"select coll[name='Jay'] as value from Profile where coll is not null", database);
Assert.assertEquals(resultset.size(), 1);
Assert.assertTrue(resultset.get(0).field("value") instanceof ODocument);
Assert.assertEquals(((ODocument) resultset.get(0).field("value")).field("name"), "Jay");
Assert.assertTrue(resultset.get(0).field("value") instanceof List);
List<ODocument> list = (List<ODocument>) resultset.get(0).field("value");
Assert.assertEquals(list.get(0).field("name"), "Jay");

database.delete(doc);
}
Expand All @@ -291,8 +294,9 @@ public void queryContainsInDocumentList() {
executeQuery(
"select coll[name='Jay'] as value from Profile where coll is not null", database);
Assert.assertEquals(resultset.size(), 1);
Assert.assertTrue(resultset.get(0).field("value") instanceof ODocument);
Assert.assertEquals(((ODocument) resultset.get(0).field("value")).field("name"), "Jay");
Assert.assertTrue(resultset.get(0).field("value") instanceof List);
List<ODocument> list = (List<ODocument>) resultset.get(0).field("value");
Assert.assertEquals(list.get(0).field("name"), "Jay");

database.delete(doc);
}
Expand Down Expand Up @@ -324,14 +328,14 @@ public void queryContainsInEmbeddedMapClassic() {

resultset =
executeQuery(
"select from Profile where customReferences[second]['name'] like 'Ja%'", database);
"select from Profile where customReferences['second'].name like 'Ja%'", database);
Assert.assertEquals(resultset.size(), 1);
Assert.assertEquals(resultset.get(0).getIdentity(), doc.getIdentity());

resultset =
executeQuery(
"select customReferences['second', 'first'] from Profile where customReferences.size()"
+ " = 2",
"select customReferences['second', 'first'] as customReferences from Profile where"
+ " customReferences.size() = 2",
database);
Assert.assertEquals(resultset.size(), 1);

Expand All @@ -351,15 +355,15 @@ public void queryContainsInEmbeddedMapClassic() {

resultset =
executeQuery(
"select customReferences[second]['name'] from Profile where"
+ " customReferences[second]['name'] is not null",
"select customReferences['second'].name from Profile where"
+ " customReferences['second'].name is not null",
database);
Assert.assertEquals(resultset.size(), 1);

resultset =
executeQuery(
"select customReferences[second]['name'] as value from Profile where"
+ " customReferences[second]['name'] is not null",
"select customReferences['second'].name as value from Profile where"
+ " customReferences['second'].name is not null",
database);
Assert.assertEquals(resultset.size(), 1);

Expand Down Expand Up @@ -526,7 +530,7 @@ public void queryCollectionInNumbers() {
database.save(record);

List<ODocument> result =
executeQuery("select * from cluster:animal where rates in [100,200]", database);
executeQuery("select * from Animal where rates in [100,200]", database);

boolean found = false;
for (int i = 0; i < result.size() && !found; ++i) {
Expand All @@ -545,7 +549,7 @@ record = result.get(i);
}
Assert.assertTrue(found);

result = executeQuery("select * from cluster:animal where rates in [200,10333]", database);
result = executeQuery("select * from Animal where rates in [200,10333]", database);

found = false;
for (int i = 0; i < result.size() && !found; ++i) {
Expand All @@ -564,10 +568,10 @@ record = result.get(i);
}
Assert.assertTrue(found);

result = executeQuery("select * from cluster:animal where rates contains 500", database);
result = executeQuery("select * from Animal where rates contains 500", database);
Assert.assertEquals(result.size(), 0);

result = executeQuery("select * from cluster:animal where rates contains 100", database);
result = executeQuery("select * from Animal where rates contains 100", database);
Assert.assertEquals(result.size(), 1);

database.delete(record);
Expand Down Expand Up @@ -640,11 +644,11 @@ public void queryOrderBy() {
Assert.assertTrue(result.size() != 0);

String lastName = null;
boolean isNullSegment = true; // NULL VALUES AT THE BEGINNING!
boolean isDataSegment = true; // NULL VALUES AT THE END!
for (ODocument d : result) {
final String fieldValue = d.field("name");
if (fieldValue != null) isNullSegment = false;
else Assert.assertTrue(isNullSegment);
if (fieldValue != null) Assert.assertTrue(isDataSegment);
else isDataSegment = false;

if (lastName != null && fieldValue != null)
Assert.assertTrue(fieldValue.compareTo(lastName) >= 0);
Expand Down Expand Up @@ -1148,7 +1152,7 @@ public void testQueryNotOperator() {
public void testSquareBracketsOnCondition() {
List<ODocument> result =
executeQuery(
"select from Account where addresses[@class='Address'][city.country.name] ="
"select from Account where addresses[@class='Address'].city.country.name ="
+ " 'Washington'",
database);
Assert.assertFalse(result.isEmpty());
Expand Down

0 comments on commit 99f0f0f

Please sign in to comment.