From f8a45da58b9e23de67b976f57f402383afcc2049 Mon Sep 17 00:00:00 2001 From: Dassi Orleando Date: Wed, 27 Dec 2017 05:16:18 +0100 Subject: [PATCH] Improve code and readme --- orientdb/README.md | 9 +++---- orientdb/pom.xml | 13 --------- .../orientdb/OrientDBDocumentAPITest.java | 8 +++--- .../orientdb/OrientDBGraphAPITest.java | 27 ++++++++++--------- .../orientdb/OrientDBObjectAPITest.java | 8 +++--- 5 files changed, 27 insertions(+), 38 deletions(-) diff --git a/orientdb/README.md b/orientdb/README.md index 7827a33f76..22d1e6081c 100644 --- a/orientdb/README.md +++ b/orientdb/README.md @@ -19,8 +19,7 @@ $ mvn clean install ### Tests -To run unit tests - -```bash -$ mvn test -``` \ No newline at end of file +Before runing unit tests: +- Install OrientDB +- Create BaeldungDB, BaeldungDBTwo and BaeldungDBThree databases +- Uncomment the test annotations on the source code \ No newline at end of file diff --git a/orientdb/pom.xml b/orientdb/pom.xml index 5a90354f76..3d3cb36a91 100644 --- a/orientdb/pom.xml +++ b/orientdb/pom.xml @@ -54,17 +54,4 @@ test - - diff --git a/orientdb/src/test/java/com/baeldung/orientdb/OrientDBDocumentAPITest.java b/orientdb/src/test/java/com/baeldung/orientdb/OrientDBDocumentAPITest.java index e82f59b3e7..c51ff6928f 100644 --- a/orientdb/src/test/java/com/baeldung/orientdb/OrientDBDocumentAPITest.java +++ b/orientdb/src/test/java/com/baeldung/orientdb/OrientDBDocumentAPITest.java @@ -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(); } diff --git a/orientdb/src/test/java/com/baeldung/orientdb/OrientDBGraphAPITest.java b/orientdb/src/test/java/com/baeldung/orientdb/OrientDBGraphAPITest.java index 7b1970d292..03bba4415e 100644 --- a/orientdb/src/test/java/com/baeldung/orientdb/OrientDBGraphAPITest.java +++ b/orientdb/src/test/java/com/baeldung/orientdb/OrientDBGraphAPITest.java @@ -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); } diff --git a/orientdb/src/test/java/com/baeldung/orientdb/OrientDBObjectAPITest.java b/orientdb/src/test/java/com/baeldung/orientdb/OrientDBObjectAPITest.java index 7051383d06..71be159107 100644 --- a/orientdb/src/test/java/com/baeldung/orientdb/OrientDBObjectAPITest.java +++ b/orientdb/src/test/java/com/baeldung/orientdb/OrientDBObjectAPITest.java @@ -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(); }