Пример #1
0
  /**
   * Test creation and delete of file in one test. If this test fails, all other test will fail to!
   */
  @org.junit.Test
  public void testCreateDeleteEmptyFile() throws Exception {
    Path filePath = Utils.resolveWithRoot(xenon.files(), getTestDir(), "testFile01");

    Files files = getFiles();

    // Previous test run could have gone wrong. Indicate here that a previous test run failed.
    boolean preExisting = files.exists(filePath);
    if (preExisting) {
      try {
        // try to delete first !
        files.delete(filePath);
      } catch (Exception e) {

      }
      assertFalse(
          "exists(): Can't test createFile is previous test file already exists. File should now be deleted, please run test again.",
          preExisting);
    }

    files.createFile(filePath);
    // enforce ?
    boolean exists = files.exists(filePath);
    assertTrue("exist(): After createFile() exists() reports false.", exists);

    files.delete(filePath);
    assertTrue("delet(): After delete, method exist() return true.", exists);
  }
Пример #2
0
  @SuppressWarnings("unused")
  public static void main(String[] args) {
    try {
      // We create a new Xenon using the XenonFactory (without providing any properties).
      Xenon xenon = XenonFactory.newXenon(null);

      // Next, we retrieve the Files, Jobs and Credentials API
      Files files = xenon.files();
      Jobs jobs = xenon.jobs();
      Credentials credentials = xenon.credentials();

      // We can now uses the interfaces to get some work done!
      // ....

      // Finally, we end Xenon to release all resources
      XenonFactory.endXenon(xenon);

    } catch (XenonException e) {
      System.out.println("CreatingXenon example failed: " + e.getMessage());
      e.printStackTrace();
    }
  }
  public static void main(String[] args) {
    try {
      // First , we create a new Xenon using the XenonFactory (without providing any properties).
      Xenon xenon = XenonFactory.newXenon(null);

      // Next, we retrieve the Files and Credentials interfaces
      Files files = xenon.files();
      Credentials credentials = xenon.credentials();

      // To create a new FileSystem we need a Credential that enable us to access the location.
      Credential c = credentials.getDefaultCredential("file");

      // We need to know the OS to determine the root of the file system
      String root;

      if (Utils.isWindows()) {
        root = "C:";
      } else {
        root = "/";
      }

      // Now we can create a FileSystem (we don't provide any properties).
      FileSystem fs = files.newFileSystem("file", root, c, null);

      // We can now uses the FileSystem to access files!
      // ....

      // If we are done we need to close the FileSystem and the credential
      credentials.close(c);
      files.close(fs);

      // Finally, we end Xenon to release all resources
      XenonFactory.endXenon(xenon);

    } catch (XenonException e) {
      System.out.println("CreateLocalFileSystem example failed: " + e.getMessage());
      e.printStackTrace();
    }
  }
Пример #4
0
  protected static Files getFiles() throws XenonException {

    // class synchronization:
    synchronized (AbstractFileTests.class) {

      // init xenon singleton instance:
      if (xenon == null) {
        xenon = XenonFactory.newXenon(null);
      }

      return xenon.files();
    }
  }
Пример #5
0
  /**
   * Create new and unique sub-directory for testing purposes. To avoid previous failed tests to
   * interfere with current test run, an unique directory has to be created each time. It is
   * recommend after each successful test run to delete the test directory and its contents.
   *
   * @param parentDirPath - parent directory to create (sub) directory in.
   * @param dirPrefix - prefix of the sub-directory. An unique number will be append to this name,
   * @return AbsolutPath of new created directory
   */
  protected Path createUniqueTestSubdir(Path parentDirPath, String dirPrefix)
      throws XenonException, XenonException {
    do {
      int myid = uniqueIdcounter++;
      Path absPath = Utils.resolveWithRoot(xenon.files(), parentDirPath, dirPrefix + "." + myid);

      if (getFiles().exists(absPath) == false) {
        infoPrintf("createUniqueTestSubdir: '%s'+%d => '%s'\n", dirPrefix, myid, absPath);
        getFiles().createDirectory(absPath);
        return absPath;
      }

    } while (true);
  }
Пример #6
0
  /**
   * Create new and unique test file.
   *
   * @param parentDirPath - parent directory to create file into.
   * @param filePrefix - filePrefix to use as filename. An unique number will be added to the
   *     fileName.
   * @param createFile - actually create (empty) file on (remote) file system.
   * @return new Path, which points to existing file if createFile was true.
   * @throws XenonException
   * @throws XenonException
   */
  protected Path createUniqueTestFile(Path parentDirPath, String filePrefix, boolean createFile)
      throws XenonException {

    do {
      int myid = uniqueIdcounter++;
      Path absPath = Utils.resolveWithRoot(xenon.files(), parentDirPath, filePrefix + "." + myid);

      if (getFiles().exists(absPath) == false) {

        infoPrintf("createUniqueTestFile: '%s'+%d => '%s'\n", filePrefix, myid, absPath);
        if (createFile) {
          getFiles().createFile(absPath);
        }
        return absPath;
      }

    } while (true);
  }
Пример #7
0
  /**
   * Test creation and deletion of directory in one test. If this test fails, all other test will
   * fail to!
   */
  @org.junit.Test
  public void testCreateDeleteEmptySubdir() throws Exception {

    Files files = getFiles();

    Path dirPath = Utils.resolveWithRoot(xenon.files(), getTestDir(), "testSubdir01");
    assertFalse(
        "Previous test directory already exists. Please clean test location.:" + dirPath,
        files.exists(dirPath));

    getFiles().createDirectory(dirPath);
    // test both ?
    boolean exists = files.exists(dirPath);
    exists = files.exists(dirPath);
    assertTrue(
        "After createDirectory(), method exists() reports false for path:" + dirPath, exists);

    assertDirIsEmpty(files, dirPath);

    files.delete(dirPath);
    exists = files.exists(dirPath);
    assertFalse("After delete() on directory, method exists() reports false.", exists);
  }
Пример #8
0
 protected Path createFile(Path parentDirPath, String subFile) throws XenonException {
   Path absPath = Utils.resolveWithRoot(xenon.files(), parentDirPath, subFile);
   getFiles().createFile(absPath);
   return absPath;
 }
Пример #9
0
 protected Path createSubdir(Path parentDirPath, String subDir) throws XenonException {
   Path absPath = Utils.resolveWithRoot(xenon.files(), parentDirPath, subDir);
   infoPrintf("createSubdir: '%s' -> '%s'\n", subDir, absPath);
   getFiles().createDirectory(absPath);
   return absPath;
 }