Skip to content

Commit

Permalink
Add test case for issue #8272 - sets on Object DB
Browse files Browse the repository at this point in the history
  • Loading branch information
luigidellaquila committed May 21, 2018
1 parent e391de6 commit 811486c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.orientechnologies.orient.object.db;

import com.orientechnologies.orient.core.db.object.ODatabaseObject;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.object.db.entity.ObjectWithSet;
import com.orientechnologies.orient.object.db.entity.SimpleChild;
import com.orientechnologies.orient.object.db.entity.SimpleParent;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Created by tglman on 17/02/17.
Expand All @@ -19,12 +21,15 @@ public class SimpleParentChildTest {

private ODatabaseObject database;

String url = "memory:" + SimpleParentChildTest.class.getSimpleName();

@Before
public void before() {
database = new OObjectDatabaseTx("memory:" + SimpleParentChildTest.class.getSimpleName());
database = new OObjectDatabaseTx(url);
database.create();
database.getEntityManager().registerEntityClass(SimpleChild.class);
database.getEntityManager().registerEntityClass(SimpleParent.class);
database.getEntityManager().registerEntityClass(ObjectWithSet.class);
}

@After
Expand All @@ -44,4 +49,30 @@ public void testParentChild() {
assertEquals(doc.fieldType("child"), OType.LINK);
}

@Test
public void testWithSets() {
ObjectWithSet parent = new ObjectWithSet();
ObjectWithSet child = new ObjectWithSet();
parent.addFriend(child);
child.setName("child1");
ObjectWithSet savedParent = database.save(parent);
String parentId = savedParent.getId();

this.database.close();
this.database = new OObjectDatabaseTx(url);
this.database.open("admin", "admin");

ObjectWithSet retrievedParent = this.database.load(new ORecordId(parentId));
ObjectWithSet retrievedChild = retrievedParent.getFriends().iterator().next();
retrievedChild.setName("child2");
this.database.save(retrievedParent);

this.database.close();
this.database = new OObjectDatabaseTx(url);
this.database.open("admin", "admin");

retrievedParent = this.database.load(new ORecordId(parentId));
Assert.assertEquals("child2", retrievedParent.getFriends().iterator().next().getName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.orientechnologies.orient.object.db.entity;

import javax.persistence.Id;
import javax.persistence.OneToMany;
import java.util.HashSet;
import java.util.Set;

public class ObjectWithSet {

@Id
public String id;

@OneToMany
Set<ObjectWithSet> friends = new HashSet<>();

String name;

public Set<ObjectWithSet> getFriends() {
return this.friends;
}

public void addFriend(ObjectWithSet friend) {
this.friends.add(friend);
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}
}

0 comments on commit 811486c

Please sign in to comment.