1 23 24 package org.objectweb.jorm.mapper.rdb.lib; 25 26 import junit.framework.TestCase; 27 28 import java.io.InputStream ; 29 import java.io.ObjectInputStream ; 30 import java.sql.Blob ; 31 32 36 public abstract class TestRdbBlob extends TestCase { 37 38 public TestRdbBlob(String testName) { 39 super(testName); 40 } 41 42 protected Blob blob = null; 43 44 protected BlobVerifier verifier = null; 45 46 protected abstract void setUp(); 47 48 protected abstract void tearDown(); 49 50 public void testGetBytes() { 52 try { 53 assertTrue("blob.length", verifier.isSize(blob.length())); 54 byte[] data = blob.getBytes(0, (int) blob.length()); 55 for (int i = 0; i < data.length; i++) { 56 println("data[" + i + "]=" + data[i]); 57 assertTrue("invalid value at " + i + " position", 58 verifier.valid(data[i], i)); 59 } 60 } 61 catch (Exception e) { 62 fail(e.getMessage()); 63 64 } 65 } 66 67 public void testRead() { 68 try { 69 InputStream is = blob.getBinaryStream(); 71 assertTrue("blob.getBinaryStream() is null", is != null); 72 for (long i = 0; i < blob.length(); i++) { 73 byte aByte = (byte) is.read(); 74 println("read [" + i + "]=" + aByte); 75 assertTrue("invalid value at " + i + " position", 76 verifier.valid(aByte, i)); 77 } 78 } 79 catch (Exception e) { 80 fail(e.getMessage()); 81 } 82 } 83 84 public void testSkip() { 86 try { 87 InputStream is = blob.getBinaryStream(); 88 assertTrue("blob.getBinaryStream() is null", is != null); 89 is.skip(blob.length() / 3); 90 for (long i = blob.length() / 3; i < blob.length(); i++) { 91 byte aByte = (byte) is.read(); 92 println("sk+read [" + i + "]=" + aByte); 93 assertTrue("invalid value at the position " + i, 94 verifier.valid(aByte, i)); 95 } 96 } 97 catch (Exception e) { 98 fail(e.getMessage()); 99 } 100 } 101 102 public void testRebuildObject() { 104 try { 105 ObjectInputStream ois = 106 new ObjectInputStream (blob.getBinaryStream()); 107 assertTrue("ObjectInputStream is null", ois != null); 108 Object o = ois.readObject(); 109 assertTrue("Deserialized object does not match", 110 verifier.isEquals(o)); 111 } 112 catch (Exception e) { 113 fail(e.getMessage()); 114 } 115 } 116 117 private void println(String msg) { 118 } 120 } 121 | Popular Tags |