Esempio n. 1
0
        public void GivenValidCapabilitiesWhenSendingCapabilitiesMessageThenTheAgrirouterShouldSetTheCapabilities()
        {
            var capabilitiesServices =
                new CapabilitiesService(new HttpMessagingService(HttpClient));
            var capabilitiesParameters = new CapabilitiesParameters
            {
                OnboardResponse         = OnboardResponse,
                ApplicationId           = ApplicationId,
                CertificationVersionId  = CertificationVersionId,
                EnablePushNotifications = CapabilitySpecification.Types.PushNotification.Disabled,
                CapabilityParameters    = new List <CapabilityParameter>()
            };

            var capabilitiesParameter = new CapabilityParameter
            {
                Direction            = CapabilitySpecification.Types.Direction.SendReceive,
                TechnicalMessageType = TechnicalMessageTypes.Iso11783TaskdataZip
            };

            capabilitiesParameters.CapabilityParameters.Add(capabilitiesParameter);
            capabilitiesServices.Send(capabilitiesParameters);

            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);
        }
        GivenExistingEndpointsWhenQueryMessagesWithoutParametersWhenPerformingQueryThenTheMessageShouldNotBeAccepted()
        {
            var queryMessagesService =
                new QueryMessagesService(new HttpMessagingService(HttpClient));
            var queryMessagesParameters = new QueryMessagesParameters
            {
                OnboardResponse = OnboardResponse
            };

            queryMessagesService.Send(queryMessagesParameters);

            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);

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

            Assert.NotNull(messages);
            Assert.NotEmpty(messages.Messages_);
            Assert.Single(messages.Messages_);
            Assert.Equal("VAL_000017", messages.Messages_[0].MessageCode);
            Assert.Equal(
                "Query does not contain any filtering criteria: messageIds, senders or validityPeriod. Information required to process message is missing or malformed.",
                messages.Messages_[0].Message_);
        }
        GivenExistingEndpointsWhenQueryMessagesWithUnknownMessageIdsMessageIdsThenTheResultShouldBeAnEmptySetOfMessages()
        {
            var queryMessagesService =
                new QueryMessagesService(new HttpMessagingService(HttpClient));
            var queryMessagesParameters = new QueryMessagesParameters
            {
                OnboardResponse = OnboardResponse,
                MessageIds      = new List <string> {
                    Guid.NewGuid().ToString()
                }
            };

            queryMessagesService.Send(queryMessagesParameters);

            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(204, decodedMessage.ResponseEnvelope.ResponseCode);
            Assert.Equal(ResponseEnvelope.Types.ResponseBodyType.AckForFeedMessage,
                         decodedMessage.ResponseEnvelope.Type);
        }
        GivenExistingEndpointsWhenQueryMessagesWithValidityPeriodThenTheResultShouldBeAnEmptySetOfMessages()
        {
            var queryMessagesService =
                new QueryMessagesService(new HttpMessagingService(HttpClient));
            var queryMessagesParameters = new QueryMessagesParameters
            {
                OnboardResponse = OnboardResponse,
                ValidityPeriod  = new ValidityPeriod()
            };

            queryMessagesParameters.ValidityPeriod.SentFrom = UtcDataService.Timestamp(TimestampOffset.FourWeeks);
            queryMessagesParameters.ValidityPeriod.SentTo   = UtcDataService.Timestamp(TimestampOffset.None);
            queryMessagesService.Send(queryMessagesParameters);

            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(204, decodedMessage.ResponseEnvelope.ResponseCode);
            Assert.Equal(ResponseEnvelope.Types.ResponseBodyType.AckForFeedMessage,
                         decodedMessage.ResponseEnvelope.Type);
        }
Esempio n. 5
0
        public void GivenEmptyMessageIdsWhenConfirmingMessagesThenTheMessageShouldNotBeAccepted()
        {
            var feedConfirmService =
                new FeedConfirmService(new HttpMessagingService(HttpClient));
            var feedConfirmParameters = new FeedConfirmParameters
            {
                OnboardResponse = OnboardResponse
            };

            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(400, decodedMessage.ResponseEnvelope.ResponseCode);

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

            Assert.NotNull(messages);
            Assert.NotEmpty(messages.Messages_);
            Assert.Single(messages.Messages_);
            Assert.Equal("VAL_000017", messages.Messages_[0].MessageCode);
            Assert.Equal(
                "messageIds information required to process message is missing or malformed.",
                messages.Messages_[0].Message_);
        }
Esempio n. 6
0
        GivenExistingEndpointsWhenFeedDeleteWithoutParametersWhenPerformingQueryThenTheMessageShouldNotBeOkBecauseTheMessageIdsAreMissing()
        {
            var feedDeleteService    = new FeedDeleteService(new HttpMessagingService(HttpClient));
            var feedDeleteParameters = new FeedDeleteParameters
            {
                OnboardResponse = OnboardResponse
            };

            feedDeleteService.Send(feedDeleteParameters);

            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);

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

            Assert.NotNull(messages);
            Assert.NotEmpty(messages.Messages_);
            Assert.Single(messages.Messages_);
            Assert.Equal("VAL_000017", messages.Messages_[0].MessageCode);
            Assert.Equal(
                "messageIds information required to process message is missing or malformed.",
                messages.Messages_[0].Message_);
        }
        GivenExistingEndpointsWhenListEndpointsIsExecutedWithDirectionSendAndEmptyTechnicalMessageTypeThenTheMessageShouldReturnAValidResult()
        {
            var listEndpointsService =
                new ListEndpointsUnfilteredService(new HttpMessagingService(HttpClient));
            var listEndpointsParameters = new ListEndpointsParameters
            {
                OnboardResponse = OnboardResponse,
                Direction       = ListEndpointsQuery.Types.Direction.Send
            };

            listEndpointsService.Send(listEndpointsParameters);

            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);
            Assert.Equal(ResponseEnvelope.Types.ResponseBodyType.EndpointsListing,
                         decodedMessage.ResponseEnvelope.Type);
        }
Esempio n. 8
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_);
        }
Esempio n. 9
0
        private static void RunWith(OnboardResponse onboardResponse)
        {
            var httpClient           = HttpClientFactory.AuthenticatedHttpClient(onboardResponse);
            var capabilitiesServices =
                new CapabilitiesService(new HttpMessagingService(httpClient));
            var capabilitiesParameters = new CapabilitiesParameters
            {
                OnboardResponse         = onboardResponse,
                ApplicationId           = ApplicationId,
                CertificationVersionId  = CertificationVersionId,
                EnablePushNotifications = CapabilitySpecification.Types.PushNotification.Disabled,
                CapabilityParameters    = new List <CapabilityParameter>()
            };

            var capabilitiesParameter = new CapabilityParameter
            {
                Direction            = CapabilitySpecification.Types.Direction.SendReceive,
                TechnicalMessageType = TechnicalMessageTypes.Iso11783TaskdataZip
            };

            capabilitiesParameters.CapabilityParameters.Add(capabilitiesParameter);
            capabilitiesServices.Send(capabilitiesParameters);

            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);
        }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 14
0
        private static void PrepareTestEnvironmentForRecipient()
        {
            var capabilitiesServices =
                new CapabilitiesService(new HttpMessagingService(HttpClientForRecipient));
            var capabilitiesParameters = new CapabilitiesParameters
            {
                OnboardResponse         = Recipient,
                ApplicationId           = ApplicationId,
                CertificationVersionId  = CertificationVersionId,
                EnablePushNotifications = CapabilitySpecification.Types.PushNotification.Disabled,
                CapabilityParameters    = new List <CapabilityParameter>()
            };
            var capabilitiesParameter = new CapabilityParameter
            {
                Direction            = CapabilitySpecification.Types.Direction.SendReceive,
                TechnicalMessageType = TechnicalMessageTypes.ImgPng
            };

            capabilitiesParameters.CapabilityParameters.Add(capabilitiesParameter);
            capabilitiesServices.Send(capabilitiesParameters);

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

            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);
        }
        public void GivenSingleSubscriptionEntryWhenSendingSubscriptionMessageThenTheMessageShouldBeAccepted()
        {
            var subscriptionService =
                new SubscriptionService(new HttpMessagingService(HttpClient));
            var subscriptionParameters = new SubscriptionParameters
            {
                OnboardResponse       = OnboardResponse,
                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(HttpClient);
            var fetch = fetchMessageService.Fetch(OnboardResponse);

            Assert.Single(fetch);

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

            Assert.Equal(201, decodedMessage.ResponseEnvelope.ResponseCode);
            Assert.Equal(ResponseEnvelope.Types.ResponseBodyType.Ack,
                         decodedMessage.ResponseEnvelope.Type);
        }
Esempio n. 16
0
        /// <summary>
        ///     The actions for the recipient are the following:
        ///     1. Query the message headers.
        ///     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 response from the AR and check.
        ///     4. Delete the messages using the message IDs to clean the feed.
        ///     5. 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)
        ///     6. Fetch the response from the AR and check.
        /// </summary>
        private static void ActionsForRecipient()
        {
            var queryMessageHeadersService =
                new QueryMessageHeadersService(new HttpMessagingService(HttpClientForRecipient));
            var queryMessageHeadersParameters = new QueryMessagesParameters
            {
                OnboardResponse = Recipient,
                Senders         = new List <string> {
                    Sender.SensorAlternateId
                }
            };

            queryMessageHeadersService.Send(queryMessageHeadersParameters);

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

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

            Assert.Single(fetch);

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

            Assert.Equal(200, decodedMessage.ResponseEnvelope.ResponseCode);
            Assert.Equal(ResponseEnvelope.Types.ResponseBodyType.AckForFeedHeaderList,
                         decodedMessage.ResponseEnvelope.Type);

            var feedMessageHeaderQuery =
                queryMessageHeadersService.Decode(decodedMessage.ResponsePayloadWrapper.Details);

            Assert.True(feedMessageHeaderQuery.QueryMetrics.TotalMessagesInQuery > 0,
                        "There has to be at least one message in the query.");

            var messageIds =
                (from feed in feedMessageHeaderQuery.Feed from feedHeader in feed.Headers select feedHeader.MessageId)
                .ToList();

            var feedDeleteService =
                new FeedDeleteService(new HttpMessagingService(HttpClientForRecipient));
            var feedDeleteParameters = new FeedDeleteParameters
            {
                OnboardResponse = Recipient,
                MessageIds      = messageIds
            };

            feedDeleteService.Send(feedDeleteParameters);

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

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

            decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message);
            Assert.Equal(200, decodedMessage.ResponseEnvelope.ResponseCode);
        }
Esempio n. 17
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);
        }
        GivenValidCapabilitiesMessageResponseWhenDecodingTheMessageThenTheResponseEnvelopeAndResponsePayloadWrapperShouldBeFilled()
        {
            const string responseMessage =
                "XgjJARACGiQ5MDAxMjg3Yi03NjA5LTQ0MjYtYjU3My0xNTE5MmQwYzEyNDIiJGMyZGViM2VlLTIyMDItNDA1Mi1hZDJhLTUxMjVkND" +
                "g3YjdmNioLCMHy1/AFEICvvnGEAQqBAQowdHlwZXMuYWdyaXJvdXRlci5jb20vYWdyaXJvdXRlci5jb21tb25zLk1lc3NhZ2VzEk0K" +
                "Swo9U2tpcHBpbmcgY2FwYWJpbGl0aWVzIHVwZGF0ZSBiZWNhdXNlIHRoZXJlIGFyZSBubyBkaWZmZXJlbmNlcxIKVkFMXzAwMDAyMg==";

            var decodedMessage = DecodeMessageService.Decode(responseMessage);

            Assert.NotNull(decodedMessage.ResponseEnvelope);
            Assert.NotNull(decodedMessage.ResponsePayloadWrapper);
            Assert.Equal(201, decodedMessage.ResponseEnvelope.ResponseCode);
        }
        GivenMultipleSubscriptionEntriesWithOneInvalidTechnicalMessageTypeWhenSendingSubscriptionMessageThenTheMessageShouldBeNotBeAccepted()
        {
            var subscriptionService =
                new SubscriptionService(new HttpMessagingService(HttpClient));
            var subscriptionParameters = new SubscriptionParameters
            {
                OnboardResponse       = OnboardResponse,
                TechnicalMessageTypes = new List <Subscription.Types.MessageTypeSubscriptionItem>()
            };
            var technicalMessageTypeForTaskdata = new Subscription.Types.MessageTypeSubscriptionItem
            {
                TechnicalMessageType = TechnicalMessageTypes.ImgPng
            };

            subscriptionParameters.TechnicalMessageTypes.Add(technicalMessageTypeForTaskdata);

            var technicalMessageTypeForProtobuf = new Subscription.Types.MessageTypeSubscriptionItem
            {
                TechnicalMessageType = TechnicalMessageTypes.Iso11783DeviceDescriptionProtobuf
            };

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

            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);
            Assert.Equal(ResponseEnvelope.Types.ResponseBodyType.AckWithFailure,
                         decodedMessage.ResponseEnvelope.Type);

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

            Assert.NotNull(messages);
            Assert.NotEmpty(messages.Messages_);
            Assert.Single(messages.Messages_);
            Assert.Equal("VAL_000006", messages.Messages_[0].MessageCode);
            Assert.Equal(
                "Subscription to \"iso:11783:-10:device_description:protobuf\" is not valid per reported capabilities.",
                messages.Messages_[0].Message_);
        }
        GivenValidCapabilitiesWhenSendingCapabilitiesMessageThenTheAgrirouterShouldSetTheCapabilities()
        {
            var mqttClient = new MqttFactory().CreateMqttClient();

            await MqttConnectionHelper.ConnectMqttClient(mqttClient, OnboardResponse);

            await MqttConnectionHelper.SubscribeToTopics(mqttClient, OnboardResponse);

            var capabilitiesServices   = new CapabilitiesService(new MqttMessagingService(mqttClient));
            var capabilitiesParameters = new CapabilitiesParameters
            {
                OnboardResponse         = OnboardResponse,
                ApplicationId           = ApplicationId,
                CertificationVersionId  = CertificationVersionId,
                EnablePushNotifications = CapabilitySpecification.Types.PushNotification.Disabled,
                CapabilityParameters    = new List <CapabilityParameter>()
            };

            var capabilitiesParameter = new CapabilityParameter
            {
                Direction            = CapabilitySpecification.Types.Direction.SendReceive,
                TechnicalMessageType = TechnicalMessageTypes.Iso11783TaskdataZip
            };

            capabilitiesParameters.CapabilityParameters.Add(capabilitiesParameter);
            capabilitiesServices.Send(capabilitiesParameters);
            var messageReceived = false;
            var counter         = 0;

            mqttClient.UseApplicationMessageReceivedHandler(e =>
            {
                messageReceived    = true;
                var messagePayload = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
                var decodedMessage = DecodeMessageService.Decode(messagePayload);
                Assert.Equal(201, decodedMessage.ResponseEnvelope.ResponseCode);
            });

            while (!messageReceived && counter < 5)
            {
                await Task.Delay(TimeSpan.FromSeconds(5));

                counter++;
            }

            Assert.True(messageReceived);
        }
Esempio n. 21
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);
        }
Esempio n. 22
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);
        }
        public void GivenValidMessageWhenDecodingTheMessageThenTheMessageShouldBeParsedCorrectly()
        {
            const string responseMessage =
                "EwiQAxADKgwIpITc8AUQgP/1sQNvCm0KMHR5cGVzLmFncmlyb3V0ZXIuY29tL2Fncmlyb3V0ZXIuY29tbW9ucy5NZXNzYWdlcxI5" +
                "CjcKKUVycm9yIG9jY3VyZWQgd2hpbGUgZGVjb2RpbmcgdGhlIG1lc3NhZ2UuEgpWQUxfMDAwMzAw";

            var decodedMessage = DecodeMessageService.Decode(responseMessage);

            Assert.NotNull(decodedMessage.ResponseEnvelope);
            Assert.NotNull(decodedMessage.ResponsePayloadWrapper);
            Assert.Equal(400, decodedMessage.ResponseEnvelope.ResponseCode);

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

            Assert.NotNull(messages);
            Assert.NotEmpty(messages.Messages_);
            Assert.Single(messages.Messages_);
            Assert.Equal("VAL_000300", messages.Messages_[0].MessageCode);
            Assert.Equal("Error occured while decoding the message.", messages.Messages_[0].Message_);
        }
        public void GivenErrorMessageWhenDecodingTheMessageThenTheMessageShouldBeParsedCorrectly()
        {
            const string responseMessage =
                "XgiQAxADGiQ0MDkyNzU3Yi1iNjIxLTRjMzktODMyMi03ODIzOGY3Mjc3NDciJDhiODA3M2Y0LThhOGItNDU5NC1iMTYwLWZmYWRmMDJm" +
                "NTFiNioLCMHNs/oFEMDDkweYAQqVAQowdHlwZXMuYWdyaXJvdXRlci5jb20vYWdyaXJvdXRlci5jb21tb25zLk1lc3NhZ2VzEmEKXwpR" +
                "Tm8gcmVjaXBpZW50cyBoYXZlIGJlZW4gaWRlbnRpZmllZCBmb3IgaXNvOjExNzgzOi0xMDpkZXZpY2VfZGVzY3JpcHRpb246cHJvdG9" +
                "idWYuEgpWQUxfMDAwMDA0";

            var decodedMessage = DecodeMessageService.Decode(responseMessage);

            Assert.NotNull(decodedMessage.ResponseEnvelope);
            Assert.NotNull(decodedMessage.ResponsePayloadWrapper);
            Assert.Equal(400, decodedMessage.ResponseEnvelope.ResponseCode);

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

            Assert.NotNull(messages);
            Assert.NotEmpty(messages.Messages_);
            Assert.Single(messages.Messages_);
            Assert.Equal("VAL_000004", messages.Messages_[0].MessageCode);
            Assert.Equal("No recipients have been identified for iso:11783:-10:device_description:protobuf.", messages.Messages_[0].Message_);
        }
Esempio n. 25
0
        GivenExistingEndpointsWhenFeedDeleteWithUnknownMessageIdsSenderIdsThenTheResultShouldNotBeOkBecauseTheMessageIdsAreMissing()
        {
            var feedDeleteService    = new FeedDeleteService(new HttpMessagingService(HttpClient));
            var feedDeleteParameters = new FeedDeleteParameters
            {
                OnboardResponse = OnboardResponse,
                Senders         = new List <string> {
                    Guid.NewGuid().ToString()
                }
            };

            feedDeleteService.Send(feedDeleteParameters);

            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);
            Assert.Equal(ResponseEnvelope.Types.ResponseBodyType.AckWithFailure,
                         decodedMessage.ResponseEnvelope.Type);

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

            Assert.NotNull(messages);
            Assert.NotEmpty(messages.Messages_);
            Assert.Single(messages.Messages_);
            Assert.Equal("VAL_000017", messages.Messages_[0].MessageCode);
            Assert.Equal(
                "messageIds information required to process message is missing or malformed.",
                messages.Messages_[0].Message_);
        }
Esempio n. 26
0
        public void GivenExistingEndpointsWhenFeedDeleteWithUnknownMessageIdsMessageIdsThenTheResultShouldBeOk()
        {
            var feedDeleteService    = new FeedDeleteService(new HttpMessagingService(HttpClient));
            var feedDeleteParameters = new FeedDeleteParameters
            {
                OnboardResponse = OnboardResponse,
                MessageIds      = new List <string> {
                    Guid.NewGuid().ToString()
                }
            };

            feedDeleteService.Send(feedDeleteParameters);

            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);
            Assert.Equal(ResponseEnvelope.Types.ResponseBodyType.AckWithMessages,
                         decodedMessage.ResponseEnvelope.Type);

            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_);
        }
        public void GivenEmptySubscriptionWhenSendingSubscriptionMessageThenTheMessageShouldBeAccepted()
        {
            var subscriptionService =
                new SubscriptionService(new HttpMessagingService(HttpClient));
            var subscriptionParameters = new SubscriptionParameters
            {
                OnboardResponse = OnboardResponse
            };

            subscriptionService.Send(subscriptionParameters);

            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);
            Assert.Equal(ResponseEnvelope.Types.ResponseBodyType.Ack,
                         decodedMessage.ResponseEnvelope.Type);
        }
Esempio n. 28
0
        GivenExistingEndpointsWhenFeedDeleteWithValidityPeriodThenTheResultShouldNotBeOkBecauseTheMessageIdsAreMissing()
        {
            var feedDeleteService    = new FeedDeleteService(new HttpMessagingService(HttpClient));
            var feedDeleteParameters = new FeedDeleteParameters
            {
                OnboardResponse = OnboardResponse,
                ValidityPeriod  = new ValidityPeriod()
            };

            feedDeleteParameters.ValidityPeriod.SentTo = UtcDataService.Timestamp(TimestampOffset.None);
            feedDeleteParameters.ValidityPeriod.SentTo = UtcDataService.Timestamp(TimestampOffset.FourWeeks);
            feedDeleteService.Send(feedDeleteParameters);

            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);
            Assert.Equal(ResponseEnvelope.Types.ResponseBodyType.AckWithFailure,
                         decodedMessage.ResponseEnvelope.Type);

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

            Assert.NotNull(messages);
            Assert.NotEmpty(messages.Messages_);
            Assert.Single(messages.Messages_);
            Assert.Equal("VAL_000017", messages.Messages_[0].MessageCode);
            Assert.Equal(
                "messageIds information required to process message is missing or malformed.",
                messages.Messages_[0].Message_);
        }
 public void GivenInvalidDataAsMessageWhenDecodingTheMessageThenThereShouldBeAnException()
 {
     Assert.Throws <CouldNotDecodeMessageException>(() => DecodeMessageService.Decode("INVALID MESSAGE"));
 }
 public void GivenWhitespacesAsMessageWhenDecodingTheMessageThenThereShouldBeAnException()
 {
     Assert.Throws <ArgumentException>(() => DecodeMessageService.Decode("   "));
 }