use of jakarta.nosql.column.Column in project jnosql-diana by eclipse.
the class SelectQueryParserTest method shouldReturnParserQuery18.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God where siblings = {\"apollo\": \"Brother\", \"Zeus\": \"Father\"}" })
public void shouldReturnParserQuery18(String query) {
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
parser.query(query, manager, observer);
Mockito.verify(manager).select(captor.capture());
ColumnQuery columnQuery = captor.getValue();
checkBaseQuery(columnQuery, 0L, 0L);
assertTrue(columnQuery.getCondition().isPresent());
ColumnCondition condition = columnQuery.getCondition().get();
assertEquals(Condition.EQUALS, condition.getCondition());
Column column = condition.getColumn();
List<Column> columns = column.get(new TypeReference<List<Column>>() {
});
assertThat(columns, containsInAnyOrder(Column.of("apollo", "Brother"), Column.of("Zeus", "Father")));
assertEquals("siblings", column.getName());
}
use of jakarta.nosql.column.Column in project jnosql-diana by eclipse.
the class InsertQueryParserTest method shouldReturnParserQuery10.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert Person {\"name\": \"Ada Lovelace\", \"age\": 12, \"sibling\":" + " [\"Ana\" ,\"Maria\"]," + " \"address\":{\"country\": \"United Kingdom\", \"city\": \"London\"}}" })
public void shouldReturnParserQuery10(String query) {
ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
parser.query(query, manager, observer);
Mockito.verify(manager).insert(captor.capture());
ColumnEntity entity = captor.getValue();
List<String> siblings = entity.find("sibling").get().get(new TypeReference<List<String>>() {
});
List<Column> address = entity.find("address").get().get(new TypeReference<List<Column>>() {
});
assertEquals("Person", entity.getName());
assertEquals(Column.of("name", "Ada Lovelace"), entity.find("name").get());
assertEquals(Column.of("age", BigDecimal.valueOf(12)), entity.find("age").get());
assertThat(siblings, contains("Ana", "Maria"));
assertThat(address, containsInAnyOrder(Column.of("country", "United Kingdom"), Column.of("city", "London")));
}
use of jakarta.nosql.column.Column in project jnosql-diana by eclipse.
the class UpdateQueryParserTest method shouldReturnParserQuery4.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update Person {\"name\": \"Ada Lovelace\", \"age\": 12, \"sibling\":" + " [\"Ana\" ,\"Maria\"]," + " \"address\":{\"country\": \"United Kingdom\", \"city\": \"London\"}}" })
public void shouldReturnParserQuery4(String query) {
ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
parser.query(query, manager, observer);
Mockito.verify(manager).update(captor.capture());
ColumnEntity entity = captor.getValue();
List<String> siblings = entity.find("sibling").get().get(new TypeReference<List<String>>() {
});
List<Column> address = entity.find("address").get().get(new TypeReference<List<Column>>() {
});
assertEquals("Person", entity.getName());
assertEquals(Column.of("name", "Ada Lovelace"), entity.find("name").get());
assertEquals(Column.of("age", BigDecimal.valueOf(12)), entity.find("age").get());
assertThat(siblings, contains("Ana", "Maria"));
assertThat(address, containsInAnyOrder(Column.of("country", "United Kingdom"), Column.of("city", "London")));
}
use of jakarta.nosql.column.Column in project jnosql-diana by eclipse.
the class ColumnRepositoryProxyTest method shouldFindBySalary_CurrencyOrderByCurrency_Name.
@Test
public void shouldFindBySalary_CurrencyOrderByCurrency_Name() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
personRepository.findBySalary_CurrencyOrderByCurrency_Name("USD");
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
verify(template).select(captor.capture());
ColumnQuery query = captor.getValue();
ColumnCondition condition = query.getCondition().get();
final Sort sort = query.getSorts().get(0);
final Column document = condition.getColumn();
assertEquals("Person", query.getColumnFamily());
assertEquals("salary.currency", document.getName());
assertEquals("currency.name", sort.getName());
}
use of jakarta.nosql.column.Column in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method shouldCreateUDTWithSet.
@Test
public void shouldCreateUDTWithSet() {
ColumnEntity entity = createEntityWithIterableSet();
entityManager.insert(entity);
ColumnQuery query = ColumnQuery.select().from("agenda").build();
final ColumnEntity result = entityManager.singleResult(query).get();
Assert.assertEquals(Column.of("user", "otaviojava"), result.find("user").get());
Assert.assertEquals(2, result.size());
List<List<Column>> names = (List<List<Column>>) result.find("names").get().get();
assertEquals(3, names.size());
assertTrue(names.stream().allMatch(n -> n.size() == 2));
}
Aggregations