Search in sources :

Example 56 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana by eclipse.

the class DefaultSelectQueryBuilderTest method shouldSelectNegate.

@Test
public void shouldSelectNegate() {
    String columnFamily = "columnFamily";
    ColumnQuery query = select().from(columnFamily).where("city").not().eq("Assis").and("name").not().eq("Lucas").build();
    ColumnCondition condition = query.getCondition().orElseThrow(RuntimeException::new);
    assertEquals(columnFamily, query.getColumnFamily());
    Column column = condition.getColumn();
    List<ColumnCondition> conditions = column.get(new TypeReference<List<ColumnCondition>>() {
    });
    assertEquals(Condition.AND, condition.getCondition());
    assertThat(conditions, containsInAnyOrder(eq(Column.of("city", "Assis")).negate(), eq(Column.of("name", "Lucas")).negate()));
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Column(org.jnosql.diana.api.column.Column) List(java.util.List) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 57 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana by eclipse.

the class DefaultSelectQueryBuilderTest method shouldSelectColumns.

@Test
public void shouldSelectColumns() {
    String columnFamily = "columnFamily";
    ColumnQuery query = select("column", "column2").from(columnFamily).build();
    assertThat(query.getColumns(), containsInAnyOrder("column", "column2"));
    assertFalse(query.getCondition().isPresent());
    assertEquals(columnFamily, query.getColumnFamily());
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Test(org.junit.jupiter.api.Test)

Example 58 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana by eclipse.

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameAnd.

@Test
public void shouldSelectWhereNameAnd() {
    String columnFamily = "columnFamily";
    String name = "Ada Lovelace";
    ColumnQuery query = select().from(columnFamily).where("name").eq(name).and("age").gt(10).build();
    ColumnCondition condition = query.getCondition().get();
    Column column = condition.getColumn();
    List<ColumnCondition> conditions = column.get(new TypeReference<List<ColumnCondition>>() {
    });
    assertEquals(Condition.AND, condition.getCondition());
    assertThat(conditions, containsInAnyOrder(eq(Column.of("name", name)), ColumnCondition.gt(Column.of("age", 10))));
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Column(org.jnosql.diana.api.column.Column) List(java.util.List) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 59 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana by eclipse.

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameEq.

@Test
public void shouldSelectWhereNameEq() {
    String columnFamily = "columnFamily";
    String name = "Ada Lovelace";
    ColumnQuery query = select().from(columnFamily).where("name").eq(name).build();
    ColumnCondition condition = query.getCondition().get();
    Column column = condition.getColumn();
    assertTrue(query.getColumns().isEmpty());
    assertEquals(columnFamily, query.getColumnFamily());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals("name", column.getName());
    assertEquals(name, column.get());
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Column(org.jnosql.diana.api.column.Column) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 60 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana by eclipse.

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameGt.

@Test
public void shouldSelectWhereNameGt() {
    String columnFamily = "columnFamily";
    Number value = 10;
    ColumnQuery query = select().from(columnFamily).where("name").gt(value).build();
    ColumnCondition condition = query.getCondition().get();
    Column column = condition.getColumn();
    assertTrue(query.getColumns().isEmpty());
    assertEquals(columnFamily, query.getColumnFamily());
    assertEquals(Condition.GREATER_THAN, condition.getCondition());
    assertEquals("name", column.getName());
    assertEquals(value, column.get());
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Column(org.jnosql.diana.api.column.Column) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)117 Test (org.junit.jupiter.api.Test)113 Person (org.jnosql.artemis.model.Person)37 ColumnCondition (org.jnosql.diana.api.column.ColumnCondition)35 Column (org.jnosql.diana.api.column.Column)29 List (java.util.List)26 ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)26 Collections.singletonList (java.util.Collections.singletonList)20 ColumnDeleteQuery (org.jnosql.diana.api.column.ColumnDeleteQuery)19 Arrays.asList (java.util.Arrays.asList)15 Duration (java.time.Duration)14 ColumnQueryBuilder.delete (org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete)14 ColumnQueryBuilder.select (org.jnosql.diana.api.column.query.ColumnQueryBuilder.select)14 BeforeEach (org.junit.jupiter.api.BeforeEach)14 Optional (java.util.Optional)13 Consumer (java.util.function.Consumer)13 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)13 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)13 Inject (javax.inject.Inject)12 CDIExtension (org.jnosql.artemis.CDIExtension)12