Java Code Examples for javax.microedition.io.file.FileConnection#getName()

The following examples show how to use javax.microedition.io.file.FileConnection#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetName.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests getName() on a non-existing file url
 */
public void test0001() {
	boolean passed = false;
	try {
		String url="file://"+getTestPath()+"file";
		
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
		ensureNotExists(conn);
		try {
			addOperationDesc("Using file url: " + url);
			
			String name = conn.getName();
			addOperationDesc("getName() returned " + name);

			passed = "file".equals(name);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getName() on a non-existing file url", passed);
}
 
Example 2
Source File: GetName.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests getName() on a non-existing directory url
 */
public void test0002() {
	boolean passed = false;
	try {

		String url="file://"+getTestPath()+"dir/";
					
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
		ensureNotExists(conn);
		try {
			addOperationDesc("Using directory url: " + url);
			
			String name = conn.getName();
			addOperationDesc("getName() returned " + name);
			
			passed = "dir/".equals(name);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getName() on a non-existing directory url", passed);
}
 
Example 3
Source File: GetName.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests getName() on an existing file url
 */
public void test0003() {
	boolean passed = false;
	try {
		String url="file://"+getTestPath()+"file";
		
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
		ensureFileExists(conn);
		try {
			addOperationDesc("Using file url: " + url);
			
			String name = conn.getName();
			addOperationDesc("getName() returned " + name);

			passed = "file".equals(name);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getName() on an existing file url", passed);
}
 
Example 4
Source File: GetName.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests getName() on an existing directory url
 */
public void test0004() {
	boolean passed = false;
	try {

		String url="file://"+getTestPath()+"dir/";
					
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
		ensureDirExists(conn);
		try {
			addOperationDesc("Using directory url: " + url);
			
			String name = conn.getName();
			addOperationDesc("getName() returned " + name);
			
			passed = "dir/".equals(name);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getName() on an existing directory url", passed);
}
 
Example 5
Source File: GetName.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests getName() on an encoded file URL
 */
public void test0007() {
	boolean passed = false;
	try {
		String url="file://"+getTestPath()+"foo%5e%25bar";
		
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
		try {
			addOperationDesc("Using file url: " + url);
			
			String name = conn.getName();
			addOperationDesc("getName() returned " + name);
			
			passed = "foo^%bar".equals(name);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getName() on an encoded file URL", passed);
}
 
Example 6
Source File: GetName.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests if getName() returns in unescaped URL format
 */
public void test0008() {
	boolean passed = false;
	try {
		String unEscapedUrl ="file://"+getTestPath()+ "a file";

		FileConnection conn = (FileConnection)Connector.open(unEscapedUrl, Connector.READ_WRITE);
		try {
			addOperationDesc("Using file url: " + unEscapedUrl);
			
			String name = conn.getName();
			addOperationDesc("getName() returned: " + name);
			
			passed = name.equals("a file");
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests if getName() returns in unescaped URL format", passed);
}
 
Example 7
Source File: GetName.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests getName() on a file url with host
 */
public void test0009() {
	boolean passed = false;
	try {
			String url = "file://" + URLSupport.getPathWithHost(getTestPath())+ "file";
			
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);

		try {
			addOperationDesc("Using file url with host: " + url);
			
			String name = conn.getName();
			addOperationDesc("getName() returned " + name);

			passed = name.equals("file");				
		} finally {
			conn.close();
		}

	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getName() on a file url with host", passed);
}
 
Example 8
Source File: GetName.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests getName() on an existing file, and a connection url ending with '/'
 */
public void test0005() {
	boolean passed = false;
	try {
		String url0="file://"+getTestPath()+"file";
		FileConnection conn0 = (FileConnection)Connector.open(url0, Connector.READ_WRITE);

		addOperationDesc("Creating file: " + url0);
		ensureFileExists(conn0);
		conn0.close();

		String url="file://"+getTestPath()+"file/";		
									
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);

		try {
			addOperationDesc("Using directory url: " + url);
			
			String name = conn.getName();
			addOperationDesc("getName() returned " + name);

			passed = "file".equals(name);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getName() on an existing file, and a connection url ending with '/'", passed);
}
 
Example 9
Source File: GetName.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests getName() on an existing directory, and a connection url not ending with '/'
 */
public void test0006() {
	boolean passed = false;
	try {

		String url0 = "file://" + getTestPath() + "dir/";
		FileConnection conn0 = (FileConnection)Connector.open(url0, Connector.READ_WRITE);

		addOperationDesc("Creating directory: " + url0);
		ensureDirExists(conn0);
		conn0.close();

		String url = "file://" + getTestPath() + "dir";						
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
		
		try {
			addOperationDesc("Using file url: " + url);
			
			String name = conn.getName();
			addOperationDesc("getName() returned " + name);
			
			passed = "dir/".equals(name);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getName() on an existing directory,and a connection url not ending with '/'", passed);
}