Skip to content

Commit 851a8a4

Browse files
committed
tests(integration): changed codes to improve the test cases
Signed-off-by: Maximillian Arruda <[email protected]>
1 parent 17f9b00 commit 851a8a4

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

jnosql-elasticsearch/src/test/java/org/eclipse/jnosql/databases/elasticsearch/integration/TemplateIntegrationTest.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import jakarta.inject.Inject;
1919
import jakarta.nosql.document.DocumentTemplate;
20+
import org.awaitility.Awaitility;
21+
import org.eclipse.jnosql.databases.elasticsearch.communication.DocumentDatabase;
2022
import org.eclipse.jnosql.databases.elasticsearch.communication.ElasticsearchConfigurations;
2123
import org.eclipse.jnosql.mapping.Convert;
2224
import org.eclipse.jnosql.mapping.config.MappingConfigurations;
@@ -26,18 +28,21 @@
2628
import org.jboss.weld.junit5.auto.AddExtensions;
2729
import org.jboss.weld.junit5.auto.AddPackages;
2830
import org.jboss.weld.junit5.auto.EnableAutoWeld;
31+
import org.junit.jupiter.api.AfterEach;
32+
import org.junit.jupiter.api.BeforeEach;
2933
import org.junit.jupiter.api.Test;
3034
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
3135

3236
import java.util.Optional;
3337
import java.util.concurrent.atomic.AtomicReference;
3438

3539
import static java.util.UUID.randomUUID;
40+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
41+
import static java.util.concurrent.TimeUnit.SECONDS;
3642
import static org.assertj.core.api.Assertions.assertThat;
3743
import static org.awaitility.Awaitility.await;
3844
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
3945
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
40-
import static org.eclipse.jnosql.databases.elasticsearch.communication.DocumentDatabase.INSTANCE;
4146

4247
@EnableAutoWeld
4348
@AddPackages(value = {Convert.class, DocumentEntityConverter.class})
@@ -50,15 +55,28 @@ class TemplateIntegrationTest {
5055
@Inject
5156
private DocumentTemplate template;
5257

58+
public static final String INDEX = "library";
59+
5360
static {
54-
INSTANCE.get("library");
55-
System.setProperty(ElasticsearchConfigurations.HOST.get() + ".1", INSTANCE.host());
56-
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "library");
61+
DocumentDatabase instance = DocumentDatabase.INSTANCE;
62+
instance.get("library");
63+
System.setProperty(ElasticsearchConfigurations.HOST.get() + ".1", instance.host());
64+
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), INDEX);
65+
Awaitility.setDefaultPollDelay(100, MILLISECONDS);
66+
Awaitility.setDefaultTimeout(60L, SECONDS);
67+
}
68+
69+
70+
@BeforeEach
71+
@AfterEach
72+
public void clearDatabase(){
73+
DocumentDatabase.clearDatabase(INDEX);
5774
}
5875

5976
@Test
6077
public void shouldInsert() {
61-
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
78+
Author joshuaBloch = new Author("Joshua Bloch");
79+
Book book = new Book(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
6280
template.insert(book);
6381

6482
AtomicReference<Book> reference = new AtomicReference<>();
@@ -72,12 +90,13 @@ public void shouldInsert() {
7290

7391
@Test
7492
public void shouldUpdate() {
75-
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
93+
Author joshuaBloch = new Author("Joshua Bloch");
94+
Book book = new Book(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
7695
assertThat(template.insert(book))
7796
.isNotNull()
7897
.isEqualTo(book);
7998

80-
Book updated = new Book(book.id(), book.title() + " updated", 2);
99+
Book updated = book.updateEdition(book.edition() + 1);
81100

82101
assertThat(template.update(updated))
83102
.isNotNull()
@@ -95,7 +114,8 @@ public void shouldUpdate() {
95114

96115
@Test
97116
public void shouldFindById() {
98-
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
117+
Author joshuaBloch = new Author("Joshua Bloch");
118+
Book book = new Book(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
99119
assertThat(template.insert(book))
100120
.isNotNull()
101121
.isEqualTo(book);
@@ -112,7 +132,8 @@ public void shouldFindById() {
112132

113133
@Test
114134
public void shouldDelete() {
115-
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
135+
Author joshuaBloch = new Author("Joshua Bloch");
136+
Book book = new Book(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
116137
assertThat(template.insert(book))
117138
.isNotNull()
118139
.isEqualTo(book);

0 commit comments

Comments
 (0)