public void TestAggregatorWithPojoCompletionStrategy()
        {
            IMessageChannel     input    = (IMessageChannel)_ctx.GetObject("aggregatorWithPojoCompletionStrategyInput");
            EventDrivenConsumer endpoint = (EventDrivenConsumer)_ctx.GetObject("aggregatorWithPojoCompletionStrategy");

            ICompletionStrategy completionStrategy =
                (ICompletionStrategy)
                TestUtils.GetFieldValue(TestUtils.GetFieldValue(endpoint, "_handler"), "_completionStrategy");

            Assert.IsTrue(completionStrategy is CompletionStrategyAdapter);

            //DirectFieldAccessor completionStrategyAccessor = new DirectFieldAccessor(completionStrategy);
            IMethodInvoker invoker = (IMethodInvoker)TestUtils.GetFieldValue(completionStrategy, "_invoker");

            Assert.IsTrue(TestUtils.GetFieldValue(invoker, "_obj") is MaxValueCompletionStrategy);
            Assert.IsTrue(
                ((MethodInfo)TestUtils.GetFieldValue(completionStrategy, "_method")).Name.Equals("CheckCompleteness"));
            input.Send(CreateMessage(1l, "id1", 0, 0, null));
            input.Send(CreateMessage(2l, "id1", 0, 0, null));
            input.Send(CreateMessage(3l, "id1", 0, 0, null));
            IPollableChannel outputChannel = (IPollableChannel)_ctx.GetObject("outputChannel");
            IMessage         reply         = outputChannel.Receive(TimeSpan.Zero);

            Assert.IsNull(reply);
            input.Send(CreateMessage(5l, "id1", 0, 0, null));
            reply = outputChannel.Receive(TimeSpan.Zero);
            Assert.IsNotNull(reply);
            Assert.That(reply.Payload, Is.EqualTo(11l));
        }
Esempio n. 2
0
 public void ReceiveMessage()
 {
     Expect.Call(_replyChannel.Receive()).Return(_messageMock);
     Expect.Call(_messageMock.Payload).Return("test").Repeat.Any(); //.anyTimes();
     _mocks.ReplayAll();
     Assert.That(_simpleMessagingGateway.Receive(), NUnit.Framework.Is.EqualTo("test"));
     _mocks.VerifyAll();
 }
        public void TestPriorityChannelWithIntegerDatatypeEnforced()
        {
            IApplicationContext ctx     = TestUtils.GetContext(@"Channel\Config\PriorityChannelParserTests.xml");
            IPollableChannel    channel = (IPollableChannel)ctx.GetObject("integerOnlyPriorityChannel");

            channel.Send(new Message <int>(3));
            channel.Send(new Message <int>(2));
            channel.Send(new Message <int>(1));
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo(1));
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo(2));
            Assert.That(channel.Receive(TimeSpan.Zero).Payload, Is.EqualTo(3));
        }
        public void wireTapWithRejectingSelector()
        {
            IApplicationContext ctx            = TestUtils.GetContext(@"Config\WireTapParserTests.xml");
            IMessageChannel     mainChannel    = (IMessageChannel)ctx.GetObject("rejecting");
            IPollableChannel    wireTapChannel = (IPollableChannel)ctx.GetObject("wireTapChannel");

            Assert.IsNull(wireTapChannel.Receive(TimeSpan.Zero));
            IMessage original = new StringMessage("test");

            mainChannel.Send(original);
            IMessage intercepted = wireTapChannel.Receive(TimeSpan.Zero);

            Assert.IsNull(intercepted);
        }
        public void simpleWireTap()
        {
            IApplicationContext ctx            = TestUtils.GetContext(@"Config\WireTapParserTests.xml");
            IMessageChannel     mainChannel    = (IMessageChannel)ctx.GetObject("noSelectors");
            IPollableChannel    wireTapChannel = (IPollableChannel)ctx.GetObject("wireTapChannel");

            Assert.IsNull(wireTapChannel.Receive(TimeSpan.Zero));
            IMessage original = new StringMessage("test");

            mainChannel.Send(original);
            IMessage intercepted = wireTapChannel.Receive(TimeSpan.Zero);

            Assert.IsNotNull(intercepted);
            Assert.That(intercepted, Is.EqualTo(original));
        }
Esempio n. 6
0
        public void GatewayWithConnectionFactoryAndDestinationName()
        {
            XmlApplicationContext ctx =
                (XmlApplicationContext)
                NmsTestUtils.GetContext(@"Nms\Config\NmsGatewayWithConnectionFactoryAndDestinationName.xml");
            IPollableChannel         channel = (IPollableChannel)ctx.GetObject("requestChannel");
            NmsMessageDrivenEndpoint gateway = (NmsMessageDrivenEndpoint)ctx.GetObject("nmsGateway");

            Assert.That(gateway.GetType(), Is.EqualTo(typeof(NmsMessageDrivenEndpoint)));
            ctx.Start();

            ThreadPerTaskExecutor executor = new ThreadPerTaskExecutor();

            executor.Execute(delegate
            {
                SimpleMessageListenerContainer listenerContainer =
                    (SimpleMessageListenerContainer)
                    ctx.GetObject("Spring.Messaging.Nms.Listener.SimpleMessageListenerContainer#0");
                ISessionAwareMessageListener messageListener =
                    (ISessionAwareMessageListener)listenerContainer.MessageListener;
                messageListener.OnMessage(new StubTextMessage("message-driven-test"),
                                          new StubSession("message-driven-test"));
            });

            IMessage message = channel.Receive(TimeSpan.FromMilliseconds(3000));

            Assert.That(message, Is.Not.Null);
            Assert.That(message.Payload, Is.EqualTo("message-driven-test"));
            ctx.Stop();
        }
        protected IMessage Receive(IPollableChannel channel, int additionalMultiplier)
        {
            var startTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
            var receive   = channel.Receive((int)(1000 * TimeoutMultiplier * additionalMultiplier));
            var elapsed   = DateTimeOffset.Now.ToUnixTimeMilliseconds() - startTime;

            return(receive);
        }
Esempio n. 8
0
        public void AdapterWithConnectionFactoryAndDestination()
        {
            IApplicationContext ctx     = NmsTestUtils.GetContext(@"Nms\Config\NmsInboundWithConnectionFactoryAndDestinationName.xml");
            IPollableChannel    output  = (IPollableChannel)ctx.GetObject("output");
            IMessage            message = output.Receive(timeoutOnReceive);

            Assert.That(message, Is.Not.Null);
            Assert.That(message.Payload, Is.EqualTo("polling-test"));
        }
        // TODO public void TestCheckedExceptionRethrownAsIs
        //[Test, ExpectedException(typeof(TestException))]
        //public void TestCheckedExceptionRethrownAsIs() {
        //    GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject();
        //    DirectChannel channel = new DirectChannel();
        //    EventDrivenConsumer consumer = new EventDrivenConsumer(channel, new MessageHandler() {
        //        public void handleMessage(Message<?> message) {
        //            MethodInfo method = ReflectionUtils.GetMethod(typeof(GatewayProxyFactoryObjectTests), "throwTestException",null);
        //            method.Invoke(this, null);
        //        }
        //    });
        //    consumer.start();
        //    proxyFactory.setDefaultRequestChannel(channel);
        //    proxyFactory.setServiceInterface(TestExceptionThrowingInterface.class);
        //    proxyFactory.afterPropertiesSet();
        //    TestExceptionThrowingInterface proxy = (TestExceptionThrowingInterface) proxyFactory.getObject();
        //    proxy.throwCheckedException("test");
        //}


        private static void StartResponder(IPollableChannel requestChannel)
        {
            new Thread(new ThreadStart(delegate
            {
                IMessage input      = requestChannel.Receive();
                StringMessage reply = new StringMessage(input.Payload + "bar");
                ((IMessageChannel)input.Headers.ReplyChannel).Send(reply);
            })).Start();
        }
Esempio n. 10
0
        public void CheckExceptionPlacedOnErrorChannel()
        {
            IApplicationContext context      = TestUtils.GetContext(@"Endpoint\pollingEndpointErrorHandlingTests.xml");
            IPollableChannel    errorChannel = (IPollableChannel)context.GetObject("errorChannel");
            IMessage            errorMessage = errorChannel.Receive(TimeSpan.FromMilliseconds(5000));

            Assert.IsNotNull(errorMessage, "No error message received");
            Assert.That(errorMessage.GetType(), Is.EqualTo(typeof(ErrorMessage)),
                        "Message received was not an ErrorMessage");
        }
        public void TestPriorityChannelWithDefaultComparator()
        {
            IApplicationContext ctx                 = TestUtils.GetContext(@"Channel\Config\PriorityChannelParserTests.xml");
            IPollableChannel    channel             = (IPollableChannel)ctx.GetObject("priorityChannelWithDefaultComparator");
            IMessage            lowPriorityMessage  = MessageBuilder.WithPayload("low").SetPriority(MessagePriority.LOW).Build();
            IMessage            midPriorityMessage  = MessageBuilder.WithPayload("mid").SetPriority(MessagePriority.NORMAL).Build();
            IMessage            highPriorityMessage = MessageBuilder.WithPayload("high").SetPriority(MessagePriority.HIGH).Build();

            channel.Send(lowPriorityMessage);
            channel.Send(highPriorityMessage);
            channel.Send(midPriorityMessage);
            IMessage reply1 = channel.Receive(TimeSpan.Zero);
            IMessage reply2 = channel.Receive(TimeSpan.Zero);
            IMessage reply3 = channel.Receive(TimeSpan.Zero);

            Assert.That(reply1.Payload, Is.EqualTo("high"));
            Assert.That(reply2.Payload, Is.EqualTo("mid"));
            Assert.That(reply3.Payload, Is.EqualTo("low"));
        }
        public void TestPriorityChannelWithCustomComparator()
        {
            IApplicationContext ctx     = TestUtils.GetContext(@"Channel\Config\PriorityChannelParserTests.xml");
            IPollableChannel    channel = (IPollableChannel)ctx.GetObject("priorityChannelWithCustomComparator");

            channel.Send(new StringMessage("C"));
            channel.Send(new StringMessage("A"));
            channel.Send(new StringMessage("D"));
            channel.Send(new StringMessage("B"));
            IMessage reply1 = channel.Receive(TimeSpan.Zero);
            IMessage reply2 = channel.Receive(TimeSpan.Zero);
            IMessage reply3 = channel.Receive(TimeSpan.Zero);
            IMessage reply4 = channel.Receive(TimeSpan.Zero);

            Assert.That(reply1.Payload, Is.EqualTo("A"));
            Assert.That(reply2.Payload, Is.EqualTo("B"));
            Assert.That(reply3.Payload, Is.EqualTo("C"));
            Assert.That(reply4.Payload, Is.EqualTo("D"));
        }
Esempio n. 13
0
        public void AdpaterWithDestinationAndDefaultConnectionFactory()
        {
            XmlApplicationContext ctx    = (XmlApplicationContext)NmsTestUtils.GetContext(@"Nms\Config\NmsInboundWithDestinationAndDefaultConnectionFactory.xml");
            IPollableChannel      output = (IPollableChannel)ctx.GetObject("output");
            IMessage message             = output.Receive(timeoutOnReceive);

            Assert.That(message, Is.Not.Null);
            Assert.That(message.Payload, Is.EqualTo("polling-test"));
            ctx.Stop();
        }
        public void TestChannelInteceptorInnerBean()
        {
            IApplicationContext ctx     = TestUtils.GetContext(@"Channel\Config\ChannelInterceptorParserTests.xml");
            IPollableChannel    channel = (IPollableChannel)ctx.GetObject("channelWithInterceptorInnerBean");

            channel.Send(new StringMessage("test"));
            IMessage transformed = channel.Receive(TimeSpan.FromMilliseconds(1000));

            Assert.That(transformed.Payload, Is.EqualTo("TEST"));
        }
Esempio n. 15
0
        public void AdapterWithHeaderMapper()
        {
            IApplicationContext ctx     = NmsTestUtils.GetContext(@"Nms\Config\NmsInboundWithHeaderMapper.xml");
            IPollableChannel    output  = (IPollableChannel)ctx.GetObject("output");
            IMessage            message = output.Receive(timeoutOnReceive);

            Assert.That(message, Is.Not.Null);
            Assert.That(message.Payload, Is.EqualTo("polling-test"));
            Assert.That(message.Headers["testProperty"], Is.EqualTo("foo"));
            Assert.That(message.Headers["testAttribute"], Is.EqualTo(123));
        }
Esempio n. 16
0
        public void filterWithSelectorAdapterRejects()
        {
            IApplicationContext ctx          = TestUtils.GetContext(@"Config\FilterParserTests-context.xml");
            IMessageChannel     adapterInput = (IMessageChannel)ctx.GetObject("adapterInput");

            adapterInput.Send(new StringMessage(""));
            IPollableChannel adapterOutput = (IPollableChannel)ctx.GetObject("adapterOutput");
            IMessage         reply         = adapterOutput.Receive(TimeSpan.Zero);

            Assert.IsNull(reply);
        }
Esempio n. 17
0
        protected override bool DoPoll()
        {
            IMessage message = _receiveTimeout.TotalMilliseconds >= 0 ? _inputChannel.Receive(_receiveTimeout) : _inputChannel.Receive();

            if (message == null)
            {
                return(false);
            }
            _handler.HandleMessage(message);
            return(true);
        }
Esempio n. 18
0
        public void exceptionThrowingFilterAccepts()
        {
            IApplicationContext ctx            = TestUtils.GetContext(@"Config\FilterParserTests-context.xml");
            IMessageChannel     exceptionInput = (IMessageChannel)ctx.GetObject("exceptionInput");

            exceptionInput.Send(new StringMessage("test"));
            IPollableChannel implementationOutput = (IPollableChannel)ctx.GetObject("implementationOutput");
            IMessage         reply = implementationOutput.Receive(TimeSpan.Zero);

            Assert.IsNotNull(reply);
        }
 private static void StartResponder(IPollableChannel requestChannel, IMessageChannel replyChannel)
 {
     Executors.NewSingleThreadExecutor().Execute(delegate
                                                     {
                                                         IMessage request = requestChannel.Receive();
                                                         IMessage reply =
                                                             MessageBuilder.FromMessage(request).SetCorrelationId
                                                                 (request.Headers.Id).Build();
                                                         replyChannel.Send(reply);
                                                     });
 }
Esempio n. 20
0
        public void TestOneWay()
        {
            IApplicationContext context = TestUtils.GetContext(@"Config\Xml\gatewayParserTests.xml");
            ITestService        service = (ITestService)context.GetObject("oneWay");

            service.OneWay("foo");
            IPollableChannel channel = (IPollableChannel)context.GetObject("requestChannel");
            IMessage         result  = channel.Receive(TimeSpan.FromMilliseconds(1000));

            Assert.That(result.Payload, Is.EqualTo("foo"));
        }
Esempio n. 21
0
 private static void StartResponder(IPollableChannel requestChannel, IMessageChannel replyChannel)
 {
     Executors.NewSingleThreadExecutor().Execute(delegate
     {
         IMessage request = requestChannel.Receive();
         IMessage reply   =
             MessageBuilder.FromMessage(request).SetCorrelationId
                 (request.Headers.Id).Build();
         replyChannel.Send(reply);
     });
 }
Esempio n. 22
0
        public void filterWithSelectorImplementationAccepts()
        {
            IApplicationContext ctx = TestUtils.GetContext(@"Config\FilterParserTests-context.xml");
            IMessageChannel     implementationInput = (IMessageChannel)ctx.GetObject("implementationInput");

            implementationInput.Send(new StringMessage("test"));
            IPollableChannel implementationOutput = (IPollableChannel)ctx.GetObject("implementationOutput");
            IMessage         reply = implementationOutput.Receive(TimeSpan.Zero);

            Assert.IsNotNull(reply);
            Assert.That(reply.Payload, Is.EqualTo("test"));
        }
        public void PollableChannel()
        {
            IApplicationContext context         = TestUtils.GetContext(@"Config\Xml\BridgeParserTests-context.xml");
            IMessage            message         = new StringMessage("test1");
            IPollableChannel    pollableChannel = (IPollableChannel)context.GetObject("pollableChannel");

            pollableChannel.Send(message);
            IPollableChannel output1 = (IPollableChannel)context.GetObject("output1");
            IMessage         reply   = output1.Receive(TimeSpan.FromMilliseconds(1000));

            Assert.That(reply, Is.EqualTo(message));
        }
        public void SubscribableChannel()
        {
            IApplicationContext context             = TestUtils.GetContext(@"Config\Xml\BridgeParserTests-context.xml");
            IMessage            message             = new StringMessage("test2");
            IMessageChannel     subscribableChannel = (IMessageChannel)context.GetObject("subscribableChannel");

            subscribableChannel.Send(message);
            IPollableChannel output2 = (IPollableChannel)context.GetObject("output2");
            IMessage         reply   = output2.Receive(TimeSpan.Zero);

            Assert.That(reply, Is.EqualTo(message));
        }
        private IMessage DoReceive(IPollableChannel channel)
        {
            AssertUtils.ArgumentNotNull(channel, "channel", "channel must not be null");
            TimeSpan timeout = _receiveTimeout;
            IMessage message = (timeout.TotalMilliseconds >= 0) ? channel.Receive(timeout) : channel.Receive();

            if (message == null && _logger.IsTraceEnabled)
            {
                _logger.Trace("failed to receive message from channel '" + channel + "' within timeout: " + timeout);
            }
            return(message);
        }
        public void QueueChannelWithStringMessage()
        {
            IApplicationContext context =
                TestUtils.GetContext(@"Config\Xml\ObjectToStringTransformerParserTests-context.xml");
            IMessageChannel queueInput = (IMessageChannel)context.GetObject("queueInput");

            queueInput.Send(new StringMessage("foo"));
            IPollableChannel output = (IPollableChannel)context.GetObject("output");
            IMessage         result = output.Receive(TimeSpan.FromMilliseconds(3000));

            Assert.IsNotNull(result);
            Assert.That(result.Payload, Is.EqualTo("foo"));
        }
        public void DirectChannelWithObjectMessage()
        {
            IApplicationContext context =
                TestUtils.GetContext(@"Config\Xml\ObjectToStringTransformerParserTests-context.xml");
            IMessageChannel directInput = (IMessageChannel)context.GetObject("directInput");

            directInput.Send(new Message <TestBean>(new TestBean()));
            IPollableChannel output = (IPollableChannel)context.GetObject("output");
            IMessage         result = output.Receive(TimeSpan.Zero);

            Assert.IsNotNull(result);
            Assert.That(result.Payload, Is.EqualTo("test"));
        }
        public void chainWithRejectingFilter()
        {
            IApplicationContext ctx         = TestUtils.GetContext(@"Config\ChainParserTests-context.xml");
            IMessage            message     = MessageBuilder.WithPayload(123).Build();
            IMessageChannel     filterInput = (IMessageChannel)ctx.GetObject("filterInput");

            filterInput.Send(message);

            IPollableChannel output = (IPollableChannel)ctx.GetObject("output");
            IMessage         reply  = output.Receive(TimeSpan.Zero);

            Assert.IsNull(reply);
        }
        public void TestChannelInteceptorRef()
        {
            IApplicationContext    ctx         = TestUtils.GetContext(@"Channel\Config\ChannelInterceptorParserTests.xml");
            IPollableChannel       channel     = (IPollableChannel)ctx.GetObject("channelWithInterceptorRef");
            TestChannelInterceptor interceptor = (TestChannelInterceptor)ctx.GetObject("interceptor");

            Assert.That(interceptor.SendCount, Is.EqualTo(0));
            channel.Send(new StringMessage("test"));
            Assert.That(interceptor.SendCount, Is.EqualTo(1));
            Assert.That(interceptor.ReceiveCount, Is.EqualTo(0));
            channel.Receive();
            Assert.That(interceptor.ReceiveCount, Is.EqualTo(1));
        }
        public void chainWithPollableInput()
        {
            IApplicationContext ctx     = TestUtils.GetContext(@"Config\ChainParserTests-context.xml");
            IMessage            message = MessageBuilder.WithPayload("test").Build();

            IMessageChannel pollableInput = (IMessageChannel)ctx.GetObject("pollableInput");

            pollableInput.Send(message);
            IPollableChannel output = (IPollableChannel)ctx.GetObject("output");
            IMessage         reply  = output.Receive(TimeSpan.FromMilliseconds(3000));

            Assert.IsNotNull(reply);
            Assert.That(reply.Payload, Is.EqualTo("foo"));
        }
        static void Main(string[] args)
        {
            NamespaceParserRegistry.RegisterParser(typeof(IntegrationNamespaceParser));

            IApplicationContext ctx = new XmlApplicationContext("HelloWorld.xml");

            IChannelResolver channelResolver = new ObjectFactoryChannelResolver(ctx);
            IMessageChannel  inputChannel    = channelResolver.ResolveChannelName("inputChannel");
            IPollableChannel outputChannel   = (IPollableChannel)channelResolver.ResolveChannelName("outputChannel");

            inputChannel.Send(new StringMessage("World"));
            Console.WriteLine(outputChannel.Receive(TimeSpan.Zero).Payload);
            Console.ReadKey();
        }
 // TODO public void TestCheckedExceptionRethrownAsIs
 //[Test, ExpectedException(typeof(TestException))]
 //public void TestCheckedExceptionRethrownAsIs() {
 //    GatewayProxyFactoryObject proxyFactory = new GatewayProxyFactoryObject();
 //    DirectChannel channel = new DirectChannel();
 //    EventDrivenConsumer consumer = new EventDrivenConsumer(channel, new MessageHandler() {
 //        public void handleMessage(Message<?> message) {
 //            MethodInfo method = ReflectionUtils.GetMethod(typeof(GatewayProxyFactoryObjectTests), "throwTestException",null);
 //            method.Invoke(this, null);
 //        }
 //    });
 //    consumer.start();
 //    proxyFactory.setDefaultRequestChannel(channel);
 //    proxyFactory.setServiceInterface(TestExceptionThrowingInterface.class);
 //    proxyFactory.afterPropertiesSet();
 //    TestExceptionThrowingInterface proxy = (TestExceptionThrowingInterface) proxyFactory.getObject();
 //    proxy.throwCheckedException("test");
 //}
 private static void StartResponder(IPollableChannel requestChannel)
 {
     new Thread(new ThreadStart(delegate
                                    {
                                        IMessage input = requestChannel.Receive();
                                        StringMessage reply = new StringMessage(input.Payload + "bar");
                                        ((IMessageChannel) input.Headers.ReplyChannel).Send(reply);
                                    })).Start();
 }