KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > MarshallingBrokerTest


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.broker;
19
20 import java.io.IOException JavaDoc;
21
22 import junit.framework.Test;
23
24 import org.apache.activemq.command.Command;
25 import org.apache.activemq.command.Response;
26 import org.apache.activemq.openwire.OpenWireFormat;
27 import org.apache.activemq.wireformat.WireFormat;
28
29 /**
30  * Runs against the broker but marshals all request and response commands.
31  *
32  * @version $Revision$
33  */

34 public class MarshallingBrokerTest extends BrokerTest {
35
36     public WireFormat wireFormat = new OpenWireFormat();
37     
38     public void initCombos() {
39         
40         OpenWireFormat wf1 = new OpenWireFormat();
41         wf1.setCacheEnabled(false);
42         OpenWireFormat wf2 = new OpenWireFormat();
43         wf2.setCacheEnabled(true);
44         
45         addCombinationValues( "wireFormat", new Object JavaDoc[]{
46                 wf1,
47                 wf2,
48                 });
49     }
50     
51     protected StubConnection createConnection() throws Exception JavaDoc {
52         return new StubConnection(broker) {
53             public Response request(Command command) throws Exception JavaDoc {
54                 Response r = super.request((Command) wireFormat.unmarshal(wireFormat.marshal(command)));
55                 if( r != null ) {
56                     r = (Response) wireFormat.unmarshal(wireFormat.marshal(r));
57                 }
58                 return r;
59             }
60             public void send(Command command) throws Exception JavaDoc {
61                 super.send((Command) wireFormat.unmarshal(wireFormat.marshal(command)));
62             }
63             protected void dispatch(Command command) throws InterruptedException JavaDoc, IOException JavaDoc {
64                 super.dispatch((Command) wireFormat.unmarshal(wireFormat.marshal(command)));
65             };
66         };
67     }
68     public static Test suite() {
69         return suite(MarshallingBrokerTest.class);
70     }
71     
72     public static void main(String JavaDoc[] args) {
73         junit.textui.TestRunner.run(suite());
74     }
75     
76
77 }
78
Popular Tags