package edu.uw.apl.tupelo.fuse;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import fuse.FuseMount;

import edu.uw.apl.tupelo.model.Session;
import edu.uw.apl.tupelo.model.DiskImage;
import edu.uw.apl.tupelo.model.FlatDisk;
import edu.uw.apl.tupelo.store.Store;
import edu.uw.apl.tupelo.store.filesys.FilesystemStore;

public class ManagedDiskFileSystemTest extends junit.framework.TestCase {

	public void testNull() {
	}

	public void testMountUnmount() throws Exception {
		boolean loadManagedDisks = false;
		Store store = new FilesystemStore( new File( "test-store" ),
										   loadManagedDisks );

		File mount = new File( "test-mount" );
		mount.mkdirs();
		ManagedDiskFileSystem mdfs = new ManagedDiskFileSystem( store );

		boolean ownThread = true;
		mdfs.mount( mount, ownThread );

		// Wait for the mount point to become available
		Thread.sleep( 1000 * 4 );

		// and just unmount it
		int sc = mdfs.umount();
		assertEquals( sc, 0 );
	}

	public void testCanAccessPut() throws Exception {
		boolean loadManagedDisks = false;
		Store store = new FilesystemStore( new File( "test-store" ),
										   loadManagedDisks );

		File f = new File( "src/test/resources/1m" );
		if( !f.exists() )
			return;

		Session session = Session.CANNED;
		DiskImage di = new DiskImage( f );
		FlatDisk fd1 = new FlatDisk( di, session );
		store.put( fd1 );

		File mount = new File( "test-mount" );
		mount.mkdirs();
		ManagedDiskFileSystem mdfs = new ManagedDiskFileSystem( store );
		boolean ownThread = true;
		mdfs.mount( mount, ownThread );

		// Wait for the mount point to become available
		Thread.sleep( 1000 * 4 );

		// Now locate in the mdfs the data we just put...
		String cmd = "ls " + mount + "/" + f.getName() + "/" + session;
		System.out.println( cmd );
		Process p = Runtime.getRuntime().exec( cmd );
		p.waitFor();
		int sc = p.exitValue();
		assertEquals( sc, 0 );

		sc = mdfs.umount();
		assertEquals( sc, 0 );
	}
}

// eof

												
@@ -447,24 +447,140 @@
 ull() %7B%0A%09%7D%0A%0A
+%09/**%0A%09 * Test that we can mount and unmount a fuse filesystem representing%0A%09 * the contents of a Tupelo store.%0A%09 */%0A
 %09public void
@@ -610,32 +610,32 @@
 ows Exception %7B%0A
-
 %09%09boolean loadMa
@@ -1100,16 +1100,306 @@
  );%0A%09%7D%0A%0A
+%09/**%0A%09 * Test that we can mount a fuse filesystem representing the%0A%09 * contents of a Tupelo store, add a managed disk to that store%0A%09 * and then locate that disk by name in the advertised filesystem,%0A%09 * using a simple ls (LOOK: just use new File() ??). The ls should%0A%09 * return zero.%0A%09 */%0A
 %09public 
@@ -2294,24 +2294,24 @@
 xitValue();%0A
-
 %09%09assertEqua
@@ -2324,16 +2324,1060 @@
 , 0 );%0A%0A
+%09%09sc = mdfs.umount();%0A%09%09assertEquals( sc, 0 );%0A%09%7D%0A%0A%09/**%0A%09 * Test that we can mount a fuse filesystem representing the%0A%09 * contents of a Tupelo store, and then attempt a locate of some%0A%09 * bogus file by name in the advertised filesystem, using a simple%0A%09 * ls (LOOK: just use new File() ??).  The ls should return%0A%09 * non-zero.%0A%09 */%0A%09public void testCannotAccessBogus() throws Exception %7B%0A%09%09boolean loadManagedDisks = false;%0A%09%09Store store = new FilesystemStore( new File( %22test-store%22 ),%0A%09%09%09%09%09%09%09%09%09%09   loadManagedDisks );%0A%0A%09%09File mount = new File( %22test-mount%22 );%0A%09%09mount.mkdirs();%0A%09%09ManagedDiskFileSystem mdfs = new ManagedDiskFileSystem( store );%0A%09%09boolean ownThread = true;%0A%09%09mdfs.mount( mount, ownThread );%0A%0A%09%09// Wait for the mount point to become available%0A%09%09Thread.sleep( 1000 * 4 );%0A%0A%09%09// Now attempt to locate in the mdfs some bogus file by name...%0A%09%09String cmd = %22ls %22 + mount + %22/FOOBARBAZ%22;%0A%09%09System.out.println( cmd );%0A%09%09Process p = Runtime.getRuntime().exec( cmd );%0A%09%09p.waitFor();%0A%09%09int sc = p.exitValue();%0A%09%09assertTrue( sc != 0 );%0A%0A
 %09%09sc = m

Add unit test for expected failure of lookup of bogus file name