Skip to content

Commit db6beda

Browse files
committed
tests(Discovery): Added tests for Expansions and TokenizationDict
1 parent 1ed41de commit db6beda

File tree

1 file changed

+142
-1
lines changed

1 file changed

+142
-1
lines changed

test/IBM.WatsonDeveloperCloud.Discovery.v1.IntegrationTests/DiscoveryIntegrationTests.cs

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ public void TestCreateEvent_Success()
644644
}
645645
#endregion
646646

647-
#region metrics
647+
#region Metrics
648648
[TestMethod]
649649
public void TestMetrics_Success()
650650
{
@@ -675,6 +675,90 @@ public void TestMetrics_Success()
675675
}
676676
#endregion
677677

678+
#region Expansions
679+
[TestMethod]
680+
public void TestExpansions_Success()
681+
{
682+
CreateCollectionRequest createCollectionRequest = new CreateCollectionRequest()
683+
{
684+
Language = CreateCollectionRequest.LanguageEnum.JA,
685+
Name = _createdCollectionName,
686+
Description = _createdCollectionDescription,
687+
ConfigurationId = _createdConfigurationId
688+
};
689+
690+
var createCollectionResult = CreateCollection(_environmentId, createCollectionRequest);
691+
_createdCollectionId = createCollectionResult.CollectionId;
692+
693+
Expansions body = new Expansions()
694+
{
695+
_Expansions = new List<Expansion>()
696+
{
697+
new Expansion()
698+
{
699+
InputTerms = new List<string>()
700+
{
701+
"input-term"
702+
},
703+
ExpandedTerms = new List<string>()
704+
{
705+
"expanded-term"
706+
}
707+
}
708+
}
709+
};
710+
711+
var createExpansionsResult = CreateExpansions(_environmentId, _createdCollectionId, body);
712+
var listExpansionsResult = ListExpansions(_environmentId, _createdCollectionId);
713+
var deleteExpansionResult = DeleteExpansions(_environmentId, _createdCollectionId);
714+
715+
TokenDict tokenizationDictionary = new TokenDict()
716+
{
717+
TokenizationRules = new List<TokenDictRule>()
718+
{
719+
new TokenDictRule()
720+
{
721+
Text = "すしネコ",
722+
Tokens = new List<string>()
723+
{
724+
"すし", "ネコ"
725+
},
726+
Readings = new List<string>()
727+
{
728+
"寿司", "ネコ"
729+
},
730+
PartOfSpeech = "カスタム名詞"
731+
}
732+
}
733+
};
734+
735+
try
736+
{
737+
var createTokenizationDictionaryResult = CreateTokenizationDictionary(_environmentId, _createdCollectionId, tokenizationDictionary);
738+
var getTokenizationDictionaryStatusResult = GetTokenizationDictionaryStatus(_environmentId, _createdCollectionId);
739+
var deleteTokenizationDictionary = DeleteTokenizationDictionary(_environmentId, _createdCollectionId);
740+
741+
Assert.IsNotNull(deleteTokenizationDictionary);
742+
Assert.IsNotNull(getTokenizationDictionaryStatusResult);
743+
Assert.IsTrue(getTokenizationDictionaryStatusResult.Status == TokenDictStatusResponse.StatusEnum.PENDING);
744+
Assert.IsNotNull(createTokenizationDictionaryResult);
745+
Assert.IsTrue(createTokenizationDictionaryResult.Status == TokenDictStatusResponse.StatusEnum.PENDING);
746+
}
747+
catch(Exception e)
748+
{
749+
Console.WriteLine(e.Message);
750+
}
751+
752+
Assert.IsNotNull(deleteExpansionResult);
753+
Assert.IsNotNull(listExpansionsResult);
754+
Assert.IsTrue(listExpansionsResult._Expansions[0].ExpandedTerms[0] == "expanded-term");
755+
Assert.IsTrue(listExpansionsResult._Expansions[0].InputTerms[0] == "input-term");
756+
Assert.IsNotNull(createExpansionsResult);
757+
Assert.IsTrue(createExpansionsResult._Expansions[0].ExpandedTerms[0] == "expanded-term");
758+
Assert.IsTrue(createExpansionsResult._Expansions[0].InputTerms[0] == "input-term");
759+
}
760+
#endregion
761+
678762
#region IsEnvironmentReady
679763
private void IsEnvironmentReady(string environmentId)
680764
{
@@ -1097,6 +1181,63 @@ private Expansions ListExpansions(string environmentId, string collectionId, Dic
10971181
}
10981182
#endregion
10991183

1184+
#region CreateTokenizationDictionary
1185+
private TokenDictStatusResponse CreateTokenizationDictionary(string environmentId, string collectionId, TokenDict tokenizationDictionary, Dictionary<string, object> customData = null)
1186+
{
1187+
Console.WriteLine("\nAttempting to CreateTokenizationDictionary()");
1188+
var result = _service.CreateTokenizationDictionary(environmentId: environmentId, collectionId: collectionId, tokenizationDictionary: tokenizationDictionary, customData: customData);
1189+
1190+
if (result != null)
1191+
{
1192+
Console.WriteLine("CreateTokenizationDictionary() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
1193+
}
1194+
else
1195+
{
1196+
Console.WriteLine("Failed to CreateTokenizationDictionary()");
1197+
}
1198+
1199+
return result;
1200+
}
1201+
#endregion
1202+
1203+
#region DeleteTokenizationDictionary
1204+
private BaseModel DeleteTokenizationDictionary(string environmentId, string collectionId, Dictionary<string, object> customData = null)
1205+
{
1206+
Console.WriteLine("\nAttempting to DeleteTokenizationDictionary()");
1207+
var result = _service.DeleteTokenizationDictionary(environmentId: environmentId, collectionId: collectionId, customData: customData);
1208+
1209+
if (result != null)
1210+
{
1211+
Console.WriteLine("DeleteTokenizationDictionary() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
1212+
}
1213+
else
1214+
{
1215+
Console.WriteLine("Failed to DeleteTokenizationDictionary()");
1216+
}
1217+
1218+
return result;
1219+
}
1220+
#endregion
1221+
1222+
#region GetTokenizationDictionaryStatus
1223+
private TokenDictStatusResponse GetTokenizationDictionaryStatus(string environmentId, string collectionId, Dictionary<string, object> customData = null)
1224+
{
1225+
Console.WriteLine("\nAttempting to GetTokenizationDictionaryStatus()");
1226+
var result = _service.GetTokenizationDictionaryStatus(environmentId: environmentId, collectionId: collectionId, customData: customData);
1227+
1228+
if (result != null)
1229+
{
1230+
Console.WriteLine("GetTokenizationDictionaryStatus() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
1231+
}
1232+
else
1233+
{
1234+
Console.WriteLine("Failed to GetTokenizationDictionaryStatus()");
1235+
}
1236+
1237+
return result;
1238+
}
1239+
#endregion
1240+
11001241
#region AddDocument
11011242
private DocumentAccepted AddDocument(string environmentId, string collectionId, System.IO.FileStream file = null, string metadata = null, string fileContentType = null, Dictionary<string, object> customData = null)
11021243
{

0 commit comments

Comments
 (0)