Skip to content

Commit

Permalink
refactor: removed usage of legacy object APIs from test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Jan 12, 2025
1 parent 1e9a953 commit 33fd2a1
Show file tree
Hide file tree
Showing 26 changed files with 218 additions and 402 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,11 @@ public OObjectDatabasePool() {
super();
}

public OObjectDatabasePool(
final String iURL, final String iUserName, final String iUserPassword) {
super(iURL, iUserName, iUserPassword);
}

public static OObjectDatabasePool global() {
globalInstance.setup();
return globalInstance;
}

public static OObjectDatabasePool global(final int iPoolMin, final int iPoolMax) {
globalInstance.setup(iPoolMin, iPoolMax);
return globalInstance;
}

@Override
protected OObjectDatabaseTx createResource(
final Object owner, final String iDatabaseName, final Object... iAdditionalArgs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,46 @@

import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializer;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
import com.orientechnologies.orient.object.db.BaseObjectTest;
import com.orientechnologies.orient.object.serialization.OObjectSerializerContext;
import com.orientechnologies.orient.object.serialization.OObjectSerializerHelper;
import org.junit.Assert;
import org.junit.Test;

public class CustomDatatypeTest {
public class CustomDatatypeTest extends BaseObjectTest {

@Test
public void reproduce() throws Exception {
final OObjectDatabaseTx db = new OObjectDatabaseTx("memory:CustomDatatypeTest");
db.create();
try {
// WrappedString custom datatype registration (storing it as
// OType.STRING)
OObjectSerializerContext serializerContext = new OObjectSerializerContext();
serializerContext.bind(
new OObjectSerializer<WrappedString, String>() {
@Override
public String serializeFieldValue(Class<?> iClass, WrappedString iFieldValue) {
return iFieldValue.getValue();
}

@Override
public WrappedString unserializeFieldValue(Class<?> iClass, String iFieldValue) {
final WrappedString result = new WrappedString();
result.setValue(iFieldValue);
return result;
}
},
db);
OObjectSerializerHelper.bindSerializerContext(WrappedString.class, serializerContext);

// we want schema to be generated
db.setAutomaticSchemaGeneration(true);

// register our entity
db.getEntityManager().registerEntityClass(Entity.class);

// Validate DB did figure out schema properly
Assert.assertEquals(
db.getMetadata().getSchema().getClass(Entity.class).getProperty("data").getType(),
OType.STRING);
} finally {
db.drop();
}
// WrappedString custom datatype registration (storing it as
// OType.STRING)
OObjectSerializerContext serializerContext = new OObjectSerializerContext();
serializerContext.bind(
new OObjectSerializer<WrappedString, String>() {
@Override
public String serializeFieldValue(Class<?> iClass, WrappedString iFieldValue) {
return iFieldValue.getValue();
}

@Override
public WrappedString unserializeFieldValue(Class<?> iClass, String iFieldValue) {
final WrappedString result = new WrappedString();
result.setValue(iFieldValue);
return result;
}
},
database);
OObjectSerializerHelper.bindSerializerContext(WrappedString.class, serializerContext);

// we want schema to be generated
database.setAutomaticSchemaGeneration(true);

// register our entity
database.getEntityManager().registerEntityClass(Entity.class);

// Validate DB did figure out schema properly
Assert.assertEquals(
database.getMetadata().getSchema().getClass(Entity.class).getProperty("data").getType(),
OType.STRING);
}

public static class WrappedString {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.orientechnologies.orient.object.db;

import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.db.object.ODatabaseObject;
import org.junit.After;
import org.junit.Before;

public class BaseObjectTest {

protected ODatabaseObject database;
protected OrientDBObject ctx;

@Before
public void before() {
ctx = new OrientDBObject("memory:", OrientDBConfig.defaultConfig());
ctx.execute(
"create database "
+ getDatabaseName()
+ " memory users (admin identified by 'adminpwd' role admin)")
.close();
database = ctx.open(getDatabaseName(), "admin", "adminpwd");
}

protected String getDatabaseName() {
return this.getClass().getSimpleName();
}

@After
public void after() {
database.close();
ctx.drop(getDatabaseName());
ctx.close();
}

protected void reopen(String user, String password) {
database.close();
database = ctx.open(getDatabaseName(), user, password);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@

import static org.junit.Assert.assertEquals;

import com.orientechnologies.orient.core.db.object.ODatabaseObject;
import com.orientechnologies.orient.object.db.entity.NestedContainer;
import com.orientechnologies.orient.object.db.entity.NestedContent;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/** Created by tglman on 17/07/17. */
public class NestedCollectionsTest {

private ODatabaseObject database;
public class NestedCollectionsTest extends BaseObjectTest {

@Before
public void before() {
database = new OObjectDatabaseTx("memory:" + NestedCollectionsTest.class.getSimpleName());
database.create();
super.before();
database.getEntityManager().registerEntityClass(NestedContainer.class);
database.getEntityManager().registerEntityClass(NestedContent.class);
}
Expand All @@ -31,9 +26,4 @@ public void testNestedCollections() {
assertEquals(1, saved.getFoo().size());
assertEquals(3, saved.getFoo().get("key-1").size());
}

@After
public void after() {
database.drop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,22 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import com.orientechnologies.orient.core.db.object.ODatabaseObject;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/** Created by Anders Heintz on 20/06/15. */
public class OObjectLazyListTest {
private ODatabaseObject database;
public class OObjectLazyListTest extends BaseObjectTest {
private int count;

@Before
public void setUp() throws Exception {
database = new OObjectDatabaseTx("memory:OObjectEnumLazyListTest");
database.create();

public void before() {
super.before();
database.getEntityManager().registerEntityClass(EntityObject.class);
database.getEntityManager().registerEntityClass(EntityObjectWithList.class);
}

@After
public void tearDown() {

database.drop();
}

@Test
public void positionTest() {
EntityObjectWithList listObject = getTestObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,27 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.orientechnologies.orient.core.db.object.ODatabaseObject;
import java.util.HashMap;
import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
* @author JN <a href="mailto:jn@brain-activit.com">Julian Neuhaus</a>
* @since 21.08.2014
*/
public class OObjectLazyMapTest {
public class OObjectLazyMapTest extends BaseObjectTest {
private final int idOfRootEntity = 0;
private final int idOfFirstMapEntry = 1;
private final int idOfSecondMapEntry = 2;
private final int invalidId = 3;
private ODatabaseObject database;

@Before
public void setUp() throws Exception {
database = new OObjectDatabaseTx("memory:OObjectLazyMapTest");
database.create();

public void before() {
super.before();
database.getEntityManager().registerEntityClass(EntityWithMap.class);
}

@After
public void tearDown() {
database.drop();
}

@Test
public void isEmptyTest() {
Map<String, EntityWithMap> testMap = getMapWithPersistedEntries();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +1,35 @@
package com.orientechnologies.orient.object.db;

import com.orientechnologies.orient.core.db.OPartitionedDatabasePool;
import com.orientechnologies.orient.core.db.object.ODatabaseObject;
import com.orientechnologies.orient.core.entity.OEntityManager;
import com.orientechnologies.orient.object.db.entity.Car;
import com.orientechnologies.orient.object.db.entity.Person;
import java.util.HashMap;
import java.util.Map;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/** Created by tglman on 16/12/15. */
public class OPersistentEmbeddedMapTest {

private OPartitionedDatabasePool pool;
private ODatabaseObject createdDb;
public class OPersistentEmbeddedMapTest extends BaseObjectTest {

@Before
public void setup() {
final String url = "memory:tmpdb";
createdDb = new OObjectDatabaseTx(url);
createdDb.create();

pool = new OPartitionedDatabasePool(url, "admin", "admin");

OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire());
try {
db.setAutomaticSchemaGeneration(true);
OEntityManager entityManager = db.getEntityManager();
entityManager.registerEntityClass(Car.class);
entityManager.registerEntityClass(Person.class);

db.getMetadata().getSchema().synchronizeSchema();
} finally {
db.close();
}
}

@After
public void destroy() {
pool.close();
createdDb.drop();
public void before() {
super.before();
database.setAutomaticSchemaGeneration(true);
OEntityManager entityManager = database.getEntityManager();
entityManager.registerEntityClass(Car.class);
entityManager.registerEntityClass(Person.class);

database.getMetadata().getSchema().synchronizeSchema();
}

@Test
public void embeddedMapShouldContainCorrectValues() {
Person person = createTestPerson();
Person retrievedPerson;
OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire());
try {
db.save(person);
retrievedPerson = db.browseClass(Person.class).next();
retrievedPerson = db.detachAll(retrievedPerson, true);
} finally {
db.close();
}
database.save(person);
retrievedPerson = database.browseClass(Person.class).next();
retrievedPerson = database.detachAll(retrievedPerson, true);

Assert.assertEquals(person, retrievedPerson);
}
Expand Down
Loading

0 comments on commit 33fd2a1

Please sign in to comment.