other.clearDatabase(true);
}
@Test
public void testEmbedded() {
EmbeddedEmail sub = new EmbeddedEmail();
sub.setIdkey(67);
sub.setName("dean");
sub.setType("nosqltype");
EmbeddedEmail e1 = new EmbeddedEmail();
e1.setIdkey(65);
e1.setName("name1");
e1.setType("type1");
//e1.getEmails().add(sub);
EmbeddedEmail e2 = new EmbeddedEmail();
e2.setIdkey(66);
e2.setName("name2");
e2.setType("type2");
EmbeddedEmail e3 = new EmbeddedEmail();
e3.setIdkey(68);
e3.setName("name3");
e3.setType("type3");
User user = new User();
List<EmbeddedEmail> listEmails = new ArrayList<EmbeddedEmail>();
listEmails.add(e1);
listEmails.add(e2);
listEmails.add(e3);
user.setEmails(listEmails);
user.setEmail(sub);
mgr.fillInWithKey(e1);
mgr.fillInWithKey(e1);
mgr.fillInWithKey(e3);
mgr.fillInWithKey(sub);
mgr.put(user);
mgr.flush();
NoSqlEntityManager mgr2 = factory.createEntityManager();
User user2 = mgr2.find(User.class, user.getId());
//Check single entity
EmbeddedEmail emailSub = user2.getEmail();
Assert.assertNotNull(emailSub);
Assert.assertEquals(sub.getIdkey(), emailSub.getIdkey());
Assert.assertEquals(sub.getName(), emailSub.getName());
//Check List of entities
List<EmbeddedEmail> emails = user2.getEmails();
Assert.assertEquals(3, emails.size());
EmbeddedEmail email = emails.get(0);
Assert.assertNotNull(email);
Assert.assertEquals(e1.getIdkey(), email.getIdkey());
Assert.assertEquals(e1.getName(), email.getName());
EmbeddedEmail email2 = emails.get(1);
Assert.assertEquals(e2.getName(), email2.getName());
// check if deleting embedded stuff is working fine
NoSqlEntityManager mgr3 = factory.createEntityManager();
user2.getEmails().remove(0);
mgr3.put(user2);