Beispiel #1
0
        /// <summary>
        ///     The actions for the sender are the following:
        ///     1. Send the message containing the image file.
        ///     2. Let the AR process the message for some seconds to be sure (this depends on the use case and is just an example
        ///     time limit)
        ///     3. Fetch the message response and validate it.
        /// </summary>
        private static void ActionsForSender()
        {
            var sendMessageService =
                new SendDirectMessageService(new HttpMessagingService(HttpClientForSender));
            var sendMessageParameters = new SendMessageParameters
            {
                OnboardResponse      = Sender,
                ApplicationMessageId = MessageIdService.ApplicationMessageId(),
                TechnicalMessageType = TechnicalMessageTypes.ImgPng,
                Recipients           = new List <string> {
                    Recipient.SensorAlternateId
                },
                Base64MessageContent = DataProvider.ReadBase64EncodedImage()
            };

            sendMessageService.Send(sendMessageParameters);

            Thread.Sleep(TimeSpan.FromSeconds(2));

            var fetchMessageService = new FetchMessageService(HttpClientForSender);
            var fetch = fetchMessageService.Fetch(Sender);

            Assert.Single(fetch);

            var decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message);

            Assert.Equal(201, decodedMessage.ResponseEnvelope.ResponseCode);
        }
Beispiel #2
0
        public void GivenNonExistingMessageIdWhenConfirmingMessagesThenTheMessageShouldBeAccepted()
        {
            var feedConfirmService =
                new FeedConfirmService(new HttpMessagingService(HttpClient));
            var feedConfirmParameters = new FeedConfirmParameters
            {
                OnboardResponse = OnboardResponse,
                MessageIds      = new List <string> {
                    MessageIdService.ApplicationMessageId()
                }
            };

            feedConfirmService.Send(feedConfirmParameters);

            Thread.Sleep(TimeSpan.FromSeconds(5));

            var fetchMessageService = new FetchMessageService(HttpClient);
            var fetch = fetchMessageService.Fetch(OnboardResponse);

            Assert.Single(fetch);

            var decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message);

            Assert.Equal(200, decodedMessage.ResponseEnvelope.ResponseCode);

            var messages = DecodeMessageService.Decode(decodedMessage.ResponsePayloadWrapper.Details);

            Assert.NotNull(messages);
            Assert.NotEmpty(messages.Messages_);
            Assert.Single(messages.Messages_);
            Assert.Equal("VAL_000205", messages.Messages_[0].MessageCode);
            Assert.Equal(
                "Feed message cannot be found.",
                messages.Messages_[0].Message_);
        }
Beispiel #3
0
        public void GivenNonExistingEndpointIdWhenOffboardingVcuThenTheArShouldReturnErrorMessage()
        {
            var offboardVcuService =
                new OffboardVcuService(new HttpMessagingService(HttpClient));
            var offboardVcuParameters = new OffboardVcuParameters
            {
                OnboardResponse      = OnboardResponse,
                ApplicationMessageId = MessageIdService.ApplicationMessageId(),
                Endpoints            = new List <string>
                {
                    "8597bd75-0366-41a9-b13c-3e685a47909e"
                }
            };

            offboardVcuService.Send(offboardVcuParameters);

            Thread.Sleep(TimeSpan.FromSeconds(5));

            var fetchMessageService = new FetchMessageService(HttpClient);
            var fetch = fetchMessageService.Fetch(OnboardResponse);

            Assert.Single(fetch);

            var decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message);

            Assert.Equal(400, decodedMessage.ResponseEnvelope.ResponseCode);
        }
Beispiel #4
0
        public void GivenValidMessageContentWhenSendingMessageToSingleRecipientThenTheMessageShouldBeDelivered()
        {
            PrepareTestEnvironment(Sender, HttpClientForSender);
            PrepareTestEnvironment(Recipient, HttpClientForRecipient);

            var sendMessageService =
                new SendDirectMessageService(new HttpMessagingService(HttpClientForSender));
            var sendMessageParameters = new SendMessageParameters
            {
                OnboardResponse      = Sender,
                ApplicationMessageId = MessageIdService.ApplicationMessageId(),
                TechnicalMessageType = TechnicalMessageTypes.ImgPng,
                Recipients           = new List <string> {
                    Recipient.SensorAlternateId
                },
                Base64MessageContent = DataProvider.ReadBase64EncodedLargeBmp()
            };

            sendMessageService.Send(sendMessageParameters);

            Thread.Sleep(TimeSpan.FromSeconds(5));

            var fetchMessageService = new FetchMessageService(HttpClientForSender);
            var fetch = fetchMessageService.Fetch(Sender);

            Assert.Equal(6, fetch.Count);

            foreach (var messageResponse in fetch)
            {
                var decodedMessage = DecodeMessageService.Decode(messageResponse.Command.Message);
                Assert.Equal(201, decodedMessage.ResponseEnvelope.ResponseCode);
            }
        }
        public void GivenValidIdAndNameWhenOnboardingVirtualCuThenTheOnbardingShouldBePossible()
        {
            var onboardVcuService    = new OnboardVcuService(new HttpMessagingService(HttpClient));
            var onboardVcuParameters = new OnboardVcuParameters
            {
                OnboardResponse      = OnboardResponse,
                ApplicationMessageId = MessageIdService.ApplicationMessageId(),
                OnboardingRequests   = new List <OnboardingRequest.Types.EndpointRegistrationDetails>
                {
                    new OnboardingRequest.Types.EndpointRegistrationDetails
                    {
                        Id   = Guid.NewGuid().ToString(),
                        Name = "My first virtual CU..."
                    }
                }
            };

            onboardVcuService.Send(onboardVcuParameters);

            Thread.Sleep(TimeSpan.FromSeconds(5));

            var fetchMessageService = new FetchMessageService(HttpClient);
            var fetch = fetchMessageService.Fetch(OnboardResponse);

            Assert.Single(fetch);

            var decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message);

            Assert.Equal(201, decodedMessage.ResponseEnvelope.ResponseCode);
        }
Beispiel #6
0
        public void GivenExistingEndpointIdWhenOffboardingVcuThenTheArShouldReturnErrorMessage()
        {
            var onboardVcuService = new OnboardVcuService(new HttpMessagingService(HttpClient));
            var endpointId        = Guid.NewGuid().ToString();

            var onboardVcuParameters = new OnboardVcuParameters
            {
                OnboardResponse      = OnboardResponse,
                ApplicationMessageId = MessageIdService.ApplicationMessageId(),
                OnboardingRequests   = new List <OnboardingRequest.Types.EndpointRegistrationDetails>
                {
                    new OnboardingRequest.Types.EndpointRegistrationDetails
                    {
                        Id   = endpointId,
                        Name = "My first virtual CU which is deleted directly..."
                    }
                }
            };

            onboardVcuService.Send(onboardVcuParameters);

            Thread.Sleep(TimeSpan.FromSeconds(5));

            var fetchMessageService = new FetchMessageService(HttpClient);
            var fetch = fetchMessageService.Fetch(OnboardResponse);

            Assert.Single(fetch);

            var decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message);

            Assert.Equal(201, decodedMessage.ResponseEnvelope.ResponseCode);

            var offboardVcuService =
                new OffboardVcuService(new HttpMessagingService(HttpClient));
            var offboardVcuParameters = new OffboardVcuParameters
            {
                OnboardResponse      = OnboardResponse,
                ApplicationMessageId = MessageIdService.ApplicationMessageId(),
                Endpoints            = new List <string>
                {
                    endpointId
                }
            };

            offboardVcuService.Send(offboardVcuParameters);

            Thread.Sleep(TimeSpan.FromSeconds(5));

            fetch = fetchMessageService.Fetch(OnboardResponse);
            Assert.Single(fetch);

            decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message);
            Assert.Equal(400, decodedMessage.ResponseEnvelope.ResponseCode);
        }
Beispiel #7
0
        public void GivenMultipleValidMessageContentWhenPublishingMessagesThenTheMessageShouldBeDelivered()
        {
            var publishAndSendMultipleDirectMessagesService =
                new PublishAndSendMultipleDirectMessagesService(new HttpMessagingService(HttpClientForSender));
            var sendMessageParameters = new SendMultipleMessagesParameters
            {
                OnboardResponse        = Sender,
                ApplicationMessageId   = MessageIdService.ApplicationMessageId(),
                MultipleMessageEntries = new List <MultipleMessageEntry>
                {
                    new MultipleMessageEntry
                    {
                        ApplicationMessageId = MessageIdService.ApplicationMessageId(),
                        TechnicalMessageType = TechnicalMessageTypes.ImgPng,
                        Recipients           = new List <string> {
                            Recipient.SensorAlternateId
                        },
                        Base64MessageContent = DataProvider.ReadBase64EncodedImage()
                    },
                    new MultipleMessageEntry
                    {
                        ApplicationMessageId = MessageIdService.ApplicationMessageId(),
                        TechnicalMessageType = TechnicalMessageTypes.ImgPng,
                        Recipients           = new List <string> {
                            Recipient.SensorAlternateId
                        },
                        Base64MessageContent = DataProvider.ReadBase64EncodedImage()
                    }
                }
            };

            publishAndSendMultipleDirectMessagesService.Send(sendMessageParameters);

            Thread.Sleep(TimeSpan.FromSeconds(5));

            var fetchMessageService = new FetchMessageService(HttpClientForSender);
            var fetch = fetchMessageService.Fetch(Sender);

            Assert.Equal(2, fetch.Count);

            Assert.Equal(201, DecodeMessageService.Decode(fetch[0].Command.Message).ResponseEnvelope.ResponseCode);
            Assert.Equal(201, DecodeMessageService.Decode(fetch[1].Command.Message).ResponseEnvelope.ResponseCode);
        }
Beispiel #8
0
        GivenValidMessageContentWhenPublishingAndSendingMessageToSingleRecipientThenTheMessageShouldBeDelivered()
        {
            // Description of the messaging process.

            // 1. Set all capabilities for each endpoint - this is done once, not each time.
            SetCapabilitiesForSender();
            SetCapabilitiesForRecipient();

            // 2. Recipient has to create his subscriptions in order to get the messages. If they are not set correctly the AR will return a HTTP 400.
            // Done once before the test.

            // 3. Set routes within the UI - this is done once, not each time.
            // Done manually, not API interaction necessary.

            // 4. Publish message from sender to recipient.
            var publishAndSendMessageService =
                new PublishAndSendMessageService(new HttpMessagingService(HttpClientForSender));
            var sendMessageParameters = new SendMessageParameters
            {
                OnboardResponse      = Sender,
                ApplicationMessageId = MessageIdService.ApplicationMessageId(),
                TechnicalMessageType = TechnicalMessageTypes.ImgPng,
                Recipients           = new List <string> {
                    Recipient.SensorAlternateId
                },
                Base64MessageContent = DataProvider.ReadBase64EncodedImage()
            };

            publishAndSendMessageService.Send(sendMessageParameters);

            // 5. Let the AR handle the message - this can take up to multiple seconds before receiving the ACK.
            Thread.Sleep(TimeSpan.FromSeconds(5));

            // 6. Fetch and analyze the ACK from the AR.
            var fetchMessageService = new FetchMessageService(HttpClientForSender);
            var fetch = fetchMessageService.Fetch(Sender);

            Assert.Single(fetch);

            var decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message);

            Assert.Equal(201, decodedMessage.ResponseEnvelope.ResponseCode);
        }
Beispiel #9
0
        /// <summary>
        ///     Please see base class declaration for documentation.
        /// </summary>
        /// <param name="sendMessageParameters">-</param>
        /// <returns>-</returns>
        public MessagingResult Send(SendMessageParameters sendMessageParameters)
        {
            var encodedMessages = new List <string>();

            if (string.IsNullOrWhiteSpace(sendMessageParameters.Base64MessageContent))
            {
                throw new CouldNotSendEmptyMessageException("Sending empty messages does not make any sense.");
            }

            if (MessageCanBeChunked(sendMessageParameters.TechnicalMessageType))
            {
                if (MessageHasToBeChunked(sendMessageParameters.Base64MessageContent))
                {
                    var chunkContextId = Guid.NewGuid().ToString();
                    var totalSize      = Encoding.Unicode.GetByteCount(sendMessageParameters.Base64MessageContent);

                    var chunkedMessages = ChunkMessageContent(sendMessageParameters.Base64MessageContent,
                                                              sendMessageParameters.ChunkSize > 0
                            ? sendMessageParameters.ChunkSize
                            : ChunkSizeDefinition.MaximumSupported);

                    var current = 0;
                    foreach (var chunkedMessage in chunkedMessages)
                    {
                        var sendMessageParametersDuplicate = new SendChunkedMessageParameters
                        {
                            Recipients           = sendMessageParameters.Recipients,
                            TypeUrl              = sendMessageParameters.TypeUrl,
                            TechnicalMessageType = sendMessageParameters.TechnicalMessageType,
                            ApplicationMessageId = MessageIdService.ApplicationMessageId()
                        };
                        var chunkComponent = new ChunkComponent
                        {
                            Current   = current++,
                            Total     = chunkedMessage.Length,
                            ContextId = chunkContextId,
                            TotalSize = totalSize
                        };
                        sendMessageParametersDuplicate.ChunkInfo            = chunkComponent;
                        sendMessageParametersDuplicate.Base64MessageContent = chunkedMessage;
                        encodedMessages.Add(Encode(sendMessageParametersDuplicate).Content);
                    }
                }
                else
                {
                    encodedMessages = new List <string> {
                        Encode(sendMessageParameters).Content
                    };
                }
            }
            else
            {
                encodedMessages = new List <string> {
                    Encode(sendMessageParameters).Content
                };
            }

            var messagingParameters = sendMessageParameters.BuildMessagingParameter(encodedMessages);

            return(_messagingService.Send(messagingParameters));
        }
Beispiel #10
0
        public void GivenMultipleValidMessageContentWhenPublishingMessagesThenTheMessageShouldBeDelivered()
        {
            var subscriptionService =
                new SubscriptionService(new HttpMessagingService(HttpClientForRecipient));
            var subscriptionParameters = new SubscriptionParameters
            {
                OnboardResponse       = Recipient,
                TechnicalMessageTypes = new List <Subscription.Types.MessageTypeSubscriptionItem>()
            };
            var technicalMessageType = new Subscription.Types.MessageTypeSubscriptionItem
            {
                TechnicalMessageType = TechnicalMessageTypes.ImgPng
            };

            subscriptionParameters.TechnicalMessageTypes.Add(technicalMessageType);
            subscriptionService.Send(subscriptionParameters);

            Thread.Sleep(TimeSpan.FromSeconds(5));

            var fetchMessageService = new FetchMessageService(HttpClientForRecipient);
            var fetch = fetchMessageService.Fetch(Recipient);

            Assert.Single(fetch);

            var decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message);

            Assert.Equal(201, decodedMessage.ResponseEnvelope.ResponseCode);

            var publishMultipleMessagesService =
                new PublishMultipleMessagesService(new HttpMessagingService(HttpClientForSender));
            var sendMessageParameters = new SendMultipleMessagesParameters
            {
                OnboardResponse        = Sender,
                ApplicationMessageId   = MessageIdService.ApplicationMessageId(),
                MultipleMessageEntries = new List <MultipleMessageEntry>
                {
                    new MultipleMessageEntry
                    {
                        ApplicationMessageId = MessageIdService.ApplicationMessageId(),
                        TechnicalMessageType = TechnicalMessageTypes.ImgPng,
                        Base64MessageContent = DataProvider.ReadBase64EncodedImage()
                    },
                    new MultipleMessageEntry
                    {
                        ApplicationMessageId = MessageIdService.ApplicationMessageId(),
                        TechnicalMessageType = TechnicalMessageTypes.ImgPng,
                        Base64MessageContent = DataProvider.ReadBase64EncodedImage()
                    }
                }
            };

            publishMultipleMessagesService.Send(sendMessageParameters);

            Thread.Sleep(TimeSpan.FromSeconds(5));

            fetchMessageService = new FetchMessageService(HttpClientForSender);
            fetch = fetchMessageService.Fetch(Sender);
            Assert.Equal(2, fetch.Count);

            Assert.Equal(201, DecodeMessageService.Decode(fetch[0].Command.Message).ResponseEnvelope.ResponseCode);
            Assert.Equal(201, DecodeMessageService.Decode(fetch[1].Command.Message).ResponseEnvelope.ResponseCode);
        }