本文整理汇总了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();
}
}
示例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();
}
示例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;
}
示例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);
}
示例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;
}
示例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 );
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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());
}
示例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);
}
}
示例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 ;
}
示例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());
}
示例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());
}