com.google.common.jimfs.Configuration Java Examples
The following examples show how to use
com.google.common.jimfs.Configuration.
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: CellTest.java From buck with Apache License 2.0 | 6 votes |
@Test public void fileSystemViewForSourceFilesShouldListExistingFile() throws IOException { FileSystem vfs = Jimfs.newFileSystem(Configuration.unix()); Path root = vfs.getPath("/opt/local/"); Path cellRoot = root.resolve("repo"); Files.createDirectories(cellRoot); Path someFile = cellRoot.resolve("somefile"); Files.createFile(someFile); ProjectFilesystem filesystem = TestProjectFilesystems.createProjectFilesystem(cellRoot.toAbsolutePath()); Cells cell = new TestCellBuilder().setFilesystem(filesystem).build(); ProjectFilesystemView view = cell.getRootCell().getFilesystemViewForSourceFiles(); ImmutableCollection<Path> list = view.getDirectoryContents(cellRoot); assertTrue(list.contains(cellRoot.relativize(someFile))); }
Example #2
Source File: ZipPackagerTest.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
@Before public void setUp() { fileSystem = Jimfs.newFileSystem(Configuration.unix()); workingDir = fileSystem.getPath("/wd"); Path f1 = workingDir.resolve("f1"); Path f2 = workingDir.resolve("f2"); Path f3 = workingDir.resolve("f3.gz"); try { Files.createDirectories(workingDir); try (BufferedWriter f1Writer = Files.newBufferedWriter(f1, StandardCharsets.UTF_8); BufferedWriter f2Writer = Files.newBufferedWriter(f2, StandardCharsets.UTF_8); OutputStream f3Writer = new GZIPOutputStream(Files.newOutputStream(f3))) { f1Writer.write("foo"); f2Writer.write("bar"); f3Writer.write(Strings.toByteArray("hello")); } } catch (IOException e) { fail(); } }
Example #3
Source File: EdenProjectFilesystemDelegateTest.java From buck with Apache License 2.0 | 6 votes |
@Test public void computeSha1ForOrdinaryFileUnderMount() throws IOException, EdenError, TException { FileSystem fs = Jimfs.newFileSystem(Configuration.unix()); Path root = fs.getPath(JIMFS_WORKING_DIRECTORY); ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root); EdenMount mount = createMock(EdenMount.class); Path path = fs.getPath("foo/bar"); expect(mount.getPathRelativeToProjectRoot(root.resolve(path))).andReturn(Optional.of(path)); expect(mount.getSha1(path)).andReturn(DUMMY_SHA1); replay(mount); EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate); assertEquals(DUMMY_SHA1, edenDelegate.computeSha1(path)); verify(mount); }
Example #4
Source File: ComputationExceptionBuilderTest.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
@Before public void setUp() { fileSystem = Jimfs.newFileSystem(Configuration.unix()); workingDir = fileSystem.getPath("/wd"); f1 = workingDir.resolve("f1.out"); f2 = workingDir.resolve("f2.err"); try { Files.createDirectories(workingDir); try (BufferedWriter writer = Files.newBufferedWriter(f1, StandardCharsets.UTF_8); BufferedWriter w2 = Files.newBufferedWriter(f2, StandardCharsets.UTF_8);) { writer.write("foo"); w2.write("bar"); } } catch (IOException e) { fail(); } }
Example #5
Source File: BuildSymbolTablePassTest.java From js-dossier with Apache License 2.0 | 6 votes |
@Test public void worksWithWindowsAbsolutePaths() { FileSystem fs = Jimfs.newFileSystem(Configuration.windows()); Path one = fs.getPath("C:\\foo\\bar\\one.js"); Path two = fs.getPath("C:\\otherDir\\two.js"); SymbolTable table = new Scenario() .addFile(one, "export class Foo {}") .addFile(two, "export {Foo} from '../foo/bar/one.js';") .compile(); Module module = assertThat(table).hasEs6Module(two); assertThat(module.getInternalSymbolTable()).isEmpty(); assertThat(table) .hasOwnSymbol("module$C_$otherDir$two.Foo") .that() .isAReferenceTo("module$C_$foo$bar$one.Foo"); }
Example #6
Source File: MostFilesTest.java From buck with Apache License 2.0 | 6 votes |
@Test public void concatenatingTwoNonEmptyFilesReturnsTrueAndWritesConcatenatedFile() throws Exception { FileSystem vfs = Jimfs.newFileSystem(Configuration.unix()); Path fooPath = vfs.getPath("foo.txt"); Files.write(fooPath, "hello world\n".getBytes(UTF_8)); Path barPath = vfs.getPath("bar.txt"); Files.write(barPath, "goodbye world\n".getBytes(UTF_8)); Path outputPath = vfs.getPath("logs.txt"); boolean concatenated = MostFiles.concatenateFiles(outputPath, ImmutableList.of(fooPath, barPath)); assertThat(concatenated, is(true)); assertThat( Files.readAllLines(outputPath, UTF_8), Matchers.equalTo(ImmutableList.of("hello world", "goodbye world"))); }
Example #7
Source File: EurostagDDBTest.java From ipst with Mozilla Public License 2.0 | 6 votes |
@Test public void testEurostagDDB() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path folder1 = Files.createDirectory(fs.getPath("/folder1")); Path folder2 = Files.createDirectory(fs.getPath("/folder2")); Path folder3 = Files.createDirectory(fs.getPath("/folder3")); Path generator1 = Files.createFile(folder1.resolve("generator1.tg")); Path generator2 = Files.createFile(folder1.resolve("generator2.tg")); Files.createFile(folder2.resolve("generator3.tg.bck")); Path link = Files.createSymbolicLink(folder2.resolve("folder3"), folder3); Path generator4 = Files.createFile(link.resolve("generator4.tg")); Path dataFile = Files.createFile(folder3.resolve("generator.data")); Files.createSymbolicLink(folder3.resolve("generator5.tg"), dataFile); EurostagDDB eurostagDDB = new EurostagDDB(Arrays.asList(folder1, folder2)); assertEquals(generator1, eurostagDDB.findGenerator("generator1")); assertEquals(generator2, eurostagDDB.findGenerator("generator2")); assertNull(eurostagDDB.findGenerator("generator3")); assertEquals(generator4, eurostagDDB.findGenerator("generator4")); assertEquals(dataFile, eurostagDDB.findGenerator("generator5")); } }
Example #8
Source File: OnDiskMavenDownloaderTest.java From buck with Apache License 2.0 | 6 votes |
@Test public void shouldDownloadFileFromLocalMavenRepoWindows() throws URISyntaxException, IOException { FileSystem filesystem = Jimfs.newFileSystem(Configuration.windows()); Path root = filesystem.getPath("C:\\Users\\bob\\.m2"); Files.createDirectories(root); URI uri = new URI("mvn:group:project:jar:0.1"); Path output = filesystem.getPath("output.txt"); Path source = root.resolve("group/project/0.1/project-0.1.jar"); Files.createDirectories(source.getParent()); Files.write(source, "cake".getBytes(UTF_8)); Downloader downloader = new OnDiskMavenDownloader(root); downloader.fetch(BuckEventBusForTests.newInstance(), uri, output); String result = new String(Files.readAllBytes(output), UTF_8); assertThat("cake", Matchers.equalTo(result)); }
Example #9
Source File: MostFilesTest.java From buck with Apache License 2.0 | 6 votes |
@Test public void concatenatingTwoEmptyFilesReturnsFalse() throws Exception { FileSystem vfs = Jimfs.newFileSystem(Configuration.unix()); Path fooPath = vfs.getPath("foo.txt"); Files.write(fooPath, new byte[0]); Path barPath = vfs.getPath("bar.txt"); Files.write(barPath, new byte[0]); Path outputPath = vfs.getPath("logs.txt"); boolean concatenated = MostFiles.concatenateFiles(outputPath, ImmutableList.of(fooPath, barPath)); assertThat(concatenated, is(false)); assertThat(Files.exists(outputPath), is(false)); }
Example #10
Source File: FileHelperTest.java From Photato with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testFileIgnoreDetection() throws IOException { try (FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix())) { Files.createDirectory(fileSystem.getPath("/data")); Files.createDirectory(fileSystem.getPath("/data/ok")); Files.createDirectory(fileSystem.getPath("/data/bad")); // Create ok file Files.createFile(fileSystem.getPath("/data/ok/toto")); // Create ignore file Files.createFile(fileSystem.getPath("/data/bad/.photatoignore")); Assert.assertFalse(FileHelper.folderContainsIgnoreFile(fileSystem.getPath("/data/ok"))); Assert.assertTrue(FileHelper.folderContainsIgnoreFile(fileSystem.getPath("/data/bad"))); } }
Example #11
Source File: TapChangeActionTest.java From ipst with Mozilla Public License 2.0 | 6 votes |
@Test public void testToTask() throws Exception { Network network = PhaseShifterTestCaseFactory.create(); PhaseTapChanger tapChanger = network.getTwoWindingsTransformer("PS1").getPhaseTapChanger(); assertEquals(1, tapChanger.getTapPosition()); TapChangeAction action = new TapChangeAction("PS1", 2); ModificationTask task = action.toTask(); try (FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix())) { Path localDir = fileSystem.getPath("/tmp"); ComputationManager computationManager = new LocalComputationManager(localDir); task.modify(network, computationManager); assertEquals(2, tapChanger.getTapPosition()); try { action.toTask(null); fail(); } catch (UnsupportedOperationException exc) { } } }
Example #12
Source File: EdenProjectFilesystemDelegateTest.java From buck with Apache License 2.0 | 6 votes |
@Test public void computeSha1ViaXattrForFileUnderMount() throws IOException { FileSystem fs = Jimfs.newFileSystem(Configuration.unix().toBuilder().setAttributeViews("user").build()); Path root = fs.getPath(JIMFS_WORKING_DIRECTORY); ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root); Path path = fs.getPath("/foo"); Files.createFile(path); UserDefinedFileAttributeView view = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class); ByteBuffer buf = ByteBuffer.wrap(DUMMY_SHA1.toString().getBytes(StandardCharsets.UTF_8)); view.write("sha1", buf); EdenMount mount = createMock(EdenMount.class); Config config = ConfigBuilder.createFromText("[eden]", "use_xattr = true"); EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate, config); assertEquals(DUMMY_SHA1, edenDelegate.computeSha1(path)); }
Example #13
Source File: PathLineIteratorUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testLineIteratorInForEach() throws IOException { try (FileSystem jimfs = Jimfs.newFileSystem(Configuration.unix())) { final Path path = jimfs.getPath("test.txt"); try (BufferedWriter bufferedWriter = Files.newBufferedWriter(path)) { bufferedWriter.write(String.join("\n", opus)); } ArrayList<String> got = new ArrayList<>(); try (PathLineIterator lines = new PathLineIterator(path)) { for (String s : lines) { got.add(s); } } Assert.assertEquals(got.toArray(), opus); } }
Example #14
Source File: CaseExporterTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Before public void setUp() throws IOException { fileSystem = Jimfs.newFileSystem(Configuration.unix()); tmpDir = Files.createDirectory(fileSystem.getPath("/tmp")); contingency = new Contingency("contingency"); network = Network.create("id", "test"); }
Example #15
Source File: DefaultCellPathResolverTest.java From buck with Apache License 2.0 | 5 votes |
@Test public void transitiveMappingForSymlinkCycle() throws Exception { Assume.assumeTrue(Platform.detect() != Platform.WINDOWS); FileSystem vfs = Jimfs.newFileSystem(Configuration.unix()); AbsPath root = AbsPath.of(vfs.getPath("/opt/local/")); AbsPath cell1Root = root.resolve("repo1"); Files.createDirectories(cell1Root.getPath()); AbsPath cell2Root = root.resolve("repo2"); Files.createDirectories(cell2Root.getPath()); AbsPath symlinkPath = cell2Root.resolve("symlink"); CreateSymlinksForTests.createSymLink(symlinkPath.getPath(), cell2Root.getPath()); DefaultCellPathResolver cellPathResolver = DefaultCellPathResolver.create( cell1Root, ConfigBuilder.createFromText(REPOSITORIES_SECTION, " two = ../repo2")); Files.write( cell2Root.resolve(".buckconfig").getPath(), ImmutableList.of(REPOSITORIES_SECTION, " three = symlink"), StandardCharsets.UTF_8); assertThat( cellPathResolver.getPathMapping(), Matchers.equalTo( ImmutableMap.of(CellName.ROOT_CELL_NAME, cell1Root, CellName.of("two"), cell2Root))); }
Example #16
Source File: IntervalUtilsUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test(dataProvider = "loadIntervalsFromFeatureFileData") public void testLoadIntervalsFromFeatureFileInJimfs( final File featureFile, final List<GenomeLoc> expectedIntervals ) throws IOException { try(final FileSystem fs = Jimfs.newFileSystem(Configuration.unix())){ final Path jimfsRootPath = fs.getRootDirectories().iterator().next(); final Path jimfsCopy = Files.copy(featureFile.toPath(), jimfsRootPath.resolve(featureFile.getName())); final String jimfsPathString = jimfsCopy.toAbsolutePath().toUri().toString(); final GenomeLocSortedSet actualIntervals = IntervalUtils.loadIntervals(Collections.singletonList(jimfsPathString), IntervalSetRule.UNION, IntervalMergingRule.ALL, 0, hg19GenomeLocParser); Assert.assertEquals(actualIntervals, expectedIntervals, "Wrong intervals loaded from Feature file " + jimfsPathString); } }
Example #17
Source File: DefaultCellPathResolverTest.java From buck with Apache License 2.0 | 5 votes |
@Test public void errorMessageIncludesAllCellsWhenNoSpellingSuggestionsAreAvailable() { FileSystem vfs = Jimfs.newFileSystem(Configuration.unix()); DefaultCellPathResolver cellPathResolver = TestCellPathResolver.create( vfs.getPath("/foo/root"), ImmutableMap.of( "root", vfs.getPath("/foo/root"), "apple", vfs.getPath("/foo/cell"), "maple", vfs.getPath("/foo/cell"))); thrown.expectMessage( "Unknown cell: does_not_exist. Did you mean one of [apple, maple, root] instead?"); cellPathResolver.getCellPathOrThrow(Optional.of("does_not_exist")); }
Example #18
Source File: FileRepositoryUnitTest.java From tutorials with MIT License | 5 votes |
@Test @DisplayName("Should read the content of the file") void givenOSXSystem_whenReadingFile_thenContentIsReturned() throws Exception { final FileSystem fileSystem = Jimfs.newFileSystem(Configuration.osX()); final Path resourceFilePath = fileSystem.getPath(RESOURCE_FILE_NAME); Files.copy(getResourceFilePath(), resourceFilePath); final String content = fileRepository.read(resourceFilePath); assertEquals(FILE_CONTENT, content); }
Example #19
Source File: WCARestrictingThresholdLevelConfigTest.java From ipst with Mozilla Public License 2.0 | 5 votes |
@Before public void setUp() throws Exception { fileSystem = Jimfs.newFileSystem(Configuration.unix()); platformConfig = new InMemoryPlatformConfig(fileSystem); Path xpressPath = fileSystem.getPath("/tmp/xpress"); moduleConfig = platformConfig.createModuleConfig("wca"); moduleConfig.setStringProperty("xpressHome", xpressPath.toString()); moduleConfig.setStringProperty("reducedVariableRatio", "1.5"); moduleConfig.setStringProperty("debug", "true"); moduleConfig.setStringProperty("exportStates", "true"); }
Example #20
Source File: CASFileCacheTest.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
public UnixCASFileCacheTest() { super( Iterables.getFirst( Jimfs.newFileSystem( Configuration.unix() .toBuilder() .setAttributeViews("basic", "owner", "posix", "unix") .build()) .getRootDirectories(), null)); }
Example #21
Source File: FileDirectoriesIndexTest.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
public OsFileDirectoriesIndexTest() { super( Iterables.getFirst( Jimfs.newFileSystem( Configuration.osX() .toBuilder() .setAttributeViews("basic", "owner", "posix", "unix") .build()) .getRootDirectories(), null)); }
Example #22
Source File: DefaultCellPathResolverTest.java From buck with Apache License 2.0 | 5 votes |
@Test public void canonicalCellNameForRootIsEmpty() { FileSystem vfs = Jimfs.newFileSystem(Configuration.unix()); DefaultCellPathResolver cellPathResolver = TestCellPathResolver.create( vfs.getPath("/foo/root"), ImmutableMap.of("root", vfs.getPath("/foo/root"))); assertEquals(Optional.empty(), cellPathResolver.getCanonicalCellName(vfs.getPath("/foo/root"))); }
Example #23
Source File: LoadFlowActionSimulatorConfigTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void test() throws IOException { try (FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix())) { InMemoryPlatformConfig platformConfig = new InMemoryPlatformConfig(fileSystem); MapModuleConfig moduleConfig = platformConfig.createModuleConfig("load-flow-action-simulator"); moduleConfig.setStringProperty("load-flow-name", "LoadFlowMock"); moduleConfig.setStringProperty("max-iterations", "15"); moduleConfig.setStringProperty("ignore-pre-contingency-violations", "true"); moduleConfig.setStringProperty("copy-strategy", CopyStrategy.DEEP.name()); LoadFlowActionSimulatorConfig config = LoadFlowActionSimulatorConfig.load(platformConfig); assertEquals("LoadFlowMock", config.getLoadFlowName().orElseThrow(AssertionError::new)); config.setLoadFlowName("AnotherLoadFlowMock"); assertEquals("AnotherLoadFlowMock", config.getLoadFlowName().orElseThrow(AssertionError::new)); assertEquals(15, config.getMaxIterations()); config.setMaxIterations(10); assertEquals(10, config.getMaxIterations()); assertTrue(config.isIgnorePreContingencyViolations()); config.setIgnorePreContingencyViolations(false); assertFalse(config.isIgnorePreContingencyViolations()); assertEquals(CopyStrategy.DEEP, config.getCopyStrategy()); config.setCopyStrategy(CopyStrategy.STATE); assertEquals(CopyStrategy.STATE, config.getCopyStrategy()); assertFalse(config.isDebug()); config.setDebug(true); assertTrue(config.isDebug()); } }
Example #24
Source File: MostFilesTest.java From buck with Apache License 2.0 | 5 votes |
@Test public void deleteRecursivelyNonExistentDeleteContentsIgnoreNoSuchFile() throws IOException { FileSystem vfs = Jimfs.newFileSystem(Configuration.unix()); Path fakeTmpDir = vfs.getPath("/tmp/fake-tmp-dir"); MostFiles.deleteRecursivelyWithOptions( fakeTmpDir.resolve("nonexistent"), EnumSet.of( MostFiles.DeleteRecursivelyOptions.DELETE_CONTENTS_ONLY, MostFiles.DeleteRecursivelyOptions.IGNORE_NO_SUCH_FILE_EXCEPTION)); }
Example #25
Source File: FakeProjectFilesystem.java From buck with Apache License 2.0 | 5 votes |
public static ProjectFilesystem createJavaOnlyFilesystem(String rootPath) { boolean isWindows = Platform.detect() == Platform.WINDOWS; Configuration configuration = isWindows ? Configuration.windows() : Configuration.unix(); rootPath = isWindows && !rootPath.startsWith("C:") ? "C:" + rootPath : rootPath; FileSystem vfs = Jimfs.newFileSystem(configuration.toBuilder().setAttributeViews("basic", "posix").build()); AbsPath root = AbsPath.of(vfs.getPath(rootPath)); try { Files.createDirectories(root.getPath()); } catch (IOException e) { throw new RuntimeException(e); } return new DefaultProjectFilesystem( CanonicalCellName.rootCell(), root, new DefaultProjectFilesystemDelegate(root.getPath()), DefaultProjectFilesystemFactory.getWindowsFSInstance(), TestProjectFilesystems.BUCK_OUT_INCLUDE_TARGET_CONFIG_HASH_FOR_TEST) { @Override public Path resolve(Path path) { // Avoid resolving paths from different Java FileSystems. return resolve(path.toString()); } }; }
Example #26
Source File: EchUtilsTest.java From ipst with Mozilla Public License 2.0 | 5 votes |
private EurostagEchExportConfig getConfig(boolean noSwitch, boolean exportMainCCOnly) { FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix()); InMemoryPlatformConfig platformConfig = new InMemoryPlatformConfig(fileSystem); MapModuleConfig moduleConfig = platformConfig.createModuleConfig("eurostag-ech-export"); moduleConfig.setStringProperty("noSwitch", Boolean.toString(noSwitch)); moduleConfig.setStringProperty("exportMainCCOnly", Boolean.toString(exportMainCCOnly)); return EurostagEchExportConfig.load(platformConfig); }
Example #27
Source File: MostFilesTest.java From buck with Apache License 2.0 | 5 votes |
@Test public void deleteRecursivelyIfExistsShouldNotFailOnFile() throws IOException { FileSystem vfs = Jimfs.newFileSystem(Configuration.unix()); Path fakeTmpDir = vfs.getPath("/tmp/fake-tmp-dir"); Path fileToDelete = fakeTmpDir.resolve("delete-me"); Files.createDirectories(fakeTmpDir); MostFiles.writeLinesToFile(ImmutableList.of(""), fileToDelete); MostFiles.deleteRecursivelyWithOptions( fileToDelete, EnumSet.noneOf(MostFiles.DeleteRecursivelyOptions.class)); assertThat(Files.exists(fileToDelete), is(false)); }
Example #28
Source File: EntsoeCaseRepositoryConfigTest.java From ipst with Mozilla Public License 2.0 | 5 votes |
@Before public void setUp() throws Exception { fileSystem = Jimfs.newFileSystem(Configuration.unix()); Path configDir = Files.createDirectory(fileSystem.getPath("/config")); platformConfig = new InMemoryPlatformConfig(fileSystem); moduleConfig = platformConfig.createModuleConfig("entsoecaserepo"); moduleConfig.setPathProperty("rootDir", configDir); }
Example #29
Source File: MostFilesTest.java From buck with Apache License 2.0 | 5 votes |
@Test public void deleteRecursivelyIfExistsDeletesDirectory() throws IOException { FileSystem vfs = Jimfs.newFileSystem(Configuration.unix()); Path fakeTmpDir = vfs.getPath("/tmp/fake-tmp-dir"); Path dirToDelete = fakeTmpDir.resolve("delete-me"); Path childDir = dirToDelete.resolve("child-dir"); Files.createDirectories(childDir); MostFiles.deleteRecursivelyIfExists(dirToDelete); assertThat(Files.exists(dirToDelete), is(false)); }
Example #30
Source File: TableUtilsUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Check that TableWriter can accept a Path and doesn't just convert it * to a File along the way. * * @throws IOException */ @Test(dependsOnMethods = "testReader") public void testWriter0Nio() throws IOException { try (FileSystem jimfs = Jimfs.newFileSystem(Configuration.unix())) { final Path testPath = jimfs.getPath("testWriter0Nio.tsv"); testWriter0_internal(testPath); } }