Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/io/util/ByteArrayFragmentationTest.java


1   /*
2    * Created on Jan 14, 2005
3    *
4    * To change the template for this generated file go to
5    * Window - Preferences - Java - Code Generation - Code and Comments
6    */
7   package org.activemq.io.util;
8   
9   
10  import junit.framework.TestCase;
11  
12  /**
13   *
14   * ByteArrayFragmentationTest
15   */
16  public class ByteArrayFragmentationTest extends TestCase {
17      static final int DATA_SIZE = 32 * 1024;
18      byte[] testData;
19      String testString = "";
20      /*
21       * @see TestCase#setUp()
22       */
23      protected void setUp() throws Exception {
24          super.setUp();
25          testString = "";
26          for (int i = 0; testString.length() < DATA_SIZE; i++ ){
27              testString += "abcdefg";
28          }
29          testData = testString.getBytes();
30      }
31  
32      /*
33       * @see TestCase#tearDown()
34       */
35      protected void tearDown() throws Exception {
36          super.tearDown();
37      }
38  
39      /**
40       * Constructor for ByteArrayFragmentationTest.
41       * @param arg0
42       */
43      public ByteArrayFragmentationTest(String arg0) {
44          super(arg0);
45      }
46  
47      public void testDoFragmentation() {
48          ByteArray ba = new ByteArray(testData);
49          ByteArrayFragmentation test = new ByteArrayFragmentation();
50          test.setFragmentationLimit(DATA_SIZE/3);
51          
52          assertTrue(test.doFragmentation(ba));
53          ByteArray[] fragments = test.fragment(ba);
54          assertTrue(fragments.length > 1);
55          ByteArray assembled = test.assemble(fragments);
56          assertTrue(isSame(ba,assembled));
57      }
58      
59      protected boolean isSame (ByteArray b1, ByteArray b2){
60          boolean result = b1.getLength() == b2.getLength();
61          for (int i =0;i < b1.getLength(); i++){
62              result &= b1.get(i) == b2.get(i);
63          }
64          return result;
65      }
66  }