bool ValidateDoorFaultMessage(NotificationMessageHolderType notification, MessageCheckSettings settings, StringBuilder logger) { MessageDescription messageInfo = GetDoorFaultMessageDescription(); return(ValidateDoorMessage(notification, settings, logger, messageInfo)); }
bool ValidateDoorMessage(NotificationMessageHolderType notification, MessageCheckSettings settings, StringBuilder logger, MessageDescription messageInfo) { XmlElement messageElement = notification.Message; XmlElement messageRawElement = settings.RawMessageElements[notification]; TopicInfo topicInfo = settings.ExpectedTopic; XmlNamespaceManager manager = settings.NamespaceManager; // Init StringBuilder dump = new StringBuilder(); bool ok = true; ok = ValidateMessageCommonElements(notification, messageRawElement, topicInfo, settings.ExpectedPropertyOperation, manager, dump); if (messageElement != null) { // check message source and data // source bool localOk = ValidateDoorEventSource(messageElement, manager, settings.Data, dump); ok = ok && localOk; XmlElement messageInnerElement = messageRawElement.GetMessageContentElement(); XmlElement dataElement = messageInnerElement.GetMessageData(); localOk = ValidateMessageDataSimpleItems(dataElement, messageInfo, dump); ok = ok && localOk; } if (!ok) { logger.Append(dump.ToString()); } return(ok); }
void CommonDoorPropertyEventStateChangeTest(Func <DoorInfo, bool> doorCapabilitiesTest, TopicInfo topicInfo, ValidateMessageFunction validateMessageFunction) { EndpointReferenceType subscriptionReference = null; System.DateTime subscribeStarted = System.DateTime.MaxValue; int timeout = 60; RunTest( () => { //3. Get complete list of doors from the DUT (see Annex A.1). List <DoorInfo> fullDoorInfosList = GetDoorInfoList(); //4. Check that there is at least one Door with Capabilities.[CAPABILITIES FOR THE TEST]= “true”. // Otherwise skip other steps and go to the next test. List <DoorInfo> doorsList = null; if (doorCapabilitiesTest != null) { doorsList = fullDoorInfosList.Where(A => doorCapabilitiesTest(A)).ToList(); if (doorsList.Count == 0) { LogTestEvent("No Doors with required Capabilities found, exit the test" + Environment.NewLine); return; } } else { doorsList = fullDoorInfosList; } //5. ONVIF Client will select one random Door (token = Token1) with // Capabilities.DoorMonitor= “true”. // ToDo: may be change it to really random selection DoorInfo selectedDoor = doorsList[0]; // filter for current test TestTool.Proxies.Event.FilterType filter = CreateSubscriptionFilter(topicInfo); //6. ONVIF Client will invoke SubscribeRequest message with tns1:DoorControl/DoorPhysicalState Topic as Filter and an InitialTerminationTime of 60s to ensure that the SubscriptionManager is deleted after one minute. //7. Verify that the DUT sends a SubscribeResponse message. //8. Test Operator will invoke change of DoorPhysicalState property for Door with token = Token1. //9. Verify that DUT sends Notify message. string message = string.Format("{0} event is expected \r\n for the Door with token={{0}}", topicInfo.GetDescription()); DoorSelectionData data = new DoorSelectionData(); data.SelectedToken = selectedDoor.token; data.MessageTemplate = message; data.Doors = doorsList.Select( D => new DoorSelectionData.DoorShortInfo() { Token = D.token, Name = D.Name }).ToList(); Dictionary <NotificationMessageHolderType, XmlElement> notifications = new Dictionary <NotificationMessageHolderType, XmlElement>(); try { subscriptionReference = ReceiveMessages(filter, timeout, new Action(() => { _operator.ShowDoorSelectionMessage(data); }), 1, (n) => CheckMessagePropertyOperation(n, OnvifMessage.CHANGED), notifications, out subscribeStarted); } finally { _operator.HideDoorSelectionMessage(); } Assert(notifications.Count > 0, string.Format("Message with PropertyOperation='Changed' for the door with token='{0}' has not been received", data.SelectedToken), "Check that the message for selected door has been received"); //10. Verify received Notify messages (correct value for UTC time, TopicExpression and // wsnt:Message). //11. Verify that TopicExpression is equal to [TOPIC] for // received Notify message. //12. Verify that notification contains Source.SimpleItem item with Name="DoorToken" // and Value= “Token1”. //13. Verify that notification contains Data.SimpleItem item with Name=[ITEMNAME] and // Value with type is equal to [TYPE]. BeginStep("Validate messages"); XmlNamespaceManager manager = CreateNamespaceManager(notifications.First().Value.OwnerDocument); StringBuilder logger = new StringBuilder(); bool ok = true; MessageCheckSettings settings = new MessageCheckSettings(); settings.Data = data.SelectedToken; settings.ExpectedTopic = topicInfo; settings.RawMessageElements = notifications; settings.NamespaceManager = manager; foreach (NotificationMessageHolderType m in notifications.Keys) { bool local = validateMessageFunction(m, settings, logger); ok = ok && local; } if (!ok) { throw new AssertException(logger.ToStringTrimNewLine()); } StepPassed(); }, () => { _operator.HideDoorSelectionMessage(); ReleaseSubscription(subscribeStarted, subscriptionReference, timeout); }); }
void ConfigurationEventTest( TopicInfo topicInfo, Action <XmlElement, TopicInfo> validateTopic, ValidateConfigurationMessageFunction validateMessageFunction, string sourceTokenSimpleItem, Action <string> validateConfigurationFunction) { EndpointReferenceType subscriptionReference = null; System.DateTime subscribeStarted = System.DateTime.MaxValue; int timeout = 60; RunTest( () => { // Get topic description from the DUT. XmlElement topicElement = GetTopicElement(topicInfo); BeginStep("Check if the event topic is supported"); if (topicElement == null) { LogStepEvent(string.Format("Topic {0} not supported", topicInfo.GetDescription())); } StepPassed(); if (topicElement == null) { return; } XmlElement messageDescription = topicElement.GetMessageDescription(); validateTopic(messageDescription, topicInfo); // filter for current test TestTool.Proxies.Event.FilterType filter = CreateSubscriptionFilter(topicInfo); string message = string.Format("{0} event is expected!", topicInfo.GetDescription()); Notify notify = null; XmlDocument doc = new XmlDocument(); try { subscriptionReference = ReceiveMessages(filter, timeout, () => Operator.ShowMessage(message), doc, out notify, out subscribeStarted); } finally { Operator.HideMessage(); } Assert(notify.NotificationMessage.Length == 1, string.Format("{0} messages received - unable to check actual configuration", notify.NotificationMessage.Length), "Check that exactly one notification is received"); BeginStep("Validate message"); XmlNamespaceManager manager = CreateNamespaceManager(doc); Dictionary <NotificationMessageHolderType, XmlElement> notifications = GetRawElements(notify.NotificationMessage, doc, manager, true); StringBuilder logger = new StringBuilder(); bool ok = true; MessageCheckSettings settings = new MessageCheckSettings(); settings.ExpectedTopic = topicInfo; settings.RawMessageElements = notifications; settings.NamespaceManager = manager; NotificationMessageHolderType m = notify.NotificationMessage[0]; ok = validateMessageFunction(m, notifications[m], manager, logger); if (!ok) { throw new AssertException(logger.ToStringTrimNewLine()); } StepPassed(); // validateMessageFunction should return false, if this simple item is missing string token = m.Message.GetMessageSourceSimpleItems()[sourceTokenSimpleItem]; validateConfigurationFunction(token); }, () => { Operator.HideMessage(); ReleaseSubscription(subscribeStarted, subscriptionReference, timeout); }); }
void ConfigurationEventTestBis( TopicInfo topicInfo, Action <XmlElement, TopicInfo> validateTopic, ValidateConfigurationMessageFunction validateMessageFunction, string sourceTokenSimpleItem, Action <string> validateConfigurationFunction) { int actualTerminationTime = 60; if (_eventSubscriptionTimeout != 0) { actualTerminationTime = _eventSubscriptionTimeout; } int timeout = _operationDelay / 1000; RunTest( () => { // Get topic description from the DUT. XmlElement topicElement = GetTopicElement(topicInfo); Assert(null != topicElement, string.Format("Topic {0} not supported", topicInfo.GetDescription()), "Check if the event topic is supported"); XmlElement messageDescription = topicElement.GetMessageDescription(); validateTopic(messageDescription, topicInfo); // filter for current test TestTool.Proxies.Event.FilterType filter = CreateSubscriptionFilter(topicInfo); string message = string.Format("{0} event is expected!", topicInfo.GetDescription()); bool UseNotify = UseNotifyToGetEvents; Dictionary <NotificationMessageHolderType, XmlElement> notifications = null; SubscriptionHandler Handler = null; try { Handler = new SubscriptionHandler(this, UseNotify, GetEventServiceAddress()); Handler.Subscribe(filter, actualTerminationTime); Operator.ShowMessage(message); var pullingCondition = new SubscriptionHandler.WaitFirstNotificationPollingCondition(timeout); Handler.WaitMessages(1, pullingCondition, out notifications); } finally { Operator.HideMessage(); SubscriptionHandler.Unsubscribe(Handler); } Assert(null != notifications && notifications.Any(), string.Format("No notification messages are received.{0}WARNING: may be Operation delay is too low", Environment.NewLine), "Check that DUT sent any notification messages"); Assert(notifications.Count == 1, string.Format("{0} messages received - unable to check actual configuration", notifications.Count), "Check that exactly one notification is received"); BeginStep("Validate message"); XmlNamespaceManager manager = CreateNamespaceManager(notifications.First().Value.OwnerDocument); StringBuilder logger = new StringBuilder(); bool ok = true; MessageCheckSettings settings = new MessageCheckSettings(); settings.ExpectedTopic = topicInfo; settings.RawMessageElements = notifications; settings.NamespaceManager = manager; NotificationMessageHolderType m = notifications.Keys.First(); ok = validateMessageFunction(m, notifications[m], manager, logger); if (!ok) { throw new AssertException(logger.ToStringTrimNewLine()); } StepPassed(); // validateMessageFunction should return false, if this simple item is missing string token = m.Message.GetMessageSourceSimpleItems()[sourceTokenSimpleItem]; validateConfigurationFunction(token); }, () => { }); }
void CommonDoorPropertyEventStateChangeTestBis(Func <DoorInfo, bool> doorCapabilitiesTest, TopicInfo topicInfo, ValidateMessageFunction validateMessageFunction) { int actualTerminationTime = 60; if (_eventSubscriptionTimeout != 0) { actualTerminationTime = _eventSubscriptionTimeout; } int timeout = _operationDelay / 1000; RunTest( () => { //3. Get complete list of doors from the DUT (see Annex A.1). List <DoorInfo> fullDoorInfosList = GetDoorInfoList(); //4. Check that there is at least one Door with Capabilities.[CAPABILITIES FOR THE TEST]= “true”. // Otherwise skip other steps and go to the next test. List <DoorInfo> doorsList = null; if (doorCapabilitiesTest != null) { doorsList = fullDoorInfosList.Where(A => doorCapabilitiesTest(A)).ToList(); } else { doorsList = fullDoorInfosList; } Assert(doorsList.Any(), "No Doors with required Capabilities found, exit the test.", "Check there is appropriate door for test"); //5. ONVIF Client will select one random Door (token = Token1) with // Capabilities.DoorMonitor= “true”. // ToDo: may be change it to really random selection DoorInfo selectedDoor = doorsList[0]; // filter for current test Proxies.Event.FilterType filter = CreateSubscriptionFilter(topicInfo); //6. ONVIF Client will invoke SubscribeRequest message with tns1:DoorControl/DoorPhysicalState Topic as Filter and an InitialTerminationTime of 60s to ensure that the SubscriptionManager is deleted after one minute. //7. Verify that the DUT sends a SubscribeResponse message. //8. Test Operator will invoke change of DoorPhysicalState property for Door with token = Token1. //9. Verify that DUT sends Notify message. string message = string.Format("{0} event is expected \r\n for the Door with token={{0}}", topicInfo.GetDescription()); DoorSelectionData data = new DoorSelectionData { SelectedToken = selectedDoor.token, MessageTemplate = message, Doors = doorsList.Select(D => new DoorSelectionData.DoorShortInfo() { Token = D.token, Name = D.Name }).ToList() }; string Message = string.Format("{0} event is expected \r\n for the Door with token = '{1}'", topicInfo.GetDescription(), selectedDoor.token); bool UseNotify = UseNotifyToGetEvents; Dictionary <NotificationMessageHolderType, XmlElement> notifications = null; CurrentSubsciption = null; try { CurrentSubsciption = new SubscriptionHandler(this, UseNotify, GetEventServiceAddress()); CurrentSubsciption.Subscribe(filter, actualTerminationTime); Operator.ShowMessage(Message); // Handler.WaitMessages( // timeout, // (n) => CheckMessagePropertyOperation(n, OnvifMessage.CHANGED), // SubscriptionHandler.WaitCondition.WC_ALL, // out notifications); var pullingCondition = new SubscriptionHandler.WaitFirstNotificationPollingCondition(timeout) { Filter = msg => CheckMessagePropertyOperation(msg, OnvifMessage.CHANGED) }; CurrentSubsciption.WaitMessages(1, pullingCondition, out notifications); } finally { Operator.HideMessage(); UnsubscribeCurrentSubsciption(); } Assert(null != notifications && notifications.Any(), string.Format("Message with PropertyOperation='Changed' for the door with token='{0}' has not been received.{1}WARNING: may be Operation delay is too low", data.SelectedToken, Environment.NewLine), "Check that the message for selected door has been received"); //10. Verify received Notify messages (correct value for UTC time, TopicExpression and // wsnt:Message). //11. Verify that TopicExpression is equal to [TOPIC] for // received Notify message. //12. Verify that notification contains Source.SimpleItem item with Name="DoorToken" // and Value= “Token1”. //13. Verify that notification contains Data.SimpleItem item with Name=[ITEMNAME] and // Value with type is equal to [TYPE]. BeginStep("Validate messages"); XmlNamespaceManager manager = CreateNamespaceManager(notifications.First().Value.OwnerDocument); StringBuilder logger = new StringBuilder(); bool ok = true; MessageCheckSettings settings = new MessageCheckSettings(); settings.Data = data.SelectedToken; settings.ExpectedTopic = topicInfo; settings.RawMessageElements = notifications; settings.NamespaceManager = manager; foreach (NotificationMessageHolderType m in notifications.Keys) { bool local = validateMessageFunction(m, settings, logger); ok = ok && local; } if (!ok) { throw new AssertException(logger.ToStringTrimNewLine()); } StepPassed(); }, () => { Operator.HideMessage(); //Operator.HideDoorSelectionMessage(); }); }