Skip to content

Commit e2972e4

Browse files
committed
test: create cassndra integration test
Signed-off-by: Otavio Santana <[email protected]>
1 parent 5b0178e commit e2972e4

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
18+
import jakarta.inject.Inject;
19+
import org.eclipse.jnosql.communication.driver.ConfigurationReader;
20+
import org.eclipse.jnosql.databases.cassandra.communication.CassandraConfigurations;
21+
import org.eclipse.jnosql.databases.cassandra.communication.ColumnDatabase;
22+
import org.eclipse.jnosql.databases.cassandra.mapping.CassandraTemplate;
23+
import org.eclipse.jnosql.mapping.Convert;
24+
import org.eclipse.jnosql.mapping.column.ColumnEntityConverter;
25+
import org.eclipse.jnosql.mapping.column.spi.ColumnExtension;
26+
import org.eclipse.jnosql.mapping.config.MappingConfigurations;
27+
import org.eclipse.jnosql.mapping.reflection.EntityMetadataExtension;
28+
import org.jboss.weld.junit5.auto.AddExtensions;
29+
import org.jboss.weld.junit5.auto.AddPackages;
30+
import org.jboss.weld.junit5.auto.EnableAutoWeld;
31+
import org.junit.jupiter.api.Test;
32+
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
33+
34+
import java.util.HashMap;
35+
import java.util.Map;
36+
import java.util.Optional;
37+
38+
import static java.util.UUID.randomUUID;
39+
import static org.assertj.core.api.Assertions.assertThat;
40+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
41+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
42+
43+
@EnableAutoWeld
44+
@AddPackages(value = {Convert.class, ColumnEntityConverter.class})
45+
@AddPackages(Book.class)
46+
@AddPackages(CassandraTemplate.class)
47+
@AddExtensions({EntityMetadataExtension.class,
48+
ColumnExtension.class})
49+
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
50+
class CassandraTemplateIntegrationTest {
51+
52+
@Inject
53+
private CassandraTemplate template;
54+
55+
static {
56+
Map<String, Object> configuration = new HashMap<>(ConfigurationReader.from("mapping.properties"));
57+
for (Map.Entry<String, Object> entry : configuration.entrySet()) {
58+
System.setProperty(entry.getKey(), entry.getValue().toString());
59+
}
60+
System.setProperty(MappingConfigurations.COLUMN_DATABASE.get(), "library");
61+
System.setProperty(CassandraConfigurations.HOST.get()+".1", ColumnDatabase.INSTANCE.host());
62+
System.setProperty(CassandraConfigurations.PORT.get(), Integer.toString(ColumnDatabase.INSTANCE.port()));
63+
}
64+
65+
@Test
66+
public void shouldInsert() {
67+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
68+
template.insert(book);
69+
Optional<Book> optional = template.find(Book.class, book.id());
70+
assertThat(optional).isNotNull().isNotEmpty()
71+
.get().isEqualTo(book);
72+
}
73+
74+
@Test
75+
public void shouldUpdate() {
76+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
77+
assertThat(template.insert(book))
78+
.isNotNull()
79+
.isEqualTo(book);
80+
81+
Book updated = new Book(book.id(), book.title() + " updated", 2);
82+
83+
assertThat(template.update(updated))
84+
.isNotNull()
85+
.isNotEqualTo(book);
86+
87+
assertThat(template.find(Book.class, book.id()))
88+
.isNotNull().get().isEqualTo(updated);
89+
90+
}
91+
92+
@Test
93+
public void shouldFindById() {
94+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
95+
assertThat(template.insert(book))
96+
.isNotNull()
97+
.isEqualTo(book);
98+
99+
assertThat(template.find(Book.class, book.id()))
100+
.isNotNull().get().isEqualTo(book);
101+
}
102+
103+
@Test
104+
public void shouldDelete() {
105+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
106+
assertThat(template.insert(book))
107+
.isNotNull()
108+
.isEqualTo(book);
109+
110+
template.delete(Book.class, book.id());
111+
assertThat(template.find(Book.class, book.id()))
112+
.isNotNull().isEmpty();
113+
}
114+
115+
116+
}

0 commit comments

Comments
 (0)