本文整理汇总了Java中org.junit.rules.TemporaryFolder类的典型用法代码示例。如果您正苦于以下问题:Java TemporaryFolder类的具体用法?Java TemporaryFolder怎么用?Java TemporaryFolder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TemporaryFolder类属于org.junit.rules包,在下文中一共展示了TemporaryFolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beforeClass
import org.junit.rules.TemporaryFolder; //导入依赖的package包/类
public static void beforeClass(TemporaryFolder junitFolder) throws IOException {
if (System.getProperties().getProperty("MCR.Home") == null) {
File baseDir = junitFolder.newFolder("mcrhome");
System.out.println("Setting MCR.Home=" + baseDir.getAbsolutePath());
System.getProperties().setProperty("MCR.Home", baseDir.getAbsolutePath());
}
if (System.getProperties().getProperty("MCR.AppName") == null) {
String currentComponentName = getCurrentComponentName();
System.out.println("Setting MCR.AppName=" + currentComponentName);
System.getProperties().setProperty("MCR.AppName", getCurrentComponentName());
}
File configDir = new File(System.getProperties().getProperty("MCR.Home"),
System.getProperties().getProperty("MCR.AppName"));
System.out.println("Creating config directory: " + configDir);
configDir.mkdirs();
}
示例2: gradleFile
import org.junit.rules.TemporaryFolder; //导入依赖的package包/类
static BiConsumer<TemporaryFolder, File> gradleFile(String name) {
return (folder, buildFile) -> {
Path path = Paths.get(String.format(BUILD_FILE_PATH_FORMAT, name));
try (BufferedWriter writer = Files.newBufferedWriter(buildFile.toPath())) {
List<String> input = Files.readAllLines(path);
for (String line : input) {
writer.write(line);
writer.newLine();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
};
}
示例3: test0
import org.junit.rules.TemporaryFolder; //导入依赖的package包/类
public void test0(){
if (System.getenv().get("SKIP_HEAVY")!=null){
return;
}
TemporaryFolder tempSwaggerApis=new TemporaryFolder();
TemporaryFolder tempRAMLApis=new TemporaryFolder();
try{
File fs=File.createTempFile("ddd", "tmp");
FileUtils.copyInputStreamToFile(RegistryManager.getInstance().getClass().getResourceAsStream("/azure-specs.zip"), fs);
tempSwaggerApis.create();
tempRAMLApis.create();
extractFolder(fs.getAbsolutePath(), tempSwaggerApis.getRoot().getAbsolutePath());
WriteApis.write(tempSwaggerApis.getRoot().getAbsolutePath(), tempRAMLApis.getRoot().getAbsolutePath());
tempSwaggerApis.delete();
tempRAMLApis.delete();
}catch (Exception e) {
throw new IllegalStateException();
}
}
示例4: create
import org.junit.rules.TemporaryFolder; //导入依赖的package包/类
public Preferences create(String name, TemporaryFolder folder) {
try {
final File srcDir = folder.newFolder();
final File backupDir = folder.newFolder();
final File lockDir = folder.newFolder();
DirectoryProvider directoryProvider = new DirectoryProvider() {
@Override
public File getStoreDirectory() {
return srcDir;
}
@Override
public File getBackupDirectory() {
return backupDir;
}
@Override
public File getLockDirectory() {
return lockDir;
}
};
return create(name, directoryProvider);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: 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();
}
}
示例6: createZipFile
import org.junit.rules.TemporaryFolder; //导入依赖的package包/类
/**
* Create a zip file with the given lines.
*
* @param expected A list of expected lines, populated in the zip file.
* @param folder A temporary folder used to create files.
* @param filename Optionally zip file name (can be null).
* @param fieldsEntries Fields to write in zip entries.
* @return The zip filename.
* @throws Exception In case of a failure during zip file creation.
*/
private static File createZipFile(
List<String> expected, TemporaryFolder folder, String filename, String[]... fieldsEntries)
throws Exception {
File tmpFile = folder.getRoot().toPath().resolve(filename).toFile();
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(tmpFile));
PrintStream writer = new PrintStream(out, true /* auto-flush on write */);
int index = 0;
for (String[] entry : fieldsEntries) {
out.putNextEntry(new ZipEntry(Integer.toString(index)));
for (String field : entry) {
writer.println(field);
expected.add(field);
}
out.closeEntry();
index++;
}
writer.close();
out.close();
return tmpFile;
}
示例7: parameters
import org.junit.rules.TemporaryFolder; //导入依赖的package包/类
@Parameterized.Parameters
public static Collection<AbstractStateBackend> parameters() throws IOException {
TemporaryFolder tempFolder = new TemporaryFolder();
tempFolder.create();
MemoryStateBackend syncMemBackend = new MemoryStateBackend(MAX_MEM_STATE_SIZE, false);
MemoryStateBackend asyncMemBackend = new MemoryStateBackend(MAX_MEM_STATE_SIZE, true);
FsStateBackend syncFsBackend = new FsStateBackend("file://" + tempFolder.newFolder().getAbsolutePath(), false);
FsStateBackend asyncFsBackend = new FsStateBackend("file://" + tempFolder.newFolder().getAbsolutePath(), true);
RocksDBStateBackend fullRocksDbBackend = new RocksDBStateBackend(new MemoryStateBackend(MAX_MEM_STATE_SIZE), false);
fullRocksDbBackend.setDbStoragePath(tempFolder.newFolder().getAbsolutePath());
RocksDBStateBackend incRocksDbBackend = new RocksDBStateBackend(new MemoryStateBackend(MAX_MEM_STATE_SIZE), true);
incRocksDbBackend.setDbStoragePath(tempFolder.newFolder().getAbsolutePath());
return Arrays.asList(
syncMemBackend,
asyncMemBackend,
syncFsBackend,
asyncFsBackend,
fullRocksDbBackend,
incRocksDbBackend);
}
示例8: 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();
}
示例9: runWorkflow
import org.junit.rules.TemporaryFolder; //导入依赖的package包/类
public static void runWorkflow(TemporaryFolder folder, String resource, Map<String, String> params, Map<String, String> config, int expectedStatus)
throws IOException
{
Path workflow = Paths.get(resource);
Path tempdir = folder.newFolder().toPath();
Path file = tempdir.resolve(workflow.getFileName());
Path configFile = folder.newFolder().toPath().resolve("config");
List<String> configLines = config.entrySet().stream()
.map(e -> e.getKey() + " = " + e.getValue())
.collect(Collectors.toList());
Files.write(configFile, configLines);
List<String> runCommand = new ArrayList<>(asList("run",
"-c", configFile.toAbsolutePath().normalize().toString(),
"-o", tempdir.toString(),
"--project", tempdir.toString(),
workflow.getFileName().toString()));
params.forEach((k, v) -> runCommand.addAll(asList("-p", k + "=" + v)));
try {
copyResource(resource, file);
CommandStatus status = main(runCommand);
assertThat(status.errUtf8(), status.code(), is(expectedStatus));
}
finally {
FileUtils.deleteQuietly(tempdir.toFile());
}
}
示例10: setUpBefore
import org.junit.rules.TemporaryFolder; //导入依赖的package包/类
@Before
public void setUpBefore() throws IOException {
super.setUp();
plugin = new ValidateMojo();
plugin.setLog(log);
plugin.setPropertyDir(getFile(""));
// Use XHTML5 as it is much faster
plugin.setXhtmlSchema(HtmlValidator.XHTML5);
File dictionaryDir = new File(this.getClass().getClassLoader().getResource("").getFile());
plugin.setDictionaryDir(dictionaryDir);
CustomPattern listPattern = new CustomPattern("List", "([A-Z](:[A-Z])+)?", ".list.");
CustomPattern anotherPattern = new CustomPattern("List", "([A-Z](:[A-Z])+)?", new String[] { ".pattern1.",
".pattern2." });
plugin.setCustomPatterns(new CustomPattern[] { listPattern, anotherPattern });
// Junit bug can't use tmpFolder
plugin.setReportsDir(new TemporaryFolder().newFolder());
// Use default configuration for the rest
plugin.initialize();
}
示例11: setUp
import org.junit.rules.TemporaryFolder; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
BrokerService.disableWrapper = disableWrapper;
File tmpRoot = new File("./target/tmp");
tmpRoot.mkdirs();
temporaryFolder = new TemporaryFolder(tmpRoot);
temporaryFolder.create();
if (artemisBroker == null) {
artemisBroker = createArtemisBroker();
}
startBroker();
connectionFactory = createConnectionFactory();
destination = createDestination();
template = createJmsTemplate();
template.setDefaultDestination(destination);
template.setPubSubDomain(useTopic);
template.afterPropertiesSet();
}
示例12: getTestDirectoryWithFiles
import org.junit.rules.TemporaryFolder; //导入依赖的package包/类
public static File getTestDirectoryWithFiles (TemporaryFolder tmpFolder, String directoryName, String fileNamePrefix, int numberOfFiles) throws IOException
{
assert (numberOfFiles >= 0) ;
File folder = tmpFolder.newFolder(directoryName) ;
if (numberOfFiles == 0)
return folder ;
StringBuilder fileNameBase = new StringBuilder () ;
fileNameBase.append(directoryName) ;
fileNameBase.append(File.separator) ;
fileNameBase.append(fileNamePrefix) ;
fileNameBase.append("_") ;
File [] fileList = new File [numberOfFiles] ;
for (int i = 0 ; i < numberOfFiles ; ++i)
{
final String fileName = fileNameBase.toString() + i ;
fileList[i] = getTestFile (tmpFolder, fileName, (long) (Math.random() * 1000 + 1)) ;
}
return folder ;
}
示例13: apply
import org.junit.rules.TemporaryFolder; //导入依赖的package包/类
@Override
public Statement apply(final Statement statement, Description description) {
final TemporaryFolder tmp = new TemporaryFolder();
return tmp.apply(new Statement() {
@Override
public void evaluate() throws Throwable {
try {
wc = WorkingCopy.prepareFor(getJarUnderTest(tmp, jar));
statement.evaluate();
} finally {
if (wc != null) {
wc.close();
}
}
}
}, description);
}
示例14: 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;
}
示例15: createEnvironment
import org.junit.rules.TemporaryFolder; //导入依赖的package包/类
private void createEnvironment() throws IOException, PersistitException {
closeDb();
temporaryFolder = new TemporaryFolder();
temporaryFolder.create();
persistit = new Persistit();
persistit.setPersistitLogger(new Slf4jAdapter(LoggerFactory.getLogger("PERSISTIT")));
Properties props = new Properties();
props.setProperty("datapath", temporaryFolder.getRoot().getAbsolutePath());
props.setProperty("logpath", "${datapath}/log");
props.setProperty("logfile", "${logpath}/persistit_${timestamp}.log");
props.setProperty("buffer.count.8192", "5000");
props.setProperty("journalpath", "${datapath}/journal");
props.setProperty("tmpvoldir", "${datapath}");
props.setProperty("volume.1", "${datapath}/persistit,create,pageSize:8192,initialPages:10,extensionPages:100,maximumPages:25000");
props.setProperty("jmx", "false");
persistit.setProperties(props);
persistit.initialize();
volume = persistit.createTemporaryVolume();
}