Skip to content

Commit d8b6bd4

Browse files
committed
chore: create mapping test scenario
Signed-off-by: Otavio Santana <[email protected]>
1 parent 5758917 commit d8b6bd4

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.databases.cassandra.integration;
16+
17+
import jakarta.nosql.Column;
18+
import jakarta.nosql.Entity;
19+
import jakarta.nosql.Id;
20+
21+
@Entity
22+
public record Book(@Id String id, @Column("title") String title, @Column("edition") int edition) {
23+
24+
25+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.databases.mongodb.integration;
16+
17+
18+
import jakarta.inject.Inject;
19+
import jakarta.nosql.document.DocumentTemplate;
20+
import org.eclipse.jnosql.databases.mongodb.communication.MongoDBDocumentConfigurations;
21+
import org.eclipse.jnosql.mapping.Convert;
22+
import org.eclipse.jnosql.mapping.config.MappingConfigurations;
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.Test;
30+
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
31+
32+
import java.util.Optional;
33+
34+
import static java.util.UUID.randomUUID;
35+
import static org.assertj.core.api.Assertions.assertThat;
36+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
37+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
38+
import static org.eclipse.jnosql.databases.mongodb.communication.DocumentDatabase.INSTANCE;
39+
40+
@EnableAutoWeld
41+
@AddPackages(value = {Convert.class, DocumentEntityConverter.class})
42+
@AddPackages(Book.class)
43+
@AddExtensions({EntityMetadataExtension.class,
44+
DocumentExtension.class})
45+
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
46+
class TemplateIntegrationTest {
47+
48+
@Inject
49+
private DocumentTemplate template;
50+
51+
static {
52+
INSTANCE.get("library");
53+
System.setProperty(MongoDBDocumentConfigurations.HOST.get() + ".1", INSTANCE.host());
54+
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "library");
55+
}
56+
57+
@Test
58+
public void shouldInsert() {
59+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
60+
template.insert(book);
61+
Optional<Book> optional = template.find(Book.class, book.id());
62+
assertThat(optional).isNotNull().isNotEmpty()
63+
.get().isEqualTo(book);
64+
}
65+
66+
@Test
67+
public void shouldUpdate() {
68+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
69+
assertThat(template.insert(book))
70+
.isNotNull()
71+
.isEqualTo(book);
72+
73+
Book updated = new Book(book.id(), book.title() + " updated", 2);
74+
75+
assertThat(template.update(updated))
76+
.isNotNull()
77+
.isNotEqualTo(book);
78+
79+
assertThat(template.find(Book.class, book.id()))
80+
.isNotNull().get().isEqualTo(updated);
81+
82+
}
83+
84+
@Test
85+
public void shouldFindById() {
86+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
87+
assertThat(template.insert(book))
88+
.isNotNull()
89+
.isEqualTo(book);
90+
91+
assertThat(template.find(Book.class, book.id()))
92+
.isNotNull().get().isEqualTo(book);
93+
}
94+
95+
@Test
96+
public void shouldDelete() {
97+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
98+
assertThat(template.insert(book))
99+
.isNotNull()
100+
.isEqualTo(book);
101+
102+
template.delete(Book.class, book.id());
103+
assertThat(template.find(Book.class, book.id()))
104+
.isNotNull().isEmpty();
105+
}
106+
107+
108+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
jnosql.cassandra.query.1=CREATE KEYSPACE IF NOT EXISTS library WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};
2+
jnosql.cassandra.query.2=CREATE COLUMNFAMILY IF NOT EXISTS library.book ( id text PRIMARY KEY, title text, edition int);

0 commit comments

Comments
 (0)