Search in sources :

Example 56 with ColumnDeleteQuery

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

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameNot.

@Test
public void shouldSelectWhereNameNot() {
    String columnFamily = "columnFamily";
    String name = "Ada Lovelace";
    ColumnDeleteQuery query = delete().from(columnFamily).where("name").not().eq(name).build();
    ColumnCondition condition = query.getCondition().get();
    Column column = condition.getColumn();
    ColumnCondition negate = column.get(ColumnCondition.class);
    assertTrue(query.getColumns().isEmpty());
    assertEquals(columnFamily, query.getColumnFamily());
    assertEquals(Condition.NOT, condition.getCondition());
    assertEquals(Condition.EQUALS, negate.getCondition());
    assertEquals("name", negate.getColumn().getName());
    assertEquals(name, negate.getColumn().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 57 with ColumnDeleteQuery

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

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameAnd.

@Test
public void shouldSelectWhereNameAnd() {
    String columnFamily = "columnFamily";
    String name = "Ada Lovelace";
    ColumnDeleteQuery query = delete().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, Matchers.containsInAnyOrder(ColumnCondition.eq(Column.of("name", name)), ColumnCondition.gt(Column.of("age", 10))));
}
Also used : Column(jakarta.nosql.column.Column) List(java.util.List) ColumnCondition(jakarta.nosql.column.ColumnCondition) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 58 with ColumnDeleteQuery

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

the class DefaultDeleteQueryBuilderTest method shouldExecuteDelete.

@Test
public void shouldExecuteDelete() {
    String columnFamily = "columnFamily";
    ColumnFamilyManager manager = mock(ColumnFamilyManager.class);
    ArgumentCaptor<ColumnDeleteQuery> queryCaptor = ArgumentCaptor.forClass(ColumnDeleteQuery.class);
    delete().from(columnFamily).delete(manager);
    verify(manager).delete(queryCaptor.capture());
    ColumnDeleteQuery query = queryCaptor.getValue();
    assertTrue(query.getColumns().isEmpty());
    assertFalse(query.getCondition().isPresent());
    assertEquals(columnFamily, query.getColumnFamily());
}
Also used : ColumnFamilyManager(jakarta.nosql.column.ColumnFamilyManager) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 59 with ColumnDeleteQuery

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

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameLte.

@Test
public void shouldSelectWhereNameLte() {
    String columnFamily = "columnFamily";
    Number value = 10;
    ColumnDeleteQuery query = delete().from(columnFamily).where("name").lte(value).build();
    ColumnCondition columnCondition = query.getCondition().get();
    Column column = columnCondition.getColumn();
    assertTrue(query.getColumns().isEmpty());
    assertEquals(columnFamily, query.getColumnFamily());
    assertEquals(Condition.LESSER_EQUALS_THAN, columnCondition.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 60 with ColumnDeleteQuery

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

the class DeleteQueryParserTest method shouldReturnParserQuery16.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete  from God where name = \"diana\"" })
public void shouldReturnParserQuery16(String query) {
    ArgumentCaptor<ColumnDeleteQuery> captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).delete(captor.capture());
    ColumnDeleteQuery columnQuery = captor.getValue();
    checkBaseQuery(columnQuery);
    assertTrue(columnQuery.getCondition().isPresent());
    ColumnCondition condition = columnQuery.getCondition().get();
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals(Column.of("name", "diana"), condition.getColumn());
}
Also used : ColumnCondition(jakarta.nosql.column.ColumnCondition) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)70 Test (org.junit.jupiter.api.Test)41 ColumnCondition (jakarta.nosql.column.ColumnCondition)33 Column (jakarta.nosql.column.Column)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 ValueSource (org.junit.jupiter.params.provider.ValueSource)20 Person (jakarta.nosql.tck.entities.Person)12 List (java.util.List)12 ColumnEntity (jakarta.nosql.column.ColumnEntity)6 Params (jakarta.nosql.Params)5 ColumnDeleteQueryParams (jakarta.nosql.column.ColumnDeleteQueryParams)5 ColumnQuery (jakarta.nosql.column.ColumnQuery)5 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)4 ColumnFamilyManager (jakarta.nosql.column.ColumnFamilyManager)3 DeleteQuery (jakarta.nosql.query.DeleteQuery)3 Optional (java.util.Optional)3 QueryException (jakarta.nosql.QueryException)2 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)2 ColumnObserverParser (jakarta.nosql.column.ColumnObserverParser)2 DeleteQueryConverter (jakarta.nosql.column.DeleteQueryConverter)2