org.junit.rules.TemporaryFolder#getRoot()源码实例Demo

下面列出了org.junit.rules.TemporaryFolder#getRoot() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: graphicsfuzz   文件: Util.java
static File validateAndGetImage(
    ShaderJob shaderJob,
    String shaderJobFilename,
    TemporaryFolder temporaryFolder,
    ShaderJobFileOperations fileOps)
    throws IOException, InterruptedException {
  final File shaderJobFile = new File(
      temporaryFolder.getRoot(),
      shaderJobFilename);
  fileOps.writeShaderJobFile(shaderJob, shaderJobFile);
  return validateAndGetImage(shaderJobFile, temporaryFolder, fileOps);
}
 
源代码2 项目: localization_nifi   文件: DocGeneratorTest.java
@Test
public void testProcessorLoadsNarResources() throws IOException, ClassNotFoundException {
    TemporaryFolder temporaryFolder = new TemporaryFolder();
    temporaryFolder.create();

    NiFiProperties properties = loadSpecifiedProperties("/conf/nifi.properties",
            NiFiProperties.COMPONENT_DOCS_DIRECTORY,
            temporaryFolder.getRoot().getAbsolutePath());

    NarUnpacker.unpackNars(properties);

    NarClassLoaders.getInstance().init(properties.getFrameworkWorkingDirectory(), properties.getExtensionsWorkingDirectory());

    ExtensionManager.discoverExtensions(NarClassLoaders.getInstance().getExtensionClassLoaders());

    DocGenerator.generate(properties);

    File processorDirectory = new File(temporaryFolder.getRoot(), "org.apache.nifi.processors.WriteResourceToStream");
    File indexHtml = new File(processorDirectory, "index.html");
    Assert.assertTrue(indexHtml + " should have been generated", indexHtml.exists());
    String generatedHtml = FileUtils.readFileToString(indexHtml);
    Assert.assertNotNull(generatedHtml);
    Assert.assertTrue(generatedHtml.contains("This example processor loads a resource from the nar and writes it to the FlowFile content"));
    Assert.assertTrue(generatedHtml.contains("files that were successfully processed"));
    Assert.assertTrue(generatedHtml.contains("files that were not successfully processed"));
    Assert.assertTrue(generatedHtml.contains("resources"));
}
 
源代码3 项目: r2cloud   文件: TestUtil.java
public static File setupClasspathResource(TemporaryFolder tempFolder, String name) throws IOException {
	URL resource = TestUtil.class.getClassLoader().getResource(name);
	if (resource == null) {
		throw new IllegalArgumentException("unable to find: " + name + " in classpath");
	}
	if (resource.getProtocol().equals("file")) {
		return new File(resource.getFile());
	}
	// copy only if resource is in jar
	File result = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
	try (FileOutputStream fos = new FileOutputStream(result); InputStream is = resource.openStream()) {
		Util.copy(is, fos);
	}
	return result;
}
 
源代码4 项目: nifi   文件: DocGeneratorTest.java
@Test
public void testProcessorLoadsNarResources() throws IOException, ClassNotFoundException {
    TemporaryFolder temporaryFolder = new TemporaryFolder();
    temporaryFolder.create();

    NiFiProperties properties = loadSpecifiedProperties("/conf/nifi.properties",
            NiFiProperties.COMPONENT_DOCS_DIRECTORY,
            temporaryFolder.getRoot().getAbsolutePath());

    final Bundle systemBundle = SystemBundle.create(properties);
    final ExtensionMapping mapping = NarUnpacker.unpackNars(properties, systemBundle);

    NarClassLoadersHolder.getInstance().init(properties.getFrameworkWorkingDirectory(), properties.getExtensionsWorkingDirectory());

    final ExtensionDiscoveringManager extensionManager = new StandardExtensionDiscoveringManager();
    extensionManager.discoverExtensions(systemBundle, NarClassLoadersHolder.getInstance().getBundles());

    DocGenerator.generate(properties, extensionManager, mapping);

    final String extensionClassName = "org.apache.nifi.processors.WriteResourceToStream";
    final BundleCoordinate coordinate = mapping.getProcessorNames().get(extensionClassName).stream().findFirst().get();
    final String path = coordinate.getGroup() + "/" + coordinate.getId() + "/" + coordinate.getVersion() + "/" + extensionClassName;
    File processorDirectory = new File(temporaryFolder.getRoot(), path);
    File indexHtml = new File(processorDirectory, "index.html");
    Assert.assertTrue(indexHtml + " should have been generated", indexHtml.exists());
    String generatedHtml = FileUtils.readFileToString(indexHtml, Charset.defaultCharset());
    Assert.assertNotNull(generatedHtml);
    Assert.assertTrue(generatedHtml.contains("This example processor loads a resource from the nar and writes it to the FlowFile content"));
    Assert.assertTrue(generatedHtml.contains("files that were successfully processed"));
    Assert.assertTrue(generatedHtml.contains("files that were not successfully processed"));
    Assert.assertTrue(generatedHtml.contains("resources"));
}
 
源代码5 项目: gradle-plugins   文件: SystemdApplicationTest.java
@Test
public void check() throws IOException {
    File tempDir = new File("build/tmp");
    tempDir.mkdirs();
    testFolder = new TemporaryFolder(tempDir);

    testFolder.create();
    workingDir = new File(testFolder.getRoot(), "demo");
    workingDir.mkdirs();

    File javaFolder = new File(workingDir, "src/main/java/example");
    javaFolder.mkdirs();
    File rpmFolder = new File(workingDir, "src/main/rpm");
    rpmFolder.mkdirs();

    System.setProperty("org.gradle.daemon", "false");

    File gradleFile = new File(workingDir, "build.gradle");
    File settingsFile = new File(workingDir, "settings.gradle");
    File entityFile = new File(javaFolder, "Main.java");
    File propertiesFile = new File(rpmFolder, "application.properties");

    Assert.assertNotNull(getClass().getClassLoader().getResource("plugin-under-test-metadata.properties"));

    IOUtils.copy(getClass().getClassLoader().getResourceAsStream("helm-app/input.gradle"),
            new FileOutputStream(gradleFile));
    IOUtils.copy(getClass().getClassLoader().getResourceAsStream("helm-app/input_settings.gradle"),
            new FileOutputStream(settingsFile));
    IOUtils.copy(getClass().getClassLoader().getResourceAsStream("helm-app/input_main.java"),
            new FileOutputStream(entityFile));
    IOUtils.copy(getClass().getClassLoader().getResourceAsStream("helm-app/input_application.properties"),
            new FileOutputStream(propertiesFile));

    GradleRunner runner = GradleRunner.create();
    runner = runner.forwardOutput();
    runner = runner.withPluginClasspath();
    runner = runner.withProjectDir(workingDir).withArguments("buildRpm", "--stacktrace").forwardOutput();
    runner.build();

    File rpmFile = new File(workingDir, "build/distributions/demo.rpm");
    Assert.assertTrue(rpmFile.exists());

    File serviceFile = new File(workingDir, "build/systemd/services/demo-app.service");
    Assert.assertTrue(serviceFile.exists());

    String serviceDesc = IOUtils.toString(new FileInputStream(serviceFile));
    Assert.assertTrue(serviceDesc.contains("ExecStart=/var/demo-app/bin/demo run"));
}
 
源代码6 项目: dremio-oss   文件: TestCatalogResource.java
@Test
public void testVDSInSpaceWithSameName() throws Exception {
  final String sourceName = "src_" + System.currentTimeMillis();

  SourceUI source = new SourceUI();
  source.setName(sourceName);
  source.setCtime(1000L);

  TemporaryFolder folder = new TemporaryFolder();
  folder.create();

  final NASConf config = new NASConf();
  config.path = folder.getRoot().getAbsolutePath();
  source.setConfig(config);

  java.io.File srcFolder = folder.getRoot();

  PrintStream file = new PrintStream(new java.io.File(srcFolder.getAbsolutePath(), "myFile.json"));
  for (int i = 0; i < 10; i++) {
    file.println("{a:{b:[1,2]}}");
  }
  file.close();

  newSourceService().registerSourceWithRuntime(source);

  final DatasetPath path1 = new DatasetPath(ImmutableList.of(sourceName, "myFile.json"));
  final DatasetConfig dataset1 = new DatasetConfig()
    .setType(DatasetType.PHYSICAL_DATASET_SOURCE_FOLDER)
    .setFullPathList(path1.toPathList())
    .setName(path1.getLeaf().getName())
    .setCreatedAt(System.currentTimeMillis())
    .setTag(null)
    .setOwner(DEFAULT_USERNAME)
    .setPhysicalDataset(new PhysicalDataset()
      .setFormatSettings(new FileConfig().setType(FileType.JSON)));
  p(NamespaceService.class).get().addOrUpdateDataset(path1.toNamespaceKey(), dataset1);

  DatasetPath vdsPath = new DatasetPath(ImmutableList.of("@dremio", "myFile.json"));
  createDatasetFromSQLAndSave(vdsPath, "SELECT * FROM \"myFile.json\"", asList(sourceName));

  final String query = "select * from \"myFile.json\"";
  submitJobAndWaitUntilCompletion(
    JobRequest.newBuilder()
      .setSqlQuery(new SqlQuery(query, ImmutableList.of("@dremio"), DEFAULT_USERNAME))
      .setQueryType(QueryType.UI_INTERNAL_RUN)
      .setDatasetPath(DatasetPath.NONE.toNamespaceKey())
      .build());
}