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"));
}
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());
}
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());
}
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());
}
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());
}
Aggregations