示例#1
0
 public static boolean contentEquals(File file1, File file2) {
   try {
     return FileUtils.contentEquals(file1, file2);
   } catch (IOException e) {
     throw new UncheckedIOException(e);
   }
 }
  @Test
  public void testHTTPResultDefaultRows() throws IOException {
    File localFileForUpload = getInputFile("existingFile1", ".tmp");
    File tempFileForDownload = File.createTempFile("downloadedFile1", ".tmp");
    localFileForUpload.deleteOnExit();
    tempFileForDownload.deleteOnExit();

    Object[] r =
        new Object[] {
          HTTP_SERVER_BASEURL + "/uploadFile",
          localFileForUpload.getCanonicalPath(),
          tempFileForDownload.getCanonicalPath()
        };
    RowMeta rowMetaDefault = new RowMeta();
    rowMetaDefault.addValueMeta(new ValueMetaString("URL"));
    rowMetaDefault.addValueMeta(new ValueMetaString("UPLOAD"));
    rowMetaDefault.addValueMeta(new ValueMetaString("DESTINATION"));
    List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();
    rows.add(new RowMetaAndData(rowMetaDefault, r));
    Result previousResult = new Result();
    previousResult.setRows(rows);

    JobEntryHTTP http = new JobEntryHTTP();
    http.setParentJob(new Job());
    http.setRunForEveryRow(true);
    http.setAddFilenameToResult(false);
    http.execute(previousResult, 0);
    assertTrue(FileUtils.contentEquals(localFileForUpload, tempFileForDownload));
  }
 @Test
 public void testSimplify() throws IOException {
   final File expected = new File(RESOURCE_DIR + "simplified_network.psimi.xml");
   final File input = new File(RESOURCE_DIR + "unsimplified_network.psimi.xml");
   final File output = new File("simplifiednetwork.psimi.xml.tmp");
   output.deleteOnExit();
   NetworkPreparer prep = new NetworkPreparer();
   EntrySet entrySet = NetworkUtils.readNetwork(input);
   entrySet = prep.simplify(entrySet);
   NetworkUtils.writeNetwork(entrySet, output);
   assertTrue("Simplified file is wrong", FileUtils.contentEquals(expected, output));
   output.delete();
 }
示例#4
0
  private void testWrite(AssetFile asset) throws IOException {
    Path tmpFile = Files.createTempFile("disunity", null);

    try {
      asset.save(tmpFile);

      if (!FileUtils.contentEquals(asset.getSourceFile().toFile(), tmpFile.toFile())) {
        throw new IOException("Files are not equal");
      }
    } finally {
      Files.deleteIfExists(tmpFile);
    }
  }
示例#5
0
  @org.junit.Test
  public void parseTest() throws IOException {
    if (htmlExpectFile != null)
      assertNotNull("Missing expect file: " + htmlExpectFile.getAbsolutePath(), htmlFile);
    Object retVal = null;
    try {
      CreoleParser parser = new CreoleParser();
      parser.setPrivileges(EnumSet.allOf(JCreolePrivilege.class));
      /* Replace the statement above with something like this to test
       * privileges:
      parser.setPrivileges(EnumSet.of(
              JCreolePrivilege.ENUMFORMATS,
              JCreolePrivilege.TOC,
              JCreolePrivilege.RAWHTML,
              JCreolePrivilege.STYLESHEET,
              JCreolePrivilege.JCXBLOCK,
              JCreolePrivilege.JCXSPAN,
              JCreolePrivilege.STYLER
      ));
      */
      parser.setInterWikiMapper(
          new InterWikiMapper() {
            // Use wiki name of "nil" to force lookup failure for path.
            // Use wiki page of "nil" to force lookup failure for label.
            public String toPath(String wikiName, String wikiPage) {
              if (wikiName != null && wikiName.equals("nil")) return null;
              return "{WIKI-LINK to: " + wikiName + '|' + wikiPage + '}';
            }

            public String toLabel(String wikiName, String wikiPage) {
              if (wikiPage == null)
                throw new RuntimeException("Null page name sent to InterWikiMapper");
              if (wikiPage.equals("nil")) return null;
              return "{LABEL for: " + wikiName + '|' + wikiPage + '}';
            }
          });
      retVal = parser.parse(CreoleScanner.newCreoleScanner(creoleFile, false, null));
    } catch (Exception e) {
      if (!shouldSucceed) return; // A ok.  No output file to write.
      AssertionError ae = new AssertionError("Failed to parse '" + creoleFile + "'");
      ae.initCause(e);
      throw ae;
    }
    FileUtils.writeStringToFile(
        htmlFile, ((retVal == null) ? "" : (((WashedSymbol) retVal).toString())), "UTF-8");
    if (!shouldSucceed) fail("Should have failed, but generated '" + htmlFile + "'");
    assertTrue(
        "From '" + creoleFile + "':  '" + htmlFile + "' != '" + htmlExpectFile + "'",
        FileUtils.contentEquals(htmlExpectFile, htmlFile));
    htmlFile.delete();
  }
示例#6
0
  @Test
  public void testCopyLargeFileChannels() throws IOException {
    final File ifile = new File("test/VASSAL/tools/io/IOUtilsTest.java");
    final File ofile = new File("test/VASSAL/tools/io/test.out");

    try {
      final FileInputStream in = new FileInputStream(ifile);
      final FileOutputStream out = new FileOutputStream(ofile);

      final long count = IOUtils.copy(in, out);

      assertEquals(ifile.length(), count);
      assertTrue(FileUtils.contentEquals(ifile, ofile));
    } finally {
      ofile.delete();
    }
  }
示例#7
0
 @Test
 public void compareRobotGoalFiles() throws IOException {
   boolean result =
       FileUtils.contentEquals(new File(AGENT_GOAL_FILE), new File(AGENT_GOAL_FILE_WORKING));
   assertTrue("AGENT_GOAL_FILE <==> AGENT_GOAL_FILE_WORKING", result);
 }
示例#8
0
  public void merge() throws IOException {
    System.out.println("Enter the manifest file that is going to be the source: ");
    source = scan.next();
    // set file to MT
    File mt = new File(dir + "\\manifest\\MT");

    // set file to MR
    File mr = new File(dir + "\\manifest\\MR");

    // set file to MS
    File ms = new File(dir + "\\manifest\\MS");

    // Grabs the locations of the checkin file AKA TGT file
    String manifestR = manifestReader(source);
    System.out.println(manifestR);
    File srcDir = new File(manifestR);
    // srcDir.renameTo(mt); // renames the file

    // Sets the location of the merge files
    File mergeDir = Create_Repo.DirLeaf();

    // Copies the TGT file to the location of the merge file
    FileUtils.copyDirectory(srcDir, mergeDir);

    System.out.println("Enter how many directory is merging into the source (1 or 2)");
    int numDir = scan.nextInt();
    if (numDir == 1) {
      System.out.println("Enter the directory of the PTree you want to merge with the source: ");
      String m1 = scan.next();
      File file1 = new File(m1);
      boolean isTwoEqual = FileUtils.contentEquals(srcDir, file1);
      if (isTwoEqual == true) {
        file1.renameTo(mr); // renames the file
        FileUtils.copyDirectory(file1, mergeDir); // copies the file to
        // PTree folder
      }
    } else {
      System.out.println(
          "Enter the directory of the 1st PTree you want to merge with the source: ");
      String m1 = scan.next();
      File file1 = new File(m1);

      System.out.println(
          "Enter the directory of the 2nd PTree you want to merge with the source: ");
      String m2 = scan.next();
      File file2 = new File(m2);

      boolean isTwoEqual0 = FileUtils.contentEquals(srcDir, file1);
      if (isTwoEqual0 == true) {
        file1.renameTo(mr); // renames the file
        FileUtils.copyDirectory(file1, mergeDir); // copies the file to
        // PTree folder
      }

      boolean isTwoEqual1 = FileUtils.contentEquals(srcDir, file2);
      if (isTwoEqual1 == true) {
        file1.renameTo(ms); // renames the file
        FileUtils.copyDirectory(file2, mergeDir); // copies the file to
        // PTree folder
      }
    }
  }
 @SuppressWarnings("rawtypes")
 public void testSchemaful() {
   try {
     File file = new File("target/classad-wtih-temporals.adm");
     File expected =
         new File(getClass().getResource("/results/classad-with-temporals.adm").toURI().getPath());
     FileUtils.deleteQuietly(file);
     PrintStream printStream = new PrintStream(Files.newOutputStream(Paths.get(file.toURI())));
     String[] recordFieldNames = {
       "GlobalJobId",
       "Owner",
       "ClusterId",
       "ProcId",
       "RemoteWallClockTime",
       "CompletionDate",
       "QDate",
       "JobCurrentStartDate",
       "JobStartDate",
       "JobCurrentStartExecutingDate"
     };
     IAType[] recordFieldTypes = {
       BuiltinType.ASTRING,
       BuiltinType.ASTRING,
       BuiltinType.AINT32,
       BuiltinType.AINT32,
       BuiltinType.ADURATION,
       BuiltinType.ADATETIME,
       BuiltinType.ADATETIME,
       BuiltinType.ADATETIME,
       BuiltinType.ADATETIME,
       BuiltinType.ADATETIME
     };
     ARecordType recordType = new ARecordType("value", recordFieldNames, recordFieldTypes, true);
     int numOfTupleFields = 1;
     ISerializerDeserializer[] serdes = new ISerializerDeserializer[1];
     serdes[0] = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(recordType);
     IPrinterFactory[] printerFactories = new IPrinterFactory[1];
     printerFactories[0] = AqlADMPrinterFactoryProvider.INSTANCE.getPrinterFactory(recordType);
     // create output descriptor
     IPrinter[] printers = new IPrinter[printerFactories.length];
     for (int i = 0; i < printerFactories.length; i++) {
       printers[i] = printerFactories[i].createPrinter();
     }
     ClassAdObjectPool objectPool = new ClassAdObjectPool();
     String[] files = new String[] {"/classad-with-temporals.classads"};
     ClassAdParser parser =
         new ClassAdParser(recordType, false, false, false, null, null, null, objectPool);
     ArrayTupleBuilder tb = new ArrayTupleBuilder(numOfTupleFields);
     for (String path : files) {
       List<Path> paths = new ArrayList<>();
       paths.add(Paths.get(getClass().getResource(path).toURI()));
       FileSystemWatcher watcher = new FileSystemWatcher(paths, null, false);
       LocalFSInputStream in = new LocalFSInputStream(watcher);
       SemiStructuredRecordReader recordReader = new SemiStructuredRecordReader(in, "[", "]");
       while (recordReader.hasNext()) {
         tb.reset();
         IRawRecord<char[]> record = recordReader.next();
         parser.parse(record, tb.getDataOutput());
         tb.addFieldEndOffset();
         printTuple(tb, printers, printStream);
       }
       recordReader.close();
       printStream.close();
       Assert.assertTrue(FileUtils.contentEquals(file, expected));
     }
   } catch (Throwable th) {
     System.err.println("TEST FAILED");
     th.printStackTrace();
     Assert.assertTrue(false);
   }
   System.err.println("TEST PASSED");
 }
示例#10
0
 /**
  * 判断文件内容是否相同
  *
  * @param file1
  * @param file2
  * @return
  * @throws IOException
  */
 public static boolean equals4Content(File file1, File file2) throws IOException {
   return FileUtils.contentEquals(file1, file2);
 }