DATACASS-94 - added AbstractCqlTemplateConfiguration

This commit is contained in:
Matthew Adams
2014-02-17 11:04:12 -06:00
parent c9792e4e59
commit 9cd48548e9
5 changed files with 69 additions and 5 deletions

View File

@@ -42,7 +42,7 @@ import com.datastax.driver.core.policies.RetryPolicy;
public abstract class AbstractClusterConfiguration {
@Bean
public CassandraClusterFactoryBean cluster() throws Exception {
public CassandraClusterFactoryBean cluster() {
CassandraClusterFactoryBean bean = new CassandraClusterFactoryBean();
bean.setAuthProvider(getAuthProvider());

View File

@@ -0,0 +1,12 @@
package org.springframework.cassandra.config.java;
import org.springframework.cassandra.core.CqlTemplate;
import org.springframework.context.annotation.Bean;
public abstract class AbstractCqlTemplateConfiguration extends AbstractSessionConfiguration {
@Bean
public CqlTemplate cqlTemplate() throws Exception {
return new CqlTemplate(session().getObject());
}
}

View File

@@ -17,10 +17,16 @@ package org.springframework.cassandra.test.integration.config;
import static org.junit.Assert.assertNotNull;
import org.springframework.cassandra.core.CqlTemplate;
import com.datastax.driver.core.Session;
public class IntegrationTestUtils {
public static void assertCqlTemplate(CqlTemplate cqlTemplate) {
assertNotNull(cqlTemplate);
}
public static void assertSession(Session session) {
assertNotNull(session);
}

View File

@@ -15,6 +15,9 @@
*/
package org.springframework.cassandra.test.integration.config.java;
import static org.springframework.cassandra.core.cql.generator.CreateKeyspaceCqlGenerator.toCql;
import static org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification.createKeyspace;
import org.springframework.cassandra.config.CassandraSessionFactoryBean;
import org.springframework.cassandra.config.java.AbstractSessionConfiguration;
import org.springframework.context.annotation.Configuration;
@@ -46,10 +49,7 @@ public abstract class AbstractKeyspaceCreatingConfiguration extends AbstractSess
return;
}
// TODO: use KeyspaceBuilder to build keyspace with attributes & options
system.execute("CREATE KEYSPACE " + keyspace
+ " WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };");
system.execute(toCql(createKeyspace().name(keyspace).withSimpleReplication()));
system.shutdown();
}
}

View File

@@ -0,0 +1,46 @@
package org.springframework.cassandra.test.integration.config.java;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.config.java.AbstractCqlTemplateConfiguration;
import org.springframework.cassandra.core.CqlTemplate;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.cassandra.test.integration.config.IntegrationTestUtils;
import org.springframework.cassandra.test.unit.support.Utils;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class CqlTemplateConfigIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest {
public static final String KEYSPACE_NAME = Utils.randomKeyspaceName();
@Configuration
public static class Config extends AbstractCqlTemplateConfiguration {
@Override
protected String getKeyspaceName() {
return KEYSPACE_NAME;
}
@Override
protected int getPort() {
return CASSANDRA_NATIVE_PORT;
}
}
@Autowired
CqlTemplate template;
public CqlTemplateConfigIntegrationTest() {
super(KEYSPACE_NAME);
}
@Test
public void test() {
IntegrationTestUtils.assertCqlTemplate(template);
}
}