Improve code and readme

This commit is contained in:
Dassi Orleando 2017-12-27 05:16:18 +01:00
parent 8daa5dab4e
commit f8a45da58b
5 changed files with 27 additions and 38 deletions

View File

@ -19,8 +19,7 @@ $ mvn clean install
### Tests
To run unit tests
```bash
$ mvn test
```
Before runing unit tests:
- Install OrientDB
- Create BaeldungDB, BaeldungDBTwo and BaeldungDBThree databases
- Uncomment the test annotations on the source code

View File

@ -54,17 +54,4 @@
<scope>test</scope>
</dependency>
</dependencies>
<!--<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>-->
</project>

View File

@ -14,13 +14,13 @@ import static junit.framework.Assert.assertEquals;
public class OrientDBDocumentAPITest {
private static ODatabaseDocumentTx db = null;
@BeforeClass
// @BeforeClass
public static void setup() {
String orientDBFolder = System.getenv("ORIENTDB_HOME");
db = new ODatabaseDocumentTx("plocal:" + orientDBFolder + "/databases/BaeldungDBTwo").open("admin", "admin");
}
@Test
// @Test
public void givenDB_whenSavingDocument_thenClassIsAutoCreated() {
ODocument author = new ODocument("Author");
author.field("firstName", "Paul");
@ -33,7 +33,7 @@ public class OrientDBDocumentAPITest {
assertEquals("Author", author.getSchemaClass().getName());
}
@Test
// @Test
public void givenDB_whenSavingAuthors_thenWeGetOnesWithLevelSeven() {
for (ODocument author : db.browseClass("Author")) author.delete();
@ -53,7 +53,7 @@ public class OrientDBDocumentAPITest {
assertEquals(1, result.size());
}
@AfterClass
// @AfterClass
public static void closeDB() {
db.close();
}

View File

@ -1,12 +1,10 @@
package com.baeldung.orientdb;
import com.orientechnologies.orient.core.exception.OSchemaException;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@ -15,15 +13,22 @@ import static junit.framework.Assert.assertEquals;
public class OrientDBGraphAPITest {
private static OrientGraphNoTx graph = null;
@BeforeClass
// @BeforeClass
public static void setup() {
String orientDBFolder = System.getenv("ORIENTDB_HOME");
graph = new OrientGraphNoTx("plocal:" + orientDBFolder + "/databases/BaeldungDB", "admin", "admin");
}
@Before
public void init() throws OSchemaException {
try {
// @BeforeClass
public static void init() {
boolean articleExists = graph.getVertexType("Article") != null;
boolean writerExists = graph.getVertexType("Writer") != null;
boolean authorExists = graph.getVertexType("Author") != null;
boolean editorExists = graph.getVertexType("Editor") != null;
boolean classesExist = articleExists && writerExists && authorExists && editorExists;
if(!classesExist) {
graph.createVertexType("Article");
OrientVertexType writerType = graph.createVertexType("Writer");
@ -59,26 +64,24 @@ public class OrientDBGraphAPITest {
graph.addEdge(null, vAuthor, vEditor, "has");
graph.addEdge(null, vAuthor, vArticle, "wrote");
} catch (OSchemaException e) {
e.printStackTrace();
}
}
@Test
// @Test
public void givenBaeldungDB_checkWeHaveThreeRecords() {
long size = graph.countVertices();
assertEquals(3, size);
}
@Test
// @Test
public void givenBaeldungDB_checkWeHaveTwoWriters() {
long size = graph.countVertices("Writer");
assertEquals(2, size);
}
@Test
// @Test
public void givenBaeldungDB_getEditorWithLevelSeven() {
String onlyEditor = "";
for(Vertex v : graph.getVertices("Editor.level", 7)) {
@ -88,7 +91,7 @@ public class OrientDBGraphAPITest {
assertEquals("Maxim", onlyEditor);
}
@AfterClass
// @AfterClass
public static void closeDB() {
graph.getRawGraph().getStorage().close(true, false);
}

View File

@ -13,7 +13,7 @@ import static junit.framework.Assert.assertEquals;
public class OrientDBObjectAPITest {
private static OObjectDatabaseTx db = null;
@BeforeClass
// @BeforeClass
public static void setup() {
String orientDBFolder = System.getenv("ORIENTDB_HOME");
db = new OObjectDatabaseTx("plocal:" + orientDBFolder + "/databases/BaeldungDBThree").open("admin", "admin");
@ -21,7 +21,7 @@ public class OrientDBObjectAPITest {
db.getEntityManager().registerEntityClass(Author.class);
}
@Test
// @Test
public void givenDB_whenSavingObject_thenHisIdExists() {
Author author = db.newInstance(Author.class);
author.setFirstName("Luke");
@ -33,7 +33,7 @@ public class OrientDBObjectAPITest {
db.save(author);
}
@Test
// @Test
public void givenDB_whenSavingAuthors_thenWeGetOnesWithLevelSeven() {
for (Author author : db.browseClass(Author.class)) db.delete(author);
@ -49,7 +49,7 @@ public class OrientDBObjectAPITest {
assertEquals(1, result.size());
}
@AfterClass
// @AfterClass
public static void closeDB() {
db.close();
}