1 15 package org.apache.tapestry.junit.mock.c19; 16 17 import java.io.FileInputStream ; 18 import java.io.IOException ; 19 import java.io.InputStream ; 20 21 import org.apache.hivemind.ApplicationRuntimeException; 22 import org.apache.tapestry.Tapestry; 23 import org.apache.tapestry.html.BasePage; 24 import org.apache.tapestry.junit.mock.TestMocks; 25 import org.apache.tapestry.request.IUploadFile; 26 27 33 34 public abstract class Two extends BasePage 35 { 36 public abstract IUploadFile getFile(); 37 38 public abstract void setFile(IUploadFile file); 39 40 public boolean getUploadMatch() 41 { 42 IUploadFile file = getFile(); 43 String path = file.getFilePath(); 44 45 InputStream expected = null; 46 InputStream actual = null; 47 48 String baseDir = TestMocks.getBaseDirectory() + "/src/test-data/"; 49 50 try 51 { 52 expected = new FileInputStream (baseDir + path); 53 actual = file.getStream(); 54 55 int i = 0; 56 57 while (true) 58 { 59 int actualByte = actual.read(); 60 int expectedByte = expected.read(); 61 62 if (actualByte != expectedByte) 63 { 64 System.err.println("Input deviation at index " + i + "; expected " 65 + expectedByte + ", not " + actualByte); 66 67 return false; 68 } 69 70 if (actualByte < 0) 71 break; 72 73 i++; 74 } 75 } 76 catch (IOException ex) 77 { 78 throw new ApplicationRuntimeException(ex); 79 } 80 finally 81 { 82 Tapestry.close(expected); 83 Tapestry.close(actual); 84 } 85 86 return true; 87 } 88 } | Popular Tags |