org.assertj.core.util.Files Java Examples

The following examples show how to use org.assertj.core.util.Files. 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: TestGeneratorFactoryTest.java    From RDFUnit with 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 #2
Source File: ClientCertificateAuthenticationIntegrationTestBase.java    From spring-vault with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: ParallelBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #4
Source File: ReactiveLifecycleAwareSessionManagerIntegrationTests.java    From spring-vault with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: VaultPkiTemplateIntegrationTests.java    From spring-vault with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: NativeStoreTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #7
Source File: TransactionsPerSecondForceSyncBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #8
Source File: TransactionsPerSecondBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #9
Source File: TestPreferencesService.java    From latexdraw with GNU General Public License v3.0 6 votes vote down vote up
@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 #10
Source File: SpringBooksIntegrationTests.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
@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 #11
Source File: PodTest.java    From kubernetes-client with 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 #12
Source File: PodTest.java    From kubernetes-client with 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 #13
Source File: PodTest.java    From kubernetes-client with 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 #14
Source File: VaultConfigTlsCertAuthenticationTests.java    From spring-cloud-vault with Apache License 2.0 5 votes vote down vote up
@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 #15
Source File: DocTest.java    From MarketData with 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 #16
Source File: DocTest.java    From MarketData with 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 #17
Source File: DocTest.java    From MarketData with 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 #18
Source File: PkiSecretIntegrationTests.java    From spring-vault with 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 File: PolymorphPictureTest.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@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 #20
Source File: KubernetesAuthenticationIntegrationTestBase.java    From spring-vault with Apache License 2.0 5 votes vote down vote up
@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 #21
Source File: TestUtils.java    From ArchUnit with 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 #22
Source File: AppModelGradleResolverTest.java    From quarkus with 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 #23
Source File: DeadlockTest.java    From rdf4j with 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 #24
Source File: ParallelBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #25
Source File: ParallelBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #26
Source File: ParallelBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #27
Source File: MemInferencingTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #28
Source File: VaultConfigKubernetesTests.java    From spring-cloud-vault with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() {

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

	String minikubeIp = System.getProperty("MINIKUBE_IP");
	assumeTrue(StringUtils.hasText(minikubeIp) && vaultRule.prepare().getVersion()
			.isGreaterThanOrEqualTo(Version.parse("0.8.3")));

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

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

	Policy policy = Policy.of(
			Rule.builder().path("*").capabilities(BuiltinCapabilities.READ).build());

	vaultOperations.opsForSys().createOrUpdatePolicy("testpolicy", policy);

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

	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);
	vaultOperations.write("auth/kubernetes/config", kubeConfig);

	Map<String, String> roleData = new HashMap<>();
	roleData.put("bound_service_account_names", "default");
	roleData.put("bound_service_account_namespaces", "default");
	roleData.put("policies", "testpolicy");
	roleData.put("ttl", "1h");
	vaultOperations.write("auth/kubernetes/role/my-role", roleData);
}
 
Example #29
Source File: LongMultithreadedTransactions.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Before
public void before() {
	file = Files.newTemporaryFolder();
}
 
Example #30
Source File: TestPreferencesService.java    From latexdraw with GNU General Public License v3.0 4 votes vote down vote up
@Test
void testSetCurrentFile(@TempDir final Path tempDir) {
	final File file = Files.newFile(tempDir.toString() + File.separator + "afile.svg");
	prefs.setCurrentFile(file);
	assertEquals(file, prefs.getCurrentFile().orElseThrow());
}