You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2020/09/21 07:47:30 UTC

[incubator-nlpcraft] 01/01: Rest model test extended.

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

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

commit 8547f057f21a643b994c7eb3657f0955ad33b551
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Mon Sep 21 10:47:21 2020 +0300

    Rest model test extended.
---
 .../nlpcraft/server/rest/NCRestFeedbackSpec.scala  |  7 -------
 .../nlpcraft/server/rest/NCRestModelSpec.scala     | 23 ++++++++++++++++++++--
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestFeedbackSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestFeedbackSpec.scala
index 67abab9..fd67c19 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestFeedbackSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestFeedbackSpec.scala
@@ -96,11 +96,4 @@ class NCRestFeedbackSpec extends NCRestSpec {
 
         fId
     }
-
-    // TODO:
-    // @Test
-    def testErrors(): Unit = {
-        // Too big score.
-        postError("feedback/add", 400, "aa", "srvReqId" → rnd(), "score" → 100)
-    }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestModelSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestModelSpec.scala
index 444d38a..ce07183 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestModelSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestModelSpec.scala
@@ -22,17 +22,36 @@ import org.apache.nlpcraft.examples.alarm.AlarmModel
 import org.junit.jupiter.api.Assertions._
 import org.junit.jupiter.api.{Disabled, Test}
 
+import scala.collection.JavaConverters._
+
 // Enable it and run if context word server started.
 @Disabled
 @NCTestEnvironment(model = classOf[AlarmModel], startClient = false)
 class NCRestModelSpec extends NCRestSpec {
     @Test
     def test(): Unit = {
+        def extract(data: java.util.List[java.util.Map[String, Object]]): Seq[Double] =
+            data.asScala.map(_.get("score").asInstanceOf[Number].doubleValue())
+
+        // Note that checked values are valid for current configuration of `nlpcraft.alarm.ex` model.
         post("model/sugsyn", "mdlId" → "nlpcraft.alarm.ex")(
-            ("$.status", (status: String) ⇒ assertEquals("API_OK", status))
+            ("$.status", (status: String) ⇒ assertEquals("API_OK", status)),
+            ("$.result.suggestions[:1].x:alarm.*", (data: java.util.List[java.util.Map[String, Object]]) ⇒ {
+                val scores = extract(data)
+
+                assertTrue(scores.nonEmpty)
+                assertTrue(scores.forall(s ⇒ s >= 0 && s <= 1))
+                assertTrue(scores.exists(_ > 0.5))
+            })
         )
         post("model/sugsyn", "mdlId" → "nlpcraft.alarm.ex", "minScore" → 0.5)(
-            ("$.status", (status: String) ⇒ assertEquals("API_OK", status))
+            ("$.status", (status: String) ⇒ assertEquals("API_OK", status)),
+            ("$.result.suggestions[:1].x:alarm.*", (data: java.util.List[java.util.Map[String, Object]]) ⇒ {
+                val scores = extract(data)
+
+                assertTrue(scores.nonEmpty)
+                assertTrue(scores.forall(s ⇒ s >= 0.5 && s <= 1))
+            })
         )
     }
 }