Пример #1
0
 @Test
 public void testCreateDir() throws Exception {
   File dir = FileUtil.createDir("temp1");
   assertTrue(dir.exists());
   assertTrue(dir.isDirectory());
   FileUtil.deleteFileSystemDirectory(dir);
 }
Пример #2
0
 private String runCreateFileAndGetContent(String[] args) throws Exception {
   updater.parseCommandLine(args);
   File resultFile = updater.createUpdateList();
   String content = FileUtil.getFileContent(resultFile);
   FileUtil.deleteFile(resultFile);
   return content;
 }
Пример #3
0
 public void testOrganizeFilesOneSubDir() throws Exception {
   File dir = FileUtil.createDir("temp");
   File subDir = createSubDir(dir, "subDir");
   assertEquals(1, FileUtil.getDirectoryListing(dir).length);
   assertEquals(subDir, FileUtil.getDirectoryListing(dir)[0]);
   FileUtil.deleteFileSystemDirectory(dir);
 }
Пример #4
0
 public void testOrganizeFilesOneFile() throws Exception {
   File dir = FileUtil.createDir("temp");
   File file = createFileInDir(dir, "file.txt");
   assertEquals(1, FileUtil.getDirectoryListing(dir).length);
   assertEquals(file, FileUtil.getDirectoryListing(dir)[0]);
   FileUtil.deleteFileSystemDirectory(dir);
 }
 @Test
 public void testFileResponder() throws Exception {
   try {
     new File("testDir").mkdir();
     new File("testDir/files").mkdir();
     FileUtil.createFile("testDir/files/someFile", "this is a test");
     request.setResource("files/someFile");
     assertResponderType(FileResponder.class);
   } finally {
     FileUtil.deleteFileSystemDirectory("testDir");
   }
 }
Пример #6
0
 @Test
 public void shouldPutSpecialFilesInDifferentList() throws Exception {
   String arg1 = "-doNotReplace:MasterFolder/TestFolder/fitnesse.css";
   String arg2 = "-doNotReplace:MasterFolder/TestFolder/fitnesse_print.css";
   updater.parseCommandLine(new String[] {arg1, arg2, "MasterFolder/TestFolder"});
   File doNotUpdateFile = updater.createDoNotUpdateList();
   String doNotUpdateContent = FileUtil.getFileContent(doNotUpdateFile);
   FileUtil.deleteFile(doNotUpdateFile);
   assertSubString("TestFolder/fitnesse.css", doNotUpdateContent);
   assertSubString("TestFolder/fitnesse_print.css", doNotUpdateContent);
   assertDoesntHaveRegexp("TestFolder/TestFile", doNotUpdateContent);
 }
 @Before
 public void setUp() throws Exception {
   FileUtil.deleteFileSystemDirectory(base);
   createFileSystemDirectory(base);
   root = new FileSystemPage(defaultPath, "RooT");
   crawler = root.getPageCrawler();
 }
Пример #8
0
  public File createDoNotUpdateList() {
    if (updateDoNotCopyOverContent.equals(""))
      for (String dirName : mainDirectories) addFilePathsToList(dirName);

    return FileUtil.createFile(
        new File(outputDirectory + "updateDoNotCopyOverList"), updateDoNotCopyOverContent);
  }
Пример #9
0
  @Test
  public void systemPropertiesTakePrecedenceOverConfiguredProperties() throws Exception {
    final String configFileName =
        "systemPropertiesTakePrecedenceOverConfiguredProperties.properties";
    FileUtil.createFile(configFileName, "Theme=example");

    System.setProperty("Theme", "othertheme");
    try {
      // Checked via logging:
      String output = runFitnesseMainWith("-o", "-c", "/root", "-f", configFileName);
      assertThat(output, containsString("othertheme"));
    } finally {
      System.getProperties().remove("Theme");
      FileUtil.deleteFile(configFileName);
    }
  }
Пример #10
0
 @Before
 public void setUp() throws Exception {
   FileUtil.deleteFileSystemDirectory(base);
   createFileSystemDirectory(base);
   root =
       new FileSystemPageFactory()
           .makePage(new File(base, "RooT"), "RooT", null, new SystemVariableSource());
 }
Пример #11
0
 @Test
 public void testLogLineInNewFile() throws Exception {
   Calendar time = (Calendar) ld.time.clone();
   time.add(Calendar.DATE, 1);
   LogData nextDay = new LogData(ld.host, time, ld.requestLine, ld.status, ld.size, ld.username);
   l.log(ld);
   l.log(nextDay);
   l.close();
   File firstFile = getLogFileFor(ld);
   File secondFile = getLogFileFor(nextDay);
   assertTrue(firstFile.exists());
   assertTrue(secondFile.exists());
   String firstContent = FileUtil.getFileContent(firstFile);
   assertEquals(l.formatLogLine(ld) + System.getProperty("line.separator"), firstContent);
   String secondContent = FileUtil.getFileContent(secondFile);
   assertEquals(l.formatLogLine(nextDay) + System.getProperty("line.separator"), secondContent);
 }
Пример #12
0
 public void preparaArquivos(String dir) {
   arquivos.clear();
   FileUtil.fillAllFilesList(arquivos, new File(dir));
   fileIterator = arquivos.iterator();
   if (observer != null) {
     observer.arquivosEncontrados(arquivos.size());
   }
 }
Пример #13
0
 @Test
 public void shouldKnowIfAGivenDirectoryExists() throws Exception {
   File testFolder = new File("TestFolder");
   testFolder.mkdir();
   updater.parseCommandLine(new String[] {"TestFolder"});
   assertTrue(updater.directoriesAreValid());
   FileUtil.deleteFileSystemDirectory(testFolder);
   assertFalse(updater.directoriesAreValid());
 }
Пример #14
0
 private Response generateXMLResponse(File file) {
   try {
     response.setContent(FileUtil.getFileContent(file));
   } catch (IOException e) {
     response.setContent("Error: Unable to read file '" + file.getName() + "'\n");
   }
   response.setContentType(Format.XML);
   return response;
 }
Пример #15
0
 @Override
 public void removeChildPage(final String name) throws Exception {
   super.removeChildPage(name);
   String pathToDelete = getFileSystemPath() + "/" + name;
   final File fileToBeDeleted = new File(pathToDelete);
   cmSystem.preDelete(pathToDelete);
   FileUtil.deleteFileSystemDirectory(fileToBeDeleted);
   cmSystem.delete(pathToDelete);
 }
Пример #16
0
 @Test
 public void testLoggingOneLineInNewFile() throws Exception {
   l.log(ld);
   l.close();
   File dir = l.getDirectory();
   File file = new File(dir, filename);
   assertTrue(file.exists());
   String contents = FileUtil.getFileContent(file);
   assertEquals(logLine + System.getProperty("line.separator"), contents);
 }
Пример #17
0
 @Test
 public void testAddMultipleUrlsToClasspath() throws Exception {
   String separator = System.getProperty("path.separator");
   String paths = "/blah/blah" + separator + "C" + otherSeperator(separator) + "\\foo\\bar";
   FileUtil.addItemsToClasspath(paths);
   URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
   String classpath = classpathAsString(classLoader);
   assertSubString("/blah/blah", classpath);
   assertMatches("[C" + otherSeperator(separator) + "?foo?bar]", classpath);
 }
Пример #18
0
 /**
  * print out all the correct answers for the slot
  *
  * @param slot
  */
 public static void getLabels(String slot) {
   String[] lines = FileUtil.getTextFromFile(SFConstants.labelFile).split("\n");
   for (String line : lines) {
     String[] fields = line.split("\t");
     // Note: a set of files whose names begin with "eng" are ignored in this assignment.
     if (fields[3].equals(slot) && fields[10].equals("1") && !fields[4].startsWith("eng")) {
       System.out.println(
           String.format("%s\t%s\t%s\t%s", fields[1], fields[3], fields[4], fields[8]));
     }
   }
 }
Пример #19
0
  @Override
  public void buttonClick() {
    setBusy(true);

    Map settings = getWizardDataMap();
    String username = (String) (settings.get("jdbc.username"));
    String host = (String) (settings.get("jdbc.host"));
    String port = (String) (settings.get("jdbc.port"));
    String dbName = (String) (settings.get("jdbc.dbname"));
    String pwd = (String) (settings.get("jdbc.password"));

    // 检查数据库连接
    appendLine("正在连接数据库...");

    String url = "jdbc:mysql://" + host + ":" + port + "/";
    DatabaseManager dbman = new DatabaseManagerImplMysql();
    // 创建数据库
    try {
      Connection conn =
          dbman.checkConnection(
              ConfigParams.JDBC_DRIVER, url + ConfigParams.MYSQL_ENCODING, username, pwd);
      dbman.setConnectioin(conn);

      dbman.changeDatabase(dbName);

      appendLine("正在创建表格...");
      // Every sql statement is sperated by a ;
      StringTokenizer token =
          new StringTokenizer(util.FileUtil.readFileAsString("setup/mysql.sql", "UTF-8"), ";");
      boolean tableSuccess = true; // Whether all table has been created

      while (token.hasMoreElements()) {
        String value = token.nextElement().toString();
        System.out.println(value);
        tableSuccess &= dbman.executeUpdate(value);
      }

      if (tableSuccess) {
        appendLine("表格创建完毕.");
        setProblem(null);
      } else {
        appendLine("无法创建表格! 请检查后您的数据库服务器设置.");
        setProblem("无法创建表格! 请检查后您的数据库服务器设置.");
      }

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      dbman.closeConnection();
    }

    setBusy(false);
  }
 @Test
 public void testLoadChildrenWhenPageIsDeletedManualy() throws Exception {
   WikiPage page = crawler.addPage(root, PathParser.parse("TestPage"));
   page.getChildren();
   FileUtil.deleteFileSystemDirectory(((FileSystemPage) page).getFileSystemPath());
   try {
     page.getChildren();
   } catch (Exception e) {
     fail("No Exception should be thrown");
   }
 }
Пример #21
0
 @Test
 public void testLoggingIncludesUsername() throws Exception {
   ld = new LogData(ld.host, ld.time, ld.requestLine, ld.status, ld.size, "Joe");
   l.log(ld);
   l.close();
   File dir = l.getDirectory();
   File file = new File(dir, filename);
   assertTrue(file.exists());
   String contents = FileUtil.getFileContent(file);
   logLine = "myHost - Joe [06/Mar/2003:13:42:05 -0100] \"request\" 42 666";
   assertEquals(logLine + System.getProperty("line.separator"), contents);
 }
Пример #22
0
 private void addFilePathsToList(String path) {
   File f = new File(path);
   if (f.isDirectory()) {
     File[] files = FileUtil.getDirectoryListing(f);
     for (File childFile : files)
       if (isWikiFile(childFile)) addFilePathToAppropriateList(path, childFile);
   } else if (f.isFile()) {
     String parent = "";
     int index = path.lastIndexOf('/');
     if (index >= 0) parent = path.substring(0, index);
     if (isWikiFile(f)) addFilePathToAppropriateList(parent, f);
   }
 }
Пример #23
0
 public FileSection(String type) throws Exception {
   if ("setup".equals(type.toLowerCase())) {
     new File(FitnesseFixtureContext.rootPath).mkdir();
     File dir =
         new File(FitnesseFixtureContext.rootPath + "/" + FitnesseFixtureContext.root.getName());
     dir.mkdir();
     fileSection = new File(dir, "files");
     fileSection.mkdir();
   } else {
     FileUtil.deleteFileSystemDirectory(FitnesseFixtureContext.rootPath);
     fileSection = null;
   }
 }
Пример #24
0
 public void testOrganizeFilesFiveSubDirs() throws Exception {
   File dir = FileUtil.createDir("temp");
   File dir3 = createSubDir(dir, "dDir");
   File dir1 = createSubDir(dir, "bDir");
   File dir4 = createSubDir(dir, "eDir");
   File dir0 = createSubDir(dir, "aDir");
   File dir2 = createSubDir(dir, "cDir");
   assertEquals(5, FileUtil.getDirectoryListing(dir).length);
   assertEquals(dir0, FileUtil.getDirectoryListing(dir)[0]);
   assertEquals(dir1, FileUtil.getDirectoryListing(dir)[1]);
   assertEquals(dir2, FileUtil.getDirectoryListing(dir)[2]);
   assertEquals(dir3, FileUtil.getDirectoryListing(dir)[3]);
   assertEquals(dir4, FileUtil.getDirectoryListing(dir)[4]);
   FileUtil.deleteFileSystemDirectory(dir);
 }
Пример #25
0
 public void testOrganizeFilesFiveFiles() throws Exception {
   File dir = FileUtil.createDir("temp");
   File file3 = createFileInDir(dir, "dFile.txt");
   File file1 = createFileInDir(dir, "bFile.txt");
   File file4 = createFileInDir(dir, "eFile.txt");
   File file0 = createFileInDir(dir, "aFile.txt");
   File file2 = createFileInDir(dir, "cFile.txt");
   assertEquals(5, FileUtil.getDirectoryListing(dir).length);
   assertEquals(file0, FileUtil.getDirectoryListing(dir)[0]);
   assertEquals(file1, FileUtil.getDirectoryListing(dir)[1]);
   assertEquals(file2, FileUtil.getDirectoryListing(dir)[2]);
   assertEquals(file3, FileUtil.getDirectoryListing(dir)[3]);
   assertEquals(file4, FileUtil.getDirectoryListing(dir)[4]);
   FileUtil.deleteFileSystemDirectory(dir);
 }
Пример #26
0
  @Test
  public void testAddUrlToClasspath() throws Exception {
    ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
    assertTrue(systemClassLoader instanceof URLClassLoader);
    URLClassLoader classLoader = (URLClassLoader) systemClassLoader;

    URL sampleUrl = new File("src").toURI().toURL();

    String classpath = classpathAsString(classLoader);
    assertNotSubString(sampleUrl.toString(), classpath);

    FileUtil.addUrlToClasspath(sampleUrl);
    classpath = classpathAsString(classLoader);
    assertSubString(sampleUrl.toString(), classpath);
  }
Пример #27
0
  private Response makeTestExecutionReportResponse(
      Request request, Date resultDate, TestResultRecord testResultRecord) throws Exception {
    if (formatIsXML(request)) return generateXMLResponse(testResultRecord.getFile());
    ExecutionReport report;

    String content = FileUtil.getFileContent(testResultRecord.getFile());
    report = ExecutionReport.makeReport(content);
    if (report instanceof TestExecutionReport) {
      report.setDate(resultDate);
      return generateHtmlTestExecutionResponse(request, (TestExecutionReport) report);
    } else if (report instanceof SuiteExecutionReport) {
      pageTitle.setPageType("Suite History");
      return generateHtmlSuiteExecutionResponse(request, (SuiteExecutionReport) report);
    } else return makeCorruptFileResponse(request);
  }
Пример #28
0
 @Test
 public void testOrganizeFilesMixOfFilesAndDirs() {
   File dir = FileUtil.createDir("temp7");
   File dir3 = createSubDir(dir, "dDir");
   File file3 = createFileInDir(dir, "dFile.txt");
   File file0 = createFileInDir(dir, "aFile.txt");
   File dir1 = createSubDir(dir, "bDir");
   File file4 = createFileInDir(dir, "eFile.txt");
   File dir4 = createSubDir(dir, "eDir");
   File dir0 = createSubDir(dir, "aDir");
   File file1 = createFileInDir(dir, "bFile.txt");
   File dir2 = createSubDir(dir, "cDir");
   File file2 = createFileInDir(dir, "cFile.txt");
   assertEquals(10, FileUtil.getDirectoryListing(dir).length);
   assertEquals(dir0, FileUtil.getDirectoryListing(dir)[0]);
   assertEquals(dir1, FileUtil.getDirectoryListing(dir)[1]);
   assertEquals(dir2, FileUtil.getDirectoryListing(dir)[2]);
   assertEquals(dir3, FileUtil.getDirectoryListing(dir)[3]);
   assertEquals(dir4, FileUtil.getDirectoryListing(dir)[4]);
   assertEquals(file0, FileUtil.getDirectoryListing(dir)[5]);
   assertEquals(file1, FileUtil.getDirectoryListing(dir)[6]);
   assertEquals(file2, FileUtil.getDirectoryListing(dir)[7]);
   assertEquals(file3, FileUtil.getDirectoryListing(dir)[8]);
   assertEquals(file4, FileUtil.getDirectoryListing(dir)[9]);
   FileUtil.deleteFileSystemDirectory(dir);
 }
Пример #29
0
 @Test
 public void testGetDirectoryListingEmpty() throws Exception {
   File dir = FileUtil.createDir("temp2");
   assertEquals(0, FileUtil.getDirectoryListing(dir).length);
   FileUtil.deleteFileSystemDirectory(dir);
 }
Пример #30
0
 @Test
 public void createFileWithComplexPath() throws Exception {
   File file = FileUtil.createFile("temp/sub1/sub2/sub3/file", "");
   assertTrue(file.exists());
   FileUtil.deleteFileSystemDirectory("temp");
 }