public class AchillesTestResourceBuilder extends Object
AchillesTestResource
AchillesTestResourceBuilder
.forJunit()
.withScript("script1.cql")
.withScript("script2.cql")
.tablesToTruncate("user", "account") // entityClassesToTruncate(UserEntity.class, AccountEntity.class)
.createAndUseKeyspace("unit_test")
.
...
.build((cluster, statementsCache) -> ManagerFactoryBuilder
.builder(cluster)
.doForceSchemaCreation(true)
.withStatementCache(statementsCache)
.withDefaultKeyspaceName(DEFAULT_CASSANDRA_EMBEDDED_KEYSPACE_NAME)
.build()
);
| Modifier and Type | Method and Description |
|---|---|
<T extends AbstractManagerFactory> |
build(java.util.function.BiFunction<Cluster,StatementsCache,T> managerFactoryBuilder)
Provide a lambda function to build the ManagerFactory instance with the given Cluster object
|
AchillesTestResourceBuilder |
createAndUseKeyspace(String keyspaceName)
Keyspace name to create
|
AchillesTestResourceBuilder |
entityClassesToTruncate(Class<?>... entityClassesToTruncate)
Entity classes whose table should be truncated during unit tests
|
static AchillesTestResourceBuilder |
forJunit() |
AchillesTestResourceBuilder |
tablesToTruncate(String... tablesToTruncate)
Tables to be truncated during unit tests
|
AchillesTestResourceBuilder |
truncateAfterTest()
Truncate tables AFTER each test
|
AchillesTestResourceBuilder |
truncateBeforeAndAfterTest()
Truncate tables BEFORE and AFTER each test
|
AchillesTestResourceBuilder |
truncateBeforeTest()
Truncate tables BEFORE each test
|
AchillesTestResourceBuilder |
withCassandraParams(Map<String,Object> cassandraParams)
Use this function to add parameters to cassandra startup.
|
AchillesTestResourceBuilder |
withProtocolVersion(ProtocolVersion protocolVersion)
Set the protocol version for the Java driver to connect to the embedded Cassandra server
|
AchillesTestResourceBuilder |
withScript(String scriptLocation)
/**
Load an CQL script in the class path and execute it upon initialization
of the embedded Cassandra server
Call this method as many times as there are CQL scripts to be executed. |
AchillesTestResourceBuilder |
withScriptTemplate(String scriptTemplateLocation,
Map<String,Object> values)
Load an CQL script template in the class path, inject the values into the template
to produce the final script and execute it upon initialization
of the embedded Cassandra server
Call this method as many times as there are CQL templates to be executed. |
public static AchillesTestResourceBuilder forJunit()
public AchillesTestResourceBuilder withScript(String scriptLocation)
AchillesTestResourceBuilder
.forJunit()
.withScript("script1.cql")
.withScript("script2.cql")
...
.build(cluster -> ManagerFactoryBuilder
.builder(cluster)
.doForceSchemaCreation(true)
.withDefaultKeyspaceName(DEFAULT_CASSANDRA_EMBEDDED_KEYSPACE_NAME)
.build());
scriptLocation - location of the CQL script in the class pathpublic AchillesTestResourceBuilder withScriptTemplate(String scriptTemplateLocation, Map<String,Object> values)
Map<String, Object> map1 = new HashMap<>();
map1.put("id", 100L);
map1.put("date", new Date());
...
AchillesTestResourceBuilder
.forJunit()
.withScriptTemplate("script1.cql", map1)
.withScriptTemplate("script2.cql", map2)
...
.build();
scriptTemplateLocation - location of the CQL script in the class pathvalues - values to inject into the template.public AchillesTestResourceBuilder withProtocolVersion(ProtocolVersion protocolVersion)
protocolVersion - target protocol versionpublic AchillesTestResourceBuilder createAndUseKeyspace(String keyspaceName)
keyspaceName - keyspace namepublic AchillesTestResourceBuilder entityClassesToTruncate(Class<?>... entityClassesToTruncate)
entityClassesToTruncate - list of entity classes whose table should be truncated before and/or after testspublic AchillesTestResourceBuilder tablesToTruncate(String... tablesToTruncate)
tablesToTruncate - list of tables to truncatepublic AchillesTestResourceBuilder truncateBeforeTest()
public AchillesTestResourceBuilder truncateAfterTest()
public AchillesTestResourceBuilder truncateBeforeAndAfterTest()
public <T extends AbstractManagerFactory> AchillesTestResource<T> build(java.util.function.BiFunction<Cluster,StatementsCache,T> managerFactoryBuilder)
managerFactoryBuilder - lambda functionpublic AchillesTestResourceBuilder withCassandraParams(Map<String,Object> cassandraParams)
AchillesTestResourceBuilder
.forJunit()
.withCassandraParams(Collections.singletonMap(CASSANDRA_CQL_PORT, 9042))
...
.build();
Copyright © 2012-2021. All Rights Reserved.