use of jakarta.nosql.column.ColumnCondition in project jnosql-diana by eclipse.
the class ColumnRepositoryProxyTest method shouldFindByNameAndAgeGreaterEqualThan.
@Test
public void shouldFindByNameAndAgeGreaterEqualThan() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
personRepository.findByNameAndAgeGreaterThanEqual("Ada", 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(AND, condition.getCondition());
List<ColumnCondition> conditions = condition.getColumn().get(new TypeReference<List<ColumnCondition>>() {
});
ColumnCondition columnCondition = conditions.get(0);
ColumnCondition columnCondition2 = conditions.get(1);
assertEquals(Condition.EQUALS, columnCondition.getCondition());
assertEquals("Ada", columnCondition.getColumn().get());
assertEquals("name", columnCondition.getColumn().getName());
assertEquals(Condition.GREATER_EQUALS_THAN, columnCondition2.getCondition());
assertEquals(33, columnCondition2.getColumn().get());
assertEquals("age", columnCondition2.getColumn().getName());
}
use of jakarta.nosql.column.ColumnCondition in project jnosql-diana by eclipse.
the class ColumnRepositoryProxyTest method shouldFindByGreaterThan.
@Test
public void shouldFindByGreaterThan() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
personRepository.findByAgeGreaterThan(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(GREATER_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 shouldFindByAgeBetween.
@Test
public void shouldFindByAgeBetween() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
personRepository.findByAgeBetween(10, 15);
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(BETWEEN, condition.getCondition());
List<Value> values = condition.getColumn().get(new TypeReference<List<Value>>() {
});
assertEquals(Arrays.asList(10, 15), values.stream().map(Value::get).collect(Collectors.toList()));
assertTrue(condition.getColumn().getName().contains("age"));
}
use of jakarta.nosql.column.ColumnCondition in project jnosql-diana by eclipse.
the class ParamsBinderTest method shouldConvert2.
@Test
public void shouldConvert2() {
Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals("findByAgeAndName")).findFirst().get();
ClassMapping classMapping = mappings.get(Person.class);
RepositoryColumnObserverParser parser = new RepositoryColumnObserverParser(classMapping);
paramsBinder = new ParamsBinder(classMapping, converters);
SelectMethodProvider selectMethodFactory = SelectMethodProvider.get();
SelectQuery selectQuery = selectMethodFactory.apply(method, classMapping.getName());
SelectQueryConverter converter = ServiceLoaderProvider.get(SelectQueryConverter.class);
ColumnQueryParams queryParams = converter.apply(selectQuery, parser);
Params params = queryParams.getParams();
paramsBinder.bind(params, new Object[] { 10L, "Ada" }, method);
ColumnQuery query = queryParams.getQuery();
ColumnCondition columnCondition = query.getCondition().get();
List<ColumnCondition> conditions = columnCondition.getColumn().get(new TypeReference<List<ColumnCondition>>() {
});
List<Object> values = conditions.stream().map(ColumnCondition::getColumn).map(Column::getValue).map(Value::get).collect(Collectors.toList());
assertEquals(10, values.get(0));
assertEquals("Ada", values.get(1));
}
use of jakarta.nosql.column.ColumnCondition in project jnosql-diana by eclipse.
the class ParamsBinderTest method shouldConvert.
@Test
public void shouldConvert() {
Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals("findByAge")).findFirst().get();
ClassMapping classMapping = mappings.get(Person.class);
RepositoryColumnObserverParser parser = new RepositoryColumnObserverParser(classMapping);
paramsBinder = new ParamsBinder(classMapping, converters);
SelectMethodProvider selectMethodFactory = SelectMethodProvider.get();
SelectQuery selectQuery = selectMethodFactory.apply(method, classMapping.getName());
SelectQueryConverter converter = ServiceLoaderProvider.get(SelectQueryConverter.class);
ColumnQueryParams columnQueryParams = converter.apply(selectQuery, parser);
Params params = columnQueryParams.getParams();
Object[] args = { 10 };
paramsBinder.bind(params, args, method);
ColumnQuery query = columnQueryParams.getQuery();
ColumnCondition columnCondition = query.getCondition().get();
Value value = columnCondition.getColumn().getValue();
assertEquals(10, value.get());
}
Aggregations