public void insertDocumentById() throws Exception {
new FacesRequest() {
protected void invokeApplication() throws Exception {
EntityManager em = (EntityManager) getInstance("restrictedEntityManager");
WikiDirectory d = (WikiDirectory)
em.createQuery("select d from WikiDirectory d where d.id = :id")
.setParameter("id", 3l)
.getSingleResult();
WikiDocument newDoc = new WikiDocument();
newDoc.setName("Four");
newDoc.setWikiname("Four");
newDoc.setAreaNumber(d.getAreaNumber());
newDoc.setCreatedBy(em.find(User.class, 1l));
newDoc.setContent("Testdocument Four");
newDoc.setParent(d);
em.persist(newDoc);
em.flush();
em.clear();
WikiDocument doc = (WikiDocument)
em.createQuery("select d from WikiDocument d where d.id = :id")
.setParameter("id", newDoc.getId())
.getSingleResult();
assert doc.getName().equals("Four");
assert doc.getParent().getId().equals(d.getId());
assert doc.getAreaNumber().equals(d.getAreaNumber());
assert doc.getLastModifiedBy() == null;
assert doc.getLastModifiedOn() == null;
}
}.run();
}