public class AchillesTestResource<T extends AbstractManagerFactory>
extends org.junit.rules.ExternalResource
@Rule
public AchillesTestResource resource = AchillesTestResourceBuilder
.forJunit()
.withKeyspace("unit_test") // default keyspace = achilles_embedded
.entityClassesToTruncate(SimpleEntity.class)
.truncateBeforeAndAfterTest()
.build((cluster, statementsCache) -> ManagerFactoryBuilder
.builder(cluster)
.doForceSchemaCreation(true)
.withStatementCache(statementsCache)
.withDefaultKeyspaceName(DEFAULT_CASSANDRA_EMBEDDED_KEYSPACE_NAME)
.build()
);
private Session session = resource.getNativeSession();
private ScriptExecutor scriptExecutor = resource.getScriptExecutor();
private SimpleEntity_Manager manager = resource.getManagerFactory().forSimpleEntity();
@Test
public void should_test_xxx() throws Exception {
//Given
final long id = RandomUtils.nextLong(0, Long.MAX_VALUE);
scriptExecutor.executeScriptTemplate("SimpleEntity/insert_single_row.cql", ImmutableMap.of("id", id));
//When
//Then
Row actual = session.execute("SELECT ....").one();
assertTrue(row.getString("xxx").equals("yyy"));
...
}
| Modifier and Type | Class and Description |
|---|---|
static class |
AchillesTestResource.Steps |
| Constructor and Description |
|---|
AchillesTestResource(java.util.function.BiFunction<Cluster,StatementsCache,T> managerFactoryBuilder,
info.archinnov.achilles.type.TypedMap cassandraParams,
Optional<String> keyspaceName,
AchillesTestResource.Steps cleanUpSteps,
List<String> tablesToTruncate,
List<Class<?>> entityClassesToTruncate) |
AchillesTestResource(java.util.function.BiFunction<Cluster,StatementsCache,T> managerFactoryBuilder,
info.archinnov.achilles.type.TypedMap cassandraParams,
Optional<String> keyspaceName,
List<String> tablesToTruncate,
List<Class<?>> entityClassesToTruncate) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
after() |
protected void |
before() |
T |
getManagerFactory() |
Session |
getNativeSession() |
info.archinnov.achilles.script.ScriptExecutor |
getScriptExecutor() |
void |
truncateTables() |
public AchillesTestResource(java.util.function.BiFunction<Cluster,StatementsCache,T> managerFactoryBuilder, info.archinnov.achilles.type.TypedMap cassandraParams, Optional<String> keyspaceName, List<String> tablesToTruncate, List<Class<?>> entityClassesToTruncate)
public AchillesTestResource(java.util.function.BiFunction<Cluster,StatementsCache,T> managerFactoryBuilder, info.archinnov.achilles.type.TypedMap cassandraParams, Optional<String> keyspaceName, AchillesTestResource.Steps cleanUpSteps, List<String> tablesToTruncate, List<Class<?>> entityClassesToTruncate)
public Session getNativeSession()
public info.archinnov.achilles.script.ScriptExecutor getScriptExecutor()
public T getManagerFactory()
protected void before()
throws Throwable
before in class org.junit.rules.ExternalResourceThrowableprotected void after()
after in class org.junit.rules.ExternalResourcepublic void truncateTables()
Copyright © 2012-2021. All Rights Reserved.