11package com .example .accessingdatacassandra ;
22
3+ import java .util .List ;
4+
35import org .junit .jupiter .api .Test ;
6+
7+ import org .springframework .boot .autoconfigure .cassandra .CassandraProperties ;
48import org .springframework .boot .test .context .SpringBootTest ;
9+ import org .springframework .boot .test .context .TestConfiguration ;
10+ import org .springframework .data .cassandra .config .AbstractCassandraConfiguration ;
11+ import org .springframework .data .cassandra .config .SchemaAction ;
12+ import org .springframework .data .cassandra .core .cql .keyspace .CreateKeyspaceSpecification ;
13+ import org .springframework .data .cassandra .core .cql .keyspace .SpecificationBuilder ;
14+ import org .springframework .lang .NonNull ;
515
616@ SpringBootTest
717class AccessingDataCassandraApplicationTests {
@@ -10,4 +20,34 @@ class AccessingDataCassandraApplicationTests {
1020 void contextLoads () {
1121 }
1222
23+ @ TestConfiguration
24+ static class CreateKeyspaceConfiguration extends AbstractCassandraConfiguration {
25+
26+ private final CassandraProperties properties ;
27+
28+ CreateKeyspaceConfiguration (CassandraProperties properties ) {
29+ this .properties = properties ;
30+ }
31+
32+ @ NonNull
33+ @ Override
34+ protected List <CreateKeyspaceSpecification > getKeyspaceCreations () {
35+ CreateKeyspaceSpecification specification = SpecificationBuilder
36+ .createKeyspace (getKeyspaceName ()).ifNotExists ()
37+ .withSimpleReplication (1 );
38+
39+ return List .of (specification );
40+ }
41+
42+ @ Override
43+ public SchemaAction getSchemaAction () {
44+ return SchemaAction .RECREATE_DROP_UNUSED ;
45+ }
46+
47+ @ NonNull
48+ @ Override
49+ protected String getKeyspaceName () {
50+ return this .properties .getKeyspaceName ();
51+ }
52+ }
1353}
0 commit comments