Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH . All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: s IT Solutions AT Spardat GmbH - initial API and implementation /
 
 
 package at.spardat.xma.boot.test;
 
 import java.io.File;
 import java.net.URL;
 
 import  junit.framework.Assert;
 import  junit.framework.TestCase;
class: Tester

Author(s):
s3595 Chris Sch�fer (CGS)
Version:
0.1.0
 
 public class FCResourceTest  extends TestCase  {
 
     private static FileCache   fc ;
     private static BootRuntime rt ;
 
     public FCResourceTest(String namethrows IOException {
         super(name);
 
     }
 
     protected void setUp() throws IOException {
       if == nullinit();
     }


    

Parameters:
args
Returns:
void
 
 	public static void main(String[] args) {
         try {
             init();
 
             FCResourceTest t = new FCResourceTest("main");
 
             t.test_isCached();
             t.test_BMode();
             t.test_Interface();
 
         } catch (Exception e1) {
             e1.printStackTrace();
         }
 
 	}// main
 
     public static void init ( ) throws IOException{
 
         File f = new File. );
         if( !f.exists() )
           f.mkdirs();
 
          = BootRuntime.initialize(f, Logger.getLogger"tester"));
          = FileCache.initialize );
 
         }// init
 
     public void test_isCached( ) throws IOExceptionException {
         ..println("test_isCached: ");
 
         URL url1 = TestUtils.getSTDURL();
 
         // delete if exist
           .invalidateResource(url1);
         Assert.assertTrue( !.isCached(url1) );
         Assert.assertTrue( !.isCached(url1) );
 
           IFileCacheResource fcr = .openResourceurl1 );  // loads it from server, and store to disk
         Assert.assertTrue( .isCached(url1) );
 
         .invalidateResource(fcr);
         Assert.assertTrue( !.isCached(url1) );
 
         ..println("test_isCached ok");
     }
    public void test_BMode( ) throws IOExceptionException {
        ..println("test_BMode: ");
        URL url1 = TestUtils.getSTDURL();
        // delete if exist
          .invalidateResource(url1);
        Assert.assertTrue( !.isCached(url1) );
        IFileCacheResource fcr = .openResource(url1false );  // loads it from server, and store to disk
        Assert.assertTrue( .isCached(url1) );
        // trigger buffer loading
        InputStream is = fcr.getInputStream();
        is.close();
        .invalidateResource(fcr);
        Assert.assertTrue( !.isCached(url1) );
        ..println("test_BMode ok");
    }
    public void test_Interface( ) throws IOExceptionException {
        ..println("test_BMode: ");
        URL url1 = TestUtils.getSTDURL();
        // delete if exist
          .invalidateResource(url1);
        Assert.assertTrue( !.isCached(url1) );
        long start = System.currentTimeMillis();
        IFileCacheResource fcr = .openResource(url1false );  // loads it from server, and store to disk
        Assert.assertTrue( .isCached(url1) );
        /* start interface */
        long expires = fcr.getExpiration();
        Assert.assertEquals(0, expires);
        long lastm = fcr.getLastModified();
//        Assert.assertEquals(0, lastm); // gub: why null?
        long lastupd = fcr.getLastUpdated();
        Assert.assertTrue( lastupd >= start && lastupd <= System.currentTimeMillis() );
        URL localres = fcr.getLocalRes();
        Assert.assertNotNull(localres);
        Assert.assertTrue( localres.toExternalForm().length() > 0 );
        URL location = fcr.getLocation();
        Assert.assertTrue( location.equals(url1) );
        String strlastm = (String)fcr.getProperty"last-modified");
//        Assert.assertTrue( strlastm.equals("0") );  // gub: why null?
        fcr.getProperty("last-modified""1");
//        Assert.assertTrue( strlastm.equals("0") );  // gub: why null?
        // if 0 it is not expired
        Assert.assertTrue( !fcr.isExpired() );
        fcr.setProperty("testkey""testval");
        String testkey = fcr.getProperty("testkey");
        Assert.assertTrue( testkey.equals("testval") );
        InputStream is = fcr.getInputStream();
        File osf       = new File ( "c://temp/test.out");
        OutputStream os = new FileOutputStreamosf );
        try {
          byte bBuf[] = new byte[1024];
          while (true) {
            int cRead = is.read(bBuf, 0, bBuf.length);
            if (cRead == -1)
              break;
            os.write(bBuf, 0, cRead);
          }
        }
        finally { // close the streams
          is.close();
          os.close();
          osf.delete();
        }
        .invalidateResource(fcr);
        Assert.assertTrue( !.isCached(url1) );
        ..println("test_BMode ok");
    }
}// class
New to GrepCode? Check out our FAQ X