KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > udp > UdpTransportUsingServerTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.transport.udp;
19
20 import org.apache.activemq.command.ConsumerInfo;
21 import org.apache.activemq.command.Response;
22 import org.apache.activemq.transport.Transport;
23 import org.apache.activemq.transport.TransportFactory;
24 import org.apache.activemq.transport.TransportServer;
25
26 import java.net.URI JavaDoc;
27
28 /**
29  *
30  * @version $Revision: 464110 $
31  */

32 public class UdpTransportUsingServerTest extends UdpTestSupport {
33
34     protected int consumerPort = 9123;
35     protected String JavaDoc producerURI = "udp://localhost:" + consumerPort;
36     protected String JavaDoc serverURI = producerURI;
37
38     public void testRequestResponse() throws Exception JavaDoc {
39         ConsumerInfo expected = new ConsumerInfo();
40         expected.setSelector("Edam");
41         expected.setResponseRequired(true);
42         log.info("About to send: " + expected);
43         Response response = (Response) producer.request(expected, 2000);
44
45         log.info("Received: " + response);
46         assertNotNull("Received a response", response);
47         assertTrue("Should not be an exception", !response.isException());
48     }
49
50     protected Transport createProducer() throws Exception JavaDoc {
51         log.info("Producer using URI: " + producerURI);
52         URI JavaDoc uri = new URI JavaDoc(producerURI);
53         return TransportFactory.connect(uri);
54     }
55
56     protected TransportServer createServer() throws Exception JavaDoc {
57         return TransportFactory.bind("byBroker", new URI JavaDoc(serverURI));
58     }
59
60     protected Transport createConsumer() throws Exception JavaDoc {
61         return null;
62     }
63 }
64
Popular Tags