Java Code Examples for org.junit.rules.TemporaryFolder#getRoot()

The following examples show how to use org.junit.rules.TemporaryFolder#getRoot() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Util.java    From graphicsfuzz with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 2
Source File: DocGeneratorTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example 3
Source File: TestUtil.java    From r2cloud with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: DocGeneratorTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example 5
Source File: SystemdApplicationTest.java    From gradle-plugins with Apache License 2.0 4 votes vote down vote up
@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"));
}
 
Example 6
Source File: TestCatalogResource.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@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());
}