use of com.github.nosan.embedded.cassandra.commons.ClassPathResource in project embedded-cassandra by nosan.
the class DefaultCassandraDatabaseFactoryTests method setConfigFileString.
@Test
void setConfigFileString(@TempDir Path workingDirectory) throws Exception {
ClassPathResource resource = new ClassPathResource("cassandra-4.0.3.yaml");
this.systemProperties.put("cassandra.config", resource.toURL().toString());
CassandraDatabase database = create(Version.parse("4.0.1"), workingDirectory);
Map<String, String> systemProperties = database.getSystemProperties();
Map<String, String> environmentVariables = database.getEnvironmentVariables();
try (InputStream inputStream = resource.getInputStream()) {
assertThat(new Yaml().loadAs(inputStream, Map.class)).containsAllEntriesOf(database.getConfigProperties());
}
try (InputStream inputStream = Files.newInputStream(database.getConfigurationFile())) {
assertThat(new Yaml().loadAs(inputStream, Map.class)).containsAllEntriesOf(database.getConfigProperties());
}
assertThat(systemProperties.get("cassandra.config")).isEqualTo(database.getConfigurationFile().toUri().toString());
assertThat(environmentVariables.get("JVM_EXTRA_OPTS")).contains("-Dcassandra.config=" + database.getConfigurationFile().toUri());
}
use of com.github.nosan.embedded.cassandra.commons.ClassPathResource in project embedded-cassandra by nosan.
the class DefaultCassandraIntegrationTests method testSuccessWhenSslClientEnabled.
@ParameterizedTest
@MethodSource("versions")
void testSuccessWhenSslClientEnabled(Version version) throws Throwable {
Map<String, Object> clientEncryptionOptions = new LinkedHashMap<>();
clientEncryptionOptions.put("enabled", true);
clientEncryptionOptions.put("require_client_auth", true);
clientEncryptionOptions.put("optional", false);
clientEncryptionOptions.put("keystore", new ClassPathResource("server.keystore"));
clientEncryptionOptions.put("keystore_password", "123456");
clientEncryptionOptions.put("truststore", new ClassPathResource("server.truststore"));
clientEncryptionOptions.put("truststore_password", "123456");
this.builder.version(version).addConfigProperty("client_encryption_options", clientEncryptionOptions);
this.runner.run((cassandra, throwable) -> {
assertThat(throwable).doesNotThrowAnyException();
assertThat(cassandra.getName()).isNotBlank();
assertThat(cassandra.getWorkingDirectory()).isNotNull();
assertThat(cassandra.getVersion()).isEqualTo(version);
assertThat(cassandra.isRunning()).isTrue();
Settings settings = cassandra.getSettings();
assertThat(settings.getSslPort()).isNull();
SessionFactory sessionFactory = new SessionFactory();
sessionFactory.address = settings.getAddress();
sessionFactory.port = settings.getPort();
assertThatThrownBy(() -> createScheme(sessionFactory)).hasStackTraceContaining("Could not reach any contact point");
sessionFactory.sslEnabled = true;
sessionFactory.truststore = new ClassPathResource("client.truststore");
sessionFactory.truststorePassword = "123456";
sessionFactory.keystore = new ClassPathResource("client.keystore");
sessionFactory.keystorePassword = "123456";
createScheme(sessionFactory);
});
}
use of com.github.nosan.embedded.cassandra.commons.ClassPathResource in project embedded-cassandra by nosan.
the class DefaultCassandraIntegrationTests method testSuccessWhenSslClientEnabledSslPort.
@ParameterizedTest
@MethodSource("versions")
void testSuccessWhenSslClientEnabledSslPort(Version version) throws Throwable {
Map<String, Object> clientEncryptionOptions = new LinkedHashMap<>();
clientEncryptionOptions.put("enabled", true);
clientEncryptionOptions.put("require_client_auth", true);
clientEncryptionOptions.put("optional", false);
clientEncryptionOptions.put("keystore", "conf/server.keystore");
clientEncryptionOptions.put("keystore_password", "123456");
clientEncryptionOptions.put("truststore", "conf/server.truststore");
clientEncryptionOptions.put("truststore_password", "123456");
this.builder.version(version).addWorkingDirectoryResource(new ClassPathResource("server.keystore"), "conf/server.keystore").addWorkingDirectoryResource(new ClassPathResource("server.truststore"), "conf/server.truststore").addConfigProperty("native_transport_port_ssl", 9142).addConfigProperty("client_encryption_options", clientEncryptionOptions);
this.runner.run((cassandra, throwable) -> {
assertThat(throwable).doesNotThrowAnyException();
assertThat(cassandra.getName()).isNotBlank();
assertThat(cassandra.getWorkingDirectory()).isNotNull();
assertThat(cassandra.getVersion()).isEqualTo(version);
assertThat(cassandra.isRunning()).isTrue();
Settings settings = cassandra.getSettings();
assertThat(settings.getSslPort()).isEqualTo(9142);
SessionFactory sessionFactory = new SessionFactory();
sessionFactory.address = settings.getAddress();
sessionFactory.port = settings.getSslPort();
assertThatThrownBy(() -> createScheme(sessionFactory)).hasStackTraceContaining("Could not reach any contact point");
sessionFactory.sslEnabled = true;
sessionFactory.truststore = new ClassPathResource("client.truststore");
sessionFactory.truststorePassword = "123456";
sessionFactory.keystore = new ClassPathResource("client.keystore");
sessionFactory.keystorePassword = "123456";
createScheme(sessionFactory);
});
}
use of com.github.nosan.embedded.cassandra.commons.ClassPathResource in project embedded-cassandra by nosan.
the class CassandraBuilderTests method workingDirectoryCustomizers.
@Test
void workingDirectoryCustomizers() {
WorkingDirectoryCustomizer w1 = WorkingDirectoryCustomizer.addResource(new ClassPathResource("text.txt"), "conf/text.txt");
WorkingDirectoryCustomizer w2 = WorkingDirectoryCustomizer.addResource(new ClassPathResource("empty.txt"), "conf/empty.txt");
assertThat(this.builder.workingDirectoryCustomizers(w1).build()).hasFieldOrPropertyWithValue("workingDirectoryCustomizers", Collections.singleton(w1));
assertThat(this.builder.workingDirectoryCustomizers(w2).build()).hasFieldOrPropertyWithValue("workingDirectoryCustomizers", Collections.singleton(w2));
assertThat(this.builder.addWorkingDirectoryCustomizers(w1).build()).hasFieldOrPropertyWithValue("workingDirectoryCustomizers", new LinkedHashSet<>(Arrays.asList(w2, w1)));
}
use of com.github.nosan.embedded.cassandra.commons.ClassPathResource in project embedded-cassandra by nosan.
the class WorkingDirectoryCustomizerTests method shouldNotCopyTargetIsDirectory.
@Test
void shouldNotCopyTargetIsDirectory(@TempDir Path directory) throws IOException {
Files.createDirectories(directory.resolve("conf/schema.cql"));
ClassPathResource resource = new ClassPathResource("schema.cql");
assertThatThrownBy(() -> WorkingDirectoryCustomizer.addResource(resource, "conf/schema.cql").customize(directory, CassandraBuilder.DEFAULT_VERSION)).hasMessageContaining("is a directory");
}
Aggregations