@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The keyspace name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_keyspace_name_is_a_reserved_keyword() throws Exception { alterTable("add", "test").addColumn("test").type(DataType.ascii()); }
@Test(groups = "unit") public void should_add_column() throws Exception { // When SchemaStatement statement = alterTable("test").addColumn("location").type(DataType.ascii()); // Then assertThat(statement.getQueryString()).isEqualTo("\n\tALTER TABLE test ADD location ascii"); }
@Test(groups = "unit") public void should_add_column_with_UDT_type() throws Exception { // When SchemaStatement statement = alterTable("test").addColumn("location").udtType(frozen("address")); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tALTER TABLE test ADD location frozen<address>"); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The table name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_table_name_is_a_reserved_keyword() throws Exception { alterTable("add").addColumn("test").type(DataType.ascii()); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The new column name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_added_column_is_a_reserved_keyword() throws Exception { alterTable("test").addColumn("add").type(DataType.ascii()).getQueryString(); }
@Test(groups = "short") public void should_add_and_drop_a_column() { // Create a table, add a column to it with an alter table statement and delete that column session() .execute( SchemaBuilder.createTable("ks", "DropColumn") .ifNotExists() .addPartitionKey("a", DataType.cint())); // Add and then drop a column session() .execute(SchemaBuilder.alterTable("ks", "DropColumn").addColumn("b").type(DataType.cint())); session().execute(SchemaBuilder.alterTable("ks", "DropColumn").dropColumn("b")); // Check that only column a exist ResultSet rows = session() .execute( "SELECT column_name, type, validator " + "FROM system.schema_columns " + "WHERE keyspace_name='ks' AND columnfamily_name='dropcolumn'"); Iterator<Row> iterator = rows.iterator(); verifyNextColumnDefinition( iterator, "a", "partition_key", "org.apache.cassandra.db.marshal.Int32Type"); assertThat(iterator.hasNext()).isFalse(); }
@Test(groups = "unit") public void should_add_column() throws Exception { // When SchemaStatement statement = alterTable("test").addColumn("location").type(DataType.ascii()); // Then assertThat(statement.getQueryString()).isEqualTo("\n\tALTER TABLE test ADD location ascii"); }
@Test(groups = "unit") public void should_add_column_with_UDT_type() throws Exception { // When SchemaStatement statement = alterTable("test").addColumn("location").udtType(frozen("address")); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tALTER TABLE test ADD location frozen<address>"); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The table name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_table_name_is_a_reserved_keyword() throws Exception { alterTable("add").addColumn("test").type(DataType.ascii()); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The keyspace name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_keyspace_name_is_a_reserved_keyword() throws Exception { alterTable("add", "test").addColumn("test").type(DataType.ascii()); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The new column name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_added_column_is_a_reserved_keyword() throws Exception { alterTable("test").addColumn("add").type(DataType.ascii()).getQueryString(); }