@Test(groups = "unit") public void should_drop_table() throws Exception { // When SchemaStatement statement = dropTable("test"); // Then assertThat(statement.getQueryString()).isEqualTo("DROP TABLE test"); }
@Test(groups = "unit") public void should_drop_type() throws Exception { // When SchemaStatement statement = dropType("test"); // Then assertThat(statement.getQueryString()).isEqualTo("DROP TYPE test"); }
@Test(groups = "unit") public void should_drop_keyspace() throws Exception { // When SchemaStatement statement = dropKeyspace("test"); // Then assertThat(statement.getQueryString()).isEqualTo("DROP KEYSPACE test"); }
@Test(groups = "unit") public void should_drop_type_with_keyspace() throws Exception { // When SchemaStatement statement = dropType("ks", "test"); // Then assertThat(statement.getQueryString()).isEqualTo("DROP TYPE ks.test"); }
@Test(groups = "unit") public void should_drop_index_with_keyspace() throws Exception { // When SchemaStatement statement = dropIndex("ks", "test"); // Then assertThat(statement.getQueryString()).isEqualTo("DROP INDEX ks.test"); }
@Test(groups = "unit") public void should_drop_type_with_keyspace_if_exists() throws Exception { // When SchemaStatement statement = dropType("ks", "test").ifExists(); // Then assertThat(statement.getQueryString()).isEqualTo("DROP TYPE IF EXISTS ks.test"); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The dropped column name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_drop_column_is_a_reserved_keyword() throws Exception { alterTable("test").dropColumn("add").getQueryString(); }
@Test(groups = "unit") public void should_rename_column() throws Exception { // When SchemaStatement statement = alterTable("test").renameColumn("name").to("description"); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tALTER TABLE test RENAME name TO description"); }
@Test(groups = "unit") public void should_create_table_with_udt_partition_key() throws Exception { // When SchemaStatement statement = createTable("test").addUDTPartitionKey("u", frozen("user")); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tCREATE TABLE test(\n\t\t" + "u frozen<user>,\n\t\t" + "PRIMARY KEY(u))"); }
@Test(groups = "unit") public void should_alter_column_type_with_keyspace() throws Exception { // When SchemaStatement statement = alterTable("ks", "test").alterColumn("name").type(DataType.ascii()); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tALTER TABLE ks.test ALTER name TYPE ascii"); }
@Test(groups = "unit") public void should_add_static_column() throws Exception { // When SchemaStatement statement = alterTable("test").addStaticColumn("stat").type(DataType.text()); // Then assertThat(statement.getQueryString()).isEqualTo("\n\tALTER TABLE test ADD stat text static"); } }
@Test(groups = "unit") public void should_create_index() throws Exception { // Given //When SchemaStatement statement = createIndex("myIndex").ifNotExists().onTable("ks", "test").andColumn("col"); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tCREATE INDEX IF NOT EXISTS myIndex ON ks.test(col)"); }
@Test(groups = "unit") public void should_alter_column_type() throws Exception { // When SchemaStatement statement = alterTable("test").alterColumn("name").type(DataType.ascii()); // Then assertThat(statement.getQueryString()).isEqualTo("\n\tALTER TABLE test ALTER name TYPE 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") public void should_create_index_on_keys_of_map_column() throws Exception { // Given //When SchemaStatement statement = createIndex("myIndex").ifNotExists().onTable("ks", "test").andKeysOfColumn("col"); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tCREATE INDEX IF NOT EXISTS myIndex ON ks.test(KEYS(col))"); } }
@Test(groups = "unit") public void should_alter_column_type_to_UDT() throws Exception { // When SchemaStatement statement = alterTable("ks", "test").alterColumn("address").udtType(frozen("address")); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tALTER TABLE ks.test ALTER address TYPE frozen<address>"); }
@Test(groups = "unit") public void should_create_simple_UDT_column() throws Exception { // When SchemaStatement statement = createType("ks", "myType") .addColumn("col1", DataType.text()) .addUDTColumn("my_udt", frozen("address")); // Then assertThat(statement.getQueryString()) .isEqualTo( "\n\tCREATE TYPE ks.myType(\n\t\t" + "col1 text,\n\t\t" + "my_udt frozen<address>)"); }
@Test(groups = "unit") public void should_create_UDT() throws Exception { // When SchemaStatement statement = createType("ks", "myType") .addColumn("col1", DataType.text()) .addColumn("col2", DataType.bigint()); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tCREATE TYPE ks.myType(\n\t\t" + "col1 text,\n\t\t" + "col2 bigint)"); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The altered column name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_altered_column_is_a_reserved_keyword() throws Exception { alterTable("test").alterColumn("add").type(DataType.ascii()).getQueryString(); }