Search in sources :

Example 11 with CassandraVersion

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);
}
Also used : Option(com.datastax.driver.mapping.Mapper.Option) Test(org.testng.annotations.Test) CassandraVersion(com.datastax.driver.core.utils.CassandraVersion)

Example 12 with CassandraVersion

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();
}
Also used : Row(com.datastax.driver.core.Row) Test(org.testng.annotations.Test) CassandraVersion(com.datastax.driver.core.utils.CassandraVersion)

Example 13 with CassandraVersion

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);
}
Also used : Pattern(java.util.regex.Pattern) Test(org.testng.annotations.Test) CassandraVersion(com.datastax.driver.core.utils.CassandraVersion)

Example 14 with CassandraVersion

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);
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata) Test(org.testng.annotations.Test) CassandraVersion(com.datastax.driver.core.utils.CassandraVersion)

Example 15 with CassandraVersion

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);
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata) Test(org.testng.annotations.Test) CassandraVersion(com.datastax.driver.core.utils.CassandraVersion)

Aggregations

CassandraVersion (com.datastax.driver.core.utils.CassandraVersion)16 Test (org.testng.annotations.Test)15 ColumnMetadata (com.datastax.driver.core.ColumnMetadata)8 Row (com.datastax.driver.core.Row)3 ResultSet (com.datastax.driver.core.ResultSet)2 CustomStatement (com.datastax.driver.core.StatementWrapperTest.CustomStatement)1 UnsupportedProtocolVersionException (com.datastax.driver.core.exceptions.UnsupportedProtocolVersionException)1 DseVersion (com.datastax.driver.core.utils.DseVersion)1 Option (com.datastax.driver.mapping.Mapper.Option)1 Pattern (java.util.regex.Pattern)1