Debian Codegraph @

proton-j/src/test/java/org/apache/qpid/proton/engine/impl/EventImplTest.java

raw
1 /*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21 package org.apache.qpid.proton.engine.impl;
22
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertSame;
25
26 import org.apache.qpid.proton.engine.Connection;
27 import org.apache.qpid.proton.engine.Delivery;
28 import org.apache.qpid.proton.engine.Event;
29 import org.apache.qpid.proton.engine.EventType;
30 import org.apache.qpid.proton.engine.Link;
31 import org.apache.qpid.proton.engine.Sender;
32 import org.apache.qpid.proton.engine.Session;
33 import org.apache.qpid.proton.engine.Transport;
34 import org.junit.Test;
35
36 public class EventImplTest
37 {
38 @Test
39 public void testGetTransportWithConnectionContext()
40 {
41 Transport transport = Transport.Factory.create();
42 Connection connection = Connection.Factory.create();
43 transport.bind(connection);
44
45 EventImpl event = createEvent(connection, Event.Type.CONNECTION_BOUND);
46
47 assertNotNull("No transport returned", event.getTransport());
48 assertSame("Incorrect transport returned", transport, event.getTransport());
49 }
50
51 @Test
52 public void testGetTransportWithTransportContext()
53 {
54 Transport transport = Transport.Factory.create();
55 Connection connection = Connection.Factory.create();
56 transport.bind(connection);
57
58 EventImpl event = createEvent(transport, Event.Type.TRANSPORT);
59
60 assertNotNull("No transport returned", event.getTransport());
61 assertSame("Incorrect transport returned", transport, event.getTransport());
62 }
63
64 @Test
65 public void testGetTransportWithSessionContext()
66 {
67 Transport transport = Transport.Factory.create();
68 Connection connection = Connection.Factory.create();
69 transport.bind(connection);
70
71 Session session = connection.session();
72
73 EventImpl event = createEvent(session, Event.Type.SESSION_INIT);
74
75 assertNotNull("No transport returned", event.getTransport());
76 assertSame("Incorrect transport returned", transport, event.getTransport());
77 }
78
79 @Test
80 public void testGetTransportWithLinkContext()
81 {
82 Transport transport = Transport.Factory.create();
83 Connection connection = Connection.Factory.create();
84 transport.bind(connection);
85
86 Session session = connection.session();
87 Link link = session.receiver("myReceiver");
88
89 EventImpl event = createEvent(link, Event.Type.LINK_INIT);
90
91 assertNotNull("No transport returned", event.getTransport());
92 assertSame("Incorrect transport returned", transport, event.getTransport());
93 }
94
95 @Test
96 public void testGetTransportWithDeliveryContext()
97 {
98 Transport transport = Transport.Factory.create();
99 Connection connection = Connection.Factory.create();
100 transport.bind(connection);
101
102 Session session = connection.session();
103 Sender sender = session.sender("mySender");
104
105 Delivery delivery = sender.delivery("tag".getBytes());
106
107 EventImpl event = createEvent(delivery, Event.Type.DELIVERY);
108
109 assertNotNull("No transport returned", event.getTransport());
110 assertSame("Incorrect transport returned", transport, event.getTransport());
111 }
112
113 EventImpl createEvent(Object context, EventType type)
114 {
115 EventImpl event = new EventImpl();
116 event.init(type, context);
117 return event;
118 }
119 }