Skip to content

Commit

Permalink
refactor: moved tests to use base test with new API
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Dec 14, 2023
1 parent c3602fb commit 527a001
Show file tree
Hide file tree
Showing 16 changed files with 854 additions and 1,108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ public void beforeTest() {
context
.execute(
"create database "
+ name.getMethodName()
+ getDatabaseName()
+ " memory users(admin identified by 'adminpwd' role admin) ")
.close();
db = (ODatabaseDocumentInternal) context.open(name.getMethodName(), "admin", "adminpwd");
db = (ODatabaseDocumentInternal) context.open(getDatabaseName(), "admin", "adminpwd");
}

protected String getDatabaseName() {
return name.getMethodName();
}

@After
public void afterTest() {
db.close();
context.drop(name.getMethodName());
context.drop(getDatabaseName());
context.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import static org.junit.Assert.assertEquals;

import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
Expand All @@ -20,22 +21,26 @@ public class DocumentIndependentJavaSerializationTest {

@Test
public void testSerialization() throws IOException, ClassNotFoundException {
ODatabaseDocument db =
new ODatabaseDocumentTx(
"memory:" + DocumentIndependentJavaSerializationTest.class.getSimpleName());
db.create();
byte[] ser;
try {
OClass clazz = db.getMetadata().getSchema().createClass("Test");
clazz.createProperty("test", OType.STRING);
ODocument doc = new ODocument(clazz);
doc.field("test", "Some Value");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(doc);
ser = baos.toByteArray();
} finally {
db.drop();
try (OrientDB ctx = new OrientDB("embedded:", OrientDBConfig.defaultConfig())) {
ctx.execute(
"create database "
+ DocumentIndependentJavaSerializationTest.class.getSimpleName()
+ " memory users (admin identified by 'adminpwd' role admin)");
try (ODatabaseDocument db =
ctx.open(
DocumentIndependentJavaSerializationTest.class.getSimpleName(),
"admin",
"adminpwd")) {
OClass clazz = db.getMetadata().getSchema().createClass("Test");
clazz.createProperty("test", OType.STRING);
ODocument doc = new ODocument(clazz);
doc.field("test", "Some Value");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(doc);
ser = baos.toByteArray();
}
}

ObjectInputStream input = new ObjectInputStream(new ByteArrayInputStream(ser));
Expand All @@ -54,21 +59,25 @@ public void testDeserializationSave() throws IOException, ClassNotFoundException
oos.writeObject(doc);
byte[] ser = baos.toByteArray();

ODatabaseDocumentInternal db =
new ODatabaseDocumentTx(
"memory:" + DocumentIndependentJavaSerializationTest.class.getSimpleName());
db.create();
try (OrientDB ctx = new OrientDB("embedded:", OrientDBConfig.defaultConfig())) {
ctx.execute(
"create database "
+ DocumentIndependentJavaSerializationTest.class.getSimpleName()
+ " memory users (admin identified by 'adminpwd' role admin)");
try (ODatabaseDocument db =
ctx.open(
DocumentIndependentJavaSerializationTest.class.getSimpleName(),
"admin",
"adminpwd")) {

try {
OClass clazz = db.getMetadata().getSchema().createClass("Test");
clazz.createProperty("test", OType.STRING);
ObjectInputStream input = new ObjectInputStream(new ByteArrayInputStream(ser));
ODocument doc1 = (ODocument) input.readObject();
assertEquals(doc1.recordFormat, db.getSerializer());
assertEquals(doc1.getClassName(), "Test");
assertEquals(doc1.field("test"), "Some Value");
} finally {
db.drop();
OClass clazz = db.getMetadata().getSchema().createClass("Test");
clazz.createProperty("test", OType.STRING);
ObjectInputStream input = new ObjectInputStream(new ByteArrayInputStream(ser));
ODocument doc1 = (ODocument) input.readObject();
assertEquals(doc1.recordFormat, ((ODatabaseDocumentInternal) db).getSerializer());
assertEquals(doc1.getClassName(), "Test");
assertEquals(doc1.field("test"), "Some Value");
}
}
}
}
Loading

0 comments on commit 527a001

Please sign in to comment.