public void testSingleSelectorAccepts()
 {
     AtomicInteger counter = new AtomicInteger();
     IMessageSelector selector = new TestMessageSelector(true, counter);
     MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector);
     QueueChannel channel = new QueueChannel();
     channel.AddInterceptor(interceptor);
     Assert.That(channel.Send(new StringMessage("test1")), Is.True);
 }
        public void TestPostSendInterceptorWithSentMessage()
        {
            QueueChannel channel = new QueueChannel();
            AtomicBoolean invoked = new AtomicBoolean(false);

            channel.AddInterceptor(new TestPostSendInterceptorWithSentMessageInterceptor(invoked, channel));

            channel.Send(new StringMessage("test"));
            Assert.IsTrue(invoked.Value);
        }
 public void testMultipleSelectorsAccept()
 {
     AtomicInteger counter = new AtomicInteger();
     IMessageSelector selector1 = new TestMessageSelector(true, counter);
     IMessageSelector selector2 = new TestMessageSelector(true, counter);
     MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector1, selector2);
     QueueChannel channel = new QueueChannel();
     channel.AddInterceptor(interceptor);
     Assert.That(channel.Send(new StringMessage("test1")), Is.True);
     Assert.That(counter.Value, Is.EqualTo(2));
 }
 public void WireTapWithAcceptingSelector()
 {
     QueueChannel mainChannel = new QueueChannel();
     QueueChannel secondaryChannel = new QueueChannel();
     mainChannel.AddInterceptor(new WireTap(secondaryChannel, new TestSelector(true)));
     mainChannel.Send(new StringMessage("testing"));
     IMessage original = mainChannel.Receive(TimeSpan.Zero);
     Assert.IsNotNull(original);
     IMessage intercepted = secondaryChannel.Receive(TimeSpan.Zero);
     Assert.IsNotNull(intercepted);
     Assert.That(original, Is.EqualTo(intercepted));
 }
 public void SimpleTargetWireTap()
 {
     QueueChannel mainChannel = new QueueChannel();
     QueueChannel secondaryChannel = new QueueChannel();
     mainChannel.AddInterceptor(new WireTap(secondaryChannel));
     Assert.IsNull(secondaryChannel.Receive(TimeSpan.Zero));
     mainChannel.Send(new StringMessage("testing"));
     IMessage original = mainChannel.Receive(TimeSpan.Zero);
     Assert.IsNotNull(original);
     IMessage intercepted = secondaryChannel.Receive(TimeSpan.Zero);
     Assert.IsNotNull(intercepted);
     Assert.That(original, Is.EqualTo(intercepted));
 }
 public void TestPostReceiveInterceptor()
 {
     AtomicInteger invokedCount = new AtomicInteger();
     AtomicInteger messageCount = new AtomicInteger();
     QueueChannel channel = new QueueChannel();
     channel.AddInterceptor(new TestPostReceiveInterceptorInterceptor(invokedCount, messageCount, channel));
     channel.Receive(TimeSpan.Zero);
     Assert.That(invokedCount.Value, Is.EqualTo(1));
     Assert.That(messageCount.Value, Is.EqualTo(0));
     channel.Send(new StringMessage("test"));
     IMessage result = channel.Receive(TimeSpan.Zero);
     Assert.IsNotNull(result);
     Assert.That(invokedCount.Value, Is.EqualTo(2));
     Assert.That(messageCount.Value, Is.EqualTo(1));
 }
 public void InterceptedMessageContainsHeaderValue()
 {
     QueueChannel mainChannel = new QueueChannel();
     QueueChannel secondaryChannel = new QueueChannel();
     mainChannel.AddInterceptor(new WireTap(secondaryChannel));
     string headerName = "testAttribute";
     IMessage message = MessageBuilder.WithPayload("testing").SetHeader(headerName, 123).Build();
     mainChannel.Send(message);
     IMessage original = mainChannel.Receive(TimeSpan.Zero);
     IMessage intercepted = secondaryChannel.Receive(TimeSpan.Zero);
     object originalAttribute = original.Headers.Get(headerName);
     object interceptedAttribute = intercepted.Headers.Get(headerName);
     Assert.IsNotNull(originalAttribute);
     Assert.IsNotNull(interceptedAttribute);
     Assert.That(original, Is.EqualTo(intercepted));
 }
 public void TestPostSendInterceptorWithUnsentMessage()
 {
     AtomicInteger invokedCounter = new AtomicInteger(0);
     AtomicInteger sentCounter = new AtomicInteger(0);
     QueueChannel singleItemChannel = new QueueChannel(1);
     singleItemChannel.AddInterceptor(new TestPostSendInterceptorWithUnsentMessageInterceptor(invokedCounter,
                                                                                              sentCounter,
                                                                                              singleItemChannel));
     Assert.That(invokedCounter.Value, Is.EqualTo(0));
     Assert.That(sentCounter.Value, Is.EqualTo(0));
     singleItemChannel.Send(new StringMessage("test1"));
     Assert.That(invokedCounter.Value, Is.EqualTo(1));
     Assert.That(sentCounter.Value, Is.EqualTo(1));
     singleItemChannel.Send(new StringMessage("test2"), TimeSpan.Zero);
     Assert.That(invokedCounter.Value, Is.EqualTo(2));
     Assert.That(sentCounter.Value, Is.EqualTo(1));
 }
 public void testMultipleSelectorsReject()
 {
     bool exceptionThrown = false;
     AtomicInteger counter = new AtomicInteger();
     IMessageSelector selector1 = new TestMessageSelector(true, counter);
     IMessageSelector selector2 = new TestMessageSelector(false, counter);
     IMessageSelector selector3 = new TestMessageSelector(false, counter);
     IMessageSelector selector4 = new TestMessageSelector(true, counter);
     MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector1, selector2, selector3,
                                                                               selector4);
     QueueChannel channel = new QueueChannel();
     channel.AddInterceptor(interceptor);
     try
     {
         channel.Send(new StringMessage("test1"));
     }
     catch (MessageDeliveryException)
     {
         exceptionThrown = true;
     }
     Assert.That(exceptionThrown, Is.True);
     Assert.That(counter.Value, Is.EqualTo(2));
 }
 public void testSingleSelectorRejects()
 {
     AtomicInteger counter = new AtomicInteger();
     IMessageSelector selector = new TestMessageSelector(false, counter);
     MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector);
     QueueChannel channel = new QueueChannel();
     channel.AddInterceptor(interceptor);
     channel.Send(new StringMessage("test1"));
 }
 public void TestPreReceiveInterceptorReturnsFalse()
 {
     QueueChannel channel = new QueueChannel();
     channel.AddInterceptor(new PreReceiveReturnsFalseInterceptor());
     IMessage message = new StringMessage("test");
     channel.Send(message);
     IMessage result = channel.Receive(TimeSpan.Zero);
     Assert.That(PreReceiveReturnsFalseInterceptor.counter.Value, Is.EqualTo(1));
     Assert.IsNull(result);
 }
 public void TestPreSendInterceptorReturnsNull()
 {
     QueueChannel channel = new QueueChannel();
     PreSendReturnsNullInterceptor interceptor = new PreSendReturnsNullInterceptor();
     channel.AddInterceptor(interceptor);
     IMessage message = new StringMessage("test");
     channel.Send(message);
     Assert.That(interceptor.Count, Is.EqualTo(1));
     IMessage result = channel.Receive(TimeSpan.Zero);
     Assert.IsNull(result);
 }
        public void TestPreSendInterceptorReturnsMessage()
        {
            QueueChannel channel = new QueueChannel();

            channel.AddInterceptor(new PreSendReturnsMessageInterceptor());
            channel.Send(new StringMessage("test"));
            IMessage result = channel.Receive(TimeSpan.Zero);
            Assert.IsNotNull(result);
            Assert.That("test", Is.EqualTo(result.Payload));
            Assert.That(result.Headers.Get(typeof (PreSendReturnsMessageInterceptor).Name), Is.EqualTo(1));
        }