### Question:
TransactionalSimplePageService extends AbstractTransactionalEntityService<SimplePage, SimplePageDao> implements SimplePageService { @PreAuthorize("hasPermission(#userCreator.id, 'USER', 'ProfilePermission.CREATE_FORUM_FAQ')") @Override public SimplePage createPage(SimplePage simplePage, JCUser userCreator) throws EntityExistsException { if (getDao().isExist(simplePage.getPathName())) { String msg = "SimplePage with pathName = " + simplePage.getPathName() + " already exists."; logger.info(msg); throw new EntityExistsException(msg); } this.getDao().saveOrUpdate(simplePage); Group group = groupDao.getGroupByName(AdministrationGroup.ADMIN.getName()); securityService.createAclBuilder().grant(GeneralPermission.WRITE).to(group).on(simplePage).flush(); logger.info("SimplePage registered: {}", simplePage.getName()); return simplePage; } TransactionalSimplePageService(SimplePageDao simplePageDao,
                                          GroupDao groupDao,
                                          SecurityService securityService); @Override @PreAuthorize("hasPermission(#simplePageInfoContainer.getId(), 'USER', 'ProfilePermission.CREATE_FORUM_FAQ')") void updatePage(SimplePageInfoContainer simplePageInfoContainer); @Override SimplePage getPageByPathName(String pathName); @PreAuthorize("hasPermission(#userCreator.id, 'USER', 'ProfilePermission.CREATE_FORUM_FAQ')") @Override SimplePage createPage(SimplePage simplePage, JCUser userCreator);  }### Answer:
@Test void testCreatePage() throws EntityExistsException { SimplePage simplePage = new SimplePage(NAME, CONTENT, PATH_NAME); JCUser user = new JCUser("username", "email", "password"); when(dao.isExist(PATH_NAME)).thenReturn(false); when(groupDao.getGroupByName(AdministrationGroup.ADMIN.getName())).thenReturn(new Group()); SimplePage actualSimplePage = simplePageService.createPage(simplePage, user); assertEquals(actualSimplePage.getName(), NAME); assertEquals(actualSimplePage.getContent(), CONTENT); assertEquals(actualSimplePage.getPathName(), PATH_NAME); verify(dao).isExist(PATH_NAME); verify(dao).saveOrUpdate(simplePage); verify(aclBuilder).grant(GeneralPermission.WRITE); }
@Test(expectedExceptions = {EntityExistsException.class}) void testCreatePageFailPageAlreadyExists() throws EntityExistsException { SimplePage simplePage = new SimplePage(NAME, CONTENT, PATH_NAME); JCUser user = new JCUser("username", "email", "password"); when(dao.isExist(PATH_NAME)).thenReturn(true); SimplePage actualSimpePage = simplePageService.createPage(simplePage, user); }