Search in sources :

Example 1 with ClassPathResource

use of com.github.nosan.embedded.cassandra.commons.ClassPathResource in project embedded-cassandra by nosan.

the class WebCassandraDirectoryProviderTests method beforeAll.

@BeforeAll
static void beforeAll() throws IOException {
    httpServer = HttpServer.create(new InetSocketAddress(0), 0);
    httpServer.createContext("/", exchange -> {
        String uri = exchange.getRequestURI().toString();
        ClassPathResource resource = new ClassPathResource(uri.substring(uri.lastIndexOf('/')));
        long size = Files.size(Paths.get(resource.toURI()));
        exchange.sendResponseHeaders(200, size);
        try (InputStream inputStream = resource.getInputStream()) {
            StreamUtils.copy(inputStream, exchange.getResponseBody());
        } finally {
            exchange.close();
        }
    });
    httpServer.setExecutor(Executors.newCachedThreadPool());
    httpServer.start();
    httpClient = new JdkHttpClient(Duration.ofSeconds(1), Duration.ofSeconds(1));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) InputStream(java.io.InputStream) JdkHttpClient(com.github.nosan.embedded.cassandra.commons.web.JdkHttpClient) ClassPathResource(com.github.nosan.embedded.cassandra.commons.ClassPathResource) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with ClassPathResource

use of com.github.nosan.embedded.cassandra.commons.ClassPathResource in project embedded-cassandra by nosan.

the class WorkingDirectoryCustomizerTests method shouldNotCopyOutOfDirectory.

@Test
void shouldNotCopyOutOfDirectory(@TempDir Path directory) {
    ClassPathResource resource = new ClassPathResource("schema.cql");
    assertThatThrownBy(() -> WorkingDirectoryCustomizer.addResource(resource, "/conf/schema.cql").customize(directory, CassandraBuilder.DEFAULT_VERSION)).hasMessageContaining("is out of a directory");
}
Also used : ClassPathResource(com.github.nosan.embedded.cassandra.commons.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 3 with ClassPathResource

use of com.github.nosan.embedded.cassandra.commons.ClassPathResource in project embedded-cassandra by nosan.

the class DefaultCassandraDatabaseFactoryTests method setConfigFileUri.

@Test
void setConfigFileUri(@TempDir Path workingDirectory) throws Exception {
    ClassPathResource resource = new ClassPathResource("cassandra-4.0.3.yaml");
    this.systemProperties.put("cassandra.config", resource.toURI());
    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 4 with ClassPathResource

use of com.github.nosan.embedded.cassandra.commons.ClassPathResource in project embedded-cassandra by nosan.

the class DefaultCassandraDatabaseFactoryTests method setConfigPropertyClassPathResource.

@Test
void setConfigPropertyClassPathResource(@TempDir Path workingDirectory) throws Exception {
    ClassPathResource resource = new ClassPathResource("cassandra-4.0.3.yaml");
    this.configProperties.put("test", resource);
    CassandraDatabase database = create(Version.parse("4.0"), workingDirectory);
    Map<String, Object> configProperties = database.getConfigProperties();
    assertThat(configProperties.get("test")).isEqualTo(Paths.get(resource.toURI()).toString());
}
Also used : ClassPathResource(com.github.nosan.embedded.cassandra.commons.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 5 with ClassPathResource

use of com.github.nosan.embedded.cassandra.commons.ClassPathResource in project embedded-cassandra by nosan.

the class DefaultCassandraDatabaseFactoryTests method setConfigPropertyArrayClassPathResource.

@Test
void setConfigPropertyArrayClassPathResource(@TempDir Path workingDirectory) throws Exception {
    ClassPathResource resource = new ClassPathResource("cassandra-4.0.3.yaml");
    this.configProperties.put("test", new ClassPathResource[] { resource });
    CassandraDatabase database = create(Version.parse("4.0"), workingDirectory);
    Map<String, Object> configProperties = database.getConfigProperties();
    assertThat(((Collection<Object>) configProperties.get("test"))).containsExactly(Paths.get(resource.toURI()).toString());
}
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