@@ -35,31 +35,32 @@ namespace IBM.Watson.Tests
35
35
public class DiscoveryV2IntegrationTests
36
36
{
37
37
private DiscoveryService service ;
38
- private string versionDate = "2019-11-25 " ;
38
+ private string versionDate = "2020-08-12 " ;
39
39
40
- private string projectId = "{project_id}" ;
40
+ private string projectId ;
41
41
private string documentId ;
42
- private string collectionId = "{collection_id}" ;
42
+ private string collectionId ;
43
+ private string enrichmentId ;
43
44
private string addDocumentFile ;
45
+ private string enrichmentFile ;
46
+ private string analyzeDocumentFile ;
44
47
private string queryId ;
45
48
46
49
[ OneTimeSetUp ]
47
50
public void OneTimeSetup ( )
48
51
{
49
52
LogSystem . InstallDefaultReactors ( ) ;
50
53
addDocumentFile = Application . dataPath + "/Watson/Tests/TestData/DiscoveryV2/TestAddDoc.pdf" ;
54
+ enrichmentFile = Application . dataPath + "/Watson/Tests/TestData/DiscoveryV2/TestEnrichments.csv" ;
51
55
}
52
56
53
57
[ UnitySetUp ]
54
58
public IEnumerator UnityTestSetup ( )
55
59
{
56
- BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator ( bearerToken : "{bearer_token}" ) ;
57
60
if ( service == null )
58
61
{
59
- service = new DiscoveryService ( versionDate , authenticator ) ;
62
+ service = new DiscoveryService ( versionDate ) ;
60
63
}
61
- service . SetServiceUrl ( "service_url" ) ;
62
- service . DisableSslVerification = true ;
63
64
64
65
while ( ! service . Authenticator . CanAuthenticate ( ) )
65
66
yield return null ;
@@ -71,8 +72,59 @@ public void TestSetup()
71
72
service . WithHeader ( "X-Watson-Test" , "1" ) ;
72
73
}
73
74
74
- #region ListCollections
75
+ #region CreateProject
76
+ [ UnityTest , Order ( 0 ) ]
77
+ public IEnumerator TestCreateProject ( )
78
+ {
79
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to CreateProject..." ) ;
80
+ ProjectDetails createProjectResponse = null ;
81
+ service . CreateProject (
82
+ callback : ( DetailedResponse < ProjectDetails > response , IBMError error ) =>
83
+ {
84
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "CreateProject result: {0}" , response . Response ) ;
85
+ createProjectResponse = response . Result ;
86
+ Assert . IsNotNull ( createProjectResponse ) ;
87
+ projectId = createProjectResponse . ProjectId ;
88
+ Assert . IsNotNull ( projectId ) ;
89
+ Assert . IsNull ( error ) ;
90
+ } ,
91
+ name : "Unity SDK test project" ,
92
+ type : "other"
93
+ ) ;
94
+
95
+ while ( createProjectResponse == null )
96
+ yield return null ;
97
+ }
98
+ #endregion
99
+
100
+ #region CreateCollection
75
101
[ UnityTest , Order ( 1 ) ]
102
+ public IEnumerator TestCreateCollection ( )
103
+ {
104
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to CreateCollection..." ) ;
105
+ CollectionDetails createCollectionResponse = null ;
106
+ service . CreateCollection (
107
+ callback : ( DetailedResponse < CollectionDetails > response , IBMError error ) =>
108
+ {
109
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "CreateCollection result: {0}" , response . Response ) ;
110
+ createCollectionResponse = response . Result ;
111
+ Assert . IsNotNull ( createCollectionResponse ) ;
112
+ collectionId = createCollectionResponse . CollectionId ;
113
+ Assert . IsNotNull ( createCollectionResponse . CollectionId ) ;
114
+ Assert . IsNull ( error ) ;
115
+ } ,
116
+ projectId : projectId ,
117
+ name : "Unity SDK test collection" ,
118
+ description : "test collection"
119
+ ) ;
120
+
121
+ while ( createCollectionResponse == null )
122
+ yield return null ;
123
+ }
124
+ #endregion
125
+
126
+ #region ListCollections
127
+ [ UnityTest , Order ( 2 ) ]
76
128
public IEnumerator TestListCollections ( )
77
129
{
78
130
Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to ListCollections..." ) ;
@@ -96,7 +148,7 @@ public IEnumerator TestListCollections()
96
148
#endregion
97
149
98
150
#region Query
99
- [ UnityTest , Order ( 2 ) ]
151
+ [ UnityTest , Order ( 4 ) ]
100
152
public IEnumerator TestQuery ( )
101
153
{
102
154
Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to Query..." ) ;
@@ -122,7 +174,7 @@ public IEnumerator TestQuery()
122
174
123
175
124
176
#region GetAutocompletion
125
- [ UnityTest , Order ( 3 ) ]
177
+ [ UnityTest , Order ( 5 ) ]
126
178
public IEnumerator TestGetAutocompletion ( )
127
179
{
128
180
Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to GetAutocompletion..." ) ;
@@ -146,7 +198,7 @@ public IEnumerator TestGetAutocompletion()
146
198
#endregion
147
199
148
200
#region GetComponentSettings
149
- [ UnityTest , Order ( 4 ) ]
201
+ [ UnityTest , Order ( 6 ) ]
150
202
public IEnumerator TestGetComponentSettings ( )
151
203
{
152
204
Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to GetComponentSettings..." ) ;
@@ -170,7 +222,7 @@ public IEnumerator TestGetComponentSettings()
170
222
#endregion
171
223
172
224
#region AddDocument
173
- [ UnityTest , Order ( 5 ) ]
225
+ [ UnityTest , Order ( 3 ) ]
174
226
public IEnumerator TestAddDocument ( )
175
227
{
176
228
Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to AddDocument..." ) ;
@@ -205,7 +257,7 @@ public IEnumerator TestAddDocument()
205
257
#endregion
206
258
207
259
#region UpdateDocument
208
- [ UnityTest , Order ( 6 ) ]
260
+ [ UnityTest , Order ( 7 ) ]
209
261
public IEnumerator TestUpdateDocument ( )
210
262
{
211
263
Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to UpdateDocument..." ) ;
@@ -435,5 +487,208 @@ public IEnumerator TestListFields()
435
487
yield return null ;
436
488
}
437
489
#endregion
490
+
491
+ #region CreateEnrichment
492
+ [ UnityTest , Order ( 13 ) ]
493
+ public IEnumerator TestCreateEnrichment ( )
494
+ {
495
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to CreateEnrichment..." ) ;
496
+ Enrichment createEnrichmentResponse = null ;
497
+ var languages = new List < string > ( ) ;
498
+ languages . Add ( "en" ) ;
499
+ CreateEnrichment enrichment = new CreateEnrichment ( )
500
+ {
501
+ Name = "Dictionary Unity" ,
502
+ Description = "test dictionary" ,
503
+ Type = "dictionary" ,
504
+ Options = new EnrichmentOptions ( )
505
+ {
506
+ EntityType = "keyword" ,
507
+ Languages = languages
508
+ }
509
+ } ;
510
+
511
+ using ( FileStream fs = File . OpenRead ( enrichmentFile ) )
512
+ {
513
+ using ( MemoryStream ms = new MemoryStream ( ) )
514
+ {
515
+ fs . CopyTo ( ms ) ;
516
+ service . CreateEnrichment (
517
+ callback : ( DetailedResponse < Enrichment > response , IBMError error ) =>
518
+ {
519
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "CreateEnrichment result: {0}" , response . Response ) ;
520
+ createEnrichmentResponse = response . Result ;
521
+ enrichmentId = createEnrichmentResponse . EnrichmentId ;
522
+ Assert . IsNotNull ( createEnrichmentResponse ) ;
523
+ Assert . IsNotNull ( createEnrichmentResponse . EnrichmentId ) ;
524
+ Assert . IsNull ( error ) ;
525
+ } ,
526
+ projectId : projectId ,
527
+ file : ms ,
528
+ enrichment : enrichment
529
+ ) ;
530
+
531
+ while ( createEnrichmentResponse == null )
532
+ yield return null ;
533
+ }
534
+ }
535
+ }
536
+ #endregion
537
+
538
+ #region GetEnrichment
539
+ [ UnityTest , Order ( 14 ) ]
540
+ public IEnumerator TestGetEnrichment ( )
541
+ {
542
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to GetEnrichment..." ) ;
543
+ Enrichment getEnrichmentResponse = null ;
544
+ service . GetEnrichment (
545
+ callback : ( DetailedResponse < Enrichment > response , IBMError error ) =>
546
+ {
547
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "GetEnrichment result: {0}" , response . Response ) ;
548
+ getEnrichmentResponse = response . Result ;
549
+ Assert . IsNotNull ( getEnrichmentResponse ) ;
550
+ Assert . IsNull ( error ) ;
551
+ } ,
552
+ projectId : projectId ,
553
+ enrichmentId : enrichmentId
554
+ ) ;
555
+
556
+ while ( getEnrichmentResponse == null )
557
+ yield return null ;
558
+ }
559
+ #endregion
560
+
561
+ #region ListEnrichments
562
+ [ UnityTest , Order ( 2 ) ]
563
+ public IEnumerator TestListEnrichments ( )
564
+ {
565
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to ListEnrichments..." ) ;
566
+ Enrichments listEnrichmentsResponse = null ;
567
+ service . ListEnrichments (
568
+ callback : ( DetailedResponse < Enrichments > response , IBMError error ) =>
569
+ {
570
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "ListEnrichments result: {0}" , response . Response ) ;
571
+ listEnrichmentsResponse = response . Result ;
572
+ Assert . IsNotNull ( listEnrichmentsResponse ) ;
573
+ Assert . IsNull ( error ) ;
574
+ } ,
575
+ projectId : projectId
576
+ ) ;
577
+
578
+ while ( listEnrichmentsResponse == null )
579
+ yield return null ;
580
+ }
581
+ #endregion
582
+
583
+
584
+ #region DeleteEnrichment
585
+ [ UnityTest , Order ( 17 ) ]
586
+ public IEnumerator TestDeleteEnrichment ( )
587
+ {
588
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to DeleteEnrichment..." ) ;
589
+ bool deleteEnrichmentResponse = false ;
590
+ service . DeleteEnrichment (
591
+ callback : ( DetailedResponse < object > response , IBMError error ) =>
592
+ {
593
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "DeleteEnrichment result: {0}" , response . Response ) ;
594
+ deleteEnrichmentResponse = true ;
595
+ Assert . IsNull ( error ) ;
596
+ } ,
597
+ projectId : projectId ,
598
+ enrichmentId : enrichmentId
599
+ ) ;
600
+
601
+ while ( ! deleteEnrichmentResponse )
602
+ yield return null ;
603
+ }
604
+ #endregion
605
+
606
+ #region GetCollection
607
+ [ UnityTest , Order ( 18 ) ]
608
+ public IEnumerator TestGetCollection ( )
609
+ {
610
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to GetCollection..." ) ;
611
+ CollectionDetails collectionDetailsResponse = null ;
612
+ service . GetCollection (
613
+ callback : ( DetailedResponse < CollectionDetails > response , IBMError error ) =>
614
+ {
615
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "GetCollection result: {0}" , response . Response ) ;
616
+ collectionDetailsResponse = response . Result ;
617
+ Assert . IsNotNull ( collectionDetailsResponse ) ;
618
+ Assert . IsNull ( error ) ;
619
+ } ,
620
+ projectId : projectId ,
621
+ collectionId : collectionId
622
+ ) ;
623
+
624
+ while ( collectionDetailsResponse == null )
625
+ yield return null ;
626
+ }
627
+ #endregion
628
+
629
+ #region GetProject
630
+ [ UnityTest , Order ( 19 ) ]
631
+ public IEnumerator TestGetProject ( )
632
+ {
633
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to GetProject..." ) ;
634
+ ProjectDetails projectDetailsResponse = null ;
635
+ service . GetProject (
636
+ callback : ( DetailedResponse < ProjectDetails > response , IBMError error ) =>
637
+ {
638
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "GetProject result: {0}" , response . Response ) ;
639
+ projectDetailsResponse = response . Result ;
640
+ Assert . IsNotNull ( projectDetailsResponse ) ;
641
+ Assert . IsNull ( error ) ;
642
+ } ,
643
+ projectId : projectId
644
+ ) ;
645
+
646
+ while ( projectDetailsResponse == null )
647
+ yield return null ;
648
+ }
649
+ #endregion
650
+
651
+ #region DeleteCollection
652
+ [ UnityTest , Order ( 101 ) ]
653
+ public IEnumerator TestDeleteCollection ( )
654
+ {
655
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to DeleteCollection..." ) ;
656
+ bool deleteCollectionResponse = false ;
657
+ service . DeleteCollection (
658
+ callback : ( DetailedResponse < object > response , IBMError error ) =>
659
+ {
660
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "DeleteCollection result: {0}" , response . Response ) ;
661
+ deleteCollectionResponse = true ;
662
+ Assert . IsNull ( error ) ;
663
+ } ,
664
+ projectId : projectId ,
665
+ collectionId : collectionId
666
+ ) ;
667
+
668
+ while ( ! deleteCollectionResponse )
669
+ yield return null ;
670
+ }
671
+ #endregion
672
+
673
+ #region DeleteProject
674
+ [ UnityTest , Order ( 102 ) ]
675
+ public IEnumerator TestDeleteProject ( )
676
+ {
677
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "Attempting to DeleteProject..." ) ;
678
+ bool deleteProjectResponse = false ;
679
+ service . DeleteProject (
680
+ callback : ( DetailedResponse < object > response , IBMError error ) =>
681
+ {
682
+ Log . Debug ( "DiscoveryServiceV2IntegrationTests" , "DeleteProject result: {0}" , response . Response ) ;
683
+ deleteProjectResponse = true ;
684
+ Assert . IsNull ( error ) ;
685
+ } ,
686
+ projectId : projectId
687
+ ) ;
688
+
689
+ while ( ! deleteProjectResponse )
690
+ yield return null ;
691
+ }
692
+ #endregion
438
693
}
439
694
}
0 commit comments