summaryrefslogtreecommitdiff
path: root/qpid/java/client/src/test/java/org/apache/qpid/client/BasicMessageConsumer_0_8_Test.java
blob: 722cbd07524124a71a0f993eb187dd2918a9c781 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */
package org.apache.qpid.client;

import junit.framework.TestCase;

import org.apache.qpid.test.unit.message.TestAMQSession;
import org.apache.qpid.url.AMQBindingURL;

import javax.jms.Session;

public class BasicMessageConsumer_0_8_Test extends TestCase
{
    /**
     * Test that if there is a value for Reject Behaviour specified for the Destination
     * used to create the Consumer, it overrides the value for the Connection.
     */
    public void testDestinationRejectBehaviourOverridesDefaultConnection() throws Exception
    {
        /*
         * Check that when the connection does not have a value applied that this
         * is successfully overridden with a specific value by the consumer.
         */
        String connUrlString = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'";
        AMQConnection conn = new MockAMQConnection(connUrlString);

        String url = "exchangeClass://exchangeName/Destination/Queue?rejectbehaviour='server'";
        AMQBindingURL burl = new AMQBindingURL(url);
        AMQDestination queue = new AMQQueue(burl);

        TestAMQSession testSession = new TestAMQSession(conn);
        BasicMessageConsumer_0_8 consumer =
                new BasicMessageConsumer_0_8(0, conn, queue, "", false, null, testSession, null, null, 10, 5, false, Session.SESSION_TRANSACTED, false, false);

        assertEquals("Reject behaviour was was not as expected", RejectBehaviour.SERVER, consumer.getRejectBehaviour());
    }

    /**
     * Check that when the connection does have a specific value applied that this
     * is successfully overridden with another specific value by the consumer.
     */
    public void testDestinationRejectBehaviourSpecified() throws Exception
    {
        final String connUrlString = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&rejectbehaviour='server'";
        final AMQConnection conn = new MockAMQConnection(connUrlString);

        final String url = "exchangeClass://exchangeName/Destination/Queue?rejectbehaviour='normal'";
        final AMQBindingURL burl = new AMQBindingURL(url);
        final AMQDestination queue = new AMQQueue(burl);

        final TestAMQSession testSession = new TestAMQSession(conn);
        final BasicMessageConsumer_0_8 consumer =
                new BasicMessageConsumer_0_8(0, conn, queue, "", false, null, testSession, null, null, 10, 5, false, Session.SESSION_TRANSACTED, false, false);

        assertEquals("Reject behaviour was was not as expected", RejectBehaviour.NORMAL, consumer.getRejectBehaviour());
    }

    /**
     * Test that if no value for Reject Behaviour is applied to the Destination, then the value
     * from the connection is used and acts as expected.
     */
    public void testRejectBehaviourDetectedFromConnection() throws Exception
    {
        /*
         * Check that when the connection does have a specific value applied that this
         * is successfully detected by the consumer.
         */
        String connUrlString = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&rejectbehaviour='normal'";
        AMQConnection conn = new MockAMQConnection(connUrlString);

        String url = "exchangeClass://exchangeName/Destination/Queue";
        AMQBindingURL burl = new AMQBindingURL(url);
        AMQDestination queue = new AMQQueue(burl);

        assertNull("Reject behaviour should have been null", queue.getRejectBehaviour());

        TestAMQSession testSession = new TestAMQSession(conn);
        BasicMessageConsumer_0_8 consumer =
                new BasicMessageConsumer_0_8(0, conn, queue, "", false, null, testSession, null, null, 10, 5, false, Session.SESSION_TRANSACTED, false, false);

        assertEquals("Reject behaviour was was not as expected", RejectBehaviour.NORMAL, consumer.getRejectBehaviour());
    }


    protected RejectBehaviour getRejectBehaviour(AMQDestination destination)
    {
        return destination.getRejectBehaviour();
    }
}