Search in sources :

Example 21 with ColumnCondition

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

the class ColumnRepositoryProxyTest method shouldFindByNameInstance.

@Test
public void shouldFindByNameInstance() {
    when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional.of(Person.builder().build()));
    personRepository.findByName("name");
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).singleResult(captor.capture());
    ColumnQuery query = captor.getValue();
    ColumnCondition condition = query.getCondition().get();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals(Column.of("name", "name"), condition.getColumn());
    assertNotNull(personRepository.findByName("name"));
    when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional.empty());
    assertNull(personRepository.findByName("name"));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 22 with ColumnCondition

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

the class ColumnRepositoryProxyTest method shouldFindByAgeLessEqual.

@Test
public void shouldFindByAgeLessEqual() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
    personRepository.findByAgeLessThan(33);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    ColumnQuery query = captor.getValue();
    ColumnCondition condition = query.getCondition().get();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(LESSER_THAN, condition.getCondition());
    assertEquals(Column.of("age", 33), condition.getColumn());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Person(jakarta.nosql.tck.entities.Person) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 23 with ColumnCondition

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

the class ColumnRepositoryProxyTest method shouldFindByStringWhenFieldIsSet.

@Test
public void shouldFindByStringWhenFieldIsSet() {
    Vendor vendor = new Vendor("vendor");
    vendor.setPrefixes(Collections.singleton("prefix"));
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(vendor));
    vendorRepository.findByPrefixes("prefix");
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).singleResult(captor.capture());
    ColumnQuery query = captor.getValue();
    ColumnCondition condition = query.getCondition().get();
    assertEquals("vendors", query.getColumnFamily());
    assertEquals(EQUALS, condition.getCondition());
    assertEquals(Column.of("prefixes", "prefix"), condition.getColumn());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Vendor(jakarta.nosql.tck.entities.Vendor) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 24 with ColumnCondition

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

the class ColumnReactiveRepositoryProxyTest method shouldDeleteByName.

@Test
public void shouldDeleteByName() {
    ArgumentCaptor<ColumnDeleteQuery> captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class);
    final Publisher<Void> publisher = personRepository.deleteByName("Ada");
    final CompletionSubscriber<Void, Optional<Void>> subscriber = ReactiveStreams.<Void>builder().findFirst().build();
    publisher.subscribe(subscriber);
    final CompletionStage<Optional<Void>> completion = subscriber.getCompletion();
    AtomicBoolean atomicBoolean = new AtomicBoolean();
    completion.thenAccept(v -> atomicBoolean.set(true));
    verify(template).delete(captor.capture());
    ColumnDeleteQuery deleteQuery = captor.getValue();
    ColumnCondition condition = deleteQuery.getCondition().get();
    assertEquals("Person", deleteQuery.getColumnFamily());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals(Column.of("name", "Ada"), condition.getColumn());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Optional(java.util.Optional) ColumnCondition(jakarta.nosql.column.ColumnCondition) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 25 with ColumnCondition

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

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameEq.

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

Aggregations

ColumnCondition (jakarta.nosql.column.ColumnCondition)130 Test (org.junit.jupiter.api.Test)68 ColumnQuery (jakarta.nosql.column.ColumnQuery)64 Column (jakarta.nosql.column.Column)57 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 ValueSource (org.junit.jupiter.params.provider.ValueSource)37 List (java.util.List)34 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)33 Person (jakarta.nosql.tck.entities.Person)17 Pagination (jakarta.nosql.mapping.Pagination)13 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)10 TypeReference (jakarta.nosql.TypeReference)7 Params (jakarta.nosql.Params)6 ColumnEntity (jakarta.nosql.column.ColumnEntity)6 Collections.singletonList (java.util.Collections.singletonList)5 QueryException (jakarta.nosql.QueryException)4 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)4 ColumnFamilyManager (jakarta.nosql.column.ColumnFamilyManager)4 ColumnObserverParser (jakarta.nosql.column.ColumnObserverParser)4 ColumnQueryParams (jakarta.nosql.column.ColumnQueryParams)4