Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement insert at Graph database manager
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
- Loading branch information
1 parent
a977c93
commit d246263
Showing
3 changed files
with
64 additions
and
1 deletion.
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
35 changes: 35 additions & 0 deletions
35
...src/test/java/org/eclipse/jnosql/communication/graph/DefaultGraphDatabaseManagerTest.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,35 @@ | ||
package org.eclipse.jnosql.communication.graph; | ||
|
||
import org.apache.tinkerpop.gremlin.structure.Graph; | ||
import org.assertj.core.api.SoftAssertions; | ||
import org.eclipse.jnosql.communication.semistructured.CommunicationEntity; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class DefaultGraphDatabaseManagerTest { | ||
|
||
private GraphDatabaseManager databaseManager; | ||
|
||
@BeforeEach | ||
void setUp(){ | ||
Graph graph = GraphSupplier.INSTANCE.get(); | ||
this.databaseManager = DefaultGraphDatabaseManager.of(graph); | ||
} | ||
|
||
@Test | ||
void shouldInsertEntity(){ | ||
var entity = CommunicationEntity.of("Person"); | ||
entity.add("name", "Ada Lovelace"); | ||
entity.add("age", 30); | ||
var communicationEntity = databaseManager.insert(entity); | ||
assertNotNull(communicationEntity); | ||
|
||
SoftAssertions.assertSoftly(softly -> { | ||
softly.assertThat(communicationEntity.find("name", String.class)).get().isEqualTo("Ada Lovelace"); | ||
softly.assertThat(communicationEntity.find("age", int.class)).get().isEqualTo(30); | ||
softly.assertThat(communicationEntity.find(DefaultGraphDatabaseManager.ID_PROPERTY)).isPresent(); | ||
}); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...sql-mapping-graph/src/test/java/org/eclipse/jnosql/communication/graph/GraphSupplier.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,23 @@ | ||
package org.eclipse.jnosql.communication.graph; | ||
|
||
import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph; | ||
import org.apache.tinkerpop.gremlin.structure.Graph; | ||
|
||
import java.io.File; | ||
import java.util.function.Supplier; | ||
import java.util.logging.Logger; | ||
|
||
import static java.lang.System.currentTimeMillis; | ||
|
||
public enum GraphSupplier implements Supplier<Graph> { | ||
INSTANCE; | ||
|
||
private static final Logger LOGGER = Logger.getLogger(GraphSupplier.class.getName()); | ||
|
||
@Override | ||
public Graph get() { | ||
var directory = new File("").getAbsolutePath() + "/target/jnosql-communication-graph/" + currentTimeMillis() + "/"; | ||
LOGGER.info("Starting Graph database at directory: " + directory); | ||
return Neo4jGraph.open(directory); | ||
} | ||
} |