-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add repository integration tests for MongoDB implementation
Signed-off-by: Maximillian Arruda <maximillian.arruda@MBP-de-Digibee.local>
- Loading branch information
Maximillian Arruda
authored and
Maximillian Arruda
committed
Nov 13, 2023
1 parent
73a16a7
commit b7e3b40
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...ongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/BookRepository.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,8 @@ | ||
package org.eclipse.jnosql.databases.mongodb.integration; | ||
|
||
import jakarta.data.repository.PageableRepository; | ||
import jakarta.data.repository.Repository; | ||
|
||
@Repository | ||
public interface BookRepository extends PageableRepository<Book,String> { | ||
} |
101 changes: 101 additions & 0 deletions
101
...test/java/org/eclipse/jnosql/databases/mongodb/integration/RepositoryIntegrationTest.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,101 @@ | ||
package org.eclipse.jnosql.databases.mongodb.integration; | ||
|
||
import jakarta.inject.Inject; | ||
import org.eclipse.jnosql.databases.mongodb.communication.MongoDBDocumentConfigurations; | ||
import org.eclipse.jnosql.mapping.Convert; | ||
import org.eclipse.jnosql.mapping.Converters; | ||
import org.eclipse.jnosql.mapping.Database; | ||
import org.eclipse.jnosql.mapping.DatabaseType; | ||
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.Reflections; | ||
import org.eclipse.jnosql.mapping.spi.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 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) | ||
@AddPackages(Reflections.class) | ||
@AddPackages(Converters.class) | ||
@AddExtensions({EntityMetadataExtension.class, | ||
DocumentExtension.class}) | ||
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES) | ||
class RepositoryIntegrationTest { | ||
|
||
static { | ||
INSTANCE.get("library"); | ||
System.setProperty(MongoDBDocumentConfigurations.HOST.get() + ".1", INSTANCE.host()); | ||
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "library"); | ||
} | ||
|
||
@Inject | ||
@Database(DatabaseType.DOCUMENT) | ||
BookRepository repository; | ||
|
||
@Test | ||
void shouldSave() { | ||
Book book = new Book(randomUUID().toString(), "Effective Java", 1); | ||
assertThat(repository.save(book)) | ||
.isNotNull() | ||
.isEqualTo(book); | ||
|
||
Book updated = new Book(book.id(), book.title() + " updated", 2); | ||
|
||
assertThat(repository.save(updated)) | ||
.isNotNull() | ||
.isNotEqualTo(book); | ||
|
||
assertThat(repository.findById(book.id())) | ||
.isNotNull().get().isEqualTo(updated); | ||
|
||
} | ||
|
||
@Test | ||
void shouldDelete() { | ||
Book book = new Book(randomUUID().toString(), "Effective Java", 1); | ||
assertThat(repository.save(book)) | ||
.isNotNull() | ||
.isEqualTo(book); | ||
|
||
repository.delete(book); | ||
assertThat(repository.findById(book.id())) | ||
.isNotNull().isEmpty(); | ||
} | ||
|
||
@Test | ||
void shouldDeleteById() { | ||
Book book = new Book(randomUUID().toString(), "Effective Java", 1); | ||
assertThat(repository.save(book)) | ||
.isNotNull() | ||
.isEqualTo(book); | ||
|
||
repository.deleteById(book.id()); | ||
assertThat(repository.findById(book.id())) | ||
.isNotNull().isEmpty(); | ||
} | ||
|
||
@Test | ||
void shouldDeleteAll(){ | ||
for (int index = 0; index < 20; index++) { | ||
Book book = new Book(randomUUID().toString(), "Effective Java", 1); | ||
assertThat(repository.save(book)) | ||
.isNotNull() | ||
.isEqualTo(book); | ||
} | ||
|
||
repository.deleteAll(); | ||
assertThat(repository.findAll()).isEmpty(); | ||
} | ||
|
||
} |