use of com.datastax.driver.core.utils.CassandraVersion in project java-driver by datastax.
the class MapperOptionTest method should_use_delete_options.
@Test(groups = "short")
@CassandraVersion("2.0.0")
void should_use_delete_options() {
User todelete = new User(45, "todelete");
mapper.save(todelete);
Option opt = Option.timestamp(35);
BoundStatement bs = (BoundStatement) mapper.deleteQuery(45, opt, Option.consistencyLevel(QUORUM));
assertThat(bs.preparedStatement().getQueryString()).contains("USING TIMESTAMP");
assertThat(bs.getConsistencyLevel()).isEqualTo(QUORUM);
}
use of com.datastax.driver.core.utils.CassandraVersion in project java-driver by datastax.
the class MapperAccessorTest method should_allow_null_argument_in_accessor_when_set_by_name.
@Test(groups = "short")
@CassandraVersion("2.0.0")
public void should_allow_null_argument_in_accessor_when_set_by_name() {
FooAccessor accessor = new MappingManager(session()).createAccessor(FooAccessor.class);
accessor.insert(1, null);
Row row = session().execute("select * from foo where k = 1").one();
assertThat(row.getString("v")).isNull();
}
use of com.datastax.driver.core.utils.CassandraVersion in project java-driver by datastax.
the class MapperOptionTest method should_use_if_not_exists_option.
@Test(groups = "short")
@CassandraVersion("2.0.0")
void should_use_if_not_exists_option() {
Pattern ifNotExistsPattern = Pattern.compile(".*\\sIF\\s+NOT\\s+EXISTS(\\s+)?;?(\\s+)?$", Pattern.CASE_INSENSITIVE);
User user = new User(42, "Cin Ali");
// test default
BoundStatement saveDefault = (BoundStatement) mapper.saveQuery(user);
DefaultPreparedStatement stmt = (DefaultPreparedStatement) saveDefault.preparedStatement();
assertThat(stmt.getQueryString()).doesNotMatch(ifNotExistsPattern);
// test disabled
saveDefault = (BoundStatement) mapper.saveQuery(user, Option.ifNotExists(false));
stmt = (DefaultPreparedStatement) saveDefault.preparedStatement();
assertThat(stmt.getQueryString()).doesNotMatch(ifNotExistsPattern);
// test enabled
saveDefault = (BoundStatement) mapper.saveQuery(user, Option.ifNotExists(true));
stmt = (DefaultPreparedStatement) saveDefault.preparedStatement();
assertThat(stmt.getQueryString()).matches(ifNotExistsPattern);
// test default enabled
mapper.setDefaultSaveOptions(Option.ifNotExists(true));
saveDefault = (BoundStatement) mapper.saveQuery(user);
stmt = (DefaultPreparedStatement) saveDefault.preparedStatement();
assertThat(stmt.getQueryString()).matches(ifNotExistsPattern);
// test default disabled
mapper.setDefaultSaveOptions(Option.ifNotExists(false));
saveDefault = (BoundStatement) mapper.saveQuery(user);
stmt = (DefaultPreparedStatement) saveDefault.preparedStatement();
assertThat(stmt.getQueryString()).doesNotMatch(ifNotExistsPattern);
}
use of com.datastax.driver.core.utils.CassandraVersion in project java-driver by datastax.
the class IndexMetadataTest method should_create_metadata_for_index_on_map_keys.
@Test(groups = "short")
@CassandraVersion("2.1.0")
public void should_create_metadata_for_index_on_map_keys() {
String createKeysIndex = String.format("CREATE INDEX map_keys_index ON %s.indexing (keys(map_keys));", keyspace);
session().execute(createKeysIndex);
ColumnMetadata column = getColumn("map_keys");
IndexMetadata index = getIndex("map_keys_index");
assertThat(index).hasName("map_keys_index").hasParent((TableMetadata) column.getParent()).isNotCustomIndex().hasTarget("keys(map_keys)").hasKind(COMPOSITES).asCqlQuery(createKeysIndex);
assertThat((TableMetadata) column.getParent()).hasIndex(index);
}
use of com.datastax.driver.core.utils.CassandraVersion in project java-driver by datastax.
the class IndexMetadataTest method should_create_metadata_for_full_index_on_map.
@Test(groups = "short")
@CassandraVersion("2.1.3")
public void should_create_metadata_for_full_index_on_map() {
String createFullIndex = String.format("CREATE INDEX map_full_index ON %s.indexing (full(map_full));", keyspace);
session().execute(createFullIndex);
ColumnMetadata column = getColumn("map_full");
IndexMetadata index = getIndex("map_full_index");
assertThat(index).hasName("map_full_index").hasParent((TableMetadata) column.getParent()).isNotCustomIndex().hasTarget("full(map_full)").hasKind(COMPOSITES).asCqlQuery(createFullIndex);
assertThat((TableMetadata) column.getParent()).hasIndex(index);
}
Aggregations