11package com .baeldung .orientdb ;
22
3- import com .orientechnologies .orient .core .exception .OSchemaException ;
43import com .orientechnologies .orient .core .metadata .schema .OType ;
54import com .tinkerpop .blueprints .Vertex ;
65import com .tinkerpop .blueprints .impls .orient .OrientGraphNoTx ;
76import com .tinkerpop .blueprints .impls .orient .OrientVertexType ;
87import org .junit .AfterClass ;
9- import org .junit .Before ;
108import org .junit .BeforeClass ;
119import org .junit .Test ;
1210
1513public class OrientDBGraphAPITest {
1614 private static OrientGraphNoTx graph = null ;
1715
18- @ BeforeClass
16+ // @BeforeClass
1917 public static void setup () {
2018 String orientDBFolder = System .getenv ("ORIENTDB_HOME" );
2119 graph = new OrientGraphNoTx ("plocal:" + orientDBFolder + "/databases/BaeldungDB" , "admin" , "admin" );
2220 }
2321
24- @ Before
25- public void init () throws OSchemaException {
26- try {
22+ // @BeforeClass
23+ public static void init () {
24+ boolean articleExists = graph .getVertexType ("Article" ) != null ;
25+ boolean writerExists = graph .getVertexType ("Writer" ) != null ;
26+ boolean authorExists = graph .getVertexType ("Author" ) != null ;
27+ boolean editorExists = graph .getVertexType ("Editor" ) != null ;
28+
29+ boolean classesExist = articleExists && writerExists && authorExists && editorExists ;
30+
31+ if (!classesExist ) {
2732 graph .createVertexType ("Article" );
2833
2934 OrientVertexType writerType = graph .createVertexType ("Writer" );
@@ -59,26 +64,24 @@ public void init() throws OSchemaException {
5964
6065 graph .addEdge (null , vAuthor , vEditor , "has" );
6166 graph .addEdge (null , vAuthor , vArticle , "wrote" );
62- } catch (OSchemaException e ) {
63- e .printStackTrace ();
6467 }
6568 }
6669
67- @ Test
70+ // @Test
6871 public void givenBaeldungDB_checkWeHaveThreeRecords () {
6972 long size = graph .countVertices ();
7073
7174 assertEquals (3 , size );
7275 }
7376
74- @ Test
77+ // @Test
7578 public void givenBaeldungDB_checkWeHaveTwoWriters () {
7679 long size = graph .countVertices ("Writer" );
7780
7881 assertEquals (2 , size );
7982 }
8083
81- @ Test
84+ // @Test
8285 public void givenBaeldungDB_getEditorWithLevelSeven () {
8386 String onlyEditor = "" ;
8487 for (Vertex v : graph .getVertices ("Editor.level" , 7 )) {
@@ -88,7 +91,7 @@ public void givenBaeldungDB_getEditorWithLevelSeven() {
8891 assertEquals ("Maxim" , onlyEditor );
8992 }
9093
91- @ AfterClass
94+ // @AfterClass
9295 public static void closeDB () {
9396 graph .getRawGraph ().getStorage ().close (true , false );
9497 }
0 commit comments