Java Code Examples for org.junit.rules.TemporaryFolder#create()
The following examples show how to use
org.junit.rules.TemporaryFolder#create() .
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: MiniOzoneClusterImpl.java From hadoop-ozone with Apache License 2.0 | 6 votes |
protected void configureRecon() throws IOException { ConfigurationProvider.resetConfiguration(); TemporaryFolder tempFolder = new TemporaryFolder(); tempFolder.create(); File tempNewFolder = tempFolder.newFolder(); conf.set(OZONE_RECON_DB_DIR, tempNewFolder.getAbsolutePath()); conf.set(OZONE_RECON_OM_SNAPSHOT_DB_DIR, tempNewFolder .getAbsolutePath()); conf.set(OZONE_RECON_SCM_DB_DIR, tempNewFolder.getAbsolutePath()); conf.set(OZONE_RECON_SQL_DB_JDBC_URL, "jdbc:derby:" + tempNewFolder.getAbsolutePath() + "/ozone_recon_derby.db"); conf.set(OZONE_RECON_HTTP_ADDRESS_KEY, "0.0.0.0:0"); conf.set(OZONE_RECON_DATANODE_ADDRESS_KEY, "0.0.0.0:0"); ConfigurationProvider.setConfiguration(conf); }
Example 2
Source File: MessageTest.java From iaf with Apache License 2.0 | 6 votes |
@Test public void testSerializeWithURL() throws Exception { TemporaryFolder folder = new TemporaryFolder(); folder.create(); File file = folder.newFile(); writeContentsToFile(file, testString); URL source = file.toURL(); Message in = new Message(source); byte[] wire = serializationTester.serialize(in); writeContentsToFile(file, "fakeContentAsReplacementOfThePrevious"); Message out = serializationTester.deserialize(wire); assertTrue(out.isBinary()); assertEquals(testString,out.asString()); }
Example 3
Source File: WorkMgrTest.java From batfish with Apache License 2.0 | 6 votes |
@Test public void testRemoveFromSerializedListEmptyBaseList() throws IOException { TemporaryFolder tmp = new TemporaryFolder(); tmp.create(); File serializedList = tmp.newFile(); Path serializedListPath = serializedList.toPath(); // Write empty base serialized list List<NodeInterfacePair> interfaces = new ArrayList<>(); writeFile(serializedListPath, BatfishObjectMapper.writePrettyString(interfaces)); removeFromSerializedList( serializedListPath, ImmutableList.of(), new TypeReference<List<NodeInterfacePair>>() {}); // Confirm no issue if base list didn't exist assertThat( BatfishObjectMapper.mapper() .readValue( CommonUtil.readFile(serializedListPath), new TypeReference<List<NodeInterfacePair>>() {}), iterableWithSize(0)); }
Example 4
Source File: WorkMgrTest.java From batfish with Apache License 2.0 | 6 votes |
@Test public void testAddToSerializedListNoAddition() throws IOException { TemporaryFolder tmp = new TemporaryFolder(); tmp.create(); File serializedList = tmp.newFile(); Path serializedListPath = serializedList.toPath(); NodeInterfacePair baseInterface = NodeInterfacePair.of("n1", "iface1"); // Write base serialized list List<NodeInterfacePair> interfaces = new ArrayList<>(); interfaces.add(baseInterface); writeFile(serializedListPath, BatfishObjectMapper.writePrettyString(interfaces)); addToSerializedList( serializedListPath, ImmutableList.of(), new TypeReference<List<NodeInterfacePair>>() {}); // Confirm original interface shows up in the merged list, even if there are no additions assertThat( BatfishObjectMapper.mapper() .readValue( CommonUtil.readFile(serializedListPath), new TypeReference<List<NodeInterfacePair>>() {}), containsInAnyOrder(baseInterface)); }
Example 5
Source File: FileUtilTest.java From cc-dbp with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { folder = new TemporaryFolder(); folder.create(); testDir = folder.newFolder("fileTests"); childDirA = testDir+File.separator+"childDirA"; childDirB = testDir+File.separator+"childDirB"; childDirC = childDirA+File.separator+"childDirC"; childDirD = childDirC+File.separator+"childDirD/"; fileName1 = childDirA+File.separator+"testFile1.txt"; fileName1Zipped = fileName1+".gz"; fileName2 = childDirD+File.separator+"testFile2.txt"; fileName3 = childDirB+File.separator+".testFile3.txt"; objectFileName = childDirA+File.separator+"person1.ser"; objectFileNameZipped = objectFileName+".gz"; fileText = "Sample Text"; }
Example 6
Source File: WorkMgrTest.java From batfish with Apache License 2.0 | 5 votes |
@Test public void testAddToSerializedList() throws IOException { TemporaryFolder tmp = new TemporaryFolder(); tmp.create(); File serializedList = tmp.newFile(); Path serializedListPath = serializedList.toPath(); NodeInterfacePair baseInterface = NodeInterfacePair.of("n1", "iface1"); NodeInterfacePair additionalInterface = NodeInterfacePair.of("n2", "iface2"); // Write base serialized list List<NodeInterfacePair> interfaces = new ArrayList<>(); interfaces.add(baseInterface); writeFile(serializedListPath, BatfishObjectMapper.writePrettyString(interfaces)); addToSerializedList( serializedListPath, ImmutableList.of(additionalInterface), new TypeReference<List<NodeInterfacePair>>() {}); // Confirm the additional and original interfaces show up in the merged list assertThat( BatfishObjectMapper.mapper() .readValue( CommonUtil.readFile(serializedListPath), new TypeReference<List<NodeInterfacePair>>() {}), containsInAnyOrder(baseInterface, additionalInterface)); }
Example 7
Source File: WorkMgrTest.java From batfish with Apache License 2.0 | 5 votes |
@Test public void testDeserializeAndDeleteInterfaceBlacklist_invalidBlacklist() throws IOException { // Invalid blacklist: Should return an empty list and delete file TemporaryFolder tmp = new TemporaryFolder(); tmp.create(); File blacklistFile = tmp.newFile(); Path blacklistPath = blacklistFile.toPath(); writeFile(blacklistPath, "invalid json"); assertThat(deserializeAndDeleteInterfaceBlacklist(blacklistPath), empty()); assertFalse(blacklistFile.exists()); }
Example 8
Source File: RuleKeyLogFileUploaderTest.java From buck with Apache License 2.0 | 5 votes |
@Before public void setUp() throws IOException { TemporaryFolder tempDirectory = new TemporaryFolder(); tempDirectory.create(); filesystem = TestProjectFilesystems.createProjectFilesystem(tempDirectory.getRoot().toPath()); buildReportConfig = FakeBuckConfig.builder().build().getView(BuildReportConfig.class); clock = new DefaultClock(); ruleKeyLogFile = tempDirectory.newFile(BuckConstant.RULE_KEY_LOGGER_FILE_NAME).toPath(); String ruleKeyLogContent = "target\t//test/com/facebook/buck/testutil/integration:util\tbf90764fa7d161f6ac7988dfaeed4f1b6f7d03d1\n"; filesystem.writeContentsToPath(ruleKeyLogContent, ruleKeyLogFile); }
Example 9
Source File: DirConfigSource.java From vespa with Apache License 2.0 | 5 votes |
private static TemporaryFolder createTemporaryFolder() { TemporaryFolder folder = new TemporaryFolder(); try { folder.create(); } catch (IOException e) { throw new RuntimeException(e); } return folder; }
Example 10
Source File: EventTimeWindowCheckpointingITCase.java From flink with Apache License 2.0 | 5 votes |
protected Configuration createClusterConfig() throws IOException { TemporaryFolder temporaryFolder = new TemporaryFolder(); temporaryFolder.create(); final File haDir = temporaryFolder.newFolder(); Configuration config = new Configuration(); config.setString(AkkaOptions.FRAMESIZE, String.valueOf(MAX_MEM_STATE_SIZE) + "b"); if (zkServer != null) { config.setString(HighAvailabilityOptions.HA_MODE, "ZOOKEEPER"); config.setString(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, zkServer.getConnectString()); config.setString(HighAvailabilityOptions.HA_STORAGE_PATH, haDir.toURI().toString()); } return config; }
Example 11
Source File: AmazonS3FileSystemTestHelper.java From iaf with Apache License 2.0 | 5 votes |
@Override public OutputStream _createFile(final String foldername, final String filename) throws IOException { TemporaryFolder folder = new TemporaryFolder(); folder.create(); String fileName = folder.getRoot().getAbsolutePath()+"tempFile"; final File file = new File(fileName); final FileOutputStream fos = new FileOutputStream(file); final BufferedOutputStream bos = new BufferedOutputStream(fos); FilterOutputStream filterOutputStream = new FilterOutputStream(bos) { @Override public void close() throws IOException { super.close(); bos.close(); FileInputStream fis = new FileInputStream(file); ObjectMetadata metaData = new ObjectMetadata(); metaData.setContentLength(file.length()); String filePath = foldername == null ? filename : foldername + "/" + filename; s3Client.putObject(bucketName, filePath, fis, metaData); fis.close(); file.delete(); } }; return filterOutputStream; }
Example 12
Source File: CustomChecksSensorTest.java From sonar-tsql-plugin with GNU General Public License v3.0 | 5 votes |
@Test public void testTSQLGrammarFiles() throws IOException { TemporaryFolder folder = new TemporaryFolder(); folder.create(); SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot()); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP, false); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP_CUSTOM_RULES, false); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP_CUSTOM, false); ctxTester.settings().setProperty(Constants.PLUGIN_MAX_FILE_SIZE, 100); String dirPath = "..\\grammars\\tsql"; File dir = new File(dirPath); Collection<File> files = FileUtils.listFiles(dir, new String[] { "sql" }, true); for (File f : files) { String tempName = f.getName() + System.nanoTime(); File dest = folder.newFile(tempName); FileUtils.copyFile(f, dest); DefaultInputFile file1 = new TestInputFileBuilder(folder.getRoot().getAbsolutePath(), tempName) .initMetadata(new String(Files.readAllBytes(f.toPath()))).setLanguage(TSQLLanguage.KEY).build(); ctxTester.fileSystem().add(file1); } CustomChecksSensor sensor = new CustomChecksSensor(); sensor.execute(ctxTester); Collection<Issue> issues = ctxTester.allIssues(); Assert.assertEquals(183, issues.size()); }
Example 13
Source File: SmtpTestRule.java From james-project with Apache License 2.0 | 5 votes |
@Override public void beforeTest() throws Exception { inMemoryDNSService = new InMemoryDNSService(); folder = new TemporaryFolder(); folder.create(); jamesServer = createJamesServer.build(folder, inMemoryDNSService); jamesServer.start(); createSessionFactory(); }
Example 14
Source File: CustomChecksSensorTest.java From sonar-tsql-plugin with GNU General Public License v3.0 | 5 votes |
@Test public void testSingleFile() throws IOException { TemporaryFolder folder = new TemporaryFolder(); folder.create(); SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot()); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP, false); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP_CUSTOM_RULES, false); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP_CUSTOM, false); ctxTester.settings().setProperty(Constants.PLUGIN_MAX_FILE_SIZE, 100); String tempName = "test.sql"; File f = folder.newFile(tempName); FileUtils.write(f, "select * from dbo.test;\r\n--test", Charset.defaultCharset()); DefaultInputFile file1 = new TestInputFileBuilder(folder.getRoot().getAbsolutePath(), tempName) .initMetadata(new String(Files.readAllBytes(f.toPath()))).setLanguage(TSQLLanguage.KEY).build(); ctxTester.fileSystem().add(file1); CustomChecksSensor sensor = new CustomChecksSensor(); sensor.execute(ctxTester); Collection<Issue> issues = ctxTester.allIssues(); for (Issue i : issues) { System.out.println(i.ruleKey() + " " + i.primaryLocation()); } Assert.assertEquals(1, issues.size()); Assert.assertEquals(2, ctxTester.cpdTokens(file1.key()).size()); Assert.assertEquals(1, ctxTester.highlightingTypeAt(file1.key(), 2, 1).size()); Assert.assertEquals(4, ctxTester.measures(file1.key()).size()); }
Example 15
Source File: ResourceFetcherTest.java From writelatex-git-bridge with MIT License | 4 votes |
@Test public void fetchesFilesThatAreMissingFromUrlStoreCache() throws IOException, GitUserException { final String testProjectName = "123abc"; final String testUrl = "http://localhost:" + mockServerRule.getPort() + "/123abc"; final String oldTestPath = "testPath"; final String newTestPath = "missingPath"; mockServerClient.when( request() .withMethod("GET") .withPath("/123abc") ) .respond( response() .withStatusCode(200) .withBody("content") ); final Mockery context = new Mockery(); final DBStore dbStore = context.mock(DBStore.class); context.checking(new Expectations() {{ // It should fetch the file once it finds it is missing. oneOf(dbStore).getPathForURLInProject(testProjectName, testUrl); will(returnValue(oldTestPath)); // It should update the URL index store once it has fetched; // at present, it does not actually change the stored path. oneOf(dbStore).addURLIndexForProject( testProjectName, testUrl, oldTestPath); }}); ResourceCache resources = new UrlResourceCache(dbStore); TemporaryFolder repositoryFolder = new TemporaryFolder(); repositoryFolder.create(); String repoStorePath = repositoryFolder.getRoot().getAbsolutePath(); RepoStore repoStore = new FSGitRepoStore(repoStorePath, Optional.empty()); ProjectRepo repo = repoStore.initRepo("repo"); Map<String, RawFile> fileTable = repo.getDirectory().getFileTable(); Map<String, byte[]> fetchedUrls = new HashMap<>(); resources.get( testProjectName, testUrl, newTestPath, fileTable, fetchedUrls, Optional.empty()); // We don't bother caching in this case, at present. assertEquals(0, fetchedUrls.size()); }
Example 16
Source File: StatefulOperatorChainedTaskTest.java From flink with Apache License 2.0 | 4 votes |
@Before public void setup() throws IOException { RESTORED_OPERATORS.clear(); temporaryFolder = new TemporaryFolder(); temporaryFolder.create(); }
Example 17
Source File: DirectoryListenerTest.java From iaf with Apache License 2.0 | 4 votes |
@Override public void setUp() throws Exception { folder = new TemporaryFolder(); folder.create(); super.setUp(); }
Example 18
Source File: SystemdApplicationTest.java From gradle-plugins with Apache License 2.0 | 4 votes |
@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 19
Source File: CheckpointStreamWithResultProviderTest.java From flink with Apache License 2.0 | 4 votes |
@BeforeClass public static void beforeClass() throws IOException { temporaryFolder = new TemporaryFolder(); temporaryFolder.create(); }
Example 20
Source File: TestSchemaConverter.java From dremio-oss with Apache License 2.0 | 4 votes |
@Test public void mixed() throws Exception { BatchSchema schema = BatchSchema.newBuilder() .addField(CompleteType.INT.toField("rownum")) .addField(CompleteType.VARCHAR.toField("name")) .addField(CompleteType.INT.toField("age")) .addField(CompleteType.FLOAT.toField("gpa")) .addField(CompleteType.BIGINT.toField("studentnum")) .addField(CompleteType.TIMESTAMP.toField("create_time")) .addField(CompleteType.VARCHAR.asList().toField("interests")) .addField(CompleteType.struct( CompleteType.VARCHAR.toField("color"), CompleteType.VARCHAR.toField("sport"), CompleteType.VARCHAR.toField("food") ).toField("favorites")) .build(); org.apache.iceberg.Schema expectedSchema = new org.apache.iceberg.Schema( NestedField.optional(1, "rownum", Types.IntegerType.get()), NestedField.optional(2, "name", Types.StringType.get()), NestedField.optional(3, "age", Types.IntegerType.get()), NestedField.optional(4, "gpa", Types.FloatType.get()), NestedField.optional(5, "studentnum", Types.LongType.get()), NestedField.optional(6, "create_time", Types.TimestampType.withZone()), NestedField.optional(7, "interests", Types.ListType.ofOptional(9, Types.StringType.get())), NestedField.optional(8, "favorites", Types.StructType.of( NestedField.optional(10, "color", Types.StringType.get()), NestedField.optional(11, "sport", Types.StringType.get()), NestedField.optional(12, "food", Types.StringType.get()) )) ); org.apache.iceberg.Schema icebergResult = schemaConverter.toIceberg(schema); assertEquals(expectedSchema.toString(), icebergResult.toString()); TemporaryFolder folder = new TemporaryFolder(); folder.create(); String rootPath = folder.getRoot().toString(); Configuration conf = new Configuration(); IcebergCatalog catalog = new IcebergCatalog(rootPath, conf); catalog.beginCreateTable(schema, Collections.emptyList()); catalog.endCreateTable(); Table table = new HadoopTables(conf).load(rootPath); assertEquals(expectedSchema.toString(), table.schema().toString()); }