Skip to content

Commit

Permalink
refactor: removed usage of deprecated API from test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Oct 23, 2023
1 parent 4ac62e8 commit fa2eac6
Show file tree
Hide file tree
Showing 23 changed files with 298 additions and 530 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.orientechnologies.orient.core.metadata.security;

import com.orientechnologies.BaseMemoryDatabase;
import com.orientechnologies.common.directmemory.ODirectMemoryAllocator;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.record.impl.ODocument;
Expand All @@ -11,65 +10,58 @@
import org.junit.Assert;
import org.junit.Test;

public class ORestricetedUserCleanUpTest {
public class ORestricetedUserCleanUpTest extends BaseMemoryDatabase {

@Test
public void testAutoCleanUserAfterDelate() {
ODatabaseDocument db =
new ODatabaseDocumentTx("memory:" + ORestricetedUserCleanUpTest.class.getSimpleName());
db.create();
try {
OSchema schema = db.getMetadata().getSchema();
schema.createClass("TestRecord", schema.getClass(OSecurityShared.RESTRICTED_CLASSNAME));
OSchema schema = db.getMetadata().getSchema();
schema.createClass("TestRecord", schema.getClass(OSecurityShared.RESTRICTED_CLASSNAME));

System.gc();
ODirectMemoryAllocator.instance().checkTrackedPointerLeaks();
System.gc();
ODirectMemoryAllocator.instance().checkTrackedPointerLeaks();

OSecurity security = db.getMetadata().getSecurity();
OUser auser = security.createUser("auser", "wherever", new String[] {});
OUser reader = security.getUser("admin");
ODocument doc = new ODocument("TestRecord");
Set<OIdentifiable> users = new HashSet<OIdentifiable>();
users.add(auser.getIdentity());
users.add(reader.getIdentity());
doc.field(OSecurityShared.ALLOW_READ_FIELD, users);
doc.field(OSecurityShared.ALLOW_UPDATE_FIELD, users);
doc.field(OSecurityShared.ALLOW_DELETE_FIELD, users);
doc.field(OSecurityShared.ALLOW_ALL_FIELD, users);
ODocument rid = db.save(doc);
OSecurity security = db.getMetadata().getSecurity();
OUser auser = security.createUser("auser", "wherever", new String[] {});
OUser reader = security.getUser("admin");
ODocument doc = new ODocument("TestRecord");
Set<OIdentifiable> users = new HashSet<OIdentifiable>();
users.add(auser.getIdentity());
users.add(reader.getIdentity());
doc.field(OSecurityShared.ALLOW_READ_FIELD, users);
doc.field(OSecurityShared.ALLOW_UPDATE_FIELD, users);
doc.field(OSecurityShared.ALLOW_DELETE_FIELD, users);
doc.field(OSecurityShared.ALLOW_ALL_FIELD, users);
ODocument rid = db.save(doc);

System.gc();
ODirectMemoryAllocator.instance().checkTrackedPointerLeaks();
security.dropUser("auser");
db.getLocalCache().clear();
doc = db.load(rid.getIdentity());
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 2);
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).size(), 2);
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).size(), 2);
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 2);
doc.field("abc", "abc");
doc.save();
System.gc();
ODirectMemoryAllocator.instance().checkTrackedPointerLeaks();
security.dropUser("auser");
db.getLocalCache().clear();
doc = db.load(rid.getIdentity());
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 2);
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).size(), 2);
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).size(), 2);
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 2);
doc.field("abc", "abc");
doc.save();

System.gc();
ODirectMemoryAllocator.instance().checkTrackedPointerLeaks();
db.getLocalCache().clear();
doc = db.load(rid.getIdentity());
((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).remove(null);
((Set<?>) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).remove(null);
((Set<?>) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).remove(null);
((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).remove(null);
System.gc();
ODirectMemoryAllocator.instance().checkTrackedPointerLeaks();
db.getLocalCache().clear();
doc = db.load(rid.getIdentity());
((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).remove(null);
((Set<?>) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).remove(null);
((Set<?>) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).remove(null);
((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).remove(null);

Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 1);
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).size(), 1);
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).size(), 1);
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 1);
doc.field("abc", "abc");
doc.save();
System.gc();
ODirectMemoryAllocator.instance().checkTrackedPointerLeaks();
} finally {
db.drop();
}
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 1);
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_UPDATE_FIELD)).size(), 1);
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_DELETE_FIELD)).size(), 1);
Assert.assertEquals(((Set<?>) doc.field(OSecurityShared.ALLOW_ALL_FIELD)).size(), 1);
doc.field("abc", "abc");
doc.save();
System.gc();
ODirectMemoryAllocator.instance().checkTrackedPointerLeaks();

System.gc();
ODirectMemoryAllocator.instance().checkTrackedPointerLeaks();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.orientechnologies.orient.core.sql.executor;

import com.orientechnologies.BaseMemoryDatabase;
import com.orientechnologies.orient.core.command.script.OCommandScript;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.record.ridbag.ORidBag;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.record.impl.ODocument;
Expand All @@ -10,33 +10,20 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** @author Artem Orobets (enisher-at-gmail.com) */
@RunWith(JUnit4.class)
public class OCommandExecutorSQLCreateEdgeTest {
public class OCommandExecutorSQLCreateEdgeTest extends BaseMemoryDatabase {

private ODatabaseDocumentTx db;
private ODocument owner1;
private ODocument owner2;

@Before
public void setUp() throws Exception {
db =
new ODatabaseDocumentTx(
"memory:" + OCommandExecutorSQLCreateEdgeTest.class.getSimpleName());

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

db.create();
public void beforeTest() {
super.beforeTest();

final OSchema schema = db.getMetadata().getSchema();
schema.createClass("Owner", schema.getClass("V"));
Expand All @@ -50,15 +37,6 @@ public void setUp() throws Exception {
owner2.save();
}

@After
public void tearDown() throws Exception {
db.drop();

db = null;
owner1 = null;
owner2 = null;
}

@Test
public void testParametersBinding() throws Exception {
db.command(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,24 @@
*/
package com.orientechnologies.orient.core.sql.executor;

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.BaseMemoryDatabase;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import java.util.List;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */
public class OCommandExecutorSQLDeleteVertexTest {
public class OCommandExecutorSQLDeleteVertexTest extends BaseMemoryDatabase {

private ODatabaseDocumentTx db;

@Before
public void init() throws Exception {
db =
new ODatabaseDocumentTx(
"memory:" + OCommandExecutorSQLDeleteVertexTest.class.getSimpleName());
db.create();
public void beforeTest() {
super.beforeTest();
final OSchema schema = db.getMetadata().getSchema();
schema.createClass("User", schema.getClass("V"));
}

@After
public void tearDown() throws Exception {
db.drop();
db = null;
}

@Test
public void testDeleteVertexLimit() throws Exception {
// for issue #4148
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
package com.orientechnologies.orient.core.sql.executor;

import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.BaseMemoryDatabase;
import java.util.List;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */
public class OCreateUserStatementExecutionTest {
static ODatabaseDocument db;

@BeforeClass
public static void beforeClass() {
db = new ODatabaseDocumentTx("memory:OCreateUserStatementExecutionTest");
db.create();
}

@AfterClass
public static void afterClass() {
db.close();
}
public class OCreateUserStatementExecutionTest extends BaseMemoryDatabase {

@Test
public void testPlain() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
package com.orientechnologies.orient.core.sql.executor;

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.exception.OCommandExecutionException;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */
public class ODropPropertyStatementExecutionTest {
static ODatabaseDocument db;

@BeforeClass
public static void beforeClass() {
db = new ODatabaseDocumentTx("memory:ODropPropertyStatementExecutionTest");
db.create();
}

@AfterClass
public static void afterClass() {
db.close();
}
public class ODropPropertyStatementExecutionTest extends BaseMemoryDatabase {

@Test
public void testPlain() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
package com.orientechnologies.orient.core.sql.executor;

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.exception.OCommandExecutionException;
import com.orientechnologies.orient.core.exception.ODatabaseException;
import com.orientechnologies.orient.core.metadata.sequence.OSequence;
import com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */
public class ODropSequenceStatementExecutionTest {
static ODatabaseDocument db;

@BeforeClass
public static void beforeClass() {
db = new ODatabaseDocumentTx("memory:ODropSequenceStatementExecutionTest");
db.create();
}

@AfterClass
public static void afterClass() {
db.close();
}
public class ODropSequenceStatementExecutionTest extends BaseMemoryDatabase {

@Test
public void testPlain() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
package com.orientechnologies.orient.core.sql.executor;

import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.BaseMemoryDatabase;
import java.util.List;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */
public class ODropUserStatementExecutionTest {
static ODatabaseDocument db;

@BeforeClass
public static void beforeClass() {
db = new ODatabaseDocumentTx("memory:ODropUserStatementExecutionTest");
db.create();
}

@AfterClass
public static void afterClass() {
db.close();
}
public class ODropUserStatementExecutionTest extends BaseMemoryDatabase {

@Test
public void testPlain() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
package com.orientechnologies.orient.core.sql.executor;

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.BaseMemoryDatabase;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/** @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */
public class ODropViewStatementExecutionTest {
static ODatabaseDocument db;

@BeforeClass
public static void beforeClass() {
db = new ODatabaseDocumentTx("memory:ODropViewStatementExecutionTest");
db.create();
OClass v = db.getMetadata().getSchema().getClass("V");
if (v == null) {
db.getMetadata().getSchema().createClass("V");
}
}

@AfterClass
public static void afterClass() {
db.close();
}
public class ODropViewStatementExecutionTest extends BaseMemoryDatabase {

@Test
public void testPlain() {
Expand Down
Loading

0 comments on commit fa2eac6

Please sign in to comment.