This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/master by this push:
new 7f1af4d Conversation test fixed.
7f1af4d is described below
commit 7f1af4db8dab3e5af9275aac6a54cd6e63d6feb2
Author: Sergey Kamov <[email protected]>
AuthorDate: Sat Nov 21 11:26:35 2020 +0300
Conversation test fixed.
---
nlpcraft/pom.xml | 2 -
.../model/conversation/NCConversationSpec.scala | 53 ++++++++++++++++------
2 files changed, 39 insertions(+), 16 deletions(-)
diff --git a/nlpcraft/pom.xml b/nlpcraft/pom.xml
index a813516..6be99be 100644
--- a/nlpcraft/pom.xml
+++ b/nlpcraft/pom.xml
@@ -375,8 +375,6 @@
Some tests skipped on maven `verify` phase.
===========================================
-->
- <!-- Reason: weather service is not stable
enough and can be used for local tests only. -->
- <exclude>**/NCConversationSpec.*</exclude>
<!-- Reason: output is to big. -->
<exclude>**/NCDateGeneratorSpec.*</exclude>
<!-- Reason: 'contextWordServer' should be
started. -->
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala
index 8615995..ecaf02d 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala
@@ -17,34 +17,59 @@
package org.apache.nlpcraft.model.conversation
-import java.io.IOException
+import java.util
+import java.util.Collections
-import org.apache.nlpcraft.common.NCException
-import org.apache.nlpcraft.examples.weather.WeatherModel
+import org.apache.nlpcraft.model.{NCElement, NCIntent, NCModel, NCResult}
import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
-import org.junit.jupiter.api.Assertions.assertTrue
+import org.junit.jupiter.api.Assertions.{assertFalse, assertTrue}
import org.junit.jupiter.api.Test
+import scala.collection.JavaConverters._
+
/**
- * @see WeatherModel
+ * Test model.
*/
-@NCTestEnvironment(model = classOf[WeatherModel], startClient = true)
+class NCConversationSpecModel extends NCModel {
+ override def getId: String = this.getClass.getSimpleName
+ override def getName: String = this.getClass.getSimpleName
+ override def getVersion: String = "1.0.0"
+
+ private def mkElement(id: String): NCElement = new NCElement {
+ override def getId: String = id
+ override def getSynonyms: util.List[String] =
Collections.singletonList(id)
+ }
+
+ override def getElements: util.Set[NCElement] = Set(mkElement("test1"),
mkElement("test2")).asJava
+
+ // 'test1' is mandatory, 'test2' is optional.
+ @NCIntent("intent=testIntentId term~{id == 'test1'} term~{id == 'test2'}?")
+ def onMatch(): NCResult = NCResult.text("ok")
+}
+/**
+ * @see NCConversationSpecModel
+ */
+@NCTestEnvironment(model = classOf[NCConversationSpecModel], startClient =
true)
class NCConversationSpec extends NCTestContext {
@Test
- @throws[NCException]
- @throws[IOException]
+ @throws[Exception]
private[conversation] def test(): Unit = {
val cli = getClient
- assertTrue(cli.ask("What's the weather in Moscow?").isOk)
+ // missed 'test1'
+ assertFalse(cli.ask("test2").isOk)
+ assertTrue(cli.ask("test1 test2").isOk)
- // Can be answered with conversation.
- assertTrue(cli.ask("Chance of snow?").isOk)
- assertTrue(cli.ask("Moscow").isOk)
+ // 'test1' received from conversation.
+ assertTrue(cli.ask("test2").isOk)
cli.clearConversation()
- // Cannot be answered without conversation.
- assertTrue(cli.ask("Moscow").isFailed)
+ // missed 'test1' again.
+ assertFalse(cli.ask("test2").isOk)
+ assertTrue(cli.ask("test1 test2").isOk)
+
+ // 'test1' received from conversation.
+ assertTrue(cli.ask("test2").isOk)
}
}