public WaitHandle ShowDoorSelectionMessage(DoorSelectionData data) { Func <Forms.BaseMessageForm> formInitializer = new Func <TestTool.GUI.Forms.BaseMessageForm>( () => { _doorSelectionForm = new TestTool.GUI.Forms.DoorSelectionMessageForm(); _doorSelectionForm.DoorSelectionData = data; return(_doorSelectionForm); }); return(DisplayBaseMessageForm(formInitializer)); }
public WaitHandle ShowCountdownMessage(int timeout, DoorSelectionData data) { Func <Forms.BaseMessageForm> formInitializer = new Func <TestTool.GUI.Forms.BaseMessageForm>( () => { _countdownMessageForm = new TestTool.GUI.Forms.CountdownMessageForm(); _countdownMessageForm.Timeout = timeout / 1000; _countdownMessageForm.DoorSelectionData = data; return(_countdownMessageForm); }); return(DisplayBaseMessageForm(formInitializer)); }
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 CommonDoorOperationEventTest( Func<DoorInfo, bool> doorCapabilitiesTest, string operationName, TopicInfo topic, ValidateMessageFunction validateMessage, Action<string> doorOperation, string stateItemName, string expectedState, bool equal) { EndpointReferenceType subscriptionReference = null; System.DateTime subscribeStarted = System.DateTime.MaxValue; int timeout = _eventSubscriptionTimeout; RunTest( () => { // Get full list List<DoorInfo> fullDoorsList = GetDoorInfoList(); // Check if there are Doors with required properties List<DoorInfo> doorInfos = fullDoorsList.Where(doorCapabilitiesTest).ToList(); // if there are no Doors with required capabilities, skip other steps. if (doorInfos.Count == 0) { LogTestEvent("No Doors with required Capabilities found, exit the test."); return; } // Select one Door. DoorInfo selectedDoor = doorInfos[0]; string selectedToken = selectedDoor.token; List<DoorSelectionData.DoorShortInfo> tokens = doorInfos.Select( D => new DoorSelectionData.DoorShortInfo(){ Token = D.token, Name=D.Name}).ToList(); string message = string.Format("Put the Door with token '{{0}}' into state which allows '{0}' operation", operationName); DoorSelectionData data = new DoorSelectionData(); data.Doors = tokens; data.SelectedToken = selectedToken; data.MessageTemplate = message; WaitHandle formHandle = _operator.ShowCountdownMessage(_messageTimeout, data); try { Sleep(_messageTimeout, new WaitHandle[] { formHandle }); } finally { _operator.HideCountdownMessage(); } selectedToken = data.SelectedToken; LogTestEvent(string.Format("Door with token '{0}' will be used for test{1}", selectedToken, Environment.NewLine)); EnsureEventPortTypeClientCreated(); TestTool.Proxies.Event.FilterType filter = CreateSubscriptionFilter(topic); // Subscribe Utils.NotifyCollectingServer eventServer = new TestTool.Tests.TestCases.Utils.NotifyCollectingServer(_nic); SetupNotifyServer2(eventServer); string notificationsUri = eventServer.GetNotificationUri(); System.DateTime localSubscribeStarted = System.DateTime.MaxValue; Func<NotificationMessageHolderType, bool> messageCheck = (n) => CheckDoorEventSource(n, selectedToken); { AutoResetEvent subscribedEvent = new AutoResetEvent(false); // collect "Initialized" messaged Action setSynchronizationPointAction = new Action( () => { StepPassed(); subscriptionReference = CreateSubscription(filter, timeout, notificationsUri, out localSubscribeStarted); subscribedEvent.Set(); }); BeginStep("Start listening"); // collect messages for all door infos Dictionary<Notify, byte[]> notifications = eventServer.CollectNotifications(setSynchronizationPointAction, _operationDelay, 1, messageCheck, subscribedEvent, _semaphore.StopEvent); subscribeStarted = localSubscribeStarted; Assert(notifications.Count > 0, string.Format("No notifications were received for Door with token='{0}'", selectedToken), "Check that the DUT sent expected notification(s)"); // Create raw elements list Dictionary<NotificationMessageHolderType, XmlElement> messages = GetRawElements(notifications); Dictionary<NotificationMessageHolderType, XmlElement> filtered = GetFilteredList(messages, messageCheck); // Validate messages ValidateMessages(filtered, topic, OnvifMessage.INITIALIZED, doorInfos, validateMessage); } { // Perform operation AutoResetEvent initializedEvent = new AutoResetEvent(false); Action initiationAction = new Action(() => { doorOperation(selectedToken); initializedEvent.Set(); }); // Check state change message Dictionary<Notify, byte[]> notifications = eventServer.CollectNotifications(initiationAction, _operationDelay, 1, messageCheck, initializedEvent, _semaphore.StopEvent); Assert(notifications.Count > 0, string.Format("No notifications were received for Door with token='{0}'", selectedToken), "Check that the DUT sent notification(s)"); // Create raw elements list Dictionary<NotificationMessageHolderType, XmlElement> messages = GetRawElements(notifications); Dictionary<NotificationMessageHolderType, XmlElement> filtered = GetFilteredList(messages, messageCheck); // validate state changed message ValidateMessages(filtered, topic, OnvifMessage.CHANGED, selectedToken, validateMessage); BeginStep("Validate current State"); Dictionary<string, string> dataSimpleItems = messages.Keys.First().Message.GetMessageDataSimpleItems(); if (equal) { if (dataSimpleItems[stateItemName] != expectedState) { throw new AssertException(string.Format("{0} is incorrect: expected {1}, actual {2}", stateItemName, expectedState, dataSimpleItems[stateItemName])); } } else { if (dataSimpleItems[stateItemName] == expectedState) { throw new AssertException(string.Format("{0} is incorrect: must be different from {1}", stateItemName, dataSimpleItems[stateItemName])); } } StepPassed(); } RemoveHandlers2(eventServer); }, () => { _operator.HideMessage(); ReleaseSubscription(subscribeStarted, subscriptionReference, timeout); }); }
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(); }); }