com.google.common.jimfs.Jimfs Java Examples
The following examples show how to use
com.google.common.jimfs.Jimfs.
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: 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 #2
Source File: DistributedSecurityAnalysisTest.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
/** * Checks config class read from config file. */ @Test public void testConfigFromFile() throws IOException { try (FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix())) { InMemoryPlatformConfig platformConfig = new InMemoryPlatformConfig(fileSystem); ExternalSecurityAnalysisConfig config = ExternalSecurityAnalysisConfig.load(platformConfig); assertFalse(config.isDebug()); assertEquals("itools", config.getItoolsCommand()); MapModuleConfig moduleConfig = platformConfig.createModuleConfig("external-security-analysis-config"); moduleConfig.setStringProperty("debug", "true"); moduleConfig.setStringProperty("itools-command", "/path/to/itools"); config = ExternalSecurityAnalysisConfig.load(platformConfig); assertTrue(config.isDebug()); assertEquals("/path/to/itools", config.getItoolsCommand()); } }
Example #3
Source File: InitCommandTest.java From startup-os with Apache License 2.0 | 6 votes |
@Before public void setup() { // XXX parametrize test FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix()); TestComponent component = DaggerInitCommandTest_TestComponent.builder() .commonModule( new CommonModule() { @Provides @Singleton @Override public FileSystem provideDefaultFileSystem() { return fileSystem; } }) .build(); initCommand = component.getCommand(); fileUtils = component.getFileUtils(); }
Example #4
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 #5
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 #6
Source File: NetworkStateComparatorTest.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
@Before public void setUp() { fileSystem = Jimfs.newFileSystem(Configuration.unix()); network = EurostagTutorialExample1Factory.create(); network.getBusView().getBus("VLGEN_0").setV(24.5).setAngle(2.33); network.getBusView().getBus("VLHV1_0").setV(402.14).setAngle(0); network.getBusView().getBus("VLHV2_0").setV(389.95).setAngle(-3.5); network.getBusView().getBus("VLLOAD_0").setV(147.58).setAngle(9.61); network.getLine("NHV1_NHV2_1").getTerminal1().setP(302.4).setQ(98.7); network.getLine("NHV1_NHV2_1").getTerminal2().setP(-300.4).setQ(-137.1); network.getLine("NHV1_NHV2_2").getTerminal1().setP(302.4).setQ(98.7); network.getLine("NHV1_NHV2_2").getTerminal2().setP(-300.4).setQ(-137.1); network.getTwoWindingsTransformer("NGEN_NHV1").getTerminal1().setP(607).setQ(225.4); network.getTwoWindingsTransformer("NGEN_NHV1").getTerminal2().setP(-606.3).setQ(-197.4); network.getTwoWindingsTransformer("NHV2_NLOAD").getTerminal1().setP(600).setQ(274.3); network.getTwoWindingsTransformer("NHV2_NLOAD").getTerminal2().setP(-600).setQ(-200); network.getGenerator("GEN").getTerminal().setP(607).setQ(225.4); network.getLoad("LOAD").getTerminal().setP(600).setQ(200); }
Example #7
Source File: TableFormatterConfigTest.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
@Test public void testConfig() throws IOException { TableFormatterConfig config = new TableFormatterConfig(); testConfig(config, Locale.getDefault(), ';', "inv", true, true); try (FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix())) { InMemoryPlatformConfig platformConfig = new InMemoryPlatformConfig(fileSystem); MapModuleConfig moduleConfig = platformConfig.createModuleConfig("table-formatter"); moduleConfig.setStringProperty("language", "en-US"); moduleConfig.setStringProperty("separator", "\t"); moduleConfig.setStringProperty("invalid-string", "NaN"); moduleConfig.setStringProperty("print-header", "false"); moduleConfig.setStringProperty("print-title", "false"); config = TableFormatterConfig.load(platformConfig); testConfig(config, Locale.US, '\t', "NaN", false, false); } }
Example #8
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 #9
Source File: FilePermissionSampleTest.java From cloud-search-samples with Apache License 2.0 | 5 votes |
@Before public void createFileSystem() { Configuration filesystemConfig = Configuration.unix().toBuilder() .setAttributeViews("basic", "owner", "posix", "unix", "acl") .setWorkingDirectory("/home/user") .setBlockSize(4096) .build(); fileSystem = Jimfs.newFileSystem(filesystemConfig); }
Example #10
Source File: WorkspaceCommandTest.java From startup-os with Apache License 2.0 | 5 votes |
@Before public void setup() throws IOException { // XXX parametrize test FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix()); TestComponent component = DaggerWorkspaceCommandTest_TestComponent.builder() .commonModule( new CommonModule() { @Override @Provides @Singleton public FileSystem provideDefaultFileSystem() { return fileSystem; } }) .aaModule( new AaModule() { @Override @Provides @Singleton @Named("Base path") public String provideBasePath(FileUtils fileUtils) { return "/base"; } }) .build(); fileUtils = component.getFileUtils(); initEmptyWorkspace(); workspaceCommand = component.getCommand(); outContent = new ByteArrayOutputStream(); errContent = new ByteArrayOutputStream(); System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); Flags.resetForTesting(); WorkspaceCommand.force.resetValueForTesting(); }
Example #11
Source File: UploadOutputsTest.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
@Before public void setUp() throws ConfigurationException { MockitoAnnotations.initMocks(this); fileSystem = Jimfs.newFileSystem(config); root = Iterables.getFirst(fileSystem.getRootDirectories(), null); resultBuilder = ActionResult.newBuilder(); }
Example #12
Source File: SdkToolsLocatorTest.java From bundletool with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { fileSystem = Jimfs.newFileSystem(osConfiguration); platformToolsDir = Files.createDirectories(fileSystem.getPath(sdkPath).resolve(PLATFORM_TOOLS_DIR)); systemEnvironmentProvider = new FakeSystemEnvironmentProvider( /* variables= */ ImmutableMap.of( ANDROID_HOME_VARIABLE, Files.createDirectories(fileSystem.getPath(sdkPath)).toString())); }
Example #13
Source File: SdkToolsLocatorTest.java From bundletool with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { fileSystem = Jimfs.newFileSystem(osConfiguration); checkState(systemPath.contains(goodPathDir)); Files.createDirectories(fileSystem.getPath(goodPathDir)); systemEnvironmentProvider = new FakeSystemEnvironmentProvider( /* variables= */ ImmutableMap.of(SYSTEM_PATH_VARIABLE, systemPath), /* properties= */ ImmutableMap.of("path.separator", pathSeparator)); }
Example #14
Source File: CASFileCacheTest.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
public WindowsCASFileCacheTest() { super( Iterables.getFirst( Jimfs.newFileSystem( Configuration.windows() .toBuilder() .setAttributeViews("basic", "owner", "dos", "acl", "posix", "user") .build()) .getRootDirectories(), null)); }
Example #15
Source File: DirectoriesTest.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
public OsXDirectoriesTest() { super( Iterables.getFirst( Jimfs.newFileSystem( Configuration.osX() .toBuilder() .setAttributeViews("basic", "owner", "posix", "unix") .build()) .getRootDirectories(), null)); }
Example #16
Source File: ReferencedClassesParserTest.java From BUILD_file_generator with Apache License 2.0 | 5 votes |
@Before public void setUp() throws IOException { FileSystem fileSystem = Jimfs.newFileSystem(Configuration.forCurrentPlatform().toBuilder().build()); srcMain = fileSystem.getPath("/src/main/"); Files.createDirectories(srcMain); srcTest = fileSystem.getPath("/src/test/"); Files.createDirectories(srcTest); }
Example #17
Source File: DirectoriesTest.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
public UnixDirectoriesTest() { super( Iterables.getFirst( Jimfs.newFileSystem( Configuration.unix() .toBuilder() .setAttributeViews("basic", "owner", "posix", "unix") .build()) .getRootDirectories(), null)); }
Example #18
Source File: AbstractDataSourceTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Before public void setUp() throws Exception { fileSystem = Jimfs.newFileSystem(Configuration.unix()); testDir = fileSystem.getPath("/tmp"); Files.createDirectories(testDir); dataSource = createDataSource(); }
Example #19
Source File: FileDirectoriesIndexTest.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
public WindowsFileDirectoriesIndexTest() { super( Iterables.getFirst( Jimfs.newFileSystem( Configuration.windows() .toBuilder() .setAttributeViews("basic", "owner", "dos", "acl", "posix", "user") .build()) .getRootDirectories(), null)); }
Example #20
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 #21
Source File: FileContentStreamProviderTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() throws IOException { testFs = Jimfs.newFileSystem("FileContentStreamProviderTest"); testFile = testFs.getPath("test_file.dat"); try (OutputStream os = Files.newOutputStream(testFile)) { os.write("test".getBytes(StandardCharsets.UTF_8)); } }
Example #22
Source File: XmlPlatformConfigTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void properties2XmlConvertionTest() throws IOException, XMLStreamException { try (FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix())) { Path cfgDir = Files.createDirectory(fileSystem.getPath("config")); Properties prop1 = new Properties(); prop1.setProperty("a", "hello"); prop1.setProperty("b", "bye"); try (Writer w = Files.newBufferedWriter(cfgDir.resolve("mod1.properties"), StandardCharsets.UTF_8)) { prop1.store(w, null); } Properties prop2 = new Properties(); prop2.setProperty("c", "thanks"); try (Writer w = Files.newBufferedWriter(cfgDir.resolve("mod2.properties"), StandardCharsets.UTF_8)) { prop2.store(w, null); } PlatformConfig propsConfig = new PlatformConfig(new PropertiesModuleConfigRepository(cfgDir), cfgDir); assertEquals("hello", propsConfig.getModuleConfig("mod1").getStringProperty("a")); assertEquals("bye", propsConfig.getModuleConfig("mod1").getStringProperty("b")); assertEquals("thanks", propsConfig.getModuleConfig("mod2").getStringProperty("c")); Path xmlConfigFile = cfgDir.resolve("config.xml"); PropertiesModuleConfigRepository.writeXml(cfgDir, xmlConfigFile); PlatformConfig xmlConfig = new PlatformConfig(new XmlModuleConfigRepository(xmlConfigFile), cfgDir); assertEquals("hello", xmlConfig.getModuleConfig("mod1").getStringProperty("a")); assertEquals("bye", xmlConfig.getModuleConfig("mod1").getStringProperty("b")); assertEquals("thanks", xmlConfig.getModuleConfig("mod2").getStringProperty("c")); } }
Example #23
Source File: ComponentDefaultConfigTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Before public void setUp() throws IOException { fileSystem = Jimfs.newFileSystem(Configuration.unix()); InMemoryPlatformConfig platformConfig = new InMemoryPlatformConfig(fileSystem); moduleConfig = platformConfig.createModuleConfig("componentDefaultConfig"); config = new ComponentDefaultConfig.Impl(moduleConfig); }
Example #24
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 #25
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 #26
Source File: LoadFlowBasedPhaseShifterOptimizerConfigTest.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-based-phase-shifter-optimizer"); moduleConfig.setStringProperty("load-flow-name", "LoadFlowMock"); LoadFlowBasedPhaseShifterOptimizerConfig config = LoadFlowBasedPhaseShifterOptimizerConfig.load(platformConfig); assertEquals("LoadFlowMock", config.getLoadFlowName().orElseThrow(AssertionError::new)); config.setLoadFlowName("LoadFlowMock2"); assertEquals("LoadFlowMock2", config.getLoadFlowName().orElseThrow(AssertionError::new)); } }
Example #27
Source File: FileDirectoriesIndexTest.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
public UnixFileDirectoriesIndexTest() { super( Iterables.getFirst( Jimfs.newFileSystem( Configuration.unix() .toBuilder() .setAttributeViews("basic", "owner", "posix", "unix") .build()) .getRootDirectories(), null)); }
Example #28
Source File: LimitViolationFilterTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Before public void setUp() throws Exception { fileSystem = Jimfs.newFileSystem(Configuration.unix()); platformConfig = new InMemoryPlatformConfig(fileSystem); MapModuleConfig moduleConfig = platformConfig.createModuleConfig("limit-violation-default-filter"); moduleConfig.setStringListProperty("violationTypes", Arrays.asList("CURRENT", "LOW_VOLTAGE")); moduleConfig.setStringProperty("minBaseVoltage", "150"); moduleConfig.setStringListProperty("countries", Arrays.asList("FR", "BE")); }
Example #29
Source File: ConversionTester.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
public void validateBusBalances(Network network) throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { ValidationConfig config = loadFlowValidationConfig(validateBusBalancesThreshold); Path working = Files.createDirectories(fs.getPath("lf-validation")); computeMissingFlows(network, config.getLoadFlowParameters()); assertTrue(ValidationType.BUSES.check(network, config, working)); } }
Example #30
Source File: ConversionTester.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
private void testConversion(Network expected, TestGridModel gm, ComparisonConfig cconfig, String impl) throws IOException { Properties iparams = importParams == null ? new Properties() : importParams; iparams.put("storeCgmesModelAsNetworkExtension", "true"); iparams.put("powsyblTripleStore", impl); // This is to be able to easily compare the topology computed // by powsybl against the topology present in the CGMES model iparams.put("createBusbarSectionForEveryConnectivityNode", "true"); try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { CgmesImport i = new CgmesImport(); ReadOnlyDataSource ds = gm.dataSource(); Network network = i.importData(ds, new NetworkFactoryImpl(), iparams); if (network.getSubstationCount() == 0) { fail("Model is empty"); } CgmesModel cgmes = network.getExtension(CgmesModelExtension.class).getCgmesModel(); if (!new TopologyTester(cgmes, network).test(strictTopologyTest)) { fail("Topology test failed"); } if (expected != null) { new Comparison(expected, network, cconfig).compare(); } if (exportXiidm) { exportXiidm(gm.name(), impl, expected, network); } if (exportCgmes) { exportCgmes(gm.name(), impl, network); } if (testExportImportCgmes) { testExportImportCgmes(network, fs, i, iparams, cconfig); } if (validateBusBalances) { validateBusBalances(network); } lastConvertedNetwork = network; } }