KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > junit > mock > c19 > Two


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.junit.mock.c19;
16
17 import java.io.FileInputStream JavaDoc;
18 import java.io.IOException JavaDoc;
19 import java.io.InputStream JavaDoc;
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 /**
28  * Test page for the {@link org.apache.tapestry.form.Upload}component.
29  *
30  * @author Howard Lewis Ship
31  * @since 3.0
32  */

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 JavaDoc path = file.getFilePath();
44
45         InputStream JavaDoc expected = null;
46         InputStream JavaDoc actual = null;
47
48         String JavaDoc baseDir = TestMocks.getBaseDirectory() + "/src/test-data/";
49
50         try
51         {
52             expected = new FileInputStream JavaDoc(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 JavaDoc 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