Skip to content

Instantly share code, notes, and snippets.

@salomvary
Created August 10, 2018 15:34
Show Gist options
  • Save salomvary/d9ce3e4d599d128b68a5318656adfad1 to your computer and use it in GitHub Desktop.
Save salomvary/d9ce3e4d599d128b68a5318656adfad1 to your computer and use it in GitHub Desktop.
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