Java Code Examples for org.assertj.core.util.Files

The following examples show how to use org.assertj.core.util.Files. These examples are extracted from open source projects. 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
@Setup(Level.Iteration)
public void beforeClass() {
	if (connection != null) {
		connection.close();
		connection = null;
	}
	i = 0;
	file = Files.newTemporaryFolder();

	NativeStore sail = new NativeStore(file, "spoc,ospc,psoc");
	sail.setForceSync(false);
	repository = new SailRepository(sail);
	connection = repository.getConnection();

	System.gc();

}
 
Example 2
@Setup(Level.Iteration)
public void beforeClass() {
	if (connection != null) {
		connection.close();
		connection = null;
	}
	i = 0;
	file = Files.newTemporaryFolder();

	NativeStore sail = new NativeStore(file, "spoc,ospc,psoc");
	sail.setForceSync(true);
	repository = new SailRepository(sail);
	connection = repository.getConnection();

	System.gc();

}
 
Example 3
@Test
public void testContextCacheReconstruction() throws Exception {
	con.begin();
	con.addStatement(RDF.TYPE, RDF.TYPE, RDF.TYPE, RDF.ALT);
	con.commit();
	con.close();
	sail.shutDown();

	File contextFile = new File(tempDir.getRoot(), "/nativestore/contexts.dat");
	Files.delete(contextFile);

	sail.init();
	con = sail.getConnection();

	assertTrue(contextFile.exists());
	assertThat(QueryResults.asList(con.getContextIDs()).size()).isEqualTo(1);
}
 
Example 4
@Benchmark
public void nativeStoreShaclSnapshotWithoutSerializableValidation(Blackhole blackhole) throws Exception {
	File file = Files.newTemporaryFolder();

	try {
		SailRepository repository = new SailRepository(
				Utils.getInitializedShaclSail(new NativeStore(file, "spoc,ospc,psoc"), "shaclDatatype.ttl"));
		((ShaclSail) repository.getSail()).setSerializableValidation(false);

		runBenchmark(IsolationLevels.SNAPSHOT, repository, true, false, blackhole);

	} finally {
		FileUtils.deleteDirectory(file);
	}

}
 
Example 5
@BeforeEach
public void before() {

	if (!prepare().hasAuth("cert")) {
		prepare().mountAuth("cert");
	}

	prepare().getVaultOperations().opsForSys().createOrUpdatePolicy("cert-auth", POLICY);

	prepare().getVaultOperations().doWithSession((RestOperationsCallback<Object>) restOperations -> {
		File workDir = findWorkDir();

		String certificate = Files.contentOf(new File(workDir, "ca/certs/client.cert.pem"),
				StandardCharsets.US_ASCII);

		Map<String, Object> role = new LinkedHashMap<>();
		role.put("token_policies", "cert-auth");
		role.put("certificate", certificate);

		return restOperations.postForEntity("auth/cert/certs/my-role", role, Map.class);
	});
}
 
Example 6
@BeforeEach
void before() {

	this.taskScheduler.afterPropertiesSet();

	if (!prepare().hasAuth("cert")) {
		prepare().mountAuth("cert");
	}

	prepare().getVaultOperations().doWithSession((RestOperationsCallback<Object>) restOperations -> {
		File workDir = findWorkDir();

		String certificate = Files.contentOf(new File(workDir, "ca/certs/client.cert.pem"),
				StandardCharsets.US_ASCII);

		Map<String, Object> body = new HashMap<>();
		body.put("certificate", certificate);
		body.put("ttl", 2 /* seconds */);
		body.put("max_ttl", 2 /* seconds */);

		return restOperations.postForEntity("auth/cert/certs/my-role", body, Map.class);
	});
}
 
Example 7
@BeforeEach
void before() {

	this.pkiOperations = this.vaultOperations.opsForPki();

	if (!prepare().hasSecret("pki")) {
		prepare().mountSecret("pki");
	}

	File workDir = findWorkDir(new File(System.getProperty("user.dir")));
	String cert = Files.contentOf(new File(workDir, "ca/certs/intermediate.cert.pem"), "US-ASCII");
	String key = Files.contentOf(new File(workDir, "ca/private/intermediate.decrypted.key.pem"), "US-ASCII");

	Map<String, String> pembundle = Collections.singletonMap("pem_bundle", cert + key);

	this.vaultOperations.write("pki/config/ca", pembundle);

	Map<String, String> role = new HashMap<String, String>();
	role.put("allowed_domains", "localhost,example.com");
	role.put("allow_subdomains", "true");
	role.put("allow_localhost", "true");
	role.put("allow_ip_sans", "true");
	role.put("max_ttl", "72h");

	this.vaultOperations.write("pki/roles/testrole", role);
}
 
Example 8
@Test
void testWritePreferences(@TempDir final Path tempDir) {
	final File file = Files.newFile(tempDir.toString() + File.separator + "afile.svg");

	prefs.pathOpenProperty().set("pathopen");
	prefs.pathExportProperty().set("exportpath");
	prefs.setCurrentFolder(tempDir.toFile());
	prefs.setCurrentFile(file);
	prefs.gridGapProperty().set(prefs.gridGapProperty().get() * 2);
	prefs.addRecentFile("fooRecent");
	prefs.addRecentFile("barFile");
	prefs.gridStyleProperty().set(GridStyle.CUSTOMISED);
	prefs.magneticGridProperty().set(!prefs.isMagneticGrid());
	prefs.setPage(Page.HORIZONTAL);
	prefs.checkVersionProperty().set(!prefs.checkVersionProperty().get());
	prefs.unitProperty().set(Unit.INCH);
	prefs.includesProperty().set("include text");
	prefs.langProperty().set(prefs.getSupportedLocales().stream().filter(l -> l != prefs.langProperty().get()).findFirst().orElseThrow());
	prefs.nbRecentFilesProperty().set(prefs.nbRecentFilesProperty().get() * 3);

	prefs.writePreferences();
	final PreferencesService p2 = new PreferencesService(prefs.getPreferencesPath());
	p2.readPreferences();
	assertPreferencesEqual(prefs, p2);
}
 
Example 9
Source Project: RDFUnit   Source File: TestGeneratorFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTagAndCache() {
    File directory = Files.newTemporaryFolder();
    directory.deleteOnExit();

    RdfUnitTestGenerator g = new GenerateAndCacheRdfUnitTestGenerator(
            new TagRdfUnitTestGenerator(rdfUnit.getAutoGenerators()),
            directory.getAbsolutePath());

    assertThat(directory.listFiles().length == 0).isTrue();
    assertThat(g.generate(schemaSourceOwl))
            .isNotEmpty();
    assertThat(directory.listFiles().length == 1).isTrue();

    // read the cached data
    assertThat(new CacheTestGenerator(directory.getAbsolutePath())
    .generate(schemaSourceOwl))
            .isNotEmpty();
}
 
Example 10
Source Project: quarkus   Source File: AppModelGradleResolverTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testToAppDependency() {
    ResolvedArtifact artifact = mock(ResolvedArtifact.class);
    ResolvedModuleVersion version = mock(ResolvedModuleVersion.class);
    when(version.toString()).thenReturn(":commons-lang3-3.9:");
    when(artifact.getModuleVersion()).thenReturn(version);
    when(artifact.getFile()).thenReturn(Files.currentFolder());
    assertThatCode(() -> AppModelGradleResolver.toAppDependency(artifact)).doesNotThrowAnyException();
}
 
Example 11
Source Project: ArchUnit   Source File: TestUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * NOTE: The resolution of {@link Files#newTemporaryFolder()}, using {@link System#currentTimeMillis()}
 * is not good enough and makes tests flaky.
 */
public static File newTemporaryFolder() {
    String folderName = "archtmp" + System.nanoTime() + random.nextLong();
    File folder = new File(concat(temporaryFolderPath(), folderName));
    if (folder.exists()) {
        Files.delete(folder);
    }
    checkArgument(folder.mkdirs(), "Folder %s already exists", folder.getAbsolutePath());
    folder.deleteOnExit();
    return folder;
}
 
Example 12
@Test
	public void testPersistence() {
		File datadir = Files.newTemporaryFolder();

		SchemaCachingRDFSInferencer sailStack = new SchemaCachingRDFSInferencer(new MemoryStore(datadir), true);
		SailRepository repo = new SailRepository(sailStack);
		repo.initialize();
		ValueFactory vf = repo.getValueFactory();

		IRI s1 = vf.createIRI("foo:s1");
		IRI c2 = vf.createIRI("foo:c2");
		IRI c1 = vf.createIRI("foo:c1");

		try (RepositoryConnection conn = repo.getConnection()) {
			conn.begin();
			conn.add(s1, RDF.TYPE, c1);
			conn.add(c1, RDFS.SUBCLASSOF, c2);
			conn.commit();
			assertTrue(conn.hasStatement(s1, RDF.TYPE, c2, true));
		}
		repo.shutDown();

		// re-init
//		sailStack = new SchemaCachingRDFSInferencer(new MemoryStore(datadir), true);
//		repo = new SailRepository(sailStack);
		repo.initialize();

		try (RepositoryConnection conn = repo.getConnection()) {
			assertTrue(conn.hasStatement(s1, RDF.TYPE, c2, true));
		}
	}
 
Example 13
@Benchmark
public void nativeStoreShaclSerializable(Blackhole blackhole) throws Exception {
	File file = Files.newTemporaryFolder();

	try {
		SailRepository repository = new SailRepository(
				Utils.getInitializedShaclSail(new NativeStore(file, "spoc,ospc,psoc"), "shaclDatatype.ttl"));
		runBenchmark(IsolationLevels.SERIALIZABLE, repository, true, false, blackhole);

	} finally {
		FileUtils.deleteDirectory(file);
	}

}
 
Example 14
@Benchmark
public void nativeStoreShaclSerializableNotParallel(Blackhole blackhole) throws Exception {
	File file = Files.newTemporaryFolder();

	try {
		SailRepository repository = new SailRepository(
				Utils.getInitializedShaclSail(new NativeStore(file, "spoc,ospc,psoc"), "shaclDatatype.ttl"));
		runBenchmark(IsolationLevels.SERIALIZABLE, repository, false, false, blackhole);

	} finally {
		FileUtils.deleteDirectory(file);
	}

}
 
Example 15
@Benchmark
public void nativeStoreShaclSnapshot(Blackhole blackhole) throws Exception {
	File file = Files.newTemporaryFolder();

	try {
		SailRepository repository = new SailRepository(
				Utils.getInitializedShaclSail(new NativeStore(file, "spoc,ospc,psoc"), "shaclDatatype.ttl"));
		runBenchmark(IsolationLevels.SNAPSHOT, repository, true, false, blackhole);

	} finally {
		FileUtils.deleteDirectory(file);
	}

}
 
Example 16
Source Project: rdf4j   Source File: DeadlockTest.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test() throws IOException {

	for (int i = 0; i < 10; i++) {

		String shaclPath = "complexBenchmark/";

		File dataDir = Files.newTemporaryFolder();
		dataDir.deleteOnExit();

		ShaclSail shaclSail = new ShaclSail(new NativeStore(dataDir));
		SailRepository shaclRepository = new SailRepository(shaclSail);
		shaclRepository.init();

		shaclSail.setParallelValidation(true);

		Utils.loadShapeData(shaclRepository, shaclPath + "shacl.ttl");

		try (SailRepositoryConnection connection = shaclRepository.getConnection()) {

			connection.begin(IsolationLevels.SNAPSHOT);
			connection
					.prepareUpdate(IOUtil.readString(
							DeadlockTest.class.getClassLoader().getResourceAsStream(shaclPath + "transaction1.qr")))
					.execute();
			connection.commit();

			connection.begin(IsolationLevels.SNAPSHOT);
			connection
					.prepareUpdate(IOUtil.readString(
							DeadlockTest.class.getClassLoader().getResourceAsStream(shaclPath + "transaction2.qr")))
					.execute();
			connection.commit();
		}
	}
}
 
Example 17
@BeforeEach
public void before() {

	String minikubeIp = System.getProperty("MINIKUBE_IP");
	assumeTrue(StringUtils.hasText(minikubeIp));

	if (!prepare().hasAuth("kubernetes")) {
		prepare().mountAuth("kubernetes");
	}

	prepare().getVaultOperations().doWithSession((RestOperationsCallback<Object>) restOperations -> {
		File workDir = findWorkDir();

		String certificate = Files.contentOf(new File(workDir, "minikube/ca.crt"), StandardCharsets.US_ASCII);

		String host = String.format("https://%s:8443", minikubeIp);

		Map<String, String> kubeConfig = new HashMap<>();
		kubeConfig.put("kubernetes_ca_cert", certificate);
		kubeConfig.put("kubernetes_host", host);
		restOperations.postForEntity("auth/kubernetes/config", kubeConfig, Map.class);

		Map<String, String> roleData = new HashMap<>();
		roleData.put("bound_service_account_names", "default");
		roleData.put("bound_service_account_namespaces", "default");
		roleData.put("policies", "default");
		roleData.put("ttl", "1h");

		return restOperations.postForEntity("auth/kubernetes/role/my-role", roleData, Map.class);
	});
}
 
Example 18
Source Project: spring-vault   Source File: PkiSecretIntegrationTests.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the pki secret backend.
 */
@BeforeEach
void setUp() {

	if (!prepare().hasSecret("pki")) {
		prepare().mountSecret("pki");
	}

	File workDir = findWorkDir(new File(System.getProperty("user.dir")));

	String cert = Files.contentOf(new File(workDir, "ca/certs/intermediate.cert.pem"), StandardCharsets.US_ASCII);

	String key = Files.contentOf(new File(workDir, "ca/private/intermediate.decrypted.key.pem"),
			StandardCharsets.US_ASCII);

	Map<String, String> pembundle = Collections.singletonMap("pem_bundle", cert + key);

	VaultOperations vaultOperations = prepare().getVaultOperations();
	vaultOperations.write("pki/config/ca", pembundle);

	Map<String, String> role = new HashMap<String, String>();
	role.put("allowed_domains", "localhost,example.com");
	role.put("allow_subdomains", "true");
	role.put("allow_localhost", "true");
	role.put("allow_ip_sans", "true");
	role.put("max_ttl", "72h");

	vaultOperations.write("pki/roles/test", role);

}
 
Example 19
Source Project: MarketData   Source File: DocTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void should_generate_readme() throws IOException {
    File readmeFile = findFile("README.md");
    String readme = Files.contentOf(readmeFile, "UTF-8");
    String html = generateHtml(readme);
    writeHtml("README.html", html);
}
 
Example 20
Source Project: MarketData   Source File: DocTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void should_generate_plan() throws IOException {
    File planFile = findFile("PLAN.md");
    String plan = Files.contentOf(planFile, "UTF-8");
    String html = generateHtml(plan);
    writeHtml("PLAN.html", html);
}
 
Example 21
Source Project: MarketData   Source File: DocTest.java    License: Apache License 2.0 5 votes vote down vote up
private void writeHtml(String fileName, String content) throws IOException {
    String testTarget = getClass().getResource("/").getFile();
    FileOutputStream outputStream = new FileOutputStream(new File(testTarget, "../" + fileName));
    content = "<html><head><meta charset=\"UTF-8\"></head>" + content + "</html>";
    outputStream.write(content.getBytes("UTF-8"));
    Files.flushAndClose(outputStream);
}
 
Example 22
@BeforeClass
public static void beforeClass() {

	VaultRule vaultRule = new VaultRule();
	vaultRule.before();

	VaultProperties vaultProperties = Settings.createVaultProperties();

	if (!vaultRule.prepare().hasAuth(vaultProperties.getSsl().getCertAuthPath())) {
		vaultRule.prepare().mountAuth(vaultProperties.getSsl().getCertAuthPath());
	}

	VaultOperations vaultOperations = vaultRule.prepare().getVaultOperations();

	String rules = "{ \"name\": \"testpolicy\",\n" //
			+ "  \"path\": {\n" //
			+ "    \"*\": {  \"policy\": \"read\" }\n" //
			+ "  }\n" //
			+ "}";

	vaultOperations.write("sys/policy/testpolicy",
			Collections.singletonMap("rules", rules));

	vaultOperations.write(
			"secret/" + VaultConfigTlsCertAuthenticationTests.class.getSimpleName(),
			Collections.singletonMap("vault.value", "foo"));

	File workDir = findWorkDir();

	String certificate = Files.contentOf(
			new File(workDir, "ca/certs/client.cert.pem"), StandardCharsets.US_ASCII);

	Map<String, String> role = new HashMap<>();
	role.put("certificate", certificate);
	role.put("policies", "testpolicy");

	vaultOperations.write("auth/cert/certs/my-role", role);
}
 
Example 23
Source Project: kubernetes-client   Source File: PodTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testOptionalUpload() {
  Assertions.assertThrows(KubernetesClientException.class, () -> {
    KubernetesClient client = server.getClient();
    client.pods().inNamespace("ns1").withName("pod2").dir("/etc/hosts/dir").upload(Files.temporaryFolder().toPath());
  });
}
 
Example 24
Source Project: kubernetes-client   Source File: PodTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testOptionalCopy() {
  Assertions.assertThrows(KubernetesClientException.class, () -> {
    KubernetesClient client = server.getClient();
    client.pods().inNamespace("ns1").withName("pod2").file("/etc/hosts").copy(Files.temporaryFolder().toPath());
  });
}
 
Example 25
Source Project: kubernetes-client   Source File: PodTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testOptionalCopyDir() {
  Assertions.assertThrows(KubernetesClientException.class, () -> {
    KubernetesClient client = server.getClient();
    client.pods().inNamespace("ns1").withName("pod2").dir("/etc/hosts").copy(Files.temporaryFolder().toPath());
  });
}
 
Example 26
@SuppressWarnings("unchecked")
@Before
public void before() throws Exception {

	if (operations.count(new Query(), "books") == 0) {

		File file = new ClassPathResource("books.json").getFile();
		String content = Files.contentOf(file, StandardCharsets.UTF_8);
		Document wrapper = Document.parse("{wrapper: " + content + "}");
		List<Object> books = wrapper.getList("wrapper", Object.class);

		operations.insert(books, "books");
	}
}
 
Example 27
@ParameterizedTest
@MethodSource("net.sf.latexdraw.data.ShapeSupplier#createDiversifiedPicture")
default void testPathPicture(final Picture sh) throws IOException {
	final File tmpFile = Files.temporaryFolder();
	sh.setPathSource(ParameteriseShapeData.INST.getTestPNG(tmpFile.toPath()).toString());
	final Picture s2 = produceOutputShapeFrom(sh);
	assertEquals(sh.getPathSource(), s2.getPathSource());
}
 
Example 28
@Before
public void before() {
	file = Files.newTemporaryFolder();
}
 
Example 29
@Setup(Level.Trial)
public void beforeClass() throws IOException {

	tempFolder = Files.newTemporaryFolder();

	File file = File.createTempFile("idfile", "id", tempFolder);

	idFile = new IDFile(file);

	for (int i = 0; i < COUNT * 8; i++) {
		idFile.storeOffset(i);
	}

	idFile.sync(true);

	System.gc();

}
 
Example 30
@Setup(Level.Trial)
public void beforeClass() throws IOException {

	tempFolder = Files.newTemporaryFolder();

	File file = File.createTempFile("hashfile", "hash", tempFolder);

	dataFile = new DataFile(file);
	Random random = new Random(RANDOM_SEED);

	offsets = new ArrayList<>();

	for (int i = 0; i < COUNT; i++) {
		int length = random.nextInt(BYTES.length);
		long offset = dataFile.storeData(Arrays.copyOf(BYTES, length));
		offsets.add(offset);
	}

	dataFile.sync(true);

	System.gc();

}