2828import org .jboss .weld .junit5 .auto .AddExtensions ;
2929import org .jboss .weld .junit5 .auto .AddPackages ;
3030import org .jboss .weld .junit5 .auto .EnableAutoWeld ;
31+ import org .junit .jupiter .api .AfterEach ;
32+ import org .junit .jupiter .api .BeforeEach ;
3133import org .junit .jupiter .api .Test ;
3234import org .junit .jupiter .api .condition .EnabledIfSystemProperty ;
3335
@@ -55,17 +57,28 @@ class ElasticsearchTemplateIntegrationTest {
5557 private ElasticsearchTemplate template ;
5658
5759
60+ public static final String INDEX = "library" ;
61+
5862 static {
59- DocumentDatabase .INSTANCE .get ("library" );
60- System .setProperty (ElasticsearchConfigurations .HOST .get () + ".1" , DocumentDatabase .INSTANCE .host ());
61- System .setProperty (MappingConfigurations .DOCUMENT_DATABASE .get (), "library" );
63+ DocumentDatabase instance = DocumentDatabase .INSTANCE ;
64+ instance .get ("library" );
65+ System .setProperty (ElasticsearchConfigurations .HOST .get () + ".1" , instance .host ());
66+ System .setProperty (MappingConfigurations .DOCUMENT_DATABASE .get (), INDEX );
6267 Awaitility .setDefaultPollDelay (100 , MILLISECONDS );
63- Awaitility .setDefaultTimeout (2L , SECONDS );
68+ Awaitility .setDefaultTimeout (60L , SECONDS );
69+ }
70+
71+
72+ @ BeforeEach
73+ @ AfterEach
74+ public void clearDatabase (){
75+ DocumentDatabase .clearDatabase (INDEX );
6476 }
6577
6678 @ Test
6779 public void shouldInsert () {
68- Book book = new Book (randomUUID ().toString (), "Effective Java" , 1 );
80+ Author joshuaBloch = new Author ("Joshua Bloch" );
81+ Book book = new Book (randomUUID ().toString (), "Effective Java" , 1 , joshuaBloch );
6982 template .insert (book );
7083
7184 AtomicReference <Book > reference = new AtomicReference <>();
@@ -79,12 +92,13 @@ public void shouldInsert() {
7992
8093 @ Test
8194 public void shouldUpdate () {
82- Book book = new Book (randomUUID ().toString (), "Effective Java" , 1 );
95+ Author joshuaBloch = new Author ("Joshua Bloch" );
96+ Book book = new Book (randomUUID ().toString (), "Effective Java" , 1 , joshuaBloch );
8397 assertThat (template .insert (book ))
8498 .isNotNull ()
8599 .isEqualTo (book );
86100
87- Book updated = new Book ( book .id (), book .title () + " updated" , 2 );
101+ Book updated = book .updateEdition ( book .edition () + 1 );
88102
89103 assertThat (template .update (updated ))
90104 .isNotNull ()
@@ -102,7 +116,9 @@ public void shouldUpdate() {
102116
103117 @ Test
104118 public void shouldFindById () {
105- Book book = new Book (randomUUID ().toString (), "Effective Java" , 1 );
119+ Author joshuaBloch = new Author ("Joshua Bloch" );
120+ Book book = new Book (randomUUID ().toString (), "Effective Java" , 1 , joshuaBloch );
121+
106122 assertThat (template .insert (book ))
107123 .isNotNull ()
108124 .isEqualTo (book );
@@ -119,7 +135,8 @@ public void shouldFindById() {
119135
120136 @ Test
121137 public void shouldDelete () {
122- Book book = new Book (randomUUID ().toString (), "Effective Java" , 1 );
138+ Author joshuaBloch = new Author ("Joshua Bloch" );
139+ Book book = new Book (randomUUID ().toString (), "Effective Java" , 1 , joshuaBloch );
123140 assertThat (template .insert (book ))
124141 .isNotNull ()
125142 .isEqualTo (book );
0 commit comments