Interface NCTestClient
-
public interface NCTestClient
Model testing client. This client can be used for convenient unit testing of the models together with any popular unit testing framework such as TestNG or JUnit. The instance of test client should be obtained viaNCTestClientBuilder
.Here's an code snippet from
Alarm Clock
example illustrating the usage of test framework together with JUnit 5:public class AlarmTest { private NCTestClient cli; @BeforeEach void setUp() throws NCException, IOException { NCEmbeddedProbe.start(AlarmModel.class); cli = new NCTestClientBuilder().newBuilder().build(); cli.open("nlpcraft.alarm.ex"); } @AfterEach void tearDown() throws NCException, IOException { if (cli != null) cli.close(); NCEmbeddedProbe.stop(); } @Test public void test() throws NCException, IOException { // Should be passed. assertTrue(cli.ask("Ping me in 3 minutes").isOk()); assertTrue(cli.ask("Buzz me in an hour and 15mins").isOk()); assertTrue(cli.ask("Set my alarm for 30s").isOk()); } }
- See Also:
NCTestClientBuilder
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description NCTestResult
ask(String txt)
Tests single sentence and returns its result.void
clearConversation()
Clears conversation for this test client.void
close()
Closes test client connection to the server.void
open(String mdlId)
Connects test client to the server for testing with given model ID.
-
-
-
Method Detail
-
ask
NCTestResult ask(String txt) throws NCTestClientException, IOException
Tests single sentence and returns its result.- Parameters:
txt
- Text sentence to test.- Returns:
- Sentence result.
- Throws:
NCTestClientException
- Thrown if any test system errors occur.IOException
- Thrown in case of I/O errors.
-
open
void open(String mdlId) throws NCTestClientException, IOException
Connects test client to the server for testing with given model ID.- Parameters:
mdlId
- Model ID to open this client for.- Throws:
NCTestClientException
- Thrown if any test system errors occur.IOException
- Thrown in case of I/O errors.
-
close
void close() throws NCTestClientException, IOException
Closes test client connection to the server.- Throws:
NCTestClientException
- Thrown if any test system errors occur.IOException
- Thrown in case of I/O errors.
-
clearConversation
void clearConversation() throws NCTestClientException, IOException
Clears conversation for this test client. This method will clear conversation for its configured user.- Throws:
NCTestClientException
- Thrown if any test system errors occur.IOException
- Thrown in case of I/O errors.
-
-