PortalImpl implements Portal { @Override public void savePage(Page page) { PageImpl pageImpl = (PageImpl) page; Parameters.requireNonNull(pageImpl, "page"); if (getSite(pageImpl.getSiteId()) == null) { throw new EntityNotFoundException("Site " + pageImpl.getSiteId() + " doesn't exist"); } if (pageImpl.isCreate() && getPage(pageImpl.getId()) != null) { throw new EntityAlreadyExistsException("Cannot create page. Page " + pageImpl.getId() + " already exists."); } PageContext context = pageImpl.getPageContext(); try { pageService.savePage(context); if (!pageImpl.isChildrenSet()) { return; } dataStorage.save(getModelObjectFor(pageImpl)); dataStorage.save(); } catch (Throwable t) { throw new ApiException("Failed to save page " + pageImpl.getId(), t); } } PortalImpl(DataStorage dataStorage, PageService pageService, NavigationService navigationService,
                      DescriptionService descriptionService, ResourceBundleManager bundleManager, Authenticator authenticator,
                      IdentityRegistry identityRegistry, UserACL acl, UserPortalConfigService userPortalConfigService,
                      OAuthProviderAccessor oauthProviderAccessor); @Override Site getSite(SiteId siteId); @Override Site createSite(SiteId siteId); @Override Site createSite(SiteId siteId, String templateName); @Override List<Site> findSites(SiteQuery query); @Override void saveSite(Site site); @Override boolean removeSite(SiteId siteId); @Override Navigation getNavigation(SiteId siteId); @Override PageBuilder newPageBuilder(); @Override ApplicationRegistry getApplicationRegistry(); @Override Page getPage(PageId pageId); List<ContainerItem> getPageRootContainer(PageContext pageContext); @Override Page createPage(PageId pageId); @Override List<Page> findPages(PageQuery query); @Override void savePage(Page page); @Override boolean removePage(PageId pageId); @Override boolean hasPermission(User user, Permission permission); @Override OAuthProvider getOAuthProvider(String oauthProviderKey);  }
@Test public void savePage() { createSite(new SiteId("create-page")); Permission access = new Permission("*", new Group("access")); Permission edit = new Permission("*", new Group("edit")); Page page = portal.createPage(new PageId("create-page", "baz")); page.setAccessPermission(access); page.setDescription("description"); page.setDisplayName("displayName"); page.setEditPermission(edit); portal.savePage(page); page = portal.getPage(new PageId("create-page", "baz")); assertNotNull(page); assertEquals(access, page.getAccessPermission()); assertEquals("description", page.getDescription()); assertEquals("displayName", page.getDisplayName()); assertEquals(edit, page.getEditPermission()); assertEquals(new PageId("create-page", "baz"), page.getId()); assertEquals("baz", page.getName()); assertEquals(new SiteId("create-page"), page.getSiteId()); }
@Test(expected = IllegalArgumentException.class) public void savePage_Null() { portal.savePage(null); }