Skip to content

Commit 8c0fd16

Browse files
committed
test: added TemplateIntegrationTest
Signed-off-by: Maximillian Arruda <[email protected]>
1 parent ea5e257 commit 8c0fd16

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Maximillian Arruda
14+
*
15+
*/
16+
package org.eclipse.jnosql.databases.couchbase.integration;
17+
18+
19+
import jakarta.inject.Inject;
20+
import jakarta.nosql.Template;
21+
import org.eclipse.jnosql.databases.couchbase.communication.CouchbaseUtil;
22+
import org.eclipse.jnosql.mapping.Convert;
23+
import org.eclipse.jnosql.mapping.document.DocumentEntityConverter;
24+
import org.eclipse.jnosql.mapping.document.spi.DocumentExtension;
25+
import org.eclipse.jnosql.mapping.reflection.EntityMetadataExtension;
26+
import org.jboss.weld.junit5.auto.AddExtensions;
27+
import org.jboss.weld.junit5.auto.AddPackages;
28+
import org.jboss.weld.junit5.auto.EnableAutoWeld;
29+
import org.junit.jupiter.api.AfterEach;
30+
import org.junit.jupiter.api.BeforeEach;
31+
import org.junit.jupiter.api.Test;
32+
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
33+
34+
import java.util.Optional;
35+
36+
import static java.util.UUID.randomUUID;
37+
import static org.assertj.core.api.Assertions.assertThat;
38+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
39+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
40+
41+
@EnableAutoWeld
42+
@AddPackages(value = {Convert.class, DocumentEntityConverter.class})
43+
@AddPackages(Book.class)
44+
@AddExtensions({EntityMetadataExtension.class,
45+
DocumentExtension.class})
46+
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
47+
class TemplateIntegrationTest {
48+
49+
@Inject
50+
private Template template;
51+
52+
static {
53+
CouchbaseUtil.systemPropertySetup();
54+
}
55+
56+
@BeforeEach
57+
@AfterEach
58+
public void cleanUp() {
59+
template.delete(Book.class).execute();
60+
}
61+
62+
63+
@Test
64+
public void shouldInsert() {
65+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
66+
template.insert(book);
67+
Optional<Book> optional = template.find(Book.class, book.id());
68+
assertThat(optional).isNotNull().isNotEmpty()
69+
.get().isEqualTo(book);
70+
}
71+
72+
@Test
73+
public void shouldUpdate() {
74+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
75+
assertThat(template.insert(book))
76+
.isNotNull()
77+
.isEqualTo(book);
78+
79+
Book updated = new Book(book.id(), book.title() + " updated", 2);
80+
81+
assertThat(template.update(updated))
82+
.isNotNull()
83+
.isNotEqualTo(book);
84+
85+
assertThat(template.find(Book.class, book.id()))
86+
.isNotNull().get().isEqualTo(updated);
87+
88+
}
89+
90+
@Test
91+
public void shouldFindById() {
92+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
93+
assertThat(template.insert(book))
94+
.isNotNull()
95+
.isEqualTo(book);
96+
97+
assertThat(template.find(Book.class, book.id()))
98+
.isNotNull().get().isEqualTo(book);
99+
}
100+
101+
@Test
102+
public void shouldDelete() {
103+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
104+
assertThat(template.insert(book))
105+
.isNotNull()
106+
.isEqualTo(book);
107+
108+
template.delete(Book.class, book.id());
109+
assertThat(template.find(Book.class, book.id()))
110+
.isNotNull().isEmpty();
111+
}
112+
113+
114+
}

0 commit comments

Comments
 (0)