public void OptionalAndRequiredWithAnnotatedMethod()
        {
            var testService = new AnnotatedTestService();
            var method      = testService.GetType().GetMethod("OptionalAndRequiredHeader");
            var context     = GetDefaultContext();
            var processor   = new MethodInvokingMessageProcessor <object>(context, testService, method);
            var message     = MessageBuilder.WithPayload("foo")
                              .SetHeader("num", 42)
                              .Build();
            var result = processor.ProcessMessage(message);

            Assert.Equal("null42", result);
            message = MessageBuilder.WithPayload("foo")
                      .SetHeader("prop", "bar")
                      .SetHeader("num", 42)
                      .Build();
            result = processor.ProcessMessage(message);
            Assert.Equal("bar42", result);
            message = MessageBuilder.WithPayload("foo")
                      .SetHeader("prop", "bar")
                      .Build();
            var ex = Assert.Throws <MessageHandlingException>(() => processor.ProcessMessage(message));

            Assert.Contains("num", ex.InnerException.Message);
        }
        public void TestPrivateMethod()
        {
            var service   = new Foo();
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <object>(context, service, typeof(ServiceActivatorAttribute));

            Assert.Equal("FOO", processor.ProcessMessage(Message.Create("foo")));
            Assert.Equal("BAR", processor.ProcessMessage(Message.Create("bar")));
        }
        public void RequiredHeaderNotProvidedOnSecondMessage()
        {
            var method               = _testService.GetType().GetMethod("RequiredHeader");
            var context              = GetDefaultContext();
            var processor            = new MethodInvokingMessageProcessor <int>(context, _testService, method);
            var messageWithHeader    = MessageBuilder.WithPayload("foo").SetHeader("num", 123).Build();
            var messageWithoutHeader = Message.Create <string>("foo");

            processor.ProcessMessage(messageWithHeader);
            Assert.Throws <MessageHandlingException>(() => processor.ProcessMessage(messageWithoutHeader));
        }
        public void RequiredHeaderNotProvided()
        {
            var method    = _testService.GetType().GetMethod("RequiredHeader");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <int>(context, _testService, method);

            Assert.Throws <MessageHandlingException>(() => processor.ProcessMessage(Message.Create <string>("foo")));
        }
        public void FromMessageInvalidMethodWithMultipleMappingAnnotations()
        {
            var method    = typeof(MultipleMappingAnnotationTestBean).GetMethod("Test");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <object>(context, _testService, method);
            var message   = MessageBuilder.WithPayload("payload").SetHeader("foo", "bar").Build();

            Assert.Throws <MessageHandlingException>(() => processor.ProcessMessage(message));
        }
        public void FromMessageWithOptionalAndRequiredHeaderAndOnlyOptionalHeaderProvided()
        {
            var method    = _testService.GetType().GetMethod("OptionalAndRequiredHeader");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <string>(context, _testService, method);
            var message   = MessageBuilder.WithPayload("foo").SetHeader("prop", "bar").Build();

            Assert.Throws <MessageHandlingException>(() => processor.ProcessMessage(message));
        }
        public void OptionalHeader()
        {
            var method    = _testService.GetType().GetMethod("OptionalHeader");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <int?>(context, _testService, method);
            var result    = processor.ProcessMessage(Message.Create <string>("foo"));

            Assert.Null(result);
        }
        public void TestProcessMessageCheckedException()
        {
            var testService = new TestErrorService();
            var method      = testService.GetType().GetMethod("Checked");
            var context     = GetDefaultContext();
            var processor   = new MethodInvokingMessageProcessor <object>(context, testService, method);
            var ex          = Assert.Throws <MessageHandlingException>(() => processor.ProcessMessage(Message.Create("foo")));

            Assert.IsType <CheckedException>(ex.InnerException);
        }
        public void ConversionFailureWithAnnotatedMethod()
        {
            var testService = new AnnotatedTestService();
            var method      = testService.GetType().GetMethod("IntegerMethod");
            var context     = GetDefaultContext();
            var processor   = new MethodInvokingMessageProcessor <object>(context, testService, method);
            var ex          = Assert.Throws <MessageHandlingException>(() => processor.ProcessMessage(Message.Create("foo")));

            Assert.IsType <MessageConversionException>(ex.InnerException);
        }
        public void ConvertedPayloadWithAnnotatedMethod()
        {
            var testService = new AnnotatedTestService();
            var method      = testService.GetType().GetMethod("IntegerMethod");
            var context     = GetDefaultContext();
            var processor   = new MethodInvokingMessageProcessor <object>(context, testService, method);
            var result      = processor.ProcessMessage(Message.Create("456"));

            Assert.Equal(456, result);
        }
        public void MessageOnlyWithAnnotatedMethod()
        {
            var testService = new AnnotatedTestService();
            var method      = testService.GetType().GetMethod("MessageOnly");
            var context     = GetDefaultContext();
            var processor   = new MethodInvokingMessageProcessor <object>(context, testService, method);
            var result      = processor.ProcessMessage(Message.Create("foo"));

            Assert.Equal("foo", result);
        }
        public void FromMessageWithOptionalAndRequiredHeaderAndOnlyRequiredHeaderProvided()
        {
            var method    = _testService.GetType().GetMethod("OptionalAndRequiredHeader");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <string>(context, _testService, method);
            var message   = MessageBuilder.WithPayload("foo").SetHeader("num", 123).Build();
            var result    = processor.ProcessMessage(message);

            Assert.Equal("null123", result);
        }
        public void PayloadAsMethodParameterAndObjectAsReturnValue()
        {
            var testService = new TestService();
            var method      = testService.GetType().GetMethod("AcceptPayloadAndReturnObject");
            var context     = GetDefaultContext();
            var processor   = new MethodInvokingMessageProcessor <object>(context, testService, method);
            var result      = processor.ProcessMessage(Message.Create("testing"));

            Assert.Equal("testing-1", result);
        }
        public void HeaderAnnotationWithExpression()
        {
            var message   = GetMessage();
            var method    = _testService.GetType().GetMethod("HeaderAnnotationWithExpression");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <object>(context, _testService, method);
            var result    = processor.ProcessMessage(message);

            Assert.Equal("monday", result);
        }
        public void FromMessageToPayloadArgsHeaderArgs()
        {
            var method    = _testService.GetType().GetMethod("PayloadArgAndHeaderArg");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <object>(context, _testService, method);
            var message   = MessageBuilder.WithPayload(_employee).SetHeader("day", "monday").Build();
            var result    = processor.ProcessMessage(message);

            Assert.Equal("olegmonday", result);
        }
        public void TestPayloadCoercedToString()
        {
            var testService = new TestService();
            var method      = testService.GetType().GetMethod("AcceptPayloadAndReturnObject");
            var context     = GetDefaultContext();
            var processor   = new MethodInvokingMessageProcessor <object>(context, testService, method);
            var result      = processor.ProcessMessage(Message.Create(123456789));

            Assert.Equal("123456789-1", result);
        }
        public void MessageSubclassAsMethodParameterAndMessageSubclassAsReturnValue()
        {
            var testService = new TestService();
            var method      = testService.GetType().GetMethod("AcceptMessageSubclassAndReturnMessageSubclass");
            var context     = GetDefaultContext();
            var processor   = new MethodInvokingMessageProcessor <object>(context, testService, method);
            var result      = processor.ProcessMessage(Message.Create("testing")) as IMessage;

            Assert.NotNull(result);
            Assert.Equal("testing-6", result.Payload);
        }
        public void FilterSelectsAnnotationMethodsOnly()
        {
            var service   = new OverloadedMethodService();
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <object>(context, service, typeof(ServiceActivatorAttribute));

            processor.ProcessMessage(MessageBuilder.WithPayload(123).Build());
            Assert.NotNull(service._lastArg);
            Assert.IsType <string>(service._lastArg);
            Assert.Equal("123", service._lastArg);
        }
        public void FromMessageToHyphenatedHeaderName()
        {
            var method    = _testService.GetType().GetMethod("HeaderNameWithHyphen");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <object>(context, _testService, method);
            var employee  = new Employee("John", "Doe");
            var message   = MessageBuilder.WithPayload("payload").SetHeader("foo-bar", "abc").Build();
            var result    = processor.ProcessMessage(message);

            Assert.Equal("ABC", result);
        }
        public void FromMessageToPayloadArgs()
        {
            var method    = _testService.GetType().GetMethod("PayloadAnnotationFullName");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <object>(context, _testService, method);

            var message = MessageBuilder.WithPayload(_employee).SetHeader("number", "jkl").Build();
            var result  = processor.ProcessMessage(message);

            Assert.Equal("oleg zhurakousky", result);
        }
        public void IrrelevantAnnotation()
        {
            var message   = MessageBuilder.WithPayload("foo").Build();
            var method    = _testService.GetType().GetMethod("IrrelevantAnnotation");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <object>(context, _testService, method);

            var result = processor.ProcessMessage(message);

            Assert.Equal("foo", result);
        }
        public void PayloadAndHeaderAnnotationMethodParametersAndObjectAsReturnValue()
        {
            var testService = new TestService();
            var method      = testService.GetType().GetMethod("AcceptPayloadAndHeaderAndReturnObject");
            var context     = GetDefaultContext();
            var processor   = new MethodInvokingMessageProcessor <object>(context, testService, method);
            var request     = MessageBuilder.WithPayload("testing").SetHeader("number", 123).Build();
            var result      = processor.ProcessMessage(request);

            Assert.NotNull(result);
            Assert.Equal("testing-123", result);
        }
        public void MessageAndHeaderWithAnnotatedMethod()
        {
            var testService = new AnnotatedTestService();
            var method      = testService.GetType().GetMethod("MessageAndHeader");
            var context     = GetDefaultContext();
            var processor   = new MethodInvokingMessageProcessor <object>(context, testService, method);
            var request     = MessageBuilder.WithPayload("foo").SetHeader("number", 42).Build();
            var result      = processor.ProcessMessage(request);

            Assert.NotNull(result);
            Assert.Equal("foo-42", result);
        }
        public void FromMessageToPayload()
        {
            var method    = _testService.GetType().GetMethod("MapOnly");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <object>(context, _testService, method);

            var message = MessageBuilder.WithPayload(_employee).SetHeader("number", "jkl").Build();
            var result  = processor.ProcessMessage(message) as IDictionary <string, object>;

            Assert.NotNull(result);
            Assert.Equal("jkl", result["number"]);
        }
        public void FromMessageWithMapMethodAndHeadersAnnotation()
        {
            var method    = _testService.GetType().GetMethod("MapHeaders");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <object>(context, _testService, method);
            var message   = MessageBuilder.WithPayload("test")
                            .SetHeader("attrib1", 123)
                            .SetHeader("attrib2", 456)
                            .Build();
            var result = (IDictionary <string, object>)processor.ProcessMessage(message);

            Assert.Equal(123, result["attrib1"]);
            Assert.Equal(456, result["attrib2"]);
        }
        public void MultipleAnnotatedArgs()
        {
            var message   = this.GetMessage();
            var method    = _testService.GetType().GetMethod("MultipleAnnotatedArguments");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <object>(context, _testService, method);

            var parameters = (object[])processor.ProcessMessage(message);

            Assert.NotNull(parameters);
            Assert.Equal(5, parameters.Length);
            Assert.Equal("monday", parameters[0]);
            Assert.Equal("September", parameters[1]);
            Assert.Equal(parameters[2], _employee);
            Assert.Equal("oleg", parameters[3]);
            Assert.True(parameters[4] is IDictionary <string, object>);
        }
        public void FromMessageWithMapAndObjectMethod()
        {
            var method    = _testService.GetType().GetMethod("MapHeadersAndPayload");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <object>(context, _testService, method);
            var message   = MessageBuilder.WithPayload("test")
                            .SetHeader("prop1", "foo")
                            .SetHeader("prop2", "bar")
                            .Build();
            var result = (IDictionary <object, object>)processor.ProcessMessage(message);

            Assert.Equal(5, result.Count);
            Assert.True(result.ContainsKey(MessageHeaders.ID));
            Assert.True(result.ContainsKey(MessageHeaders.TIMESTAMP));
            Assert.Equal("foo", result["prop1"]);
            Assert.Equal("bar", result["prop2"]);
            Assert.Equal("test", result["payload"]);
        }
        public void FromMessageWithMapMethodAndMapPayload()
        {
            var method    = _testService.GetType().GetMethod("MapPayload");
            var context   = GetDefaultContext();
            var processor = new MethodInvokingMessageProcessor <object>(context, _testService, method);
            var payload   = new Dictionary <string, int>();

            payload.Add("attrib1", 88);
            payload.Add("attrib2", 99);
            var message = MessageBuilder.WithPayload(payload)
                          .SetHeader("attrib1", 123)
                          .SetHeader("attrib2", 456)
                          .Build();
            var result = (IDictionary <string, int>)processor.ProcessMessage(message);

            Assert.Equal(2, result.Count);
            Assert.Equal(88, result["attrib1"]);
            Assert.Equal(99, result["attrib2"]);
        }