Skip to content

Commit

Permalink
test: create ES integration
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava committed May 19, 2023
1 parent b5876c2 commit 7b04ca5
Showing 1 changed file with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


import jakarta.inject.Inject;
import org.awaitility.Awaitility;
import org.eclipse.jnosql.databases.elasticsearch.communication.DocumentDatabase;
import org.eclipse.jnosql.databases.elasticsearch.communication.ElasticsearchConfigurations;
import org.eclipse.jnosql.databases.elasticsearch.mapping.ElasticsearchTemplate;
Expand All @@ -31,9 +32,13 @@
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;

import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;

import static java.util.UUID.randomUUID;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;

Expand All @@ -49,19 +54,27 @@ class ElasticsearchTemplateIntegrationTest {
@Inject
private ElasticsearchTemplate template;


static {
DocumentDatabase.INSTANCE.get("library");
System.setProperty(ElasticsearchConfigurations.HOST.get() + ".1", DocumentDatabase.INSTANCE.host());
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "library");
Awaitility.setDefaultPollDelay(100, MILLISECONDS);
Awaitility.setDefaultTimeout(2L, SECONDS);
}

@Test
public void shouldInsert() {
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
template.insert(book);
Optional<Book> optional = template.find(Book.class, book.id());
assertThat(optional).isNotNull().isNotEmpty()
.get().isEqualTo(book);

AtomicReference<Book> reference = new AtomicReference<>();
await().until(() -> {
Optional<Book> optional = template.find(Book.class, book.id());
optional.ifPresent(reference::set);
return optional.isPresent();
});
assertThat(reference.get()).isNotNull().isEqualTo(book);
}

@Test
Expand All @@ -77,8 +90,13 @@ public void shouldUpdate() {
.isNotNull()
.isNotEqualTo(book);

assertThat(template.find(Book.class, book.id()))
.isNotNull().get().isEqualTo(updated);
AtomicReference<Book> reference = new AtomicReference<>();
await().until(() -> {
Optional<Book> optional = template.find(Book.class, book.id());
optional.ifPresent(reference::set);
return optional.isPresent();
});
assertThat(reference.get()).isNotNull().isEqualTo(updated);

}

Expand All @@ -89,8 +107,14 @@ public void shouldFindById() {
.isNotNull()
.isEqualTo(book);

assertThat(template.find(Book.class, book.id()))
.isNotNull().get().isEqualTo(book);
AtomicReference<Book> reference = new AtomicReference<>();
await().until(() -> {
Optional<Book> optional = template.find(Book.class, book.id());
optional.ifPresent(reference::set);
return optional.isPresent();
});

assertThat(reference.get()).isNotNull().isEqualTo(book);
}

@Test
Expand Down

0 comments on commit 7b04ca5

Please sign in to comment.