Skip to content

Commit

Permalink
refactor: removed old API from core test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Oct 18, 2023
1 parent 80236d2 commit 91bc8f6
Show file tree
Hide file tree
Showing 39 changed files with 178 additions and 898 deletions.
Original file line number Diff line number Diff line change
@@ -1,44 +1,29 @@
package com.orientechnologies.orient.core.db;

import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.BaseMemoryDatabase;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import org.junit.Assert;
import org.junit.Test;

public class ODatabaseCreateDropClusterTest {
public class ODatabaseCreateDropClusterTest extends BaseMemoryDatabase {

@Test
public void createDropCluster() {
ODatabaseDocument db =
new ODatabaseDocumentTx("memory:" + ODatabaseCreateDropClusterTest.class.getSimpleName());
db.create();
try {
db.addCluster("test");
Assert.assertNotEquals(db.getClusterIdByName("test"), -1);
db.dropCluster("test");
Assert.assertEquals(db.getClusterIdByName("test"), -1);
} finally {
db.drop();
}
db.addCluster("test");
Assert.assertNotEquals(db.getClusterIdByName("test"), -1);
db.dropCluster("test");
Assert.assertEquals(db.getClusterIdByName("test"), -1);
}

@Test
public void createDropClusterOnClass() {
ODatabaseDocument db =
new ODatabaseDocumentTx("memory:" + ODatabaseCreateDropClusterTest.class.getSimpleName());
db.create();
try {
OClass test = db.getMetadata().getSchema().createClass("test", 1, null);
test.addCluster("aTest");
Assert.assertNotEquals(db.getClusterIdByName("aTest"), -1);
Assert.assertEquals(test.getClusterIds().length, 2);
db.dropCluster("aTest");
Assert.assertEquals(db.getClusterIdByName("aTest"), -1);
test = db.getMetadata().getSchema().getClass("test");
Assert.assertEquals(test.getClusterIds().length, 1);
} finally {
db.drop();
}
OClass test = db.getMetadata().getSchema().createClass("test", 1, null);
test.addCluster("aTest");
Assert.assertNotEquals(db.getClusterIdByName("aTest"), -1);
Assert.assertEquals(test.getClusterIds().length, 2);
db.dropCluster("aTest");
Assert.assertEquals(db.getClusterIdByName("aTest"), -1);
test = db.getMetadata().getSchema().getClass("test");
Assert.assertEquals(test.getClusterIds().length, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,44 @@

import static org.junit.Assert.assertEquals;

import com.orientechnologies.BaseMemoryDatabase;
import com.orientechnologies.orient.core.record.impl.ODocument;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;

public class DeepLinkedDocumentSaveTest {
public class DeepLinkedDocumentSaveTest extends BaseMemoryDatabase {

@Test
public void testLinked() {
ODatabaseDocument db =
new ODatabaseDocumentTx("memory:" + DeepLinkedDocumentSaveTest.class.getSimpleName());
db.create();
try {
final Set<ODocument> docs = new HashSet<>();

db.getMetadata().getSchema().createClass("Test");
ODocument doc = new ODocument("Test");
docs.add(doc);
for (int i = 0; i < 3000; i++) docs.add(doc = new ODocument("Test").field("linked", doc));
db.save(doc);

assertEquals(3001, db.countClass("Test"));

for (ODocument d : docs) assertEquals(1, d.getVersion());
} finally {
db.drop();
}
final Set<ODocument> docs = new HashSet<>();

db.getMetadata().getSchema().createClass("Test");
ODocument doc = new ODocument("Test");
docs.add(doc);
for (int i = 0; i < 3000; i++) docs.add(doc = new ODocument("Test").field("linked", doc));
db.save(doc);

assertEquals(3001, db.countClass("Test"));

for (ODocument d : docs) assertEquals(1, d.getVersion());
}

@Test
public void testLinkedTx() {
ODatabaseDocument db =
new ODatabaseDocumentTx("memory:" + DeepLinkedDocumentSaveTest.class.getSimpleName());
db.create();
try {
final Set<ODocument> docs = new HashSet<>();

db.getMetadata().getSchema().createClass("Test");

db.begin();
ODocument doc = new ODocument("Test");
docs.add(doc);
for (int i = 0; i < 3000; i++) docs.add(doc = new ODocument("Test").field("linked", doc));
db.save(doc);
db.commit();

assertEquals(3001, db.countClass("Test"));

for (ODocument d : docs) assertEquals(1, d.getVersion());
} finally {
db.drop();
}
final Set<ODocument> docs = new HashSet<>();

db.getMetadata().getSchema().createClass("Test");

db.begin();
ODocument doc = new ODocument("Test");
docs.add(doc);
for (int i = 0; i < 3000; i++) docs.add(doc = new ODocument("Test").field("linked", doc));
db.save(doc);
db.commit();

assertEquals(3001, db.countClass("Test"));

for (ODocument d : docs) assertEquals(1, d.getVersion());
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
package com.orientechnologies.orient.core.db.document;

import com.orientechnologies.BaseMemoryDatabase;
import com.orientechnologies.orient.core.exception.OSchemaException;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.record.ORecord;
import com.orientechnologies.orient.core.record.impl.ODocument;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/** Created by tglman on 04/11/15. */
public class ODatabaseDocumentSaveClusterTest {

private ODatabaseDocument db;

@Before
public void before() {
db =
new ODatabaseDocumentTx("memory:" + ODatabaseDocumentSaveClusterTest.class.getSimpleName());
db.create();
}
public class ODatabaseDocumentSaveClusterTest extends BaseMemoryDatabase {

@Test(expected = IllegalArgumentException.class)
public void testSaveWrongCluster() {
Expand Down Expand Up @@ -59,9 +49,4 @@ public void testDeleteClassAndClusters() {
db.getMetadata().getSchema().dropClass(clazz.getName());
Assert.assertFalse(db.existsCluster("test_one"));
}

@After
public void after() {
db.drop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.orientechnologies.BaseMemoryDatabase;
import com.orientechnologies.orient.core.db.ODatabase;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
Expand All @@ -23,25 +24,10 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class ODatabaseDocumentTxTest {

private ODatabaseDocument db;

@Before
public void setUp() throws Exception {
String url = "memory:" + ODatabaseDocumentTxTest.class.getSimpleName();
db = new ODatabaseDocumentTx(url).create();
}

@After
public void tearDown() throws Exception {
db.drop();
}
public class ODatabaseDocumentTxTest extends BaseMemoryDatabase {

@Test
public void testCountClass() throws Exception {
Expand Down Expand Up @@ -466,8 +452,6 @@ public void testLinkDuplicate() {

@Test
public void selectDescTest() {
ODatabaseDocument db = new ODatabaseDocumentTx("memory:foo");
db.create();
String className = "bar";
OSchema schema = db.getMetadata().getSchema();
schema.createClass(className, 1, schema.getClass(OClass.VERTEX_CLASS_NAME));
Expand All @@ -480,7 +464,6 @@ public void selectDescTest() {
(ODatabaseDocumentInternal) db, (ODatabaseDocumentInternal) db, className, true);
Assert.assertTrue(reverseIterator.hasNext());
Assert.assertEquals(document, reverseIterator.next());
db.close();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@

import static org.junit.Assert.assertEquals;

import com.orientechnologies.BaseMemoryDatabase;
import com.orientechnologies.orient.core.record.impl.ODocument;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/** Created by tglman on 26/10/15. */
public class RecursiveLinkedSaveTest {

private ODatabaseDocument db;

@Before
public void before() {
db = new ODatabaseDocumentTx("memory:" + RecursiveLinkedSaveTest.class.getSimpleName());
db.create();
}
public class RecursiveLinkedSaveTest extends BaseMemoryDatabase {

@Test
public void testLinked() {
Expand Down Expand Up @@ -53,9 +44,4 @@ public void testTxLinked() {
doc2 = doc1.field("link");
assertEquals(doc, doc2.field("link"));
}

@After
public void after() {
db.drop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,14 @@

package com.orientechnologies.orient.core.db.document;

import com.orientechnologies.BaseMemoryDatabase;
import com.orientechnologies.orient.core.exception.OConcurrentModificationException;
import com.orientechnologies.orient.core.record.impl.ODocument;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

/** @author Sergey Sitnikov */
public class VersionedDeleteTest {

private ODatabaseDocument db;

@Before
public void before() {
db = new ODatabaseDocumentTx("memory:" + VersionedDeleteTest.class.getSimpleName());

if (db.exists()) {
db.open("admin", "admin");
db.drop();
}

db.create();
}

@After
public void after() {
db.drop();
}
public class VersionedDeleteTest extends BaseMemoryDatabase {

@Test(expected = OConcurrentModificationException.class)
public void testDeleteFutureVersion() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,42 @@
package com.orientechnologies.orient.core.db.graph;

import com.orientechnologies.orient.core.OCreateDatabaseUtil;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.BaseMemoryDatabase;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.OEdge;
import com.orientechnologies.orient.core.record.OVertex;
import com.orientechnologies.orient.core.storage.ORecordDuplicatedException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/** Created by tglman on 20/02/17. */
public class TestGraphOperations {

private OrientDB orientDB;
private ODatabaseDocument database;

@Before
public void before() {
orientDB =
OCreateDatabaseUtil.createDatabase(
"TestGraphOperations", "embedded:", OCreateDatabaseUtil.TYPE_MEMORY);
database =
orientDB.open("TestGraphOperations", "admin", OCreateDatabaseUtil.NEW_ADMIN_PASSWORD);
}

@After
public void after() {
database.close();
orientDB.close();
}
public class TestGraphOperations extends BaseMemoryDatabase {

@Test
public void testEdgeUniqueConstraint() {

database.createVertexClass("TestVertex");
db.createVertexClass("TestVertex");

OClass testLabel = database.createEdgeClass("TestLabel");
OClass testLabel = db.createEdgeClass("TestLabel");

OProperty key = testLabel.createProperty("key", OType.STRING);

key.createIndex(OClass.INDEX_TYPE.UNIQUE);

OVertex vertex = database.newVertex("TestVertex");
OVertex vertex = db.newVertex("TestVertex");

OVertex vertex1 = database.newVertex("TestVertex");
OVertex vertex1 = db.newVertex("TestVertex");

OEdge edge = vertex.addEdge(vertex1, "TestLabel");

edge.setProperty("key", "unique");
database.save(vertex);
db.save(vertex);

try {
edge = vertex.addEdge(vertex1, "TestLabel");
edge.setProperty("key", "unique");
database.save(edge);
db.save(edge);
Assert.fail("It should not be inserted a duplicated edge");
} catch (ORecordDuplicatedException e) {

Expand All @@ -68,6 +46,6 @@ public void testEdgeUniqueConstraint() {

edge.setProperty("key", "notunique");

database.save(edge);
db.save(edge);
}
}
Loading

0 comments on commit 91bc8f6

Please sign in to comment.