Search in sources :

Example 1 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.

the class AbstractColumnEntityConverter method toColumn.

@Override
public ColumnEntity toColumn(Object entityInstance) {
    requireNonNull(entityInstance, "Object is required");
    ClassRepresentation representation = getClassRepresentations().get(entityInstance.getClass());
    ColumnEntity entity = ColumnEntity.of(representation.getName());
    representation.getFields().stream().map(f -> to(f, entityInstance)).filter(FieldValue::isNotEmpty).map(f -> f.toColumn(this, getConverters())).flatMap(List::stream).forEach(entity::add);
    return entity;
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Example 2 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.

the class DefaultColumnTemplateAsyncTest method shouldReturnErrorFindByIdReturnMoreThanOne.

@Test
public void shouldReturnErrorFindByIdReturnMoreThanOne() {
    assertThrows(NonUniqueResultException.class, () -> {
        ArgumentCaptor<Consumer<List<ColumnEntity>>> dianaCallbackCaptor = ArgumentCaptor.forClass(Consumer.class);
        ArgumentCaptor<ColumnQuery> queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class);
        AtomicBoolean condition = new AtomicBoolean(false);
        AtomicReference<Person> atomicReference = new AtomicReference<>();
        Consumer<Optional<Person>> callback = p -> {
            condition.set(true);
            p.ifPresent(atomicReference::set);
        };
        subject.find(Person.class, 10L, callback);
        verify(managerMock).select(queryCaptor.capture(), dianaCallbackCaptor.capture());
        Consumer<List<ColumnEntity>> dianaCallBack = dianaCallbackCaptor.getValue();
        dianaCallBack.accept(asList(ColumnEntity.of("Person", asList(columns)), ColumnEntity.of("Person", asList(columns))));
    });
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Arrays(java.util.Arrays) Converters(org.jnosql.artemis.Converters) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery) ColumnFamilyManagerAsync(org.jnosql.diana.api.column.ColumnFamilyManagerAsync) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ColumnQueryBuilder.delete(org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collections.singletonList(java.util.Collections.singletonList) Person(org.jnosql.artemis.model.Person) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Arrays.asList(java.util.Arrays.asList) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Duration(java.time.Duration) NonUniqueResultException(org.jnosql.diana.api.NonUniqueResultException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Instance(javax.enterprise.inject.Instance) ColumnQueryBuilder(org.jnosql.diana.api.column.query.ColumnQueryBuilder) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Awaitility.await(org.awaitility.Awaitility.await) Collections.emptyList(java.util.Collections.emptyList) Collectors(java.util.stream.Collectors) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) Column(org.jnosql.diana.api.column.Column) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) ColumnQueryBuilder.select(org.jnosql.diana.api.column.query.ColumnQueryBuilder.select) Optional(java.util.Optional) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Optional(java.util.Optional) AtomicReference(java.util.concurrent.atomic.AtomicReference) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Consumer(java.util.function.Consumer) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 3 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.

the class DefaultColumnTemplateAsyncTest method shouldReturnEmptySingleResult.

@Test
public void shouldReturnEmptySingleResult() {
    ArgumentCaptor<Consumer<List<ColumnEntity>>> dianaCallbackCaptor = ArgumentCaptor.forClass(Consumer.class);
    ColumnQuery query = ColumnQueryBuilder.select().from("Person").build();
    AtomicBoolean condition = new AtomicBoolean(false);
    AtomicReference<Person> atomicReference = new AtomicReference<>();
    Consumer<Optional<Person>> callback = p -> {
        condition.set(true);
        p.ifPresent(atomicReference::set);
    };
    subject.singleResult(query, callback);
    verify(managerMock).select(Mockito.any(ColumnQuery.class), dianaCallbackCaptor.capture());
    Consumer<List<ColumnEntity>> dianaCallBack = dianaCallbackCaptor.getValue();
    dianaCallBack.accept(emptyList());
    verify(managerMock).select(Mockito.eq(query), Mockito.any());
    await().untilTrue(condition);
    assertNull(atomicReference.get());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Arrays(java.util.Arrays) Converters(org.jnosql.artemis.Converters) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery) ColumnFamilyManagerAsync(org.jnosql.diana.api.column.ColumnFamilyManagerAsync) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ColumnQueryBuilder.delete(org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collections.singletonList(java.util.Collections.singletonList) Person(org.jnosql.artemis.model.Person) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Arrays.asList(java.util.Arrays.asList) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Duration(java.time.Duration) NonUniqueResultException(org.jnosql.diana.api.NonUniqueResultException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Instance(javax.enterprise.inject.Instance) ColumnQueryBuilder(org.jnosql.diana.api.column.query.ColumnQueryBuilder) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Awaitility.await(org.awaitility.Awaitility.await) Collections.emptyList(java.util.Collections.emptyList) Collectors(java.util.stream.Collectors) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) Column(org.jnosql.diana.api.column.Column) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) ColumnQueryBuilder.select(org.jnosql.diana.api.column.query.ColumnQueryBuilder.select) Optional(java.util.Optional) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Optional(java.util.Optional) AtomicReference(java.util.concurrent.atomic.AtomicReference) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Consumer(java.util.function.Consumer) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 4 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.

the class DefaultColumnTemplateAsyncTest method shouldFindByIdReturnEmptyWhenElementDoesNotFind.

@Test
public void shouldFindByIdReturnEmptyWhenElementDoesNotFind() {
    ArgumentCaptor<Consumer<List<ColumnEntity>>> dianaCallbackCaptor = ArgumentCaptor.forClass(Consumer.class);
    ArgumentCaptor<ColumnQuery> queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class);
    AtomicBoolean condition = new AtomicBoolean(false);
    AtomicReference<Person> atomicReference = new AtomicReference<>();
    Consumer<Optional<Person>> callback = p -> {
        condition.set(true);
        p.ifPresent(atomicReference::set);
    };
    subject.find(Person.class, 10L, callback);
    verify(managerMock).select(queryCaptor.capture(), dianaCallbackCaptor.capture());
    Consumer<List<ColumnEntity>> dianaCallBack = dianaCallbackCaptor.getValue();
    dianaCallBack.accept(emptyList());
    ColumnQuery query = queryCaptor.getValue();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(ColumnCondition.eq(Column.of("_id", 10L)), query.getCondition().get());
    assertNull(atomicReference.get());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Arrays(java.util.Arrays) Converters(org.jnosql.artemis.Converters) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery) ColumnFamilyManagerAsync(org.jnosql.diana.api.column.ColumnFamilyManagerAsync) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ColumnQueryBuilder.delete(org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collections.singletonList(java.util.Collections.singletonList) Person(org.jnosql.artemis.model.Person) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Arrays.asList(java.util.Arrays.asList) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Duration(java.time.Duration) NonUniqueResultException(org.jnosql.diana.api.NonUniqueResultException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Instance(javax.enterprise.inject.Instance) ColumnQueryBuilder(org.jnosql.diana.api.column.query.ColumnQueryBuilder) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Awaitility.await(org.awaitility.Awaitility.await) Collections.emptyList(java.util.Collections.emptyList) Collectors(java.util.stream.Collectors) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) Column(org.jnosql.diana.api.column.Column) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) ColumnQueryBuilder.select(org.jnosql.diana.api.column.query.ColumnQueryBuilder.select) Optional(java.util.Optional) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Optional(java.util.Optional) AtomicReference(java.util.concurrent.atomic.AtomicReference) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Consumer(java.util.function.Consumer) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 5 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.

the class DefaultColumnTemplateAsyncTest method shouldInsertIterableTTL.

@Test
public void shouldInsertIterableTTL() {
    ColumnEntity entity = ColumnEntity.of("Person");
    entity.addAll(Stream.of(columns).collect(Collectors.toList()));
    subject.insert(singletonList(this.person), Duration.ofSeconds(1L));
    verify(managerMock).insert(Mockito.any(ColumnEntity.class), Mockito.eq(Duration.ofSeconds(1L)), Mockito.any(Consumer.class));
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)88 Test (org.junit.jupiter.api.Test)76 ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)26 Column (org.jnosql.diana.api.column.Column)22 Arrays.asList (java.util.Arrays.asList)17 List (java.util.List)17 Consumer (java.util.function.Consumer)14 Collections.singletonList (java.util.Collections.singletonList)13 ColumnDeleteQuery (org.jnosql.diana.api.column.ColumnDeleteQuery)13 Person (org.jnosql.artemis.model.Person)12 Duration (java.time.Duration)11 Collections.emptyList (java.util.Collections.emptyList)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 ColumnQueryBuilder.delete (org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete)9 ColumnQueryBuilder.select (org.jnosql.diana.api.column.query.ColumnQueryBuilder.select)9 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)9 BeforeEach (org.junit.jupiter.api.BeforeEach)9 ArrayList (java.util.ArrayList)8 Arrays (java.util.Arrays)8