This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-510
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-510 by this push:
new f3ed1cb4 Test client.
f3ed1cb4 is described below
commit f3ed1cb40bd1c0f2d66d7e140609aa0737c16868
Author: Sergey Kamov <[email protected]>
AuthorDate: Sat Aug 6 20:38:49 2022 +0300
Test client.
---
.../nlpcraft/examples/lightswitch/NCModelValidationSpec.scala | 2 +-
.../nlpcraft/examples/lightswitch/NCModelValidationSpec.scala | 2 +-
.../nlpcraft/examples/lightswitch/NCModelValidationSpec.scala | 2 +-
.../org/apache/nlpcraft/examples/time/NCModelValidationSpec.scala | 2 +-
.../main/scala/org/apache/nlpcraft/test/NCModelTestClient.scala | 8 +++++++-
.../org/apache/nlpcraft/internal/impl/NCModelClientSpec.scala | 2 +-
.../org/apache/nlpcraft/internal/impl/NCModelClientSpec2.scala | 2 +-
.../org/apache/nlpcraft/internal/impl/NCModelClientSpec3.scala | 2 +-
8 files changed, 14 insertions(+), 8 deletions(-)
diff --git
a/nlpcraft-examples/lightswitch-fr/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
b/nlpcraft-examples/lightswitch-fr/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
index ed6aa923..a58af3bc 100644
---
a/nlpcraft-examples/lightswitch-fr/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
+++
b/nlpcraft-examples/lightswitch-fr/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
@@ -28,4 +28,4 @@ import scala.util.Using
*/
class NCModelValidationSpec:
@Test
- def test(): Unit = Using.resource(new NCModelClient(new
LightSwitchFrModel)) {client => new NCModelTestClient(client).validateSamples()
}
+ def test(): Unit = Using.resource(new NCModelTestClient(new
LightSwitchFrModel)) { _.validateSamples() }
diff --git
a/nlpcraft-examples/lightswitch-ru/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
b/nlpcraft-examples/lightswitch-ru/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
index 67985ab1..ce5cd48d 100644
---
a/nlpcraft-examples/lightswitch-ru/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
+++
b/nlpcraft-examples/lightswitch-ru/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
@@ -28,4 +28,4 @@ import scala.util.Using
*/
class NCModelValidationSpec:
@Test
- def test(): Unit = Using.resource(new NCModelClient(new
LightSwitchRuModel)) { client => new
NCModelTestClient(client).validateSamples() }
+ def test(): Unit = Using.resource(new NCModelTestClient(new
LightSwitchRuModel)) { _.validateSamples() }
diff --git
a/nlpcraft-examples/lightswitch/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
b/nlpcraft-examples/lightswitch/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
index e0c63315..ef9102f0 100644
---
a/nlpcraft-examples/lightswitch/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
+++
b/nlpcraft-examples/lightswitch/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
@@ -27,7 +27,7 @@ import scala.util.Using
* JUnit models validation.
*/
class NCModelValidationSpec:
- private def test(mdl: NCModel): Unit = Using.resource(new
NCModelClient(mdl)) { client => new NCModelTestClient(client).validateSamples()
}
+ private def test(mdl: NCModel): Unit = Using.resource(new
NCModelTestClient(mdl)) { _.validateSamples() }
@Test
def test(): Unit = test(new LightSwitchScalaModel())
diff --git
a/nlpcraft-examples/time/src/test/scala/org/apache/nlpcraft/examples/time/NCModelValidationSpec.scala
b/nlpcraft-examples/time/src/test/scala/org/apache/nlpcraft/examples/time/NCModelValidationSpec.scala
index af27666c..ac0f6c24 100644
---
a/nlpcraft-examples/time/src/test/scala/org/apache/nlpcraft/examples/time/NCModelValidationSpec.scala
+++
b/nlpcraft-examples/time/src/test/scala/org/apache/nlpcraft/examples/time/NCModelValidationSpec.scala
@@ -28,4 +28,4 @@ import scala.util.Using
*/
class NCModelValidationSpec:
@Test
- def test(): Unit = Using.resource(new NCModelClient(new TimeModel())) {
client => new NCModelTestClient(client).validateSamples() }
+ def test(): Unit = Using.resource(new NCModelTestClient(new TimeModel()))
{ _.validateSamples() }
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/test/NCModelTestClient.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/test/NCModelTestClient.scala
index 5ada8efc..8e56eeb3 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/test/NCModelTestClient.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/test/NCModelTestClient.scala
@@ -17,6 +17,7 @@
package org.apache.nlpcraft.test
+import com.typesafe.scalalogging.LazyLogging
import org.apache.nlpcraft.*
import org.apache.nlpcraft.internal.ascii.NCAsciiTable
import org.apache.nlpcraft.internal.intent.matcher.NCIntentSolveType
@@ -24,7 +25,12 @@ import
org.apache.nlpcraft.internal.intent.matcher.NCIntentSolveType.*
import java.util.UUID
-class NCModelTestClient(client: NCModelClient):
+class NCModelTestClient(mdl: NCModel) extends LazyLogging, AutoCloseable:
+ private val client = new NCModelClient(mdl)
+ /**
+ * */
+ def close(): Unit = client.close()
+
def debugAsk(txt: String, data: Map[String, AnyRef], usrId: String,
saveHist: Boolean): NCCallbackData =
client.debugAsk(txt, data, usrId, saveHist)
def debugAsk(txt: String, usrId: String, saveHist: Boolean):
NCCallbackData =
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec.scala
index ff804b6d..5bb0eaf5 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec.scala
@@ -53,7 +53,7 @@ class NCModelClientSpec:
println(s"Intent: ${res.getIntentId}")
println(s"Body: ${res.getBody}")
- new NCModelTestClient(client).validateSamples()
+ Using.resource(new NCModelTestClient(mdl)) { _.validateSamples() }
val winner = client.debugAsk("Lights on at second floor kitchen",
"userId", true)
println(s"Winner intent: ${winner.getIntentId}")
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec2.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec2.scala
index 86873401..2987b57a 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec2.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec2.scala
@@ -50,7 +50,7 @@ class NCModelClientSpec2:
Using.resource(new NCModelClient(mdl)) { client =>
case class Result(txt: String):
- private val wi = new NCModelTestClient(client).debugAsk(txt,
"userId", true)
+ private val wi = Using.resource(new NCModelTestClient(mdl)) {
_.debugAsk(txt, "userId", true) }
private val allArgs: List[List[NCEntity]] =
wi.getCallbackArguments
val intentId: String = wi.getIntentId
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec3.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec3.scala
index 414b4c45..232b94a0 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec3.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec3.scala
@@ -48,7 +48,7 @@ class NCModelClientSpec3:
def onMatch(ctx: NCContext, im: NCIntentMatch, @NCIntentTerm("t1")
t1: NCEntity): NCResult = NCResult("Data", NCResultType.ASK_RESULT)
Using.resource(new NCModelClient(mdl)) { client =>
- def ask(): NCCallbackData = new
NCModelTestClient(client).debugAsk("e1", "userId", true)
+ def ask(): NCCallbackData = Using.resource(new
NCModelTestClient(mdl)) { _.debugAsk("e1", "userId", true) }
def execCallback(cb: NCCallbackData): NCResult =
cb.getCallback.apply(cb.getCallbackArguments)
def execCallbackOk(cb: NCCallbackData): Unit = println(s"Result:
${execCallback(cb).getBody}")
def execCallbackFail(cb: NCCallbackData): Unit =