-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
- Loading branch information
1 parent
5758917
commit d8b6bd4
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
jnosql-cassandra/src/test/java/org/eclipse/jnosql/databases/cassandra/integration/Book.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.databases.cassandra.integration; | ||
|
||
import jakarta.nosql.Column; | ||
import jakarta.nosql.Entity; | ||
import jakarta.nosql.Id; | ||
|
||
@Entity | ||
public record Book(@Id String id, @Column("title") String title, @Column("edition") int edition) { | ||
|
||
|
||
} |
108 changes: 108 additions & 0 deletions
108
...test/java/org/eclipse/jnosql/databases/cassandra/integration/TemplateIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.databases.mongodb.integration; | ||
|
||
|
||
import jakarta.inject.Inject; | ||
import jakarta.nosql.document.DocumentTemplate; | ||
import org.eclipse.jnosql.databases.mongodb.communication.MongoDBDocumentConfigurations; | ||
import org.eclipse.jnosql.mapping.Convert; | ||
import org.eclipse.jnosql.mapping.config.MappingConfigurations; | ||
import org.eclipse.jnosql.mapping.document.DocumentEntityConverter; | ||
import org.eclipse.jnosql.mapping.document.spi.DocumentExtension; | ||
import org.eclipse.jnosql.mapping.reflection.EntityMetadataExtension; | ||
import org.jboss.weld.junit5.auto.AddExtensions; | ||
import org.jboss.weld.junit5.auto.AddPackages; | ||
import org.jboss.weld.junit5.auto.EnableAutoWeld; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.EnabledIfSystemProperty; | ||
|
||
import java.util.Optional; | ||
|
||
import static java.util.UUID.randomUUID; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES; | ||
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED; | ||
import static org.eclipse.jnosql.databases.mongodb.communication.DocumentDatabase.INSTANCE; | ||
|
||
@EnableAutoWeld | ||
@AddPackages(value = {Convert.class, DocumentEntityConverter.class}) | ||
@AddPackages(Book.class) | ||
@AddExtensions({EntityMetadataExtension.class, | ||
DocumentExtension.class}) | ||
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES) | ||
class TemplateIntegrationTest { | ||
|
||
@Inject | ||
private DocumentTemplate template; | ||
|
||
static { | ||
INSTANCE.get("library"); | ||
System.setProperty(MongoDBDocumentConfigurations.HOST.get() + ".1", INSTANCE.host()); | ||
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "library"); | ||
} | ||
|
||
@Test | ||
public void shouldInsert() { | ||
Book book = new Book(randomUUID().toString(), "Effective Java", 1); | ||
template.insert(book); | ||
Optional<Book> optional = template.find(Book.class, book.id()); | ||
assertThat(optional).isNotNull().isNotEmpty() | ||
.get().isEqualTo(book); | ||
} | ||
|
||
@Test | ||
public void shouldUpdate() { | ||
Book book = new Book(randomUUID().toString(), "Effective Java", 1); | ||
assertThat(template.insert(book)) | ||
.isNotNull() | ||
.isEqualTo(book); | ||
|
||
Book updated = new Book(book.id(), book.title() + " updated", 2); | ||
|
||
assertThat(template.update(updated)) | ||
.isNotNull() | ||
.isNotEqualTo(book); | ||
|
||
assertThat(template.find(Book.class, book.id())) | ||
.isNotNull().get().isEqualTo(updated); | ||
|
||
} | ||
|
||
@Test | ||
public void shouldFindById() { | ||
Book book = new Book(randomUUID().toString(), "Effective Java", 1); | ||
assertThat(template.insert(book)) | ||
.isNotNull() | ||
.isEqualTo(book); | ||
|
||
assertThat(template.find(Book.class, book.id())) | ||
.isNotNull().get().isEqualTo(book); | ||
} | ||
|
||
@Test | ||
public void shouldDelete() { | ||
Book book = new Book(randomUUID().toString(), "Effective Java", 1); | ||
assertThat(template.insert(book)) | ||
.isNotNull() | ||
.isEqualTo(book); | ||
|
||
template.delete(Book.class, book.id()); | ||
assertThat(template.find(Book.class, book.id())) | ||
.isNotNull().isEmpty(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
jnosql.cassandra.query.1=CREATE KEYSPACE IF NOT EXISTS library WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3}; | ||
jnosql.cassandra.query.2=CREATE COLUMNFAMILY IF NOT EXISTS library.book ( id text PRIMARY KEY, title text, edition int); |