Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import com.datastax.driver.core.querybuilder.Select;
import org.junit.Test;
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
public class QueryBuilderTest {
@Test
public void getQueryStringWithAllowFiltering () {
Select query = select()
.all()
.from("my_table");
query.getQueryString();
query.allowFiltering();
// This fails with
// java.lang.AssertionError:
// Expected: "SELECT * FROM my_table ALLOW FILTERING;"
// but: was "SELECT * FROM my_table;"
assertThat(query.getQueryString(), equalTo("SELECT * FROM my_table ALLOW FILTERING;"));
}
// Everything else below passes
@Test
public void getQueryString () {
Select query = select()
.all()
.from("my_table");
assertThat(query.getQueryString(), equalTo("SELECT * FROM my_table;"));
}
@Test
public void getQueryString2 () {
Select.Where query = select()
.all()
.from("my_table")
.where(eq("foo", "bar"));
assertThat(query.getQueryString(), equalTo("SELECT * FROM my_table WHERE foo=?;"));
}
@Test
public void getQueryString3 () {
Select query = select()
.all()
.from("my_table");
query.getQueryString();
query.where(eq("foo", "bar"));
assertThat(query.getQueryString(), equalTo("SELECT * FROM my_table WHERE foo=?;"));
}
@Test
public void getQueryString4 () {
Select query = select()
.all()
.from("my_table")
.allowFiltering();
assertThat(query.getQueryString(), equalTo("SELECT * FROM my_table ALLOW FILTERING;"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.