You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2012/03/27 09:27:45 UTC
svn commit: r1305755 -
/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/filenaming/TestPathUtilsNamingConvention.java
Author: bfoster
Date: Tue Mar 27 07:27:44 2012
New Revision: 1305755
URL: http://svn.apache.org/viewvc?rev=1305755&view=rev
Log:
- Introduce a CAS-Metadata based renaming interface
------------
OODT-426
Modified:
oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/filenaming/TestPathUtilsNamingConvention.java
Modified: oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/filenaming/TestPathUtilsNamingConvention.java
URL: http://svn.apache.org/viewvc/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/filenaming/TestPathUtilsNamingConvention.java?rev=1305755&r1=1305754&r2=1305755&view=diff
==============================================================================
--- oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/filenaming/TestPathUtilsNamingConvention.java (original)
+++ oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/filenaming/TestPathUtilsNamingConvention.java Tue Mar 27 07:27:44 2012
@@ -16,6 +16,55 @@
*/
package org.apache.oodt.cas.metadata.filenaming;
+//JDK imports
+import java.io.File;
+import java.io.IOException;
+import java.util.UUID;
+
+//Apache imports
+import org.apache.commons.io.FileUtils;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.metadata.exceptions.NamingConventionException;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link PathUtilsNamingConvention}.
+ *
+ * @author bfoster (Brian Foster)
+ */
public class TestPathUtilsNamingConvention extends TestCase {
+ public void testRename() throws IOException, NamingConventionException {
+ File tmpFile = File.createTempFile("bogus", "bogus");
+ File tmpDir = new File(tmpFile.getParentFile(),
+ UUID.randomUUID().toString());
+ if (!tmpDir.mkdirs()) {
+ throw new IOException("Failed to create temp directory");
+ }
+ tmpFile.delete();
+ File testFile = new File(tmpDir, "TestProduct.txt");
+ Metadata m = new Metadata();
+ m.replaceMetadata("NewName", "NewProduct.txt");
+
+ // Test failure.
+ PathUtilsNamingConvention nc = new PathUtilsNamingConvention();
+ nc.setNamingConv("[NewName]");
+ try {
+ nc.rename(testFile, m);
+ fail("Should have thrown IOException");
+ } catch (NamingConventionException e) { /* expect throw */ }
+
+ // Test success.
+ FileUtils.touch(testFile);
+ File newFile = nc.rename(testFile, m);
+ assertTrue(newFile.exists());
+ assertEquals("NewProduct.txt", newFile.getName());
+ assertFalse(testFile.exists());
+
+ FileUtils.forceDelete(tmpDir);
+ }
}