Skip to content

Commit 400f97b

Browse files
committed
feat: udpate ES database
Signed-off-by: Otavio Santana <[email protected]>
1 parent 8ce39ee commit 400f97b

File tree

5 files changed

+99
-99
lines changed

5 files changed

+99
-99
lines changed

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
@EnableAutoWeld
5151
@AddPackages(value = {Database.class, Converters.class, EntityConverter.class, DocumentTemplate.class})
52-
@AddPackages(Book.class)
52+
@AddPackages(Magazine.class)
5353
@AddPackages(ElasticsearchTemplate.class)
5454
@AddExtensions({EntityMetadataExtension.class,
5555
DocumentExtension.class})
@@ -82,35 +82,35 @@ public void clearDatabase(){
8282
@Test
8383
public void shouldInsert() {
8484
Author joshuaBloch = new Author("Joshua Bloch");
85-
Book book = new Book(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
86-
template.insert(book);
85+
Magazine magazine = new Magazine(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
86+
template.insert(magazine);
8787

88-
AtomicReference<Book> reference = new AtomicReference<>();
88+
AtomicReference<Magazine> reference = new AtomicReference<>();
8989
await().until(() -> {
90-
Optional<Book> optional = template.find(Book.class, book.id());
90+
Optional<Magazine> optional = template.find(Magazine.class, magazine.id());
9191
optional.ifPresent(reference::set);
9292
return optional.isPresent();
9393
});
94-
assertThat(reference.get()).isNotNull().isEqualTo(book);
94+
assertThat(reference.get()).isNotNull().isEqualTo(magazine);
9595
}
9696

9797
@Test
9898
public void shouldUpdate() {
9999
Author joshuaBloch = new Author("Joshua Bloch");
100-
Book book = new Book(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
101-
assertThat(template.insert(book))
100+
Magazine magazine = new Magazine(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
101+
assertThat(template.insert(magazine))
102102
.isNotNull()
103-
.isEqualTo(book);
103+
.isEqualTo(magazine);
104104

105-
Book updated = book.updateEdition(book.edition() + 1);
105+
Magazine updated = magazine.updateEdition(magazine.edition() + 1);
106106

107107
assertThat(template.update(updated))
108108
.isNotNull()
109-
.isNotEqualTo(book);
109+
.isNotEqualTo(magazine);
110110

111-
AtomicReference<Book> reference = new AtomicReference<>();
111+
AtomicReference<Magazine> reference = new AtomicReference<>();
112112
await().until(() -> {
113-
Optional<Book> optional = template.find(Book.class, book.id());
113+
Optional<Magazine> optional = template.find(Magazine.class, magazine.id());
114114
optional.ifPresent(reference::set);
115115
return optional.isPresent();
116116
});
@@ -121,32 +121,32 @@ public void shouldUpdate() {
121121
@Test
122122
public void shouldFindById() {
123123
Author joshuaBloch = new Author("Joshua Bloch");
124-
Book book = new Book(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
124+
Magazine magazine = new Magazine(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
125125

126-
assertThat(template.insert(book))
126+
assertThat(template.insert(magazine))
127127
.isNotNull()
128-
.isEqualTo(book);
128+
.isEqualTo(magazine);
129129

130-
AtomicReference<Book> reference = new AtomicReference<>();
130+
AtomicReference<Magazine> reference = new AtomicReference<>();
131131
await().until(() -> {
132-
Optional<Book> optional = template.find(Book.class, book.id());
132+
Optional<Magazine> optional = template.find(Magazine.class, magazine.id());
133133
optional.ifPresent(reference::set);
134134
return optional.isPresent();
135135
});
136136

137-
assertThat(reference.get()).isNotNull().isEqualTo(book);
137+
assertThat(reference.get()).isNotNull().isEqualTo(magazine);
138138
}
139139

140140
@Test
141141
public void shouldDelete() {
142142
Author joshuaBloch = new Author("Joshua Bloch");
143-
Book book = new Book(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
144-
assertThat(template.insert(book))
143+
Magazine magazine = new Magazine(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
144+
assertThat(template.insert(magazine))
145145
.isNotNull()
146-
.isEqualTo(book);
146+
.isEqualTo(magazine);
147147

148-
template.delete(Book.class, book.id());
149-
assertThat(template.find(Book.class, book.id()))
148+
template.delete(Magazine.class, magazine.id());
149+
assertThat(template.find(Magazine.class, magazine.id()))
150150
.isNotNull().isEmpty();
151151
}
152152

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import java.util.stream.Stream;
2525

2626
@Repository
27-
public interface Library extends CrudRepository<Book, String> {
27+
public interface Library extends CrudRepository<Magazine, String> {
2828

2929
@Query("select * from Book where author.name = @name")
30-
Stream<Book> findByAuthorName(@Param("name") String name);
30+
Stream<Magazine> findByAuthorName(@Param("name") String name);
3131

32-
Stream<Book> findByTitleLike( String title);
32+
Stream<Magazine> findByTitleLike(String title);
3333

3434
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.UUID;
2323

2424
@Entity
25-
public final class Book {
25+
public final class Magazine {
2626
@Id
2727
private final String id;
2828
@Column("title")
@@ -32,7 +32,7 @@ public final class Book {
3232
@Column("author")
3333
private final Author author;
3434

35-
public Book(
35+
public Magazine(
3636
@Id String id,
3737
@Column("title") String title,
3838
@Column("edition") int edition,
@@ -43,15 +43,15 @@ public Book(
4343
this.author = author;
4444
}
4545

46-
public Book newEdition() {
47-
return new Book(UUID.randomUUID().toString(),
46+
public Magazine newEdition() {
47+
return new Magazine(UUID.randomUUID().toString(),
4848
this.title,
4949
this.edition + 1,
5050
this.author);
5151
}
5252

53-
public Book updateEdition(int edition) {
54-
return new Book(this.id,
53+
public Magazine updateEdition(int edition) {
54+
return new Magazine(this.id,
5555
this.title,
5656
edition,
5757
this.author);
@@ -77,7 +77,7 @@ public Author author() {
7777
public boolean equals(Object obj) {
7878
if (obj == this) return true;
7979
if (obj == null || obj.getClass() != this.getClass()) return false;
80-
var that = (Book) obj;
80+
var that = (Magazine) obj;
8181
return Objects.equals(this.id, that.id) &&
8282
Objects.equals(this.title, that.title) &&
8383
this.edition == that.edition &&

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

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
@EnableAutoWeld
5353
@AddPackages(value = {Database.class, Converters.class, EntityConverter.class, DocumentTemplate.class})
54-
@AddPackages(Book.class)
54+
@AddPackages(Magazine.class)
5555
@AddPackages(ElasticsearchTemplate.class)
5656
@AddExtensions({EntityMetadataExtension.class,
5757
DocumentExtension.class})
@@ -83,35 +83,35 @@ public void clearDatabase() {
8383
@Test
8484
public void shouldInsert() {
8585
Author joshuaBloch = new Author("Joshua Bloch");
86-
Book book = new Book(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
87-
library.save(book);
86+
Magazine magazine = new Magazine(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
87+
library.save(magazine);
8888

89-
AtomicReference<Book> reference = new AtomicReference<>();
89+
AtomicReference<Magazine> reference = new AtomicReference<>();
9090
await().until(() -> {
91-
Optional<Book> optional = library.findById(book.id());
91+
Optional<Magazine> optional = library.findById(magazine.id());
9292
optional.ifPresent(reference::set);
9393
return optional.isPresent();
9494
});
95-
assertThat(reference.get()).isNotNull().isEqualTo(book);
95+
assertThat(reference.get()).isNotNull().isEqualTo(magazine);
9696
}
9797

9898
@Test
9999
public void shouldUpdate() {
100100
Author joshuaBloch = new Author("Joshua Bloch");
101-
Book book = new Book(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
102-
assertThat(library.save(book))
101+
Magazine magazine = new Magazine(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
102+
assertThat(library.save(magazine))
103103
.isNotNull()
104-
.isEqualTo(book);
104+
.isEqualTo(magazine);
105105

106-
Book updated = book.updateEdition(2);
106+
Magazine updated = magazine.updateEdition(2);
107107

108108
assertThat(library.save(updated))
109109
.isNotNull()
110-
.isNotEqualTo(book);
110+
.isNotEqualTo(magazine);
111111

112-
AtomicReference<Book> reference = new AtomicReference<>();
112+
AtomicReference<Magazine> reference = new AtomicReference<>();
113113
await().until(() -> {
114-
Optional<Book> optional = library.findById(book.id());
114+
Optional<Magazine> optional = library.findById(magazine.id());
115115
optional.ifPresent(reference::set);
116116
return optional.isPresent();
117117
});
@@ -122,82 +122,82 @@ public void shouldUpdate() {
122122
@Test
123123
public void shouldFindById() {
124124
Author joshuaBloch = new Author("Joshua Bloch");
125-
Book book = new Book(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
125+
Magazine magazine = new Magazine(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
126126

127-
assertThat(library.save(book))
127+
assertThat(library.save(magazine))
128128
.isNotNull()
129-
.isEqualTo(book);
129+
.isEqualTo(magazine);
130130

131-
AtomicReference<Book> reference = new AtomicReference<>();
131+
AtomicReference<Magazine> reference = new AtomicReference<>();
132132
await().until(() -> {
133-
Optional<Book> optional = library.findById(book.id());
133+
Optional<Magazine> optional = library.findById(magazine.id());
134134
optional.ifPresent(reference::set);
135135
return optional.isPresent();
136136
});
137137

138-
assertThat(reference.get()).isNotNull().isEqualTo(book);
138+
assertThat(reference.get()).isNotNull().isEqualTo(magazine);
139139
}
140140

141141
@Test
142142
public void shouldDelete() {
143143
Author joshuaBloch = new Author("Joshua Bloch");
144-
Book book = new Book(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
145-
assertThat(library.save(book))
144+
Magazine magazine = new Magazine(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
145+
assertThat(library.save(magazine))
146146
.isNotNull()
147-
.isEqualTo(book);
147+
.isEqualTo(magazine);
148148

149149

150-
library.deleteById(book.id());
150+
library.deleteById(magazine.id());
151151

152-
assertThat(library.findById(book.id()))
152+
assertThat(library.findById(magazine.id()))
153153
.isNotNull().isEmpty();
154154
}
155155

156156

157157
@Test
158158
public void shouldFindByAuthorName() throws InterruptedException {
159159
Author joshuaBloch = new Author("Joshua Bloch");
160-
Book book = new Book(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
160+
Magazine magazine = new Magazine(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
161161

162-
List<Book> expectedBooks = List.of(book, book.newEdition(), book.newEdition());
163-
library.saveAll(expectedBooks);
162+
List<Magazine> expectedMagazines = List.of(magazine, magazine.newEdition(), magazine.newEdition());
163+
library.saveAll(expectedMagazines);
164164

165165
await().until(() ->
166-
!library.findByAuthorName(book.author().name()).toList().isEmpty());
166+
!library.findByAuthorName(magazine.author().name()).toList().isEmpty());
167167

168-
var books = library.findByAuthorName(book.author().name()).toList();
168+
var books = library.findByAuthorName(magazine.author().name()).toList();
169169
assertThat(books)
170170
.hasSize(3);
171171

172172
assertThat(books)
173-
.containsAll(expectedBooks);
173+
.containsAll(expectedMagazines);
174174
}
175175

176176
@Test
177177
public void shouldFindByTitleLike() throws InterruptedException {
178178
Author joshuaBloch = new Author("Joshua Bloch");
179179

180-
Book effectiveJava1stEdition = new Book(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
181-
Book effectiveJava2ndEdition = effectiveJava1stEdition.newEdition();
182-
Book effectiveJava3rdEdition = effectiveJava2ndEdition.newEdition();
180+
Magazine effectiveJava1stEdition = new Magazine(randomUUID().toString(), "Effective Java", 1, joshuaBloch);
181+
Magazine effectiveJava2ndEdition = effectiveJava1stEdition.newEdition();
182+
Magazine effectiveJava3rdEdition = effectiveJava2ndEdition.newEdition();
183183

184184
Author elderMoraes = new Author("Elder Moraes");
185-
Book jakartaEECookBook = new Book(randomUUID().toString(), "Jakarta EE CookBook", 1, elderMoraes);
185+
Magazine jakartaEECookMagazine = new Magazine(randomUUID().toString(), "Jakarta EE CookBook", 1, elderMoraes);
186186

187-
List<Book> allBooks = List.of(jakartaEECookBook, effectiveJava1stEdition, effectiveJava2ndEdition, effectiveJava3rdEdition);
187+
List<Magazine> allMagazines = List.of(jakartaEECookMagazine, effectiveJava1stEdition, effectiveJava2ndEdition, effectiveJava3rdEdition);
188188

189-
List<Book> effectiveBooks = List.of(effectiveJava1stEdition, effectiveJava2ndEdition, effectiveJava3rdEdition);
189+
List<Magazine> effectiveMagazines = List.of(effectiveJava1stEdition, effectiveJava2ndEdition, effectiveJava3rdEdition);
190190

191-
library.saveAll(allBooks);
191+
library.saveAll(allMagazines);
192192

193-
AtomicReference<List<Book>> booksWithEffective = new AtomicReference<>();
193+
AtomicReference<List<Magazine>> booksWithEffective = new AtomicReference<>();
194194
await().until(() -> {
195195
var books = library.findByTitleLike("Effective").toList();
196196
booksWithEffective.set(books);
197197
return !books.isEmpty();
198198
});
199199

200-
AtomicReference<List<Book>> booksWithJa = new AtomicReference<>();
200+
AtomicReference<List<Magazine>> booksWithJa = new AtomicReference<>();
201201
await().until(() -> {
202202
var books = library.findByTitleLike("Ja*").toList();
203203
booksWithJa.set(books);
@@ -206,12 +206,12 @@ public void shouldFindByTitleLike() throws InterruptedException {
206206

207207
assertSoftly(softly -> assertThat(booksWithEffective.get())
208208
.as("returned book list with 'Effective' is not equals to the expected items ")
209-
.containsAll(effectiveBooks));
209+
.containsAll(effectiveMagazines));
210210

211211

212212
assertSoftly(softly -> assertThat(booksWithJa.get())
213213
.as("returned book list with 'Ja*' is not equals to the expected items ")
214-
.containsAll(allBooks));
214+
.containsAll(allMagazines));
215215
}
216216

217217

0 commit comments

Comments
 (0)