Skip to content

Commit

Permalink
refactor(test): moved tests to the new query engine
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Nov 14, 2024
1 parent c4f7f42 commit 4ff963f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.record.impl.ORecordBytes;
import com.orientechnologies.orient.core.sql.OCommandSQLParsingException;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.core.tx.OTransaction.TXTYPE;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
import com.orientechnologies.orient.test.domain.base.Agenda;
Expand Down Expand Up @@ -2151,7 +2150,7 @@ public void oidentifableFieldsTest() {
.getBytes();
oRecordBytes =
new ORecordBytes((ODatabaseDocumentInternal) database.getUnderlying(), thumbnailImageBytes);
oRecordBytes.save();
database.getUnderlying().save(oRecordBytes);
p.setByteArray(oRecordBytes);
p = database.save(p);
Assert.assertTrue(p.getByteArray() instanceof OBlob);
Expand Down Expand Up @@ -2470,15 +2469,13 @@ public void commandWithWrongNamedParameters() {
try {
database.getMetadata().getSchema().reload();

final OSQLSynchQuery<Profile> query =
new OSQLSynchQuery<Profile>(
"select from Profile where name = :name and surname = :surname%");
final String query = "select from Profile where name = :name and surname = :surname%";

HashMap<String, String> params = new HashMap<String, String>();
params.put("name", "Barack");
params.put("surname", "Obama");

List<Profile> result = database.command(query).execute(params);
List<Profile> result = database.objectCommand(query, params);
Assert.fail();
} catch (OCommandSQLParsingException e) {
Assert.assertTrue(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.record.impl.ORecordBytes;
import com.orientechnologies.orient.core.sql.OCommandSQLParsingException;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.core.tx.OTransaction.TXTYPE;
import com.orientechnologies.orient.test.domain.base.Agenda;
import com.orientechnologies.orient.test.domain.base.EmbeddedChild;
Expand Down Expand Up @@ -2489,15 +2488,13 @@ public void commandWithWrongNamedParameters() {
try {
database.getMetadata().getSchema().reload();

final OSQLSynchQuery<Profile> query =
new OSQLSynchQuery<Profile>(
"select from Profile where name = :name and surname = :surname%");
final String query = "select from Profile where name = :name and surname = :surname%";

HashMap<String, String> params = new HashMap<String, String>();
params.put("name", "Barack");
params.put("surname", "Obama");

List<Profile> result = database.command(query).execute(params);
List<Profile> result = database.objectCommand(query, params);
Assert.fail();

} catch (OCommandSQLParsingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public void testToJSONWithNoLazyLoadAndClosedDatabase() {
database.close();
String jsonLoaded = doc.toJSON();
Assert.assertEquals(jsonFull, jsonLoaded);
database.open("admin", "admin");
reopendb("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
doc.load("*:1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,27 +386,33 @@ public void testSelectExcludeFunction() throws IOException {
.command("create edge B from " + id4.getIdentity() + " to " + id.getIdentity())
.close();

List<ODocument> res =
database.query(
new OSQLSynchQuery<Object>(
"select a,b,in_B.out.exclude('out_B') from "
List<OResult> res =
database
.query(
"select a,b,in_B.out:{*,!out_B} as in_B from "
+ id2.getIdentity()
+ " fetchplan in_B.out:1"));
+ " fetchplan in_B.out:1")
.stream()
.toList();

Assert.assertNotNull(res.get(0).field("a"));
Assert.assertNotNull(res.get(0).field("b"));
Assert.assertNull((((List<ODocument>) res.get(0).field("in_B")).get(0).field("out_B")));
Assert.assertNotNull(res.get(0).getProperty("a"));
Assert.assertNotNull(res.get(0).getProperty("b"));
Assert.assertNull(
(((List<OResult>) res.get(0).getProperty("in_B")).get(0).getProperty("out_B")));

res =
database.query(
new OSQLSynchQuery<Object>(
"SELECT out.exclude('in_B') FROM ( SELECT EXPAND(in_B) FROM "
database
.query(
"SELECT out:{*,!in_B} as out FROM ( SELECT EXPAND(in_B) FROM "
+ id2.getIdentity()
+ " ) FETCHPLAN out:0 "));

Assert.assertNotNull(res.get(0).field("out"));
Assert.assertNotNull(((ODocument) res.get(0).field("out")).field("a"));
Assert.assertNull(((ODocument) res.get(0).field("out")).field("in_B"));
+ " ) FETCHPLAN out:0 ")
.stream()
.toList();

Assert.assertNotNull(res.get(0).getProperty("out"));
OResult out = res.get(0).getProperty("out");
Assert.assertNotNull(out.getProperty("a"));
Assert.assertNull(out.getProperty("in_B"));
} finally {
database.command("drop class A unsafe ").close();
database.command("drop class B unsafe ").close();
Expand All @@ -432,17 +438,20 @@ public void testSimpleExpandExclude() {
.command("create edge C from " + id2.getIdentity() + " to " + id3.getIdentity())
.close();

List<ODocument> res =
database.query(
new OSQLSynchQuery<Object>(
"select out.exclude('in_B') from (select expand(in_C) from "
List<OResult> res =
database
.query(
"select out:{*,!in_B} as out from (select expand(in_C) from "
+ id3.getIdentity()
+ " )"));
+ " )")
.stream()
.toList();
Assert.assertEquals(res.size(), 1);
ODocument ele = res.get(0);
Assert.assertNotNull(ele.field("out"));
Assert.assertEquals(((ODocument) ele.field("out")).field("a"), "a2");
Assert.assertNull(((ODocument) ele.field("out")).field("in_B"));
OResult ele = res.get(0);
Assert.assertNotNull(ele.getProperty("out"));
OResult out = res.get(0).getProperty("out");
Assert.assertEquals(out.getProperty("a"), "a2");
Assert.assertNull(out.getProperty("in_B"));

} finally {
database.command("drop class A unsafe ").close();
Expand Down

0 comments on commit 4ff963f

Please sign in to comment.