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
e9525ed
commit 7160b05
Showing
12 changed files
with
1,445 additions
and
29 deletions.
There are no files selected for viewing
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
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
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
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
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
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
96 changes: 96 additions & 0 deletions
96
...l-mapping-graph/src/test/java/org/eclipse/jnosql/mapping/graph/AbstractTraversalTest.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,96 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 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.mapping.graph; | ||
|
||
import jakarta.inject.Inject; | ||
import org.apache.tinkerpop.gremlin.structure.Edge; | ||
import org.apache.tinkerpop.gremlin.structure.Graph; | ||
import org.apache.tinkerpop.gremlin.structure.Vertex; | ||
import org.eclipse.jnosql.mapping.graph.entities.Book; | ||
import org.eclipse.jnosql.mapping.graph.entities.Person; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
public abstract class AbstractTraversalTest { | ||
|
||
static final String READS = "reads"; | ||
|
||
@Inject | ||
protected GraphTemplate graphTemplate; | ||
|
||
@Inject | ||
protected Graph graph; | ||
|
||
|
||
protected Person otavio; | ||
protected Person poliana; | ||
protected Person paulo; | ||
|
||
protected Book shack; | ||
protected Book license; | ||
protected Book effectiveJava; | ||
|
||
protected EdgeEntity reads; | ||
protected EdgeEntity reads2; | ||
protected EdgeEntity reads3; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
|
||
graph.traversal().V().toList().forEach(Vertex::remove); | ||
graph.traversal().E().toList().forEach(Edge::remove); | ||
|
||
otavio = graphTemplate.insert(Person.builder().withAge(27) | ||
.withName("Otavio").build()); | ||
poliana = graphTemplate.insert(Person.builder().withAge(26) | ||
.withName("Poliana").build()); | ||
paulo = graphTemplate.insert(Person.builder().withAge(50) | ||
.withName("Paulo").build()); | ||
|
||
shack = graphTemplate.insert(Book.builder().withAge(2007).withName("The Shack").build()); | ||
license = graphTemplate.insert(Book.builder().withAge(2013).withName("Software License").build()); | ||
effectiveJava = graphTemplate.insert(Book.builder().withAge(2001).withName("Effective Java").build()); | ||
|
||
|
||
reads = graphTemplate.edge(otavio, READS, effectiveJava); | ||
reads2 = graphTemplate.edge(poliana, READS, shack); | ||
reads3 = graphTemplate.edge(paulo, READS, license); | ||
|
||
reads.add("motivation", "hobby"); | ||
reads.add("language", "Java"); | ||
reads2.add("motivation", "love"); | ||
reads3.add("motivation", "job"); | ||
} | ||
|
||
@AfterEach | ||
public void after() { | ||
graphTemplate.delete(otavio.getId()); | ||
graphTemplate.delete(poliana.getId()); | ||
graphTemplate.delete(paulo.getId()); | ||
|
||
graphTemplate.deleteEdge(shack.getId()); | ||
graphTemplate.deleteEdge(license.getId()); | ||
graphTemplate.deleteEdge(effectiveJava.getId()); | ||
|
||
reads.delete(); | ||
reads2.delete(); | ||
reads3.delete(); | ||
|
||
graph.traversal().V().toList().forEach(Vertex::remove); | ||
graph.traversal().E().toList().forEach(Edge::remove); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...jnosql-mapping-graph/src/test/java/org/eclipse/jnosql/mapping/graph/BookTemplateTest.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,98 @@ | ||
/* | ||
* Copyright (c) 2022 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.mapping.graph; | ||
|
||
import jakarta.inject.Inject; | ||
import org.apache.tinkerpop.gremlin.structure.Graph; | ||
import org.apache.tinkerpop.gremlin.structure.Transaction; | ||
import org.apache.tinkerpop.gremlin.structure.Transaction.Status; | ||
import org.eclipse.jnosql.mapping.core.Converters; | ||
import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; | ||
import org.eclipse.jnosql.mapping.graph.entities.Book; | ||
import org.eclipse.jnosql.mapping.graph.entities.BookTemplate; | ||
import org.eclipse.jnosql.mapping.graph.spi.GraphExtension; | ||
import org.eclipse.jnosql.mapping.reflection.Reflections; | ||
import org.eclipse.jnosql.mapping.semistructured.EntityConverter; | ||
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 java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static org.apache.tinkerpop.gremlin.structure.Transaction.Status.COMMIT; | ||
import static org.apache.tinkerpop.gremlin.structure.Transaction.Status.ROLLBACK; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@EnableAutoWeld | ||
@AddPackages(value = {Converters.class, EntityConverter.class, GraphTemplate.class}) | ||
@AddPackages(GraphProducer.class) | ||
@AddPackages(Reflections.class) | ||
@AddExtensions({EntityMetadataExtension.class, GraphExtension.class}) | ||
class BookTemplateTest { | ||
|
||
@Inject | ||
private BookTemplate template; | ||
|
||
@Inject | ||
private Graph graph; | ||
|
||
@Test | ||
void shouldSaveWithTransaction() { | ||
AtomicReference<Status> status = new AtomicReference<>(); | ||
|
||
Book book = Book.builder().withName("The Book").build(); | ||
Transaction transaction = graph.tx(); | ||
transaction.addTransactionListener(status::set); | ||
template.insert(book); | ||
assertFalse(transaction.isOpen()); | ||
assertEquals(COMMIT, status.get()); | ||
} | ||
|
||
@Test | ||
void shouldSaveWithRollback() { | ||
AtomicReference<Status> status = new AtomicReference<>(); | ||
|
||
Book book = Book.builder().withName("The Book").build(); | ||
Transaction transaction = graph.tx(); | ||
transaction.addTransactionListener(status::set); | ||
try { | ||
template.insertException(book); | ||
assert false; | ||
}catch (Exception ignored){ | ||
|
||
} | ||
|
||
assertFalse(transaction.isOpen()); | ||
assertEquals(ROLLBACK, status.get()); | ||
} | ||
|
||
@Test | ||
void shouldUseAutomaticNormalTransaction() { | ||
AtomicReference<Status> status = new AtomicReference<>(); | ||
|
||
Book book = Book.builder().withName("The Book").build(); | ||
Transaction transaction = graph.tx(); | ||
transaction.addTransactionListener(status::set); | ||
assertNull(status.get()); | ||
template.normalInsertion(book); | ||
assertEquals(COMMIT, status.get()); | ||
assertFalse(transaction.isOpen()); | ||
} | ||
} | ||
|
Oops, something went wrong.