test/java/fr/jayasoft/ivy/repository/vfs/VfsRepositoryTest.java
/**
	 * Validate that we can overwrite an existing file
	 * 
	 * @throws Exception
	 */
Validate that we can overwrite an existing file

@throws Exception
Validate that we can overwrite an existing file @throws Exception
public void testPutOverwriteTrue() throws Exception {
		String testResource = VfsTestHelper.TEST_IVY_XML;
		String srcFile = FileUtil.concat(VfsTestHelper.TEST_REPO_DIR, testResource);		
		String destResource = VfsTestHelper.SCRATCH_DIR + "/" +  testResource;
		File destFile = new File(
				FileUtil.concat(VfsTestHelper.TEST_REPO_DIR, destResource));
		Iterator vfsURIs = helper.createVFSUriSet(destResource).iterator();
		while (vfsURIs.hasNext()) {
			VfsURI vfsURI = (VfsURI) vfsURIs.next();
			if (scratchDir.exists()) {
				FileUtil.forceDelete(scratchDir);
			}
            destFile.getParentFile().mkdirs();
            destFile.createNewFile();
			try {
				repo.put(new File(srcFile), vfsURI.toString(), true);
				if (! new File(srcFile).exists()) {
					fail("Put didn't happen. Src VfsURI: " + vfsURI.toString() + 
							".\nExpected file: " + destFile);
				}
				if (destFile.length() == 0) {
					fail("Zero file size indicates file not overwritten");
				}
			} catch (IOException e) {
				fail("Caught unexpected IOException on Vfs URI: " + vfsURI.toString() + "\n" + e.getLocalizedMessage());
			}
		}
	}
public void testPutOverwriteTrue ( ) throws Exception { String testResource = VfsTestHelper . TEST_IVY_XML ; String srcFile = FileUtil . concat ( VfsTestHelper . TEST_REPO_DIR , testResource ) ; String destResource = VfsTestHelper . SCRATCH_DIR + "/" + testResource ; File destFile = new File ( FileUtil . concat ( VfsTestHelper . TEST_REPO_DIR , destResource ) ) ; Iterator vfsURIs = helper . createVFSUriSet ( destResource ) . iterator ( ) ; while ( vfsURIs . hasNext ( ) ) { VfsURI vfsURI = ( VfsURI ) vfsURIs . next ( ) ; if ( scratchDir . exists ( ) ) { FileUtil . forceDelete ( scratchDir ) ; } destFile . getParentFile ( ) . mkdirs ( ) ; destFile . createNewFile ( ) ; try { repo . put ( new File ( srcFile ) , vfsURI . toString ( ) , true ) ; if ( ! new File ( srcFile ) . exists ( ) ) { fail ( "Put didn't happen. Src VfsURI: " + vfsURI . toString ( ) + ".\nExpected file: " + destFile ) ; } if ( destFile . length ( ) == 0 ) { fail ( "Zero file size indicates file not overwritten" ) ; } } catch ( IOException e ) { fail ( "Caught unexpected IOException on Vfs URI: " + vfsURI . toString ( ) + "\n" + e . getLocalizedMessage ( ) ) ; } } }
Validate that we can overwrite an existing file
Validate that we can overwrite an existing file
// remove existing scratch dir and populate it with an empty file // that we can overwrite. We do this so that we can test file sizes. // seeded file has length 0, while put file will have a length > 0