This is an automated email from the ASF dual-hosted git repository. sergeykamov pushed a commit to branch NLPCRAFT-178 in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
commit aef336ad660c136ddfc5dae96cd520c4471cb703 Author: Sergey Kamov <[email protected]> AuthorDate: Mon Nov 23 17:59:11 2020 +0300 Dialog test added. --- .../nlpcraft/model/tools/test/NCTestClient.java | 8 ++++ .../model/tools/test/NCTestClientBuilder.java | 26 +++++++++++ .../model/conversation/NCConversationSpec.scala | 1 + .../NCDialogSpec.scala} | 52 +++++++++++++--------- 4 files changed, 67 insertions(+), 20 deletions(-) diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestClient.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestClient.java index 290dbc0..c631f57 100644 --- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestClient.java +++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestClient.java @@ -96,4 +96,12 @@ public interface NCTestClient { * @throws IOException Thrown in case of I/O errors. */ void clearConversation() throws NCTestClientException, IOException; + + /** + * TODO: + * + * @throws NCTestClientException Thrown if any test system errors occur. + * @throws IOException Thrown in case of I/O errors. + */ + void clearDialog() throws NCTestClientException, IOException; } diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestClientBuilder.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestClientBuilder.java index 059f931..896a1cb 100644 --- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestClientBuilder.java +++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestClientBuilder.java @@ -749,6 +749,14 @@ public class NCTestClientBuilder { restClearConversation(); } + @Override + public void clearDialog() throws NCTestClientException, IOException { + if (!opened) throw new IllegalStateException("Client is not opened."); + if (closed) throw new IllegalStateException("Client is already closed."); + + restClearDialog(); + } + @SuppressWarnings("unchecked") private <T> T getField(Map<String, Object> m, String fn) throws NCTestClientException { Object o = m.get(fn); @@ -901,6 +909,24 @@ public class NCTestClientBuilder { } /** + * + * @throws IOException Thrown in case of IO errors. + * @throws NCTestClientException Thrown in case of test client errors. + */ + private void restClearDialog() throws IOException, NCTestClientException { + log.info("'clear/dialog' request sent for data model: {}", mdlId); + + checkStatus(gson.fromJson( + post( + "clear/dialog", + Pair.of("acsTok", acsTok), + Pair.of("mdlId", mdlId) + ), + TYPE_RESP) + ); + } + + /** * @return Access token. * @throws IOException Thrown in case of IO errors. * @throws NCTestClientException Thrown in case of test client errors. 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 ecaf02d..b3837da 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 @@ -46,6 +46,7 @@ class NCConversationSpecModel extends NCModel { @NCIntent("intent=testIntentId term~{id == 'test1'} term~{id == 'test2'}?") def onMatch(): NCResult = NCResult.text("ok") } + /** * @see NCConversationSpecModel */ diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCDialogSpec.scala similarity index 61% copy from nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala copy to nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCDialogSpec.scala index ecaf02d..b5f2186 100644 --- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala +++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCDialogSpec.scala @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.nlpcraft.model.conversation +package org.apache.nlpcraft.model.dialog import java.util import java.util.Collections @@ -30,7 +30,7 @@ import scala.collection.JavaConverters._ /** * Test model. */ -class NCConversationSpecModel extends NCModel { +class NCDialogSpecModel extends NCModel { override def getId: String = this.getClass.getSimpleName override def getName: String = this.getClass.getSimpleName override def getVersion: String = "1.0.0" @@ -42,34 +42,46 @@ class NCConversationSpecModel extends NCModel { 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") + @NCIntent("intent=test1 term~{id == 'test1'}") + def onTest1(): NCResult = NCResult.text("ok") + + @NCIntent("intent=test2 flow='test1[1,1]' term~{id == 'test2'}") + def onTest2(): NCResult = NCResult.text("ok") } + /** - * @see NCConversationSpecModel + * @see NCDialogSpecModel */ -@NCTestEnvironment(model = classOf[NCConversationSpecModel], startClient = true) -class NCConversationSpec extends NCTestContext { +@NCTestEnvironment(model = classOf[NCDialogSpecModel], startClient = true) +class NCDialogSpec extends NCTestContext { @Test @throws[Exception] - private[conversation] def test(): Unit = { + private[dialog] def test(): Unit = { val cli = getClient - // missed 'test1' - assertFalse(cli.ask("test2").isOk) - assertTrue(cli.ask("test1 test2").isOk) + def flow(): Unit = { + // There isn't `test1` before. + assertFalse(cli.ask("test2").isOk) - // 'test1' received from conversation. - assertTrue(cli.ask("test2").isOk) + // `test1` is always ok. + assertTrue(cli.ask("test1").isOk) - cli.clearConversation() + // There is one `test1` before. + assertTrue(cli.ask("test2").isOk) + + // `test1` is always ok. + assertTrue(cli.ask("test1").isOk) + assertTrue(cli.ask("test1").isOk) - // missed 'test1' again. - assertFalse(cli.ask("test2").isOk) - assertTrue(cli.ask("test1 test2").isOk) + // There are too much `test1` before. + assertFalse(cli.ask("test2").isOk) + } + + flow() + + cli.clearConversation() + cli.clearDialog() - // 'test1' received from conversation. - assertTrue(cli.ask("test2").isOk) + flow() } }
