當前位置: 首頁>>代碼示例>>Java>>正文


Java TemporaryFolder.newFile方法代碼示例

本文整理匯總了Java中org.junit.rules.TemporaryFolder.newFile方法的典型用法代碼示例。如果您正苦於以下問題:Java TemporaryFolder.newFile方法的具體用法?Java TemporaryFolder.newFile怎麽用?Java TemporaryFolder.newFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.junit.rules.TemporaryFolder的用法示例。


在下文中一共展示了TemporaryFolder.newFile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: FakeWikidataLuceneIndexFactory

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
public FakeWikidataLuceneIndexFactory() throws IOException {
    TemporaryFolder temporaryFolder = new TemporaryFolder();
    temporaryFolder.create();

    File fakeDumpFile = temporaryFolder.newFile("wikidata-20160829-all.json.gz");
    compressFileToGzip(new File(FakeWikidataLuceneIndexFactory.class.getResource("/wikidata-20160829-all.json").getPath()), fakeDumpFile);
    MwLocalDumpFile fakeDump = new MwLocalDumpFile(fakeDumpFile.getPath());

    File dbFile = temporaryFolder.newFile();
    dbFile.delete();
    try (WikidataTypeHierarchy typeHierarchy = new WikidataTypeHierarchy(dbFile.toPath())) {
        index = new LuceneIndex(temporaryFolder.newFolder().toPath());
        DumpProcessingController dumpProcessingController = new DumpProcessingController("wikidatawiki");
        dumpProcessingController.setDownloadDirectory(temporaryFolder.newFolder().toString());
        dumpProcessingController.registerEntityDocumentProcessor(typeHierarchy.getUpdateProcessor(), null, true);
        dumpProcessingController.processDump(fakeDump);

        dumpProcessingController.registerEntityDocumentProcessor(
                new WikidataResourceProcessor(new LuceneLoader(index), dumpProcessingController.getSitesInformation(), typeHierarchy),
                null,
                true
        );
        dumpProcessingController.processDump(fakeDump);
        index.refreshReaders();
    }
}
 
開發者ID:askplatypus,項目名稱:platypus-kb-lucene,代碼行數:27,代碼來源:FakeWikidataLuceneIndexFactory.java

示例2: reinitialiseGraph

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
public void reinitialiseGraph(final TemporaryFolder testFolder, final Schema schema, final StoreProperties storeProperties) throws IOException {
    FileUtils.writeByteArrayToFile(testFolder.newFile("schema.json"), schema
            .toJson(true));

    try (OutputStream out = new FileOutputStream(testFolder.newFile("store.properties"))) {
        storeProperties.getProperties()
                       .store(out, "This is an optional header comment string");
    }

    // set properties for REST service
    System.setProperty(SystemProperty.STORE_PROPERTIES_PATH, testFolder.getRoot() + "/store.properties");
    System.setProperty(SystemProperty.SCHEMA_PATHS, testFolder.getRoot() + "/schema.json");
    System.setProperty(SystemProperty.GRAPH_ID, "graphId");

    reinitialiseGraph();
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:17,代碼來源:RestApiTestClient.java

示例3: copyToTemporary

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
/**
 * <br> Copy a file to a temporary folder <br><br>
 *
 * Note: by creating a copy of a file in the resources folder, tests can
 * change the contents of a file without consequences.
 *
 * Note: there might be easier ways to copy a file. By creating a copy
 * of the overview by invoking the save method on an overview object, the
 * helper method is a test in itself.
 *
 * @param temporaryFolder folder in which to create the new file
 * @param originalFile the original file
 * @param newFileName file name, no path
 * @return the new file as a file type object
 */
static File copyToTemporary (TemporaryFolder temporaryFolder,
                             File originalFile, String newFileName) {

    // get the overview from an existing test XML overview file
    final XMLOverview xmlOverview = new XMLOverview(originalFile);

    // try to save the overview under another, new name
    File newFile = null;
    try {
        // create a new temporary file
        newFile = temporaryFolder.newFile(newFileName);

        // save the overview in the temporary file, creating a copy
        xmlOverview.save(newFile);
    } catch (IOException e) {
        fail();
        e.printStackTrace();
    }

    return newFile;
}
 
開發者ID:clarin-eric,項目名稱:oai-harvest-manager,代碼行數:37,代碼來源:TestHelper.java

示例4: downloadStr

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
private static String downloadStr(String queryUrl, int limitFrom, int limitTo, boolean noMeta, boolean count, TemporaryFolder temp) throws Exception {
    File f = temp.newFile();
    String url = "http://localhost:9000/js?query=" + URLEncoder.encode(queryUrl, "UTF-8");
    if (limitFrom >= 0) {
        url += "&limit=" + limitFrom;
    }
    if (limitTo >= 0) {
        url += "," + limitTo;
    }

    if (noMeta) {
        url += "&nm=true";
    }

    if (count) {
        url += "&count=true";
    }

    HttpTestUtils.download(HttpTestUtils.clientBuilder(false), url, f);
    return Files.readStringFromFile(f);
}
 
開發者ID:bluestreak01,項目名稱:questdb,代碼行數:22,代碼來源:QueryHandlerTest.java

示例5: write

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static <D> File write(TemporaryFolder temp, GenericData model, Schema schema, D... data) throws IOException {
  File file = temp.newFile();
  Assert.assertTrue(file.delete());
  ParquetWriter<D> writer = AvroParquetWriter
      .<D>builder(new Path(file.toString()))
      .withDataModel(model)
      .withSchema(schema)
      .build();

  try {
    for (D datum : data) {
      writer.write(datum);
    }
  } finally {
    writer.close();
  }

  return file;
}
 
開發者ID:apache,項目名稱:parquet-mr,代碼行數:21,代碼來源:AvroTestUtil.java

示例6: setup

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
@Before
public void setup() throws Exception
{
    tmpDir = new TemporaryFolder();
    tmpDir.create();
    
    dbFile = tmpDir.newFile( "spacereclaimer.db" );

    //System.out.println(dbFile.getAbsolutePath());
    rm = new RecordManager( dbFile.getAbsolutePath() );
    rm.setPageReclaimerThreshold( 10 );
    
    uidTree = ( PersistedBTree<Integer, String> ) rm.addBTree( TREE_NAME, IntSerializer.INSTANCE, StringSerializer.INSTANCE, false );
}
 
開發者ID:apache,項目名稱:directory-mavibot,代碼行數:15,代碼來源:PageReclaimerTest.java

示例7: createFile

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
public static File createFile(TemporaryFolder folder, String stm, String fileName) throws IOException {
    File sqlFile =  folder.newFile(fileName);
    BufferedWriter writer = new BufferedWriter(new FileWriter(sqlFile));
    writer.write(stm);
    writer.close();

    return sqlFile;
}
 
開發者ID:sogis,項目名稱:gretl,代碼行數:9,代碼來源:TestUtil.java

示例8: getFileFromResource

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
public static File getFileFromResource(Object obj, String resourceName) throws IOException {
    TemporaryFolder folder = new TemporaryFolder();
    folder.create();
    File file = folder.newFile(resourceName);

    InputStream stream = obj.getClass().getClassLoader().getResourceAsStream(resourceName);

    byte[] buffer = new byte[stream.available()];
    stream.read(buffer);

    OutputStream outStream = new FileOutputStream(file);
    outStream.write(buffer);

    return file;
}
 
開發者ID:blablacar,項目名稱:android-validator,代碼行數:16,代碼來源:Utils.java

示例9: setUp

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
@Before
public void setUp() throws IOException, FileNotFoundException, JAXBException {
    this.delegate = new WorkflowInputDelegate();
    this.jcommander = new JCommander(delegate);
    WorkflowTrace trace = new WorkflowTrace();
    tempFolder = new TemporaryFolder();
    tempFolder.create();
    tempFile = tempFolder.newFile();
    WorkflowTraceSerializer.write(tempFile, trace);
}
 
開發者ID:RUB-NDS,項目名稱:TLS-Attacker,代碼行數:11,代碼來源:WorkflowInputDelegateTest.java

示例10: file

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
protected File file(TemporaryFolder temporaryFolder, byte[] contents) throws IOException {
  File result = temporaryFolder.newFile();
  try (OutputStream stream = new FileOutputStream(result)) {
    stream.write(contents);
  }
  return result;
}
 
開發者ID:Enterprise-Content-Management,項目名稱:infoarchive-sip-sdk,代碼行數:8,代碼來源:TestCase.java

示例11: run

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
@Test
public void run() throws IOException {
	TemporaryFolder folder = new TemporaryFolder();
	folder.create();
	Settings settings = new Settings();
	settings.setProperty(Constants.PLUGIN_SKIP_CUSTOM_RULES, false);
	String dirPath = "..\\grammars\\tsql";
	File dir = new File(dirPath);
	Collection<File> files = FileUtils.listFiles(dir, new String[] { "sql" }, true);
	SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
	for (File f : files) {
		String tempName = f.getName() + System.nanoTime();
		File dest = folder.newFile(tempName);
		FileUtils.copyFile(f, dest);

		DefaultInputFile file1 = new DefaultInputFile("test", tempName);
		file1.initMetadata(new String(Files.readAllBytes(f.toPath())));
		file1.setLanguage(TSQLLanguage.KEY);
		ctxTester.fileSystem().add(file1);

	}
	HighlightingSensor sensor = new HighlightingSensor(settings);
	sensor.execute(ctxTester);
	Collection<Issue> issues = ctxTester.allIssues();
	// System.out.println(files.size() + " " + issues.size() + " " + took);
	Assert.assertEquals(97, issues.size());

}
 
開發者ID:gretard,項目名稱:sonar-tsql-plugin,代碼行數:29,代碼來源:PluginRulesVerifierTest.java

示例12: copyFileFromResources

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
/**
 * Copies the resources file at the given path to a new file in the provided {@link TemporaryFolder} instance.
 *
 * @param path the path in the JAR's resources to copy from
 * @param temporaryFolder the temporary folder to copy into
 * @return the created copy
 */
public static File copyFileFromResources(String path, TemporaryFolder temporaryFolder) {
    try {
        Path source = getJarPath(path);
        File destination = temporaryFolder.newFile();
        Files.copy(source, destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
        return destination;
    } catch (IOException e) {
        throw new IllegalStateException("Could not copy test file", e);
    }
}
 
開發者ID:AuthMe,項目名稱:ConfigMe,代碼行數:18,代碼來源:TestUtils.java

示例13: getTestFile

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
public static File getTestFile (TemporaryFolder tmpFolder, String fileName, long fileSize) throws IOException
{
    byte data [] = new byte[(int) fileSize] ;
    for (int i = 0 ; i < fileSize ; ++i)
    	data[i] = (byte)(Math.random() * 256) ;

    File file = tmpFolder.newFile(fileName) ;
    
	// generate test file
	FileOutputStream out = new FileOutputStream(file);
  	out.write(data);
	out.close();
    
    return file ;
}
 
開發者ID:roikku,項目名稱:swift-explorer,代碼行數:16,代碼來源:TestUtils.java

示例14: recursiveDeleteFolderWithOneElement

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
@Test
public void recursiveDeleteFolderWithOneElement() throws IOException {
    TemporaryFolder folder = new TemporaryFolder();
    folder.create();
    File file = folder.newFile("a");
    folder.delete();
    assertFalse(file.exists());
    assertFalse(folder.getRoot().exists());
}
 
開發者ID:DIVERSIFY-project,項目名稱:sosiefier,代碼行數:10,代碼來源:TempFolderRuleTest.java

示例15: recursiveDeleteFolderWithOneRandomElement

import org.junit.rules.TemporaryFolder; //導入方法依賴的package包/類
@Test
public void recursiveDeleteFolderWithOneRandomElement() throws IOException {
    TemporaryFolder folder = new TemporaryFolder();
    folder.create();
    File file = folder.newFile();
    folder.delete();
    assertFalse(file.exists());
    assertFalse(folder.getRoot().exists());
}
 
開發者ID:DIVERSIFY-project,項目名稱:sosiefier,代碼行數:10,代碼來源:TempFolderRuleTest.java


注:本文中的org.junit.rules.TemporaryFolder.newFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。