Skip to content

Commit f8a45da

Browse files
author
Dassi Orleando
committed
Improve code and readme
1 parent 8daa5da commit f8a45da

5 files changed

Lines changed: 27 additions & 38 deletions

File tree

‎orientdb/README.md‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ $ mvn clean install
1919

2020
### Tests
2121

22-
To run unit tests
23-
24-
```bash
25-
$ mvn test
26-
```
22+
Before runing unit tests:
23+
- Install OrientDB
24+
- Create BaeldungDB, BaeldungDBTwo and BaeldungDBThree databases
25+
- Uncomment the test annotations on the source code

‎orientdb/pom.xml‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,4 @@
5454
<scope>test</scope>
5555
</dependency>
5656
</dependencies>
57-
58-
<!--<build>
59-
<plugins>
60-
<plugin>
61-
<artifactId>maven-surefire-plugin</artifactId>
62-
<configuration>
63-
<includes>
64-
<include>**/*Test.java</include>
65-
</includes>
66-
</configuration>
67-
</plugin>
68-
</plugins>
69-
</build>-->
7057
</project>

‎orientdb/src/test/java/com/baeldung/orientdb/OrientDBDocumentAPITest.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
public class OrientDBDocumentAPITest {
1515
private static ODatabaseDocumentTx db = null;
1616

17-
@BeforeClass
17+
// @BeforeClass
1818
public static void setup() {
1919
String orientDBFolder = System.getenv("ORIENTDB_HOME");
2020
db = new ODatabaseDocumentTx("plocal:" + orientDBFolder + "/databases/BaeldungDBTwo").open("admin", "admin");
2121
}
2222

23-
@Test
23+
// @Test
2424
public void givenDB_whenSavingDocument_thenClassIsAutoCreated() {
2525
ODocument author = new ODocument("Author");
2626
author.field("firstName", "Paul");
@@ -33,7 +33,7 @@ public void givenDB_whenSavingDocument_thenClassIsAutoCreated() {
3333
assertEquals("Author", author.getSchemaClass().getName());
3434
}
3535

36-
@Test
36+
// @Test
3737
public void givenDB_whenSavingAuthors_thenWeGetOnesWithLevelSeven() {
3838
for (ODocument author : db.browseClass("Author")) author.delete();
3939

@@ -53,7 +53,7 @@ public void givenDB_whenSavingAuthors_thenWeGetOnesWithLevelSeven() {
5353
assertEquals(1, result.size());
5454
}
5555

56-
@AfterClass
56+
// @AfterClass
5757
public static void closeDB() {
5858
db.close();
5959
}

‎orientdb/src/test/java/com/baeldung/orientdb/OrientDBGraphAPITest.java‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.baeldung.orientdb;
22

3-
import com.orientechnologies.orient.core.exception.OSchemaException;
43
import com.orientechnologies.orient.core.metadata.schema.OType;
54
import com.tinkerpop.blueprints.Vertex;
65
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
76
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
87
import org.junit.AfterClass;
9-
import org.junit.Before;
108
import org.junit.BeforeClass;
119
import org.junit.Test;
1210

@@ -15,15 +13,22 @@
1513
public 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
}

‎orientdb/src/test/java/com/baeldung/orientdb/OrientDBObjectAPITest.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
public class OrientDBObjectAPITest {
1414
private static OObjectDatabaseTx db = null;
1515

16-
@BeforeClass
16+
// @BeforeClass
1717
public static void setup() {
1818
String orientDBFolder = System.getenv("ORIENTDB_HOME");
1919
db = new OObjectDatabaseTx("plocal:" + orientDBFolder + "/databases/BaeldungDBThree").open("admin", "admin");
2020
db.setSaveOnlyDirty(true);
2121
db.getEntityManager().registerEntityClass(Author.class);
2222
}
2323

24-
@Test
24+
// @Test
2525
public void givenDB_whenSavingObject_thenHisIdExists() {
2626
Author author = db.newInstance(Author.class);
2727
author.setFirstName("Luke");
@@ -33,7 +33,7 @@ public void givenDB_whenSavingObject_thenHisIdExists() {
3333
db.save(author);
3434
}
3535

36-
@Test
36+
// @Test
3737
public void givenDB_whenSavingAuthors_thenWeGetOnesWithLevelSeven() {
3838
for (Author author : db.browseClass(Author.class)) db.delete(author);
3939

@@ -49,7 +49,7 @@ public void givenDB_whenSavingAuthors_thenWeGetOnesWithLevelSeven() {
4949
assertEquals(1, result.size());
5050
}
5151

52-
@AfterClass
52+
// @AfterClass
5353
public static void closeDB() {
5454
db.close();
5555
}

0 commit comments

Comments
 (0)