Skip to content

Commit

Permalink
test: added test case to check for empty parameters in custom functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Nov 8, 2023
1 parent 6ed87a3 commit a1d5530
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.arcadedb.function.sql;

import com.arcadedb.TestHelper;
import com.arcadedb.exception.CommandSQLParsingException;
import com.arcadedb.function.FunctionLibraryDefinition;
import com.arcadedb.query.sql.executor.ResultSet;
import com.arcadedb.query.sql.parser.ParseException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -23,11 +25,21 @@ public void testCallFromSQLWithParams() {

@Test
public void testCallFromSQLNoParams() {
registerFunctions();
database.command("sql", "define function math.hello \"select 'hello'\" language sql");
final ResultSet result = database.command("sql", "select `math.hello`() as result");
Assertions.assertEquals("hello", result.next().getProperty("result"));
}

@Test
public void errorTestCallFromSQLEmptyParams() {
try {
database.command("sql", "define function math.hello \"select 'hello'\" parameters [] language sql");
Assertions.fail();
} catch (CommandSQLParsingException e) {
// EXPECTED
}
}

@Test
public void testReuseSameQueryEngine() {
registerFunctions();
Expand Down Expand Up @@ -69,7 +81,6 @@ public void testRedefineFunction() {
private void registerFunctions() {
database.command("sql", "define function math.sum \"select :a + :b;\" parameters [a,b] language sql");
database.command("sql", "define function util.sum \"select :a + :b;\" parameters [a,b] language sql");
database.command("sql", "define function math.hello \"select 'hello'\" language sql");

final FunctionLibraryDefinition flib = database.getSchema().getFunctionLibrary("math");
Assertions.assertNotNull(flib);
Expand Down

0 comments on commit a1d5530

Please sign in to comment.