Skip to content

Commit 568abc8

Browse files
committed
test(discovery): add tests for metrics and events
1 parent 429fb9d commit 568abc8

File tree

2 files changed

+234
-4
lines changed

2 files changed

+234
-4
lines changed

src/IBM.WatsonDeveloperCloud.Discovery.v1/Model/EventData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class EventData : BaseModel
4040
/// in the log was used.
4141
/// </summary>
4242
[JsonProperty("client_timestamp", NullValueHandling = NullValueHandling.Ignore)]
43-
public DateTime ClientTimestamp { get; set; }
43+
public DateTime? ClientTimestamp { get; set; }
4444
/// <summary>
4545
/// The rank of the result item which the event is associated with.
4646
/// </summary>

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

Lines changed: 233 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ public void TestTrainingData()
510510
#endregion
511511

512512
#region Credentials
513-
//[TestMethod]
513+
[TestMethod]
514514
public void TestCredentials_Success()
515515
{
516516
var listCredentialsResult = ListCredentials(_environmentId);
@@ -576,6 +576,103 @@ public void TestCredentials_Success()
576576
}
577577
#endregion
578578

579+
#region Events
580+
[TestMethod]
581+
public void TestCreateEvent_Success()
582+
{
583+
Configuration configuration = new Configuration()
584+
{
585+
Name = _createdConfigurationName,
586+
Description = _createdConfigurationDescription,
587+
588+
};
589+
590+
var createConfigurationResults = CreateConfiguration(_environmentId, configuration);
591+
_createdConfigurationId = createConfigurationResults.ConfigurationId;
592+
593+
var listCollectionsResult = ListCollections(_environmentId);
594+
595+
CreateCollectionRequest createCollectionRequest = new CreateCollectionRequest()
596+
{
597+
Language = _createdCollectionLanguage,
598+
Name = _createdCollectionName,
599+
Description = _createdCollectionDescription,
600+
ConfigurationId = _createdConfigurationId
601+
};
602+
603+
var createCollectionResult = CreateCollection(_environmentId, createCollectionRequest);
604+
_createdCollectionId = createCollectionResult.CollectionId;
605+
606+
DocumentAccepted addDocumentResult;
607+
using (FileStream fs = File.OpenRead(_filepathToIngest))
608+
{
609+
addDocumentResult = AddDocument(_environmentId, _createdCollectionId, fs, _metadata);
610+
_createdDocumentId = addDocumentResult.DocumentId;
611+
}
612+
613+
var getDocumentStatusResult = GetDocumentStatus(_environmentId, _createdCollectionId, _createdDocumentId);
614+
615+
var queryResult = Query(_environmentId, _createdCollectionId, naturalLanguageQuery: "what year did watson play jeopardy");
616+
617+
CreateEventObject queryEvent = new CreateEventObject()
618+
{
619+
Type = CreateEventObject.TypeEnum.CLICK,
620+
Data = new EventData()
621+
{
622+
EnvironmentId = _environmentId,
623+
SessionToken = queryResult.SessionToken,
624+
CollectionId = _createdCollectionId,
625+
DocumentId = _createdDocumentId
626+
}
627+
};
628+
629+
var createEventResult = CreateEvent(queryEvent);
630+
631+
var deleteDocumentResult = DeleteDocument(_environmentId, _createdCollectionId, _createdDocumentId);
632+
var deleteCollectionResult = DeleteCollection(_environmentId, _createdCollectionId);
633+
var deleteConfigurationResults = DeleteConfiguration(_environmentId, _createdConfigurationId);
634+
635+
Assert.IsNotNull(queryResult);
636+
Assert.IsNotNull(createEventResult);
637+
Assert.IsNotNull(createEventResult.Data);
638+
Assert.IsTrue(createEventResult.Data.EnvironmentId == _environmentId);
639+
Assert.IsTrue(createEventResult.Data.SessionToken == queryResult.SessionToken);
640+
Assert.IsTrue(createEventResult.Data.CollectionId== _createdCollectionId);
641+
Assert.IsTrue(createEventResult.Data.DocumentId == _createdDocumentId);
642+
}
643+
#endregion
644+
645+
#region metrics
646+
[TestMethod]
647+
public void TestMetrics_Success()
648+
{
649+
var getMetricsEventRateResult = GetMetricsEventRate();
650+
651+
var getMetricsQueryResult = GetMetricsQuery();
652+
653+
var getMetricsQueryEventResult = GetMetricsQueryEvent();
654+
655+
var getMetricsQueryNoResultsResult = GetMetricsQueryNoResults();
656+
657+
var getMetricsQueryTokenEventResult = GetMetricsQueryTokenEvent();
658+
659+
var queryLogResult = QueryLog();
660+
661+
Assert.IsNotNull(queryLogResult);
662+
Assert.IsNotNull(queryLogResult.Results);
663+
Assert.IsNotNull(getMetricsQueryTokenEventResult);
664+
Assert.IsNotNull(getMetricsQueryTokenEventResult.Aggregations);
665+
Assert.IsNotNull(getMetricsQueryNoResultsResult);
666+
Assert.IsNotNull(getMetricsQueryNoResultsResult.Aggregations);
667+
Assert.IsNotNull(getMetricsQueryEventResult);
668+
Assert.IsNotNull(getMetricsQueryEventResult.Aggregations);
669+
Assert.IsNotNull(getMetricsQueryResult);
670+
Assert.IsNotNull(getMetricsQueryResult.Aggregations);
671+
Assert.IsNotNull(getMetricsEventRateResult);
672+
Assert.IsNotNull(getMetricsEventRateResult.Aggregations);
673+
}
674+
#endregion
675+
579676
#region IsEnvironmentReady
580677
private void IsEnvironmentReady(string environmentId)
581678
{
@@ -1113,10 +1210,10 @@ private QueryNoticesResponse FederatedQueryNotices(string environmentId, List<st
11131210
#endregion
11141211

11151212
#region Query
1116-
private QueryResponse Query(string environmentId, string collectionId, string filter = null, string query = null, string naturalLanguageQuery = null, bool? passages = null, string aggregation = null, long? count = null, List<string> returnFields = null, long? offset = null, List<string> sort = null, bool? highlight = null, List<string> passagesFields = null, long? passagesCount = null, long? passagesCharacters = null, bool? deduplicate = null, string deduplicateField = null, bool? similar = null, List<string> similarDocumentIds = null, List<string> similarFields = null, Dictionary<string, object> customData = null)
1213+
private QueryResponse Query(string environmentId, string collectionId, string filter = null, string query = null, string naturalLanguageQuery = null, bool? passages = null, string aggregation = null, long? count = null, List<string> returnFields = null, long? offset = null, List<string> sort = null, bool? highlight = null, List<string> passagesFields = null, long? passagesCount = null, long? passagesCharacters = null, bool? deduplicate = null, string deduplicateField = null, bool? similar = null, List<string> similarDocumentIds = null, List<string> similarFields = null, bool? loggingOptOut = null, Dictionary<string, object> customData = null)
11171214
{
11181215
Console.WriteLine("\nAttempting to Query()");
1119-
var result = _service.Query(environmentId: environmentId, collectionId: collectionId, filter: filter, query: query, naturalLanguageQuery: naturalLanguageQuery, passages: passages, aggregation: aggregation, count: count, returnFields: returnFields, offset: offset, sort: sort, highlight: highlight, passagesFields: passagesFields, passagesCount: passagesCount, passagesCharacters: passagesCharacters, deduplicate: deduplicate, deduplicateField: deduplicateField, similar: similar, similarDocumentIds: similarDocumentIds, similarFields: similarFields, customData: customData);
1216+
var result = _service.Query(environmentId: environmentId, collectionId: collectionId, filter: filter, query: query, naturalLanguageQuery: naturalLanguageQuery, passages: passages, aggregation: aggregation, count: count, returnFields: returnFields, offset: offset, sort: sort, highlight: highlight, passagesFields: passagesFields, passagesCount: passagesCount, passagesCharacters: passagesCharacters, deduplicate: deduplicate, deduplicateField: deduplicateField, similar: similar, similarDocumentIds: similarDocumentIds, similarFields: similarFields, loggingOptOut: loggingOptOut, customData: customData);
11201217

11211218
if (result != null)
11221219
{
@@ -1397,6 +1494,139 @@ private BaseModel DeleteUserData(string customerId, Dictionary<string, object> c
13971494
}
13981495
#endregion
13991496

1497+
#region CreateEvent
1498+
private CreateEventResponse CreateEvent(CreateEventObject queryEvent, Dictionary<string, object> customData = null)
1499+
{
1500+
Console.WriteLine("\nAttempting to CreateEvent()");
1501+
var result = _service.CreateEvent(queryEvent: queryEvent, customData: customData);
1502+
1503+
if (result != null)
1504+
{
1505+
Console.WriteLine("CreateEvent() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
1506+
}
1507+
else
1508+
{
1509+
Console.WriteLine("Failed to CreateEvent()");
1510+
}
1511+
1512+
return result;
1513+
}
1514+
#endregion
1515+
1516+
#region GetMetricsEventRate
1517+
private MetricResponse GetMetricsEventRate(DateTime? startTime = null, DateTime? endTime = null, string resultType = null, Dictionary<string, object> customData = null)
1518+
{
1519+
Console.WriteLine("\nAttempting to GetMetricsEventRate()");
1520+
var result = _service.GetMetricsEventRate(startTime: startTime, endTime: endTime, resultType: resultType, customData: customData);
1521+
1522+
if (result != null)
1523+
{
1524+
Console.WriteLine("GetMetricsEventRate() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
1525+
}
1526+
else
1527+
{
1528+
Console.WriteLine("Failed to GetMetricsEventRate()");
1529+
}
1530+
1531+
return result;
1532+
}
1533+
#endregion
1534+
1535+
#region GetMetricsQuery
1536+
private MetricResponse GetMetricsQuery(DateTime? startTime = null, DateTime? endTime = null, string resultType = null, Dictionary<string, object> customData = null)
1537+
{
1538+
Console.WriteLine("\nAttempting to GetMetricsQuery()");
1539+
var result = _service.GetMetricsQuery(startTime: startTime, endTime: endTime, resultType: resultType, customData: customData);
1540+
1541+
if (result != null)
1542+
{
1543+
Console.WriteLine("GetMetricsQuery() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
1544+
}
1545+
else
1546+
{
1547+
Console.WriteLine("Failed to GetMetricsQuery()");
1548+
}
1549+
1550+
return result;
1551+
}
1552+
#endregion
1553+
1554+
#region GetMetricsQueryEvent
1555+
private MetricResponse GetMetricsQueryEvent(DateTime? startTime = null, DateTime? endTime = null, string resultType = null, Dictionary<string, object> customData = null)
1556+
{
1557+
Console.WriteLine("\nAttempting to GetMetricsQueryEvent()");
1558+
var result = _service.GetMetricsQueryEvent(startTime: startTime, endTime: endTime, resultType: resultType, customData: customData);
1559+
1560+
if (result != null)
1561+
{
1562+
Console.WriteLine("GetMetricsQueryEvent() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
1563+
}
1564+
else
1565+
{
1566+
Console.WriteLine("Failed to GetMetricsQueryEvent()");
1567+
}
1568+
1569+
return result;
1570+
}
1571+
#endregion
1572+
1573+
#region GetMetricsQueryNoResults
1574+
private MetricResponse GetMetricsQueryNoResults(DateTime? startTime = null, DateTime? endTime = null, string resultType = null, Dictionary<string, object> customData = null)
1575+
{
1576+
Console.WriteLine("\nAttempting to GetMetricsQueryNoResults()");
1577+
var result = _service.GetMetricsQueryNoResults(startTime: startTime, endTime: endTime, resultType: resultType, customData: customData);
1578+
1579+
if (result != null)
1580+
{
1581+
Console.WriteLine("GetMetricsQueryNoResults() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
1582+
}
1583+
else
1584+
{
1585+
Console.WriteLine("Failed to GetMetricsQueryNoResults()");
1586+
}
1587+
1588+
return result;
1589+
}
1590+
#endregion
1591+
1592+
#region GetMetricsQueryTokenEvent
1593+
private MetricTokenResponse GetMetricsQueryTokenEvent(long? count = null, Dictionary<string, object> customData = null)
1594+
{
1595+
Console.WriteLine("\nAttempting to GetMetricsQueryTokenEvent()");
1596+
var result = _service.GetMetricsQueryTokenEvent(count: count, customData: customData);
1597+
1598+
if (result != null)
1599+
{
1600+
Console.WriteLine("GetMetricsQueryTokenEvent() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
1601+
}
1602+
else
1603+
{
1604+
Console.WriteLine("Failed to GetMetricsQueryTokenEvent()");
1605+
}
1606+
1607+
return result;
1608+
}
1609+
#endregion
1610+
1611+
#region QueryLog
1612+
private LogQueryResponse QueryLog(string filter = null, string query = null, long? count = null, long? offset = null, List<string> sort = null, Dictionary<string, object> customData = null)
1613+
{
1614+
Console.WriteLine("\nAttempting to QueryLog()");
1615+
var result = _service.QueryLog(filter: filter, query: query, count: count, offset: offset, sort: sort, customData: customData);
1616+
1617+
if (result != null)
1618+
{
1619+
Console.WriteLine("QueryLog() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
1620+
}
1621+
else
1622+
{
1623+
Console.WriteLine("Failed to QueryLog()");
1624+
}
1625+
1626+
return result;
1627+
}
1628+
#endregion
1629+
14001630
#region CreateCredentials
14011631
private Credentials CreateCredentials(string environmentId, Credentials credentialsParameter, Dictionary<string, object> customData = null)
14021632
{

0 commit comments

Comments
 (0)