Exemplo n.º 1
0
        public static TopicInfo GetTopicInfo(NotificationMessageHolderType msg, XmlElement rawMsg)
        {
            XmlNamespaceManager manager = EventsMainHelper.CreateNamespaceManager(rawMsg.OwnerDocument);

            XmlText text = null;

            if (msg.Topic.Any != null)
            {
                foreach (XmlNode any in msg.Topic.Any)
                {
                    var current = any as XmlText;
                    if (any != null)
                    {
                        text = current;
                        break;
                    }
                }
            }

            XmlNode topicNode = rawMsg.SelectSingleNode("b2:Topic", manager);

            string topic = text != null ? text.Value : "";

            return(TopicInfo.ExtractTopicInfoPACS(topic, topicNode));
        }
Exemplo n.º 2
0
        bool ValidateDoorFaultMessage(NotificationMessageHolderType notification,
                                      MessageCheckSettings settings,
                                      StringBuilder logger)
        {
            MessageDescription messageInfo = GetDoorFaultMessageDescription();

            return(ValidateDoorMessage(notification, settings, logger, messageInfo));
        }
 bool ValidateRemovedMessage(TopicInfo topicInfo,
                             string sourceSimpleItem,
                             NotificationMessageHolderType message,
                             XmlElement rawElement,
                             XmlNamespaceManager manager,
                             StringBuilder logger)
 {
     return(ValidateConfigurationMessage(message, rawElement, manager, topicInfo, sourceSimpleItem, logger));
 }
        bool ValidateAreaSetMessage(NotificationMessageHolderType message,
                                    XmlElement rawElement,
                                    XmlNamespaceManager manager,
                                    StringBuilder logger)
        {
            TopicInfo topicInfo = ConstructTopic(new string[] { "Configuration", "Area", "Changed" });

            //TopicInfo topicInfo = ConstructTopic(new string[] { "Area", "Changed" });
            return(ValidateSetMessage(topicInfo, AREATOKENSIMPLEITEM, message, rawElement, manager, logger));
        }
Exemplo n.º 5
0
        void ValidateDoorModeSimpleItem(NotificationMessageHolderType notification, string expectedMode)
        {
            XmlElement dataElement = notification.Message.GetMessageData();

            Dictionary <string, string> dataSimpleItems = dataElement.GetMessageElementSimpleItems();

            Assert(dataSimpleItems["State"] == expectedMode,
                   string.Format("'State' simple item value is incorrect. Expected: '{0}', actual '{1}'", expectedMode, dataSimpleItems["State"]),
                   "Validate 'State' simple item value");
        }
        bool ValidateAccessPointRemovedMessage(NotificationMessageHolderType message,
                                               XmlElement rawElement,
                                               XmlNamespaceManager manager,
                                               StringBuilder logger)
        {
            TopicInfo topicInfo = ConstructTopic(new string[] { "Configuration", "AccessPoint", "Removed" });

            //TopicInfo topicInfo = ConstructTopic(new string[] { "AccessPoint", "Removed" });
            return(ValidateRemovedMessage(topicInfo, ACCESSPOINTTOKENSIMPLEITEM, message, rawElement, manager, logger));
        }
Exemplo n.º 7
0
        public static TopicInfo ExtractTopicInfo(Event.NotificationMessageHolderType notification,
                                                 XmlElement messageRawElement, XmlNamespaceManager manager, out string err)
        {
            if (notification.Topic == null)
            {
                err = "Topic is null";
                return(null);
            }

            XmlText text = null;

            if (notification.Topic.Any != null)
            {
                foreach (XmlNode any in notification.Topic.Any)
                {
                    XmlText current = any as XmlText;
                    if (any != null)
                    {
                        text = current;
                        break;
                    }
                }
            }

            XmlNode topicNode = messageRawElement.SelectSingleNode("b2:Topic", manager);

            string topic = text != null ? text.Value : "";

            TopicInfo actualTopic = TopicInfo.ExtractTopicInfoAll(topic, topicNode);

            TopicInfo currentTopic = actualTopic;

            while (currentTopic != null)
            {
                if (currentTopic.ParentTopic == null && string.IsNullOrEmpty(currentTopic.NamespacePrefix))
                {
                    err = string.Format("Topic {0} is incorrect: root topic must have namespace defined", topic);
                    return(null);
                }
                if (string.IsNullOrEmpty(currentTopic.Namespace))
                {
                    err = string.Format("Topic {0} is incorrect: namespace prefix {1} not defined", topic, currentTopic.NamespacePrefix);
                    return(null);
                }
                currentTopic = currentTopic.ParentTopic;
            }

            err = string.Empty;
            return(actualTopic);
        }
        bool ValidateConfigurationMessage(NotificationMessageHolderType message,
                                          XmlElement rawElement,
                                          XmlNamespaceManager manager,
                                          TopicInfo topicInfo, string sourceItemName,
                                          StringBuilder logger)
        {
            XmlElement messageElement = message.Message;

            StringBuilder dump = new StringBuilder();
            bool          ok   = true;

            ok = ValidateMessageCommonElements(message, rawElement, topicInfo, null, manager, dump);

            if (messageElement != null)
            {
                // check message source [presence only]
                XmlElement sourceElement = messageElement.GetMessageSource();
                if (sourceElement == null)
                {
                    logger.AppendLine("   Message Source element is missing");
                    ok = false;
                }
                else
                {
                    bool   success = false;
                    string err;
                    Dictionary <string, string> sourceSimpleItems = messageElement.GetMessageSourceSimpleItems(out success, out err);
                    if (success)
                    {
                        if (!sourceSimpleItems.ContainsKey(sourceItemName))
                        {
                            logger.AppendLine(string.Format("   '{0}' SimpleItem is missing in Source", sourceItemName));
                            ok = false;
                        }
                    }
                    else
                    {
                        logger.AppendLine(string.Format("   {0}", err));
                        ok = false;
                    }
                }
            }

            if (!ok)
            {
                logger.Append(dump.ToString());
            }
            return(ok);
        }
Exemplo n.º 9
0
        DoorMode?GetDoorStateFromNotification(NotificationMessageHolderType notification)
        {
            XmlElement dataElement = notification.Message.GetMessageData();

            Dictionary <string, string> dataSimpleItems = dataElement.GetMessageElementSimpleItems();

            if (dataSimpleItems.ContainsKey("State"))
            {
                DoorMode state;
                if (DoorMode.TryParse(dataSimpleItems["State"], out state))
                {
                    return(state);
                }

                return(null);
            }

            return(null);
        }
Exemplo n.º 10
0
        void ValidateDoorModeSimpleItem(NotificationMessageHolderType notification,
                                        Func <string, bool> expectedModePredicate,
                                        Func <string, string> msgPredicate = null)
        {
            var assertHeader = "Validate 'State' simple item value";

            BeginStep(assertHeader);

            var state = GetDoorStateFromNotification(notification);

            if (state.HasValue)
            {
                var msg = "'State' simple item value is incorrect.";
                if (null != msgPredicate)
                {
                    var additionalMsg = msgPredicate(state.Value.ToString());
                    if (!string.IsNullOrEmpty(additionalMsg))
                    {
                        msg = string.Format("{0}{1}{2}", msg, Environment.NewLine, additionalMsg);
                    }
                }
                if (expectedModePredicate(state.Value.ToString()))
                {
                    LogStepEvent("Ok");
                }
                else
                {
                    //LogStepEvent(msg);
                    throw new AssertException(msg);
                }
            }
            else
            {
                var msg = "No 'State' field in received notification";
                //LogStepEvent(msg);
                throw new AssertException(msg);
            }

            StepPassed();
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        public static TopicInfo GetTopicInfo(NotificationMessageHolderType msg)
        {
            var rawMsg = msg.Topic.Any.First().OwnerDocument;
            XmlNamespaceManager manager = EventsMainHelper.CreateNamespaceManager(rawMsg);

            XmlText text = null;

            if (msg.Topic.Any != null)
            {
                foreach (XmlNode any in msg.Topic.Any)
                {
                    var current = any as XmlText;
                    if (any != null)
                    {
                        text = current;
                        break;
                    }
                }
            }

            string topic = text != null ? text.Value : "";

            return(TopicInfo.ExtractTopicInfoPACS(topic, msg.Topic));
        }
Exemplo n.º 13
0
 void ValidateDoorModeSimpleItem(NotificationMessageHolderType notification, DoorMode expectedMode)
 {
     ValidateDoorModeSimpleItem(notification, expectedMode.ToString());
 }
Exemplo n.º 14
0
 void ValidateDoorIsNotInMode(NotificationMessageHolderType notification, DoorMode notExpectedMode)
 {
     ValidateDoorModeSimpleItem(notification,
                                (s) => s != notExpectedMode.ToString(),
                                (s) => string.Format("Expected: not '{0}', actual: '{1}'", notExpectedMode, s));
 }
Exemplo n.º 15
0
 void ValidateDoorIsInMode(NotificationMessageHolderType notification, string expectedMode)
 {
     ValidateDoorModeSimpleItem(notification,
                                (s) => s == expectedMode,
                                (s) => string.Format("Expected: '{0}', actual: '{1}'", expectedMode, s));
 }
Exemplo n.º 16
0
 void ValidateDoorIsInMode(NotificationMessageHolderType notification, DoorMode expectedMode)
 {
     ValidateDoorIsInMode(notification, expectedMode.ToString());
 }
Exemplo n.º 17
0
 public static bool NotificationTopicMatch(NotificationMessageHolderType msg, TopicInfo topic)
 {
     return(TopicInfo.TopicsMatch(GetTopicInfo(msg), topic));
 }
        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 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);
            });
        }