use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.
the class MockProducer method getColumnFamilyManager.
@Produces
public ColumnFamilyManager getColumnFamilyManager() {
ColumnEntity entity = ColumnEntity.of("Person");
entity.add(Column.of("name", "Default"));
entity.add(Column.of("age", 10));
ColumnFamilyManager manager = mock(ColumnFamilyManager.class);
when(manager.insert(Mockito.any(ColumnEntity.class))).thenReturn(entity);
return manager;
}
use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.
the class DefaultColumnQueryParserTest method shouldReturnParserQuery3.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update God (name = \"Diana\")" })
public void shouldReturnParserQuery3(String query) {
ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
parser.query(query, manager, ColumnObserverParser.EMPTY);
Mockito.verify(manager).update(captor.capture());
ColumnEntity entity = captor.getValue();
assertEquals("God", entity.getName());
assertEquals(Column.of("name", "Diana"), entity.find("name").get());
}
use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.
the class DefaultColumnQueryParserTest method shouldReturnEmptySingleResult.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God where age = @age" })
public void shouldReturnEmptySingleResult(String query) {
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
Mockito.when(manager.select(Mockito.any(ColumnQuery.class))).thenReturn(Stream.empty());
ColumnPreparedStatement prepare = parser.prepare(query, manager, ColumnObserverParser.EMPTY);
prepare.bind("age", 12);
final Optional<ColumnEntity> result = prepare.getSingleResult();
Mockito.verify(manager).select(captor.capture());
ColumnQuery columnQuery = captor.getValue();
ColumnCondition columnCondition = columnQuery.getCondition().get();
Column column = columnCondition.getColumn();
assertEquals(Condition.EQUALS, columnCondition.getCondition());
assertEquals("age", column.getName());
assertEquals(12, column.get());
assertFalse(result.isPresent());
}
use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.
the class DefaultColumnQueryParserTest method shouldReturnParserQuery2.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = \"Diana\")" })
public void shouldReturnParserQuery2(String query) {
ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
parser.query(query, manager, ColumnObserverParser.EMPTY);
Mockito.verify(manager).insert(captor.capture());
ColumnEntity entity = captor.getValue();
assertEquals("God", entity.getName());
assertEquals(Column.of("name", "Diana"), entity.find("name").get());
}
use of jakarta.nosql.column.ColumnEntity 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")));
}
Aggregations