use of jakarta.nosql.column.ColumnQuery 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.ColumnQuery 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.ColumnQuery 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.ColumnQuery in project jnosql-diana by eclipse.
the class ColumnRepositoryProxyTest method shouldFindByNameANDAge.
@Test
public void shouldFindByNameANDAge() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
List<Person> persons = personRepository.findByNameAndAge("name", 20);
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
verify(template).select(captor.capture());
assertThat(persons, Matchers.contains(ada));
}
use of jakarta.nosql.column.ColumnQuery in project jnosql-diana by eclipse.
the class ColumnRepositoryProxyTest method shouldFindByNameANDAgeOrderByName.
@Test
public void shouldFindByNameANDAgeOrderByName() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
Stream<Person> persons = personRepository.findByNameAndAgeOrderByName("name", 20);
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
verify(template).select(captor.capture());
assertThat(persons.collect(Collectors.toList()), Matchers.contains(ada));
}
Aggregations