当前位置: 首页>>代码示例>>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;未经允许,请勿转载。