Search in sources :

Example 31 with Column

use of jakarta.nosql.column.Column in project jnosql-diana by eclipse.

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameLike.

@Test
public void shouldSelectWhereNameLike() {
    String columnFamily = "columnFamily";
    String name = "Ada Lovelace";
    ColumnDeleteQuery query = delete().from(columnFamily).where("name").like(name).build();
    ColumnCondition condition = query.getCondition().get();
    Column column = condition.getColumn();
    assertTrue(query.getColumns().isEmpty());
    assertEquals(columnFamily, query.getColumnFamily());
    assertEquals(Condition.LIKE, condition.getCondition());
    assertEquals("name", column.getName());
    assertEquals(name, column.get());
}
Also used : Column(jakarta.nosql.column.Column) ColumnCondition(jakarta.nosql.column.ColumnCondition) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 32 with Column

use of jakarta.nosql.column.Column in project jnosql-diana by eclipse.

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameGt.

@Test
public void shouldSelectWhereNameGt() {
    String columnFamily = "columnFamily";
    Number value = 10;
    ColumnDeleteQuery query = delete().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 : Column(jakarta.nosql.column.Column) ColumnCondition(jakarta.nosql.column.ColumnCondition) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 33 with Column

use of jakarta.nosql.column.Column in project jnosql-diana by eclipse.

the class SelectQueryParserTest method shouldReturnParserQuery20.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where name in (\"Ada\", \"Apollo\")" })
public void shouldReturnParserQuery20(String query) {
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).select(captor.capture());
    ColumnQuery columnQuery = captor.getValue();
    checkBaseQuery(columnQuery, 0L, 0L);
    assertTrue(columnQuery.getCondition().isPresent());
    ColumnCondition condition = columnQuery.getCondition().get();
    Column column = condition.getColumn();
    assertEquals(Condition.IN, condition.getCondition());
    assertEquals("name", column.getName());
    List<String> values = column.get(new TypeReference<List<String>>() {
    });
    assertThat(values, containsInAnyOrder("Ada", "Apollo"));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Column(jakarta.nosql.column.Column) List(java.util.List) ColumnCondition(jakarta.nosql.column.ColumnCondition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 34 with Column

use of jakarta.nosql.column.Column in project jnosql-diana by eclipse.

the class SelectQueryParserTest method shouldReturnParserQuery22.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God where name not like \"Ada\"" })
public void shouldReturnParserQuery22(String query) {
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).select(captor.capture());
    ColumnQuery columnQuery = captor.getValue();
    checkBaseQuery(columnQuery, 0L, 0L);
    assertTrue(columnQuery.getCondition().isPresent());
    ColumnCondition condition = columnQuery.getCondition().get();
    Column column = condition.getColumn();
    assertEquals(Condition.NOT, condition.getCondition());
    List<ColumnCondition> conditions = column.get(new TypeReference<List<ColumnCondition>>() {
    });
    ColumnCondition columnCondition = conditions.get(0);
    assertEquals(Condition.LIKE, columnCondition.getCondition());
    assertEquals(Column.of("name", "Ada"), columnCondition.getColumn());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Column(jakarta.nosql.column.Column) List(java.util.List) ColumnCondition(jakarta.nosql.column.ColumnCondition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 35 with Column

use of jakarta.nosql.column.Column in project jnosql-diana by eclipse.

the class SelectQueryParserTest method shouldReturnParserQuery24.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where name = \"Ada\" or age = 20" })
public void shouldReturnParserQuery24(String query) {
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).select(captor.capture());
    ColumnQuery columnQuery = captor.getValue();
    checkBaseQuery(columnQuery, 0L, 0L);
    assertTrue(columnQuery.getCondition().isPresent());
    ColumnCondition condition = columnQuery.getCondition().get();
    Column column = condition.getColumn();
    assertEquals(Condition.OR, condition.getCondition());
    List<ColumnCondition> conditions = column.get(new TypeReference<List<ColumnCondition>>() {
    });
    assertThat(conditions, contains(eq(Column.of("name", "Ada")), eq(Column.of("age", 20L))));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Column(jakarta.nosql.column.Column) List(java.util.List) ColumnCondition(jakarta.nosql.column.ColumnCondition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Column (jakarta.nosql.column.Column)113 Test (org.junit.jupiter.api.Test)72 ColumnCondition (jakarta.nosql.column.ColumnCondition)57 ColumnEntity (jakarta.nosql.column.ColumnEntity)39 ColumnQuery (jakarta.nosql.column.ColumnQuery)35 List (java.util.List)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 ValueSource (org.junit.jupiter.params.provider.ValueSource)26 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)24 ArrayList (java.util.ArrayList)13 Value (jakarta.nosql.Value)10 TypeReference (jakarta.nosql.TypeReference)9 Arrays.asList (java.util.Arrays.asList)9 Collections.singletonList (java.util.Collections.singletonList)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)6 Optional (java.util.Optional)4 CqlSession (com.datastax.oss.driver.api.core.CqlSession)3 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)3