Search in sources :

Example 11 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class ColumnEntityTest method shouldReturnErrorWhenAddColumnsObjectWhenHasNullColumnName.

@Test
public void shouldReturnErrorWhenAddColumnsObjectWhenHasNullColumnName() {
    Assertions.assertThrows(NullPointerException.class, () -> {
        ColumnEntity entity = new DefaultColumnEntity("columnFamily");
        entity.add(null, 10);
    });
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Example 12 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class ColumnEntityTest method shouldConvertSubColumnListToMap.

@Test
public void shouldConvertSubColumnListToMap() {
    ColumnEntity entity = ColumnEntity.of("entity");
    entity.add(Column.of("_id", "id"));
    List<Column> columns = asList(Column.of("name", "Ada"), Column.of("type", "type"), Column.of("information", "ada@lovelace.com"));
    entity.add(Column.of("contacts", columns));
    Map<String, Object> result = entity.toMap();
    assertEquals("id", result.get("_id"));
    List<Map<String, Object>> contacts = (List<Map<String, Object>>) result.get("contacts");
    assertEquals(3, contacts.size());
    assertThat(contacts, containsInAnyOrder(singletonMap("name", "Ada"), singletonMap("type", "type"), singletonMap("information", "ada@lovelace.com")));
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Test(org.junit.jupiter.api.Test)

Example 13 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class ColumnEntityTest method shouldFindTypeSupplier.

@Test
public void shouldFindTypeSupplier() {
    Column column = Column.of("name", "name");
    ColumnEntity entity = ColumnEntity.of("entity", singletonList(column));
    List<String> names = entity.find("name", new TypeReference<List<String>>() {
    }).orElse(Collections.emptyList());
    Assertions.assertNotNull(names);
    Assertions.assertFalse(names.isEmpty());
    MatcherAssert.assertThat(names, Matchers.contains("name"));
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) TypeReference(jakarta.nosql.TypeReference) Test(org.junit.jupiter.api.Test)

Example 14 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class DefaultSelectQueryBuilderTest method shouldExecuteSingleResultManager.

@Test
public void shouldExecuteSingleResultManager() {
    ColumnFamilyManager manager = Mockito.mock(ColumnFamilyManager.class);
    ArgumentCaptor<ColumnQuery> queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class);
    String columnFamily = "columnFamily";
    Optional<ColumnEntity> entities = select().from(columnFamily).getSingleResult(manager);
    Mockito.verify(manager).singleResult(queryCaptor.capture());
    checkQuery(queryCaptor, columnFamily);
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) ColumnFamilyManager(jakarta.nosql.column.ColumnFamilyManager) Test(org.junit.jupiter.api.Test)

Example 15 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class InsertQueryParserTest method shouldReturnParserQuery8.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert Person {\"name\":\"Ada Lovelace\"}" })
public void shouldReturnParserQuery8(String query) {
    ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).insert(captor.capture());
    ColumnEntity entity = captor.getValue();
    assertEquals("Person", entity.getName());
    assertEquals(Column.of("name", "Ada Lovelace"), entity.find("name").get());
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ColumnEntity (jakarta.nosql.column.ColumnEntity)146 Test (org.junit.jupiter.api.Test)103 Column (jakarta.nosql.column.Column)39 ColumnQuery (jakarta.nosql.column.ColumnQuery)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 ValueSource (org.junit.jupiter.params.provider.ValueSource)23 Duration (java.time.Duration)13 ArrayList (java.util.ArrayList)13 List (java.util.List)13 Arrays.asList (java.util.Arrays.asList)11 Person (jakarta.nosql.tck.entities.Person)9 ColumnFamilyManager (jakarta.nosql.column.ColumnFamilyManager)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 Value (jakarta.nosql.Value)6 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)6 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)5 Actor (jakarta.nosql.tck.entities.Actor)5 Director (jakarta.nosql.tck.entities.Director)5 Movie (jakarta.nosql.tck.entities.Movie)5