I would like to test my SpringBoot application that uses cassandra as CrudRepository. I finished with
@RunWith(SpringJUnit4ClassRunner.class)
@ComponentScan
@ContextConfiguration(value = { "classpath:/default-context.xml" })
@TestExecutionListeners({ CassandraUnitTestExecutionListener.class })
@CassandraDataSet(value = { "setupTables.cql" }, keyspace = "keyspaceToCreate")
@CassandraUnit
public class ApplicationTests {
@Autowired
MyCassandraRepository repo;
@Test
public void contextLoads() {
System.out.println(repo.findAll());
}
}
with
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit-spring</artifactId>
<version>3.0.0.1</version>
<scope>test</scope>
</dependency>
and
CREATE TABLE MY_CASSANDRA_ENTRY (
MY_CASS_STRING varchar PRIMARY KEY
)
It leads to
com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: localhost/127.0.0.1:9142 (com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table schema_keyspaces))
If I use an older version of cassandra-unit- spring
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit-spring</artifactId>
<version>2.1.9.2</version>
<scope>test</scope>
</dependency>
it ends with a NullPointerException because the repo value is not entered.
Sources https://github.com/StephanPraetsch/spring.boot.cassandra.unit.test
source
share