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/16 16:54:17 UTC

[incubator-nlpcraft] branch NLPCRAFT-124 updated: WIP.

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

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


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

commit 4a9b645e35ad2e8e320c8b3305fb07e104f46603
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Wed Sep 16 19:54:10 2020 +0300

    WIP.
---
 .../scala/org/apache/nlpcraft/NCTestContext.scala  | 26 +++++++++++++++++-----
 .../org/apache/nlpcraft/NCTestContextModel.java    |  4 +++-
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala
index 05d1937..7003cc4 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala
@@ -24,23 +24,29 @@ import org.apache.nlpcraft.model.NCModel
 import org.apache.nlpcraft.model.tools.embedded.NCEmbeddedProbe
 import org.apache.nlpcraft.model.tools.test.{NCTestClient, NCTestClientBuilder}
 import org.apache.nlpcraft.probe.mgrs.model.NCModelManager
-import org.junit.jupiter.api.{AfterEach, BeforeEach, TestInfo}
+import org.junit.jupiter.api.TestInstance.Lifecycle
+import org.junit.jupiter.api.{AfterEach, BeforeAll, BeforeEach, TestInfo, TestInstance}
 
 /**
   *
   */
+@TestInstance(Lifecycle.PER_CLASS)
 class NCTestContext {
     protected var cli: NCTestClient = _
 
+    private var probeStarted = false
+
     @BeforeEach
     @throws[NCException]
     @throws[IOException]
-    private def setUp(ti: TestInfo): Unit = {
+    private def beforeEach(ti: TestInfo): Unit = {
         if (ti.getTestMethod.isPresent) {
             val a = ti.getTestMethod.get().getAnnotation(classOf[NCTestContextModel])
 
             if (a != null) {
-                NCEmbeddedProbe.start(a.value().asInstanceOf[Class[NCModel]])
+                probeStarted = false
+                NCEmbeddedProbe.start(a.value())
+                probeStarted = true
 
                 cli = new NCTestClientBuilder().newBuilder.build
 
@@ -52,10 +58,20 @@ class NCTestContext {
     @AfterEach
     @throws[NCException]
     @throws[IOException]
-    private def tearDown(): Unit =
-        if (cli != null) {
+    private def afterEach(): Unit =
+        if (cli != null)
             cli.close()
 
+        if (probeStarted) {
             NCEmbeddedProbe.stop()
+
+            probeStarted = false
         }
+
+    @BeforeAll
+    @throws[NCException]
+    @throws[IOException]
+    private def beforeAll(ti: TestInfo): Unit = {
+        println("!!!ti=" + ti)
+    }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContextModel.java b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContextModel.java
index c58bd5f..5537fc7 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContextModel.java
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContextModel.java
@@ -17,6 +17,8 @@
 
 package org.apache.nlpcraft;
 
+import org.apache.nlpcraft.model.NCModel;
+
 import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
@@ -28,5 +30,5 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
 @Retention(value=RUNTIME)
 @Target(value=METHOD)
 public @interface NCTestContextModel {
-    Class value();
+    Class<? extends NCModel> value();
 }