This is an automated email from the ASF dual-hosted git repository.

sergeykamov pushed a commit to branch NLPCRAFT-278
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCRAFT-278 by this push:
     new eba8e85  WIP.
eba8e85 is described below

commit eba8e85b38a8646d9e08c8db97d190b07cc2c475
Author: Sergey Kamov <[email protected]>
AuthorDate: Tue Mar 23 15:47:36 2021 +0300

    WIP.
---
 .../idl/compiler/functions/NCIdlFunctions.scala    | 28 +++-------
 .../compiler/functions/NCIdlFunctionsColl.scala    | 12 ++---
 .../compiler/functions/NCIdlFunctionsCompany.scala | 62 +++++++---------------
 .../compiler/functions/NCIdlFunctionsDate.scala    | 31 ++++++-----
 .../compiler/functions/NCIdlFunctionsMath.scala    |  6 +--
 ...tionsRequest.scala => NCIdlFunctionsMeta.scala} | 26 ++++++---
 ...ionsRequest.scala => NCIdlFunctionsOther.scala} | 27 +++++++---
 .../compiler/functions/NCIdlFunctionsRequest.scala |  2 +-
 .../compiler/functions/NCIdlFunctionsStat.scala    |  4 +-
 .../compiler/functions/NCIdlFunctionsStrings.scala | 12 ++---
 .../compiler/functions/NCIdlFunctionsToken.scala   |  4 +-
 .../compiler/functions/NCIdlFunctionsUser.scala    | 49 +++++------------
 12 files changed, 115 insertions(+), 148 deletions(-)

diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
index a4ef1a5..5420365 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
@@ -18,7 +18,7 @@
 package org.apache.nlpcraft.model.intent.idl.compiler.functions
 
 import org.apache.nlpcraft.model.intent.compiler.{NCIdlCompiler, 
NCIdlCompilerGlobal}
-import org.apache.nlpcraft.model.intent.{NCIdlContext, NCIdlFunction, 
NCIdlStackItem}
+import org.apache.nlpcraft.model.intent.{NCIdlContext, NCIdlFunction}
 import org.apache.nlpcraft.model.{NCCompany, NCModel, NCModelView, NCRequest, 
NCToken, NCUser}
 import org.junit.jupiter.api.BeforeEach
 
@@ -43,11 +43,7 @@ private[functions] trait NCIdlFunctions {
     @BeforeEach
     def before(): Unit = NCIdlCompilerGlobal.clearCache(MODEL_ID)
 
-    case class TrueFunc(
-        truth: String,
-        token: NCToken = tkn(),
-        idlCtx: NCIdlContext = ctx()
-    ) {
+    case class TestData(truth: String, token: NCToken = tkn(), idlCtx: 
NCIdlContext = ctx()) {
         val function: NCIdlFunction = {
             val intents = NCIdlCompiler.compileIntents(s"intent=i 
term(t)={$truth}", MODEL, MODEL_ID)
 
@@ -57,10 +53,7 @@ private[functions] trait NCIdlFunctions {
 
             require(intent.terms.size == 1)
 
-            new NCIdlFunction() {
-                override def apply(v1: NCToken, v2: NCIdlContext): 
NCIdlStackItem = intent.terms.head.pred.apply(v1, v2)
-                override def toString(): String = s"Function, based on term: 
$function"
-            }
+            intent.terms.head.pred
         }
 
         private def nvl(s: String, name: String): String = if (s != null) s 
else s"$name (not set)"
@@ -120,7 +113,6 @@ private[functions] trait NCIdlFunctions {
 
         new NCToken {
             override def getModel: NCModelView = MODEL
-
             override def getServerRequestId: String = srvReqId
             override def getId: String = id
             override def getParentId: String = parentId
@@ -137,7 +129,7 @@ private[functions] trait NCIdlFunctions {
         }
     }
 
-    protected def test(funcs: TrueFunc*): Unit =
+    protected def test(funcs: TestData*): Unit =
         for (f ← funcs) {
             val res =
                 try
@@ -147,20 +139,14 @@ private[functions] trait NCIdlFunctions {
                 }
 
             res match {
-                case b: java.lang.Boolean ⇒
-                    require(
-                        b,
-                        s"Unexpected FALSE result [" +
-                            s"testFunc=$f " +
-                            s"]"
-                    )
+                case b: java.lang.Boolean ⇒ require(b, s"Unexpected FALSE 
result [testFunc=$f]")
                 case _ ⇒
                     require(
                         requirement = false,
                         s"Unexpected result type [" +
                             s"resType=${if (res == null) null else 
res.getClass.getName}, " +
-                            s"testFunc='$f', " +
-                            s"resValue=$res" +
+                            s"resValue=$res, " +
+                            s"testFunc='$f'" +
                             s"]"
                     )
             }
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala
index f1e9562..a56a9da 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala
@@ -26,11 +26,11 @@ class NCIdlFunctionsColl extends NCIdlFunctions {
     @Test
     def test(): Unit =
         test(
-            TrueFunc(truth = "is_empty(list()) == true"),
-            TrueFunc(truth = "is_empty(list(1)) == false"),
-            TrueFunc(truth = "non_empty(list()) == false"),
-            TrueFunc(truth = "non_empty(list(1)) == true"),
-            TrueFunc(truth = "first(list(1, 2, 3)) == 1"),
-            TrueFunc(truth = "last(list(1, 2, 3)) == 3")
+            TestData(truth = "is_empty(list()) == true"),
+            TestData(truth = "is_empty(list(1)) == false"),
+            TestData(truth = "non_empty(list()) == false"),
+            TestData(truth = "non_empty(list(1)) == true"),
+            TestData(truth = "first(list(1, 2, 3)) == 1"),
+            TestData(truth = "last(list(1, 2, 3)) == 3")
         )
 }
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
index 3ad354c..708e922 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
@@ -18,60 +18,36 @@
 package org.apache.nlpcraft.model.intent.idl.compiler.functions
 
 import org.apache.nlpcraft.model.NCCompany
-import org.apache.nlpcraft.server.rest.NCRestSpec
-import org.junit.jupiter.api.{BeforeEach, Test}
+import org.junit.jupiter.api.Test
 
 import java.util
 import java.util.Optional
+import scala.collection.JavaConverters._
 
 /**
   * Tests for 'company' functions.
   */
-class NCIdlFunctionsCompany extends NCRestSpec with NCIdlFunctions {
-    private var company: NCCompany = _
-
-    @BeforeEach
-    def setCompany(): Unit = {
-        var compName: String = null
-        var compWebsite: String = null
-        var compCountry: String = null
-        var compRegion: String = null
-        var compCity: String = null
-        var compAddress: String = null
-        var compPostalCode: String = null
-        var props: java.util.Map[String, AnyRef] = null
-
-        post("company/get")(
-            ("$.name", (v: String) ⇒ compName = v),
-            ("$.website", (v: String) ⇒ compWebsite = v),
-            ("$.country", (v: String) ⇒ compCountry = v),
-            ("$.region", (v: String) ⇒ compRegion = v),
-            ("$.city", (v: String) ⇒ compCity = v),
-            ("$.address", (v: String) ⇒ compAddress = v),
-            ("$.postalCode", (v: String) ⇒ compPostalCode = v),
-            ("$.properties", (v: java.util.Map[String, AnyRef]) ⇒ props = v)
-        )
-
-        company = new NCCompany() {
-            override def getId: Long = -1  // TODO: No REST API data
-            override def getName: String = compName
-            override def getWebsite: Optional[String] = 
Optional.ofNullable(compWebsite)
-            override def getCountry: Optional[String] = 
Optional.ofNullable(compCountry)
-            override def getRegion: Optional[String] = 
Optional.ofNullable(compRegion)
-            override def getCity: Optional[String] = 
Optional.ofNullable(compCity)
-            override def getAddress: Optional[String] = 
Optional.ofNullable(compAddress)
-            override def getPostalCode: Optional[String] = 
Optional.ofNullable(compPostalCode)
-            override def getMetadata: util.Map[String, AnyRef] = props
-        }
-    }
-
+class NCIdlFunctionsCompany extends NCIdlFunctions {
     @Test
     def test(): Unit = {
-        val idlCtx = ctx(comp = company)
+        val comp = new NCCompany {
+            override def getId: Long = -1 // TODO: No REST API data
+            override def getName: String = "name"
+            override def getWebsite: Optional[String] = Optional.of("website")
+            override def getCountry: Optional[String] = Optional.of("country")
+            override def getRegion: Optional[String] = Optional.of("region")
+            override def getCity: Optional[String] = Optional.of("city")
+            override def getAddress: Optional[String] = Optional.of("address")
+            override def getPostalCode: Optional[String] = Optional.of("code")
+            override def getMetadata: util.Map[String, AnyRef] =
+                Map("k1" → "v1").map(p ⇒ p._1 → 
p._2.asInstanceOf[AnyRef]).asJava
+        }
+
+        val idlCtx = ctx(comp = comp)
 
         test(
-            TrueFunc(
-                truth = s"comp_name() == '${company.getName}'",
+            TestData(
+                truth = s"comp_name() == '${comp.getName}'",
                 idlCtx = idlCtx
             )
         )
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
index 31125a7..427b341 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
@@ -29,21 +29,26 @@ import java.util.Calendar
 class NCIdlFunctionsDate extends NCIdlFunctions {
     @Test
     def test(): Unit = {
-        def test0(): Unit =
+        def test0(): Unit = {
+            val d = LocalDate.now
+            val t = LocalTime.now
+            val c = Calendar.getInstance()
+
             test(
-                TrueFunc(truth = s"year() - ${LocalDate.now.getYear} == 0"),
-                TrueFunc(truth = s"month() - ${LocalDate.now.getMonthValue} == 
0"),
-                TrueFunc(truth = s"day_of_month() - 
${LocalDate.now.getDayOfMonth} == 0"),
-                TrueFunc(truth = s"day_of_week() - 
${LocalDate.now.getDayOfWeek.getValue} == 0"),
-                TrueFunc(truth = s"day_of_year() - 
${LocalDate.now.getDayOfYear} == 0"),
-                TrueFunc(truth = s"hour() - ${LocalTime.now.getHour} == 0"),
-                TrueFunc(truth = s"minute() - ${LocalTime.now.getMinute} == 
0"),
-                TrueFunc(truth = s"second() - ${LocalTime.now.getSecond} < 5"),
-                TrueFunc(truth = s"week_of_month() - 
${Calendar.getInstance().get(Calendar.WEEK_OF_MONTH)} == 0"),
-                TrueFunc(truth = s"week_of_year() - 
${Calendar.getInstance().get(Calendar.WEEK_OF_YEAR)} == 0"),
-                TrueFunc(truth = s"quarter() - 
${LocalDate.now().get(IsoFields.QUARTER_OF_YEAR)} == 0"),
-                TrueFunc(truth = s"now() - ${System.currentTimeMillis()} < 
5000")
+                TestData(truth = s"year() - ${d.getYear} == 0"),
+                TestData(truth = s"month() - ${d.getMonthValue} == 0"),
+                TestData(truth = s"day_of_month() - ${d.getDayOfMonth} == 0"),
+                TestData(truth = s"day_of_week() - ${d.getDayOfWeek.getValue} 
== 0"),
+                TestData(truth = s"day_of_year() - ${d.getDayOfYear} == 0"),
+                TestData(truth = s"hour() - ${t.getHour} == 0"),
+                TestData(truth = s"minute() - ${t.getMinute} == 0"),
+                TestData(truth = s"second() - ${t.getSecond} < 5"),
+                TestData(truth = s"week_of_month() - 
${c.get(Calendar.WEEK_OF_MONTH)} == 0"),
+                TestData(truth = s"week_of_year() - 
${c.get(Calendar.WEEK_OF_YEAR)} == 0"),
+                TestData(truth = s"quarter() - 
${d.get(IsoFields.QUARTER_OF_YEAR)} == 0"),
+                TestData(truth = s"now() - ${System.currentTimeMillis()} < 
5000")
             )
+        }
 
         try
             test0()
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
index aa16f41..033ffb1 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
@@ -26,8 +26,8 @@ class NCIdlFunctionsMath extends NCIdlFunctions {
     @Test
     def test(): Unit =
         test(
-            TrueFunc(truth = "sin(90.0) == 0"),
-            TrueFunc(truth = "sin(90) == 0"),
-            TrueFunc(truth = "rand() < 1")
+            TestData(truth = "sin(90.0) == 0"),
+            TestData(truth = "sin(90) == 0"),
+            TestData(truth = "rand() < 1")
         )
 }
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMeta.scala
similarity index 66%
copy from 
nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
copy to 
nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMeta.scala
index 998b39b..1cd74f1 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMeta.scala
@@ -19,19 +19,29 @@ package 
org.apache.nlpcraft.model.intent.idl.compiler.functions
 
 import org.junit.jupiter.api.Test
 
+import scala.sys.SystemProperties
+
 /**
-  * Tests for 'requests' functions.
+  * Tests for 'meta' functions.
   */
-class NCIdlFunctionsRequest extends NCIdlFunctions {
+class NCIdlFunctionsMeta extends NCIdlFunctions {
+    @Test
+    def testSys(): Unit = {
+        val sys = new SystemProperties
+
+        sys.put("k1", "v1")
+
+        test(
+            TestData(truth = "get(meta_sys(), 'k1') == 'v1'")
+        )
+    }
+
     @Test
-    def test(): Unit = {
-        val idlCtx = ctx(srvReqId = "req.id")
+    def testRequest(): Unit = {
+        val idlCtx = ctx(reqData = Map("k1" → "v1"))
 
         test(
-            TrueFunc(
-                truth = s"req_id() == '${idlCtx.req.getServerRequestId}'",
-                idlCtx = idlCtx
-            )
+            TestData(truth = "get(meta_req(), 'k1') == 'v1'", idlCtx = idlCtx)
         )
     }
 }
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsOther.scala
similarity index 63%
copy from 
nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
copy to 
nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsOther.scala
index 998b39b..d1e04eb 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsOther.scala
@@ -19,19 +19,30 @@ package 
org.apache.nlpcraft.model.intent.idl.compiler.functions
 
 import org.junit.jupiter.api.Test
 
+import scala.sys.SystemProperties
+
 /**
-  * Tests for 'requests' functions.
+  * Tests for 'other' functions.
   */
-class NCIdlFunctionsRequest extends NCIdlFunctions {
+class NCIdlFunctionsOther extends NCIdlFunctions {
+    @Test
+    def test1(): Unit =
+        // If.
+        test(
+            TestData(truth = "if(true, 1, 0) == 1"),
+            TestData(truth = "if(false, 1, 0) == 0")
+        )
+
     @Test
-    def test(): Unit = {
-        val idlCtx = ctx(srvReqId = "req.id")
+    def test2(): Unit = {
+        val sys = new SystemProperties
+
+        sys.put("k1", "v1")
 
+        // JSON.
         test(
-            TrueFunc(
-                truth = s"req_id() == '${idlCtx.req.getServerRequestId}'",
-                idlCtx = idlCtx
-            )
+            TestData(truth = "has(json(meta_sys()), 'k1') == true"),
+            TestData(truth = "has(json(meta_sys()), 'k2') == false")
         )
     }
 }
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
index 998b39b..ea4b1d0 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
@@ -28,7 +28,7 @@ class NCIdlFunctionsRequest extends NCIdlFunctions {
         val idlCtx = ctx(srvReqId = "req.id")
 
         test(
-            TrueFunc(
+            TestData(
                 truth = s"req_id() == '${idlCtx.req.getServerRequestId}'",
                 idlCtx = idlCtx
             )
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala
index 674085b..5ec613f 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala
@@ -26,7 +26,7 @@ class NCIdlFunctionsStat extends NCIdlFunctions {
     @Test
     def test(): Unit =
         test(
-            TrueFunc(truth = "max(list(1, 2, 3)) == 3"),
-            TrueFunc(truth = "min(list(1, 2, 3)) == 1")
+            TestData(truth = "max(list(1, 2, 3)) == 3"),
+            TestData(truth = "min(list(1, 2, 3)) == 1")
         )
 }
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
index b370f9c..43d19b2 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
@@ -26,11 +26,11 @@ class NCIdlFunctionsStrings extends NCIdlFunctions {
     @Test
     def test(): Unit =
         test(
-            TrueFunc(truth = "trim(' a b  ') == 'a b'"),
-            TrueFunc(truth = "strip(' a b  ') == 'a b'"),
-            TrueFunc(truth = "uppercase('aB') == 'AB'"),
-            TrueFunc(truth = "lowercase('aB') == 'ab'"),
-            TrueFunc(truth = "is_num('a') == false"),
-            TrueFunc(truth = "is_num('1') == true")
+            TestData(truth = "trim(' a b  ') == 'a b'"),
+            TestData(truth = "strip(' a b  ') == 'a b'"),
+            TestData(truth = "uppercase('aB') == 'AB'"),
+            TestData(truth = "lowercase('aB') == 'ab'"),
+            TestData(truth = "is_num('a') == false"),
+            TestData(truth = "is_num('1') == true")
         )
 }
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
index d2e8b63..23b7e64 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
@@ -26,11 +26,11 @@ class NCIdlFunctionsToken extends NCIdlFunctions {
     @Test
     def test(): Unit =
         test(
-            TrueFunc(
+            TestData(
                 truth = "id() == 'a'",
                 tkn(id = "a")
             ),
-            TrueFunc(
+            TestData(
                 truth = "parent() == 'a'",
                 tkn(parentId = "a")
             )
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
index 2df88d9..3883aaa 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
@@ -18,55 +18,34 @@
 package org.apache.nlpcraft.model.intent.idl.compiler.functions
 
 import org.apache.nlpcraft.model.NCUser
-import org.apache.nlpcraft.server.rest.NCRestSpec
-import org.junit.jupiter.api.{BeforeEach, Test}
+import org.junit.jupiter.api.Test
 
 import java.util
 import java.util.Optional
+import scala.collection.JavaConverters._
 
 /**
   * Tests for 'user' functions.
   */
-class NCIdlFunctionsUser extends NCRestSpec with NCIdlFunctions {
-    private var usr: NCUser = _
-
-    @BeforeEach
-    def setCompany(): Unit = {
-        var firstName: String = null
-        var lastName: String = null
-        var avatarUrl: String = null
-        var email: String = null
-        var adm: Boolean = false
-        var props: java.util.Map[String, AnyRef] = null
-
-        // Checks updated.
-        post("user/get")(
-            ("$.firstName", (v: String) ⇒ firstName = v),
-            ("$.lastName", (v: String) ⇒ lastName = v),
-            ("$.email", (v: String) ⇒ email = v),
-            ("$.avatarUrl", (v: String) ⇒ avatarUrl = v),
-            ("$.isAdmin", (v: Boolean) ⇒ adm = v),
-            ("$.properties", (v: java.util.Map[String, AnyRef]) ⇒ props = v)
-        )
-
-        usr = new NCUser {
+class NCIdlFunctionsUser extends NCIdlFunctions {
+    @Test
+    def test(): Unit = {
+        val usr = new NCUser {
             override def getId: Long = -1  // TODO: No REST API data
-            override def getFirstName: Optional[String] = 
Optional.ofNullable(firstName)
-            override def getLastName: Optional[String] = 
Optional.ofNullable(lastName)
-            override def getEmail: Optional[String] = 
Optional.ofNullable(email)
-            override def getAvatarUrl: Optional[String] = 
Optional.ofNullable(avatarUrl)
-            override def isAdmin: Boolean = adm
+            override def getFirstName: Optional[String] = 
Optional.of("firstName")
+            override def getLastName: Optional[String] = 
Optional.of("lastName")
+            override def getEmail: Optional[String] = Optional.of("email")
+            override def getAvatarUrl: Optional[String] = Optional.of("avatar")
+            override def isAdmin: Boolean = true
             override def getSignupTimestamp: Long = -1 // TODO: No REST API 
data
-            override def getMetadata: util.Map[String, AnyRef] = props
+            override def getMetadata: util.Map[String, AnyRef] =
+                Map("k1" → "v1").map(p ⇒ p._1 → 
p._2.asInstanceOf[AnyRef]).asJava
         }
-    }
 
-    @Test
-    def test(): Unit =  {
         val idlCtx = ctx(usr = usr)
 
         test(
-            TrueFunc(
+            TestData(
                 truth = s"user_email() == '${usr.getEmail.get()}'",
                 idlCtx = idlCtx
             )

Reply via email to