mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

kenneth_suter
27.48.2007 c1041d73b620b8f13619ce5e110bd33784045b6c
This commit includes tests for the recently committed StaticUtils.renameFile method.  In addition it includes a mechanism for running Windows specific tests
2 files modified
78 ■■■■■ changed files
opends/src/build-tools/org/opends/build/tools/PrepTestNG.java 9 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/util/TestStaticUtils.java 69 ●●●●● patch | view | raw | blame | history
opends/src/build-tools/org/opends/build/tools/PrepTestNG.java
@@ -173,6 +173,10 @@
              }
            }
            writer.println("  </run>\n</groups>");
          } else {
            if (!isWindows()) {
              writer.println("    <groups><run><exclude name=\"windows\"/></run></groups>");
            }
          }
          if(packages.length > 0)
@@ -257,4 +261,9 @@
      throw new BuildException("File Error: " + e.toString());
    }
  }
  static private boolean isWindows() {
    String os = System.getProperty("os.name");
    return (os != null && os.toLowerCase().indexOf("windows") != -1);
  }
}
opends/tests/unit-tests-testng/src/server/org/opends/server/util/TestStaticUtils.java
@@ -33,7 +33,10 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -850,6 +853,72 @@
  }
  /**
   * Tests the {@link StaticUtils#renameFile(java.io.File, java.io.File)}
   * method.
   *
   * @throws Exception If the test failed unexpectedly.
   */
  @Test
  public void testRenameFileNonExistentTarget() throws Exception {
    File src = File.createTempFile("src", null);
    File target = new File(src.getParentFile(), "target");
    try {
      if (target.exists()) {
        target.delete();
        assert(!target.exists());
      }
      StaticUtils.renameFile(src, target);
      assert(!src.exists());
      assert(target.exists());
    } finally {
      src.delete();
      target.delete();
    }
  }
  /**
   * Tests the {@link StaticUtils#renameFile(java.io.File, java.io.File)}
   * method.
   *
   * @throws Exception If the test failed unexpectedly.
   */
  @Test
  public void testRenameFileExistentTarget() throws Exception {
    File src = File.createTempFile("src", null);
    File target = File.createTempFile("target", null);
    try {
      StaticUtils.renameFile(src, target);
      assert(!src.exists());
      assert(target.exists());
    } finally {
      src.delete();
      target.delete();
    }
  }
  /**
   * Tests the {@link StaticUtils#renameFile(java.io.File, java.io.File)}
   * method.  Renaming locked files is a problem on Windows but not so
   * much on other platforms.
   *
   * @throws Exception If the test failed unexpectedly.
   */
  @Test(groups = {"windows"}, expectedExceptions = IOException.class)
  public void testRenameFileLockedTarget() throws Exception {
    File src = File.createTempFile("src", null);
    File target = File.createTempFile("target", null);
    FileChannel c = new RandomAccessFile(target, "rw").getChannel();
    FileLock lock = c.lock();
    try {
      StaticUtils.renameFile(src, target);
    } finally {
      lock.release();
      src.delete();
      target.delete();
    }
  }
  /**
   * Tests the {@link StaticUtils#recursiveDelete(File)} method.
   *
   * @throws Exception