1 /*** 2 * Redistribution and use of this software and associated documentation 3 * ("Software"), with or without modification, are permitted provided 4 * that the following conditions are met: 5 * 6 * 1. Redistributions of source code must retain copyright 7 * statements and notices. Redistributions must also contain a 8 * copy of this document. 9 * 10 * 2. Redistributions in binary form must reproduce the 11 * above copyright notice, this list of conditions and the 12 * following disclaimer in the documentation and/or other 13 * materials provided with the distribution. 14 * 15 * 3. The name "Exolab" must not be used to endorse or promote 16 * products derived from this Software without prior written 17 * permission of Exoffice Technologies. For written permission, 18 * please contact info@exolab.org. 19 * 20 * 4. Products derived from this Software may not be called "Exolab" 21 * nor may "Exolab" appear in their names without prior written 22 * permission of Exoffice Technologies. Exolab is a registered 23 * trademark of Exoffice Technologies. 24 * 25 * 5. Due credit should be given to the Exolab Project 26 * (http://www.exolab.org/). 27 * 28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 39 * OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Copyright 2001 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * 44 * $Id: TestExternalXid.java,v 1.1 2003/02/06 13:42:47 tanderson Exp $ 45 * 46 * Date Author Changes 47 * 2003-02-04 Jem Initial Version 48 */ 49 package org.exolab.jms.tranlog; 50 51 import junit.framework.*; 52 53 import java.io.ByteArrayInputStream; 54 import java.io.ByteArrayOutputStream; 55 import java.io.Externalizable; 56 import java.io.ObjectInputStream; 57 import java.io.ObjectOutputStream; 58 59 import javax.transaction.xa.Xid; 60 61 62 63 /*** 64 * 65 * Basic Unit Test - needs loads more functionality :-) 66 */ 67 68 public class TestExternalXid extends TestCase 69 { 70 71 private static final int format = 8; 72 private static final byte[] global = {'1','2','3','4','5','6'}; 73 private static final byte[] branch = {'a','b','c' }; 74 75 public TestExternalXid(String s) 76 { 77 super(s); 78 } 79 80 protected void setUp() 81 { 82 } 83 84 protected void tearDown() 85 { 86 } 87 88 public void testEquals() 89 { 90 91 ExternalXid x1 = new ExternalXid(format, global, branch); 92 ExternalXid x2; 93 94 // Test Equals self 95 96 assertTrue("Failed self-equality", x1.equals(x1)); 97 98 // Test content equality 99 100 x2 = new ExternalXid(format, global, branch); 101 assertTrue("Failed Content Equality", x1.equals(x2)); 102 103 // Copy Construct 104 105 x2 = new ExternalXid(x1); 106 assertTrue("Failed Copy Construct Equality", x1.equals(x2)); 107 } 108 109 public void testExternalization() { 110 111 try { 112 113 ObjectInputStream oIn; 114 ObjectOutputStream oOut; 115 ByteArrayOutputStream baos = null; 116 ByteArrayInputStream bais = null; 117 118 // Build an instance 119 Externalizable x1 = new ExternalXid(format, global, branch); 120 121 // Externalize it 122 baos = new ByteArrayOutputStream(); 123 oOut = new ObjectOutputStream(baos); 124 125 x1.writeExternal(oOut); 126 oOut.close(); 127 128 // Read it back 129 bais = new ByteArrayInputStream(baos.toByteArray()); 130 oIn = new ObjectInputStream(bais); 131 132 Externalizable x2 = new ExternalXid(); 133 x2.readExternal(oIn); 134 135 // Equality check 136 assertEquals("Not equal() after externalization", x1, x2); 137 138 } 139 catch (Throwable t) { 140 fail(t.getMessage()); 141 } 142 } 143 144 /*** 145 * Test for equality of Strings and hashCodes 146 * 147 */ 148 public void testOtherEquality() { 149 150 Xid x1 = new ExternalXid(format, global, branch); 151 Xid x2 = new ExternalXid(format, global, branch); 152 153 int hash1, hash2; 154 155 hash1 = x1.hashCode(); 156 hash2 = x2.hashCode(); 157 158 assertEquals("Hashcode mismatch", hash1, hash2); 159 160 String s1, s2; 161 162 s1 = x1.toString(); 163 s2 = x2.toString(); 164 165 assertEquals("toString() mismatch", s1, s2); 166 } 167 }

This page was automatically generated by Maven