Improve code and readme
This commit is contained in:
parent
8daa5dab4e
commit
f8a45da58b
@ -19,8 +19,7 @@ $ mvn clean install
|
|||||||
|
|
||||||
### Tests
|
### Tests
|
||||||
|
|
||||||
To run unit tests
|
Before runing unit tests:
|
||||||
|
- Install OrientDB
|
||||||
```bash
|
- Create BaeldungDB, BaeldungDBTwo and BaeldungDBThree databases
|
||||||
$ mvn test
|
- Uncomment the test annotations on the source code
|
||||||
```
|
|
@ -54,17 +54,4 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<!--<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<includes>
|
|
||||||
<include>**/*Test.java</include>
|
|
||||||
</includes>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>-->
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -14,13 +14,13 @@ import static junit.framework.Assert.assertEquals;
|
|||||||
public class OrientDBDocumentAPITest {
|
public class OrientDBDocumentAPITest {
|
||||||
private static ODatabaseDocumentTx db = null;
|
private static ODatabaseDocumentTx db = null;
|
||||||
|
|
||||||
@BeforeClass
|
// @BeforeClass
|
||||||
public static void setup() {
|
public static void setup() {
|
||||||
String orientDBFolder = System.getenv("ORIENTDB_HOME");
|
String orientDBFolder = System.getenv("ORIENTDB_HOME");
|
||||||
db = new ODatabaseDocumentTx("plocal:" + orientDBFolder + "/databases/BaeldungDBTwo").open("admin", "admin");
|
db = new ODatabaseDocumentTx("plocal:" + orientDBFolder + "/databases/BaeldungDBTwo").open("admin", "admin");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void givenDB_whenSavingDocument_thenClassIsAutoCreated() {
|
public void givenDB_whenSavingDocument_thenClassIsAutoCreated() {
|
||||||
ODocument author = new ODocument("Author");
|
ODocument author = new ODocument("Author");
|
||||||
author.field("firstName", "Paul");
|
author.field("firstName", "Paul");
|
||||||
@ -33,7 +33,7 @@ public class OrientDBDocumentAPITest {
|
|||||||
assertEquals("Author", author.getSchemaClass().getName());
|
assertEquals("Author", author.getSchemaClass().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void givenDB_whenSavingAuthors_thenWeGetOnesWithLevelSeven() {
|
public void givenDB_whenSavingAuthors_thenWeGetOnesWithLevelSeven() {
|
||||||
for (ODocument author : db.browseClass("Author")) author.delete();
|
for (ODocument author : db.browseClass("Author")) author.delete();
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ public class OrientDBDocumentAPITest {
|
|||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
// @AfterClass
|
||||||
public static void closeDB() {
|
public static void closeDB() {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package com.baeldung.orientdb;
|
package com.baeldung.orientdb;
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.exception.OSchemaException;
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OType;
|
import com.orientechnologies.orient.core.metadata.schema.OType;
|
||||||
import com.tinkerpop.blueprints.Vertex;
|
import com.tinkerpop.blueprints.Vertex;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -15,15 +13,22 @@ import static junit.framework.Assert.assertEquals;
|
|||||||
public class OrientDBGraphAPITest {
|
public class OrientDBGraphAPITest {
|
||||||
private static OrientGraphNoTx graph = null;
|
private static OrientGraphNoTx graph = null;
|
||||||
|
|
||||||
@BeforeClass
|
// @BeforeClass
|
||||||
public static void setup() {
|
public static void setup() {
|
||||||
String orientDBFolder = System.getenv("ORIENTDB_HOME");
|
String orientDBFolder = System.getenv("ORIENTDB_HOME");
|
||||||
graph = new OrientGraphNoTx("plocal:" + orientDBFolder + "/databases/BaeldungDB", "admin", "admin");
|
graph = new OrientGraphNoTx("plocal:" + orientDBFolder + "/databases/BaeldungDB", "admin", "admin");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
// @BeforeClass
|
||||||
public void init() throws OSchemaException {
|
public static void init() {
|
||||||
try {
|
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");
|
graph.createVertexType("Article");
|
||||||
|
|
||||||
OrientVertexType writerType = graph.createVertexType("Writer");
|
OrientVertexType writerType = graph.createVertexType("Writer");
|
||||||
@ -59,26 +64,24 @@ public class OrientDBGraphAPITest {
|
|||||||
|
|
||||||
graph.addEdge(null, vAuthor, vEditor, "has");
|
graph.addEdge(null, vAuthor, vEditor, "has");
|
||||||
graph.addEdge(null, vAuthor, vArticle, "wrote");
|
graph.addEdge(null, vAuthor, vArticle, "wrote");
|
||||||
} catch (OSchemaException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void givenBaeldungDB_checkWeHaveThreeRecords() {
|
public void givenBaeldungDB_checkWeHaveThreeRecords() {
|
||||||
long size = graph.countVertices();
|
long size = graph.countVertices();
|
||||||
|
|
||||||
assertEquals(3, size);
|
assertEquals(3, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void givenBaeldungDB_checkWeHaveTwoWriters() {
|
public void givenBaeldungDB_checkWeHaveTwoWriters() {
|
||||||
long size = graph.countVertices("Writer");
|
long size = graph.countVertices("Writer");
|
||||||
|
|
||||||
assertEquals(2, size);
|
assertEquals(2, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void givenBaeldungDB_getEditorWithLevelSeven() {
|
public void givenBaeldungDB_getEditorWithLevelSeven() {
|
||||||
String onlyEditor = "";
|
String onlyEditor = "";
|
||||||
for(Vertex v : graph.getVertices("Editor.level", 7)) {
|
for(Vertex v : graph.getVertices("Editor.level", 7)) {
|
||||||
@ -88,7 +91,7 @@ public class OrientDBGraphAPITest {
|
|||||||
assertEquals("Maxim", onlyEditor);
|
assertEquals("Maxim", onlyEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
// @AfterClass
|
||||||
public static void closeDB() {
|
public static void closeDB() {
|
||||||
graph.getRawGraph().getStorage().close(true, false);
|
graph.getRawGraph().getStorage().close(true, false);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import static junit.framework.Assert.assertEquals;
|
|||||||
public class OrientDBObjectAPITest {
|
public class OrientDBObjectAPITest {
|
||||||
private static OObjectDatabaseTx db = null;
|
private static OObjectDatabaseTx db = null;
|
||||||
|
|
||||||
@BeforeClass
|
// @BeforeClass
|
||||||
public static void setup() {
|
public static void setup() {
|
||||||
String orientDBFolder = System.getenv("ORIENTDB_HOME");
|
String orientDBFolder = System.getenv("ORIENTDB_HOME");
|
||||||
db = new OObjectDatabaseTx("plocal:" + orientDBFolder + "/databases/BaeldungDBThree").open("admin", "admin");
|
db = new OObjectDatabaseTx("plocal:" + orientDBFolder + "/databases/BaeldungDBThree").open("admin", "admin");
|
||||||
@ -21,7 +21,7 @@ public class OrientDBObjectAPITest {
|
|||||||
db.getEntityManager().registerEntityClass(Author.class);
|
db.getEntityManager().registerEntityClass(Author.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void givenDB_whenSavingObject_thenHisIdExists() {
|
public void givenDB_whenSavingObject_thenHisIdExists() {
|
||||||
Author author = db.newInstance(Author.class);
|
Author author = db.newInstance(Author.class);
|
||||||
author.setFirstName("Luke");
|
author.setFirstName("Luke");
|
||||||
@ -33,7 +33,7 @@ public class OrientDBObjectAPITest {
|
|||||||
db.save(author);
|
db.save(author);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void givenDB_whenSavingAuthors_thenWeGetOnesWithLevelSeven() {
|
public void givenDB_whenSavingAuthors_thenWeGetOnesWithLevelSeven() {
|
||||||
for (Author author : db.browseClass(Author.class)) db.delete(author);
|
for (Author author : db.browseClass(Author.class)) db.delete(author);
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ public class OrientDBObjectAPITest {
|
|||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
// @AfterClass
|
||||||
public static void closeDB() {
|
public static void closeDB() {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user