Skip to content

Commit

Permalink
Completed and enabled the DB entity collections test.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Jan 16, 2015
1 parent 037d5fd commit 5cf4a2a
Showing 1 changed file with 20 additions and 6 deletions.
Expand Up @@ -23,16 +23,16 @@
import org.rapidoid.db.model.IPerson; import org.rapidoid.db.model.IPerson;
import org.rapidoid.db.model.IPost; import org.rapidoid.db.model.IPost;
import org.rapidoid.db.model.IProfile; import org.rapidoid.db.model.IProfile;
import org.rapidoid.db.model.Profile;
import org.testng.annotations.Test; import org.testng.annotations.Test;


public class DbEntityCollectionsTest extends DbTestCommons { public class DbEntityCollectionsTest extends DbTestCommons {


@Test(enabled = false) @Test
public void testCollectionsPersistence() { public void testCollectionsPersistence() {


IProfile profile = DB.create(IProfile.class); IProfile profile = DB.create(IProfile.class);
notNull(profile); notNull(profile);
eq(DB.size(), 0);


IPost post1 = DB.create(IPost.class); IPost post1 = DB.create(IPost.class);
post1.content().set("post 1"); post1.content().set("post 1");
Expand All @@ -44,10 +44,21 @@ public void testCollectionsPersistence() {
post3.content().set("post 3"); post3.content().set("post 3");


profile.posts().add(post1); profile.posts().add(post1);
eq(DB.size(), 1);

DB.persist(profile); DB.persist(profile);
eq(DB.size(), 2);

profile.posts().add(post2); profile.posts().add(post2);
eq(DB.size(), 3);

profile.posts().add(post3); profile.posts().add(post3);
eq(DB.size(), 4);

notNull(profile.id());
notNull(profile.id().get());
DB.persist(profile); DB.persist(profile);
eq(DB.size(), 4);


int pn = 1; int pn = 1;
for (IPost post : profile.posts()) { for (IPost post : profile.posts()) {
Expand All @@ -65,22 +76,25 @@ public void testCollectionsPersistence() {
eq(DB.size(), 7); eq(DB.size(), 7);


post1 = DB.get(1); post1 = DB.get(1);
notNull(post1);
notNull(post1.likes());

eq(post1.content().get(), "post 1"); eq(post1.content().get(), "post 1");
eq(post1.likes().size(), 1); eq(post1.likes().size(), 1);
eq(post1.likes().iterator().next().name().get(), "person 1"); eq(post1.likes().iterator().next().name().get(), "person 1");


Profile p = DB.get(2); IProfile p = DB.get(2);
eq(p.posts.size(), 3); eq(p.posts().size(), 3);


post2 = DB.get(3); post2 = DB.get(3);
eq(post2.content().get(), "post 2"); eq(post2.content().get(), "post 2");
eq(post2.likes().size(), 1); eq(post2.likes().size(), 1);
eq(post1.likes().iterator().next().name().get(), "person 1"); eq(post2.likes().iterator().next().name().get(), "person 2");


post3 = DB.get(4); post3 = DB.get(4);
eq(post3.content().get(), "post 3"); eq(post3.content().get(), "post 3");
eq(post3.likes().size(), 1); eq(post3.likes().size(), 1);
eq(post1.likes().iterator().next().name().get(), "person 1"); eq(post3.likes().iterator().next().name().get(), "person 3");


DB.shutdown(); DB.shutdown();
} }
Expand Down

0 comments on commit 5cf4a2a

Please sign in to comment.