001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.junit.mock.c19;
016    
017    import java.io.FileInputStream;
018    import java.io.IOException;
019    import java.io.InputStream;
020    
021    import org.apache.commons.io.IOUtils;
022    import org.apache.hivemind.ApplicationRuntimeException;
023    import org.apache.tapestry.Tapestry;
024    import org.apache.tapestry.html.BasePage;
025    import org.apache.tapestry.junit.mock.TestMockApplications;
026    import org.apache.tapestry.request.IUploadFile;
027    
028    /**
029     * Test page for the {@link org.apache.tapestry.form.Upload}component.
030     * 
031     * @author Howard Lewis Ship
032     * @since 3.0
033     */
034    
035    public abstract class Two extends BasePage
036    {
037        public abstract IUploadFile getFile();
038    
039        public abstract void setFile(IUploadFile file);
040    
041        public boolean getUploadMatch()
042        {
043            IUploadFile file = getFile();
044            String path = file.getFilePath();
045    
046            InputStream expected = null;
047            InputStream actual = null;
048            
049            String baseDir = TestMockApplications.getBaseDirectory() + "/src/test-data/";
050            
051            try
052            {
053                expected = new FileInputStream(baseDir + path);
054                actual = file.getStream();
055                
056                //this replaced the previous manual compare which didn't work
057                //across different platforms
058                IOUtils.contentEquals(expected, actual);
059            }
060            catch (IOException ex)
061            {
062                throw new ApplicationRuntimeException(ex);
063            }
064            finally
065            {
066                Tapestry.close(expected);
067                Tapestry.close(actual);
068            }
069    
070            return true;
071        }
072    }