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));
}
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");
}
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());
}
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());
}
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());
}
Aggregations