Skip to content

Commit

Permalink
Add test for live query with update callback
Browse files Browse the repository at this point in the history
  • Loading branch information
furlaneto committed Feb 14, 2018
1 parent ba5f9d5 commit 1ffc35f
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonMap;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.notNullValue;
import static org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete;
import static org.jnosql.diana.api.document.query.DocumentQueryBuilder.select;
import static org.jnosql.diana.orientdb.document.DocumentConfigurationUtils.get;
Expand Down Expand Up @@ -399,6 +402,23 @@ public void shouldLive() throws InterruptedException {
assertFalse(entities.isEmpty());
}

@Test
public void shouldLiveUpdateCallback() throws InterruptedException {
AtomicReference<DocumentEntity> reference = new AtomicReference<>();
OrientDBLiveUpdateCallback<DocumentEntity> callback = reference::set;
DocumentEntity entity = entityManager.insert(getEntity());
Document id = entity.find(OrientDBConverter.RID_FIELD).get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();

entityManager.live(query, OrientDBLiveCallback.builder().onUpdate(callback).build());
Document newName = Document.of("name", "Lucas");
entity.add(newName);
entityManager.update(entity);
await().until(reference::get, notNullValue());

assertEquals("Lucas", reference.get().find("name").get().get());
}

@Test
public void shouldLiveWithNativeQuery() throws InterruptedException {
List<DocumentEntity> entities = new ArrayList<>();
Expand Down

0 comments on commit 1ffc35f

Please sign in to comment.