Search in sources :

Example 6 with ClassPathResource

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());
}
Also used : InputStream(java.io.InputStream) ClassPathResource(com.github.nosan.embedded.cassandra.commons.ClassPathResource) Yaml(org.yaml.snakeyaml.Yaml) Test(org.junit.jupiter.api.Test)

Example 7 with ClassPathResource

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);
    });
}
Also used : ClassPathResource(com.github.nosan.embedded.cassandra.commons.ClassPathResource) LinkedHashMap(java.util.LinkedHashMap) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with ClassPathResource

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);
    });
}
Also used : ClassPathResource(com.github.nosan.embedded.cassandra.commons.ClassPathResource) LinkedHashMap(java.util.LinkedHashMap) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with ClassPathResource

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)));
}
Also used : ClassPathResource(com.github.nosan.embedded.cassandra.commons.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 10 with ClassPathResource

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");
}
Also used : ClassPathResource(com.github.nosan.embedded.cassandra.commons.ClassPathResource) Test(org.junit.jupiter.api.Test)

Aggregations

ClassPathResource (com.github.nosan.embedded.cassandra.commons.ClassPathResource)24 Test (org.junit.jupiter.api.Test)17 InputStream (java.io.InputStream)9 Yaml (org.yaml.snakeyaml.Yaml)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 LinkedHashMap (java.util.LinkedHashMap)3 CassandraBuilder (com.github.nosan.embedded.cassandra.CassandraBuilder)1 JdkHttpClient (com.github.nosan.embedded.cassandra.commons.web.JdkHttpClient)1 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1