/// <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); }
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); }
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); }
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_); }
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); }
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_); }
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); }
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); }
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); }
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); }
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); } }
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); }
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); }
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_); }
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); }
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_); }
/// <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); }
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_); }
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); }
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 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); }
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_); }
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_); }
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_); }
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); }
/// <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. Query the message with that message ID and check the results. /// 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. /// 7. Write the message content to the output folder. /// 8. Confirm the message using the message ID to clean the feed. /// 9. 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) /// 10. 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 messageId = feedMessageHeaderQuery.Feed[0].Headers[0].MessageId; var queryMessagesService = new QueryMessagesService(new HttpMessagingService(HttpClientForRecipient)); var queryMessagesParameters = new QueryMessagesParameters { OnboardResponse = Recipient, MessageIds = new List <string> { messageId } }; queryMessagesService.Send(queryMessagesParameters); 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); Assert.Equal(ResponseEnvelope.Types.ResponseBodyType.AckForFeedMessage, decodedMessage.ResponseEnvelope.Type); var feedMessage = queryMessagesService.Decode(decodedMessage.ResponsePayloadWrapper.Details); Assert.Equal(1, feedMessage.QueryMetrics.TotalMessagesInQuery); var fileName = FilePrefix + feedMessage.Messages[0].Header.MessageId + ".png"; var image = Encode.FromMessageContent(feedMessage.Messages[0].Content); File.WriteAllBytes(fileName, image); var feedConfirmService = new FeedConfirmService(new HttpMessagingService(HttpClientForRecipient)); var feedConfirmParameters = new FeedConfirmParameters { OnboardResponse = Recipient, MessageIds = new List <string> { messageId } }; feedConfirmService.Send(feedConfirmParameters); 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); var messages = DecodeMessageService.Decode(decodedMessage.ResponsePayloadWrapper.Details); Assert.NotNull(messages); Assert.NotEmpty(messages.Messages_); Assert.Single(messages.Messages_); Assert.Equal("VAL_000206", messages.Messages_[0].MessageCode); Assert.Equal( "Feed message confirmation confirmed.", messages.Messages_[0].Message_); }