PortalImpl implements Portal { @Override public Page createPage(PageId pageId) throws EntityAlreadyExistsException { if (getPage(pageId) != null) { throw new EntityAlreadyExistsException("Cannot create page. Page " + pageId + " already exists."); } if (getSite(pageId.getSiteId()) == null) { throw new EntityNotFoundException("Site " + pageId.getSiteId() + " doesn't exist"); } Permission accessPermissions = Container.DEFAULT_ACCESS_PERMISSION; Permission edit = Page.DEFAULT_EDIT_PERMISSION; Permission moveAppsPermissions = Container.DEFAULT_MOVE_APPS_PERMISSION; Permission moveContainersPermissions = Container.DEFAULT_MOVE_CONTAINERS_PERMISSION; PageState pageState = new PageState(pageId.getPageName(), null, false, null, Arrays.asList(Util.from(accessPermissions)), Util.from(edit)[0], Arrays.asList(Util.from(moveAppsPermissions)), Arrays.asList(Util.from(moveContainersPermissions))); PageImpl p = new PageImpl(this, new PageContext(Util.from(pageId), pageState)); p.setCreate(true); return p; } 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 createPage() { createSite(new SiteId("create-page")); Page page = portal.createPage(new PageId("create-page", "baz")); assertNotNull(page); assertNull(portal.getPage(new PageId("create-page", "baz"))); }
@Test(expected = IllegalArgumentException.class) public void createPage_NullPageId() { portal.createPage(null); }
@Test(expected = EntityNotFoundException.class) public void createPage_NoSite() { portal.createPage(new PageId("no-site", "baz")); }