|
| 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 | +package org.eclipse.jnosql.databases.couchbase.integration; |
| 16 | + |
| 17 | + |
| 18 | +import jakarta.inject.Inject; |
| 19 | +import jakarta.nosql.document.DocumentTemplate; |
| 20 | +import org.eclipse.jnosql.databases.couchbase.communication.CouchbaseUtil; |
| 21 | +import org.eclipse.jnosql.mapping.Convert; |
| 22 | +import org.eclipse.jnosql.mapping.document.DocumentEntityConverter; |
| 23 | +import org.eclipse.jnosql.mapping.document.spi.DocumentExtension; |
| 24 | +import org.eclipse.jnosql.mapping.reflection.EntityMetadataExtension; |
| 25 | +import org.jboss.weld.junit5.auto.AddExtensions; |
| 26 | +import org.jboss.weld.junit5.auto.AddPackages; |
| 27 | +import org.jboss.weld.junit5.auto.EnableAutoWeld; |
| 28 | +import org.junit.jupiter.api.AfterEach; |
| 29 | +import org.junit.jupiter.api.BeforeEach; |
| 30 | +import org.junit.jupiter.api.Test; |
| 31 | +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; |
| 32 | + |
| 33 | +import java.util.Optional; |
| 34 | + |
| 35 | +import static java.util.UUID.randomUUID; |
| 36 | +import static org.assertj.core.api.Assertions.assertThat; |
| 37 | +import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES; |
| 38 | +import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED; |
| 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 DocumentTemplateIntegrationTest { |
| 47 | + |
| 48 | + @Inject |
| 49 | + private DocumentTemplate template; |
| 50 | + |
| 51 | + static { |
| 52 | + CouchbaseUtil.systemPropertySetup(); |
| 53 | + } |
| 54 | + |
| 55 | + @BeforeEach |
| 56 | + @AfterEach |
| 57 | + public void cleanUp() { |
| 58 | + template.delete(Book.class).execute(); |
| 59 | + } |
| 60 | + |
| 61 | + |
| 62 | + @Test |
| 63 | + public void shouldInsert() { |
| 64 | + Book book = new Book(randomUUID().toString(), "Effective Java", 1); |
| 65 | + template.insert(book); |
| 66 | + Optional<Book> optional = template.find(Book.class, book.id()); |
| 67 | + assertThat(optional).isNotNull().isNotEmpty() |
| 68 | + .get().isEqualTo(book); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void shouldUpdate() { |
| 73 | + Book book = new Book(randomUUID().toString(), "Effective Java", 1); |
| 74 | + assertThat(template.insert(book)) |
| 75 | + .isNotNull() |
| 76 | + .isEqualTo(book); |
| 77 | + |
| 78 | + Book updated = new Book(book.id(), book.title() + " updated", 2); |
| 79 | + |
| 80 | + assertThat(template.update(updated)) |
| 81 | + .isNotNull() |
| 82 | + .isNotEqualTo(book); |
| 83 | + |
| 84 | + assertThat(template.find(Book.class, book.id())) |
| 85 | + .isNotNull().get().isEqualTo(updated); |
| 86 | + |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + public void shouldFindById() { |
| 91 | + Book book = new Book(randomUUID().toString(), "Effective Java", 1); |
| 92 | + assertThat(template.insert(book)) |
| 93 | + .isNotNull() |
| 94 | + .isEqualTo(book); |
| 95 | + |
| 96 | + assertThat(template.find(Book.class, book.id())) |
| 97 | + .isNotNull().get().isEqualTo(book); |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + public void shouldDelete() { |
| 102 | + Book book = new Book(randomUUID().toString(), "Effective Java", 1); |
| 103 | + assertThat(template.insert(book)) |
| 104 | + .isNotNull() |
| 105 | + .isEqualTo(book); |
| 106 | + |
| 107 | + template.delete(Book.class, book.id()); |
| 108 | + assertThat(template.find(Book.class, book.id())) |
| 109 | + .isNotNull().isEmpty(); |
| 110 | + } |
| 111 | + |
| 112 | + |
| 113 | +} |
0 commit comments