Search in sources :

Example 36 with ColumnQuery

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

the class DefaultColumnEventPersistManagerTest method shouldFirePreQuery.

@Test
public void shouldFirePreQuery() {
    ColumnQuery query = select().from("person").build();
    subject.firePreQuery(query);
    ArgumentCaptor<ColumnQueryExecute> captor = ArgumentCaptor.forClass(ColumnQueryExecute.class);
    verify(columnQueryExecute).fire(captor.capture());
    assertEquals(query, captor.getValue().getQuery());
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Test(org.junit.jupiter.api.Test)

Example 37 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerAsyncTest method shouldUpdateColumnsAsyncWithCallBack.

@Test
public void shouldUpdateColumnsAsyncWithCallBack() {
    ColumnEntity columnEntity = getColumnFamily();
    AtomicBoolean callBack = new AtomicBoolean(false);
    columnEntityManager.update(columnEntity, c -> callBack.set(true));
    await().untilTrue(callBack);
    ColumnQuery query = select().from(COLUMN_FAMILY).where("id").eq(10L).build();
    AtomicReference<List<ColumnEntity>> entities = new AtomicReference<>(emptyList());
    columnEntityManager.select(query, entities::set);
    await().until(() -> entities.get().size(), not(equalTo(0)));
    assertThat(entities.get(), contains(columnEntity));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 38 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerAsyncTest method shouldDeleteWithCallBack.

@Test
public void shouldDeleteWithCallBack() {
    AtomicBoolean callback = new AtomicBoolean(false);
    ColumnDeleteQuery deleteQuery = delete().from(COLUMN_FAMILY).where("id").eq(10L).build();
    columnEntityManager.delete(deleteQuery, v -> callback.set(true));
    await().untilTrue(callback);
    ColumnQuery query = select().from(COLUMN_FAMILY).where("id").eq(10L).build();
    AtomicReference<List<ColumnEntity>> entities = new AtomicReference<>(emptyList());
    callback.set(false);
    Consumer<List<ColumnEntity>> result = (l) -> {
        callback.set(true);
        entities.set(l);
    };
    columnEntityManager.select(query, result);
    await().untilTrue(callback);
    assertTrue(entities.get().isEmpty());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) EmbeddedCassandraServerHelper(org.cassandraunit.utils.EmbeddedCassandraServerHelper) TTransportException(org.apache.thrift.transport.TTransportException) Matchers.not(org.hamcrest.Matchers.not) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) ColumnQueryBuilder.delete(org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Duration(java.time.Duration) Map(java.util.Map) Columns(org.jnosql.diana.api.column.Columns) Thread.sleep(java.lang.Thread.sleep) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) KEY_SPACE(org.jnosql.diana.cassandra.column.Constants.KEY_SPACE) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Awaitility.await(org.awaitility.Awaitility.await) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Collections.emptyList(java.util.Collections.emptyList) IOException(java.io.IOException) COLUMN_FAMILY(org.jnosql.diana.cassandra.column.Constants.COLUMN_FAMILY) Column(org.jnosql.diana.api.column.Column) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) ColumnQueryBuilder.select(org.jnosql.diana.api.column.query.ColumnQueryBuilder.select) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 39 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerTest method shouldFindByIdWithConsistenceLevel.

@Test
public void shouldFindByIdWithConsistenceLevel() {
    entityManager.insert(getColumnFamily());
    ColumnQuery query = select().from(COLUMN_FAMILY).where("id").eq(10L).build();
    List<ColumnEntity> columnEntity = entityManager.select(query, CONSISTENCY_LEVEL);
    assertFalse(columnEntity.isEmpty());
    List<Column> columns = columnEntity.get(0).getColumns();
    assertThat(columns.stream().map(Column::getName).collect(toList()), containsInAnyOrder("name", "version", "options", "id"));
    assertThat(columns.stream().map(Column::getValue).map(Value::get).collect(toList()), containsInAnyOrder("Cassandra", 3.2, asList(1, 2, 3), 10L));
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Column(org.jnosql.diana.api.column.Column) Value(org.jnosql.diana.api.Value) Test(org.junit.jupiter.api.Test)

Example 40 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerTest method shouldLimitResult.

@Test
public void shouldLimitResult() {
    getEntities().forEach(entityManager::insert);
    ColumnQuery query = select().from(COLUMN_FAMILY).where("id").in(Arrays.asList(1L, 2L, 3L)).limit(2).build();
    List<ColumnEntity> columnFamilyEntities = entityManager.select(query);
    assertEquals(Integer.valueOf(2), Integer.valueOf(columnFamilyEntities.size()));
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)117 Test (org.junit.jupiter.api.Test)113 Person (org.jnosql.artemis.model.Person)37 ColumnCondition (org.jnosql.diana.api.column.ColumnCondition)35 Column (org.jnosql.diana.api.column.Column)29 List (java.util.List)26 ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)26 Collections.singletonList (java.util.Collections.singletonList)20 ColumnDeleteQuery (org.jnosql.diana.api.column.ColumnDeleteQuery)19 Arrays.asList (java.util.Arrays.asList)15 Duration (java.time.Duration)14 ColumnQueryBuilder.delete (org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete)14 ColumnQueryBuilder.select (org.jnosql.diana.api.column.query.ColumnQueryBuilder.select)14 BeforeEach (org.junit.jupiter.api.BeforeEach)14 Optional (java.util.Optional)13 Consumer (java.util.function.Consumer)13 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)13 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)13 Inject (javax.inject.Inject)12 CDIExtension (org.jnosql.artemis.CDIExtension)12