1 /*** 2 * 3 * Copyright 2004 Protique Ltd 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 **/ 18 package org.codehaus.activemq.message; 19 20 import junit.framework.TestCase; 21 22 import java.io.*; 23 24 /*** 25 * @version $Revision: 1.1 $ 26 */ 27 public class PackageFacadeTest extends TestCase { 28 29 public static void main(String[] args) { 30 junit.textui.TestRunner.run(PackageFacadeTest.class); 31 } 32 33 public void testTransactionInfo() throws Exception { 34 35 TransactionInfo info = new TransactionInfo(); 36 info.setId("SomeID"); 37 38 TransactionInfo info2 = (TransactionInfo) writeAndReadPacket(info); 39 40 assertEquals("id", info.getId(), info2.getId()); 41 } 42 43 public void testProducerInfo() throws Exception { 44 45 ProducerInfo info = new ProducerInfo(); 46 info.setId("SomeID"); 47 info.setClientId("SomeClientID"); 48 49 ProducerInfo info2 = (ProducerInfo) writeAndReadPacket(info); 50 51 assertEquals("id", info.getId(), info2.getId()); 52 assertEquals("clientID", info.getClientId(), info2.getClientId()); 53 54 } 55 56 protected Packet writeAndReadPacket(Packet info) throws IOException, ClassNotFoundException { 57 ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 58 ObjectOutputStream out = new ObjectOutputStream(buffer); 59 out.writeObject(new PacketFacade(info)); 60 out.close(); 61 62 byte[] bytes = buffer.toByteArray(); 63 ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes)); 64 Object value = in.readObject(); 65 in.close(); 66 67 assertTrue("value is PacketFacade: " + value, value instanceof PacketFacade); 68 PacketFacade facade = (PacketFacade) value; 69 70 Packet packet = facade.getPacket(); 71 assertTrue("Should have a non-null packet: " + packet, packet != null); 72 return packet; 73 } 74 75 }