24
24
using System . IO ;
25
25
using System . Collections . Generic ;
26
26
using IBM . Watson . DeveloperCloud . Connection ;
27
+ using System ;
28
+ using Environment = IBM . Watson . DeveloperCloud . Services . Discovery . v1 . Environment ;
27
29
28
30
namespace IBM . Watson . DeveloperCloud . UnitTests
29
31
{
@@ -76,6 +78,16 @@ public class TestDiscovery : UnitTest
76
78
private bool _deleteCredentialsTested = false ;
77
79
private string _createdCredentialId = null ;
78
80
81
+ private bool _listExpansionsTested = false ;
82
+ private bool _createExpansionTested = false ;
83
+ private bool _deleteExpansionTested = false ;
84
+ private bool _getTokenizationDictStatusTested = false ;
85
+ private bool _createTokenizationDictTested = false ;
86
+ private bool _deleteTokenizationDictTested = false ;
87
+ private string _createdJpCollection = null ;
88
+ private bool _createJpCollectionTested = false ;
89
+ private bool _deleteJpCollectionTested = false ;
90
+
79
91
private bool _createEventTested = false ;
80
92
private bool _getMetricsEventRateTested = false ;
81
93
private bool _getMetricsQueryTested = false ;
@@ -184,7 +196,7 @@ public override IEnumerator RunTest()
184
196
185
197
// Add Collection
186
198
Log . Debug ( "TestDiscovery.RunTest()" , "Attempting to add collection" ) ;
187
- if ( ! _discovery . AddCollection ( OnAddCollection , OnFail , _environmentId , _createdCollectionName + System . Guid . NewGuid ( ) . ToString ( ) , _createdCollectionDescription , _createdConfigurationID ) )
199
+ if ( ! _discovery . AddCollection ( OnAddCollection , OnFail , _environmentId , _createdCollectionName + System . Guid . NewGuid ( ) . ToString ( ) , _createdCollectionDescription , _createdConfigurationID , "en" ) )
188
200
Log . Debug ( "TestDiscovery.AddCollection()" , "Failed to add collection" ) ;
189
201
while ( ! _addCollectionTested )
190
202
yield return null ;
@@ -313,6 +325,88 @@ public override IEnumerator RunTest()
313
325
while ( ! _createEventTested )
314
326
yield return null ;
315
327
328
+ Log . Debug ( "TestDiscovery.RunTests()" , "Attempting to list expansions" ) ;
329
+ _discovery . ListExpansions ( OnListExpansions , OnFail , _environmentId , _createdCollectionId ) ;
330
+ while ( ! _listExpansionsTested )
331
+ yield return null ;
332
+
333
+ Log . Debug ( "TestDiscovery.RunTests()" , "Attempting to create expansion" ) ;
334
+ Expansions expansions = new Expansions ( )
335
+ {
336
+ ExpansionsProperty = new List < Expansion > ( )
337
+ {
338
+ new Expansion ( )
339
+ {
340
+ ExpandedTerms = new List < string > ( )
341
+ {
342
+ "expanded-term"
343
+ } ,
344
+ InputTerms = new List < string > ( )
345
+ {
346
+ "input-term"
347
+ }
348
+ }
349
+ }
350
+ } ;
351
+ _discovery . CreateExpansions ( OnCreateExpansion , OnFail , _environmentId , _createdCollectionId , expansions ) ;
352
+ while ( ! _createExpansionTested )
353
+ yield return null ;
354
+
355
+ Log . Debug ( "TestDiscovery.RunTests()" , "Attempting to delete expansion" ) ;
356
+ _discovery . DeleteExpansions ( OnDeleteExpansion , OnFail , _environmentId , _createdCollectionId ) ;
357
+ while ( ! _deleteExpansionTested )
358
+ yield return null ;
359
+
360
+ Log . Debug ( "TestDiscovery.RunTest()" , "Attempting to create jp collection" ) ;
361
+ _discovery . AddCollection ( OnCreateJpCollection , OnFail , _environmentId , _createdCollectionName + System . Guid . NewGuid ( ) . ToString ( ) , _createdCollectionDescription , _createdConfigurationID , "ja" ) ;
362
+ while ( ! _createJpCollectionTested )
363
+ yield return null ;
364
+
365
+ TokenDict tokenizationDictionary = new TokenDict ( )
366
+ {
367
+ TokenizationRules = new List < TokenDictRule > ( )
368
+ {
369
+ new TokenDictRule ( )
370
+ {
371
+ Text = "すしネコ" ,
372
+ Tokens = new List < string > ( )
373
+ {
374
+ "すし" , "ネコ"
375
+ } ,
376
+ Readings = new List < string > ( )
377
+ {
378
+ "寿司" , "ネコ"
379
+ } ,
380
+ PartOfSpeech = "カスタム名詞"
381
+ }
382
+ }
383
+ } ;
384
+ Log . Debug ( "TestDiscovery.RunTests()" , "Attempting to create tokenization dict" ) ;
385
+ _discovery . CreateTokenizationDictionary ( OnCreateTokenizationDictionary , OnCreateTokenizationDictionaryFail , _environmentId , _createdJpCollection , tokenizationDictionary ) ;
386
+ while ( ! _createTokenizationDictTested )
387
+ yield return null ;
388
+
389
+ if ( ! _getTokenizationDictStatusTested )
390
+ {
391
+ Log . Debug ( "TestDiscovery.RunTests()" , "Attempting to get tokenization dict status" ) ;
392
+ _discovery . GetTokenizationDictionaryStatus ( OnGetTokenizationDictonaryStatus , OnFail , _environmentId , _createdJpCollection ) ;
393
+ while ( ! _getTokenizationDictStatusTested )
394
+ yield return null ;
395
+ }
396
+
397
+ if ( ! _deleteTokenizationDictTested )
398
+ {
399
+ Log . Debug ( "TestDiscovery.RunTests()" , "Attempting to delete tokenization dict" ) ;
400
+ _discovery . DeleteTokenizationDictionary ( OnDeleteTokenizationDictionary , OnFail , _environmentId , _createdJpCollection ) ;
401
+ while ( ! _deleteTokenizationDictTested )
402
+ yield return null ;
403
+ }
404
+
405
+ Log . Debug ( "TestDiscovery.RunTest()" , "Attempting to delete jp collection" ) ;
406
+ _discovery . DeleteCollection ( OnDeleteJpCollection , OnFail , _environmentId , _createdJpCollection ) ;
407
+ while ( ! _deleteJpCollectionTested )
408
+ yield return null ;
409
+
316
410
// DeleteCredential
317
411
Log . Debug ( "TestDiscovery.RunTest()" , "Attempting to delete credential" ) ;
318
412
_discovery . DeleteCredentials ( OnDeleteCredentials , OnFail , _environmentId , _createdCredentialId ) ;
@@ -361,6 +455,73 @@ public override IEnumerator RunTest()
361
455
yield break ;
362
456
}
363
457
458
+ private void OnCreateJpCollection ( CollectionRef response , Dictionary < string , object > customData )
459
+ {
460
+ Log . Debug ( "TestDiscovery.OnAddJpCollection()" , "Discovery - add jp collection Response: added:{0}" , customData [ "json" ] . ToString ( ) ) ;
461
+ _createdJpCollection = response . collection_id ;
462
+ Test ( response != null ) ;
463
+ _createJpCollectionTested = true ;
464
+ }
465
+
466
+ private void OnDeleteJpCollection ( DeleteCollectionResponse response , Dictionary < string , object > customData )
467
+ {
468
+ Log . Debug ( "TestDiscovery.OnDeleteJpCollection()" , "Discovery - Delete jp collection Response: deleted:{0}" , customData [ "json" ] . ToString ( ) ) ;
469
+
470
+ _createdJpCollection = default ( string ) ;
471
+ Test ( response != null ) ;
472
+
473
+ _deleteJpCollectionTested = true ;
474
+ }
475
+
476
+ private void OnDeleteTokenizationDictionary ( object response , Dictionary < string , object > customData )
477
+ {
478
+ Log . Debug ( "TestDiscovery.OnDeleteTokenizationDictionary()" , "Discovery - delete tokenization dictionary: deleted:{0}" , customData [ "json" ] . ToString ( ) ) ;
479
+ Test ( response != null ) ;
480
+
481
+ _deleteTokenizationDictTested = true ;
482
+ }
483
+
484
+ private void OnGetTokenizationDictonaryStatus ( TokenDictStatusResponse response , Dictionary < string , object > customData )
485
+ {
486
+ Log . Debug ( "TestDiscovery.OnGetTokenizationDictonaryStatus()" , "Discovery - get tokenization dictionary status: {0}" , customData [ "json" ] . ToString ( ) ) ;
487
+ Test ( response != null ) ;
488
+ _getTokenizationDictStatusTested = true ;
489
+ }
490
+
491
+
492
+ private void OnCreateTokenizationDictionary ( TokenDictStatusResponse response , Dictionary < string , object > customData )
493
+ {
494
+ Log . Debug ( "TestDiscovery.OnCreateTokenizationDictionary()" , "Discovery - create tokenization dictionary status: {0}" , customData [ "json" ] . ToString ( ) ) ;
495
+ Test ( response != null ) ;
496
+ _createTokenizationDictTested = true ;
497
+ }
498
+
499
+
500
+
501
+ private void OnDeleteExpansion ( object response , Dictionary < string , object > customData )
502
+ {
503
+ Log . Debug ( "TestDiscovery.OnDeleteExpansion()" , "Discovery - delete expansion: deleted" ) ;
504
+ Test ( response != null ) ;
505
+
506
+ _deleteExpansionTested = true ;
507
+ }
508
+
509
+ private void OnCreateExpansion ( Expansions response , Dictionary < string , object > customData )
510
+ {
511
+ Log . Debug ( "TestDiscovery.OnCreateExpansion()" , "Discovery - create expansion: {0}" , customData [ "json" ] . ToString ( ) ) ;
512
+ Test ( response != null ) ;
513
+
514
+ _createExpansionTested = true ;
515
+ }
516
+
517
+ private void OnListExpansions ( Expansions response , Dictionary < string , object > customData )
518
+ {
519
+ Log . Debug ( "TestDiscovery.OnListExpansions()" , "Discovery - list expansions: {0}" , customData [ "json" ] . ToString ( ) ) ;
520
+ Test ( response != null ) ;
521
+
522
+ _listExpansionsTested = true ;
523
+ }
524
+
364
525
#region Check State
365
526
private IEnumerator CheckEnvironmentState ( float waitTime )
366
527
{
@@ -542,59 +703,69 @@ private void OnDeleteUserData(object response, Dictionary<string, object> custom
542
703
private void OnListCredentials ( CredentialsList response , Dictionary < string , object > customData )
543
704
{
544
705
Log . Debug ( "TestDiscovery.OnListCredentials()" , "Response: {0}" , customData [ "json" ] . ToString ( ) ) ;
706
+ Test ( response != null ) ;
545
707
_listCredentialsTested = true ;
546
708
}
547
709
private void OnCreateCredentials ( SourceCredentials response , Dictionary < string , object > customData )
548
710
{
549
711
Log . Debug ( "TestDiscovery.OnCreateCredentials()" , "Response: {0}" , customData [ "json" ] . ToString ( ) ) ;
712
+ Test ( response != null ) ;
550
713
_createdCredentialId = response . CredentialId ;
551
714
_createCredentialsTested = true ;
552
715
}
553
716
554
717
private void OnGetCredential ( SourceCredentials response , Dictionary < string , object > customData )
555
718
{
556
719
Log . Debug ( "TestDiscovery.OnGetCredential()" , "Response: {0}" , customData [ "json" ] . ToString ( ) ) ;
720
+ Test ( response != null ) ;
557
721
_getCredentialTested = true ;
558
722
}
559
723
560
724
private void OnDeleteCredentials ( DeleteCredentials response , Dictionary < string , object > customData )
561
725
{
562
726
Log . Debug ( "TestDiscovery.OnDeleteCredentials()" , "Response: {0}" , customData [ "json" ] . ToString ( ) ) ;
727
+ Test ( response != null ) ;
563
728
_deleteCredentialsTested = true ;
564
729
}
565
730
private void OnCreateEvent ( CreateEventResponse response , Dictionary < string , object > customData )
566
731
{
567
732
Log . Debug ( "TestDiscovery.OnCreateEvent()" , "Response: {0}" , customData [ "json" ] . ToString ( ) ) ;
733
+ Test ( response != null ) ;
568
734
_createEventTested = true ;
569
735
}
570
736
571
737
private void OnGetMetricsEventRate ( MetricResponse response , Dictionary < string , object > customData )
572
738
{
573
739
Log . Debug ( "TestDiscovery.OnGetMetricsEventRate()" , "Response: {0}" , customData [ "json" ] . ToString ( ) ) ;
740
+ Test ( response != null ) ;
574
741
_getMetricsEventRateTested = true ;
575
742
}
576
743
577
744
private void OnGetMetricsQuery ( MetricResponse response , Dictionary < string , object > customData )
578
745
{
579
746
Log . Debug ( "TestDiscovery.OnGetMetricsQuery()" , "Response: {0}" , customData [ "json" ] . ToString ( ) ) ;
747
+ Test ( response != null ) ;
580
748
_getMetricsQueryTested = true ;
581
749
}
582
750
583
751
private void OnGetMetricsQueryEvent ( MetricResponse response , Dictionary < string , object > customData )
584
752
{
585
753
Log . Debug ( "TestDiscovery.OnGetMetricsQueryEvent()" , "Response: {0}" , customData [ "json" ] . ToString ( ) ) ;
754
+ Test ( response != null ) ;
586
755
_getMetricsQueryEventTested = true ;
587
756
}
588
757
589
758
private void OnGetMetricsQueryNoResult ( MetricResponse response , Dictionary < string , object > customData )
590
759
{
591
760
Log . Debug ( "TestDiscovery.OnGetMetricsQueryNoResult()" , "Response: {0}" , customData [ "json" ] . ToString ( ) ) ;
761
+ Test ( response != null ) ;
592
762
_getMetricsQueryNoResultTested = true ;
593
763
}
594
764
595
765
private void OnGetMetricsQueryTokenEvent ( MetricTokenResponse response , Dictionary < string , object > customData )
596
766
{
597
767
Log . Debug ( "TestDiscovery.OnGetMetricsQueryTokenEvent()" , "Response: {0}" , customData [ "json" ] . ToString ( ) ) ;
768
+ Test ( response != null ) ;
598
769
_getMetricsQueryTokenEventTested = true ;
599
770
}
600
771
@@ -608,5 +779,13 @@ private void OnFail(RESTConnector.Error error, Dictionary<string, object> custom
608
779
{
609
780
Log . Error ( "TestDiscovery.OnFail()" , "Error received: {0}" , error . ToString ( ) ) ;
610
781
}
782
+
783
+ private void OnCreateTokenizationDictionaryFail ( RESTConnector . Error error , Dictionary < string , object > customData )
784
+ {
785
+ Log . Error ( "TestDiscovery.OnCreateTokenizationDictionaryFail()" , "Error received - Continuing without testing tokenization dictionaries: {0}" , error . ToString ( ) ) ;
786
+ _createTokenizationDictTested = true ;
787
+ _getTokenizationDictStatusTested = true ;
788
+ _deleteTokenizationDictTested = true ;
789
+ }
611
790
}
612
791
}
0 commit comments