String folderPath = "/testfolder_" + String.valueOf( new Date().getTime() );
Folder folder = APILocator.getFolderAPI().findFolderByPath(folderPath, host, systemUser, true);
if(!UtilMethods.isSet(folder.getInode())){
folder = APILocator.getFolderAPI().createFolders(folderPath, host, systemUser, true);
Permission p = new Permission();
p.setInode(folder.getPermissionId());
p.setRoleId(APILocator.getRoleAPI().loadCMSAnonymousRole().getId());
p.setPermission(PermissionAPI.PERMISSION_READ);
APILocator.getPermissionAPI().save(p, folder, systemUser, true);
}
/*
* Creating testing pages
*/
// Adds template children from selected box
//Identifier templateIdentifier = identifierAPI.find(templateId);
Map<String, Object> params = new HashMap<String, Object>();
params.put("title", "Quest - 1 Column");
Template template = APILocator.getTemplateAPI().findTemplates(systemUser, false, params, host.getIdentifier(), null, null, null, 0, 1, "").get(0);
HTMLPage newHtmlPage = new HTMLPage();
newHtmlPage.setParent(folder.getInode());
newHtmlPage.setPageUrl("reordertest1."+Config.getStringProperty("VELOCITY_PAGE_EXTENSION","html"));
newHtmlPage.setTitle("reordertest1");
newHtmlPage.setFriendlyName("reordertest1");
newHtmlPage.setTemplateId(template.getIdentifier());
if (UtilMethods.isSet(newHtmlPage.getFriendlyName())) {
newHtmlPage.setFriendlyName(newHtmlPage.getFriendlyName());
} else {
newHtmlPage.setFriendlyName(newHtmlPage.getTitle());
}
if (!newHtmlPage.getPageUrl().endsWith("." + Config.getStringProperty("VELOCITY_PAGE_EXTENSION","html"))) {
newHtmlPage.setPageUrl(newHtmlPage.getPageUrl() + "." + Config.getStringProperty("VELOCITY_PAGE_EXTENSION","html"));
}
WebAssetFactory.createAsset(newHtmlPage, systemUser.getUserId(), folder);
APILocator.getVersionableAPI().setLive(newHtmlPage);
WebAssetFactory.publishAsset(newHtmlPage);
HTMLPage workinghtmlPageAsset = null;
workinghtmlPageAsset = newHtmlPage;
HibernateUtil.flush();
/*
* relate the page, container and contentlet
*/
Container containerId = null;
for(Container container : APILocator.getTemplateAPI().getContainersInTemplate(template, systemUser, false)){
if(container.getTitle().equals("Large Column (lg-1)")){
containerId = container;
break;
}
}
/*
* Create test contentlet1
*/
Structure structure = StructureCache.getStructureByVelocityVarName("webPageContent");
Contentlet contentlet1 = new Contentlet();
contentlet1.setStructureInode(structure.getInode());
contentlet1.setHost(host.getIdentifier());
contentlet1.setLanguageId(APILocator.getLanguageAPI().getDefaultLanguage().getId());
contentlet1.setStringProperty("title", "test5189-1");
contentlet1.setStringProperty("body", "test5189-1");
contentlet1.setHost(host.getIdentifier());
contentlet1 = APILocator.getContentletAPI().checkin(contentlet1, systemUser,false);
if(APILocator.getPermissionAPI().doesUserHavePermission(contentlet1, PermissionAPI.PERMISSION_PUBLISH, systemUser))
APILocator.getVersionableAPI().setLive(contentlet1);
Contentlet contentlet2 = new Contentlet();
contentlet2.setStructureInode(structure.getInode());
contentlet2.setHost(host.getIdentifier());
contentlet2.setLanguageId(APILocator.getLanguageAPI().getDefaultLanguage().getId());
contentlet2.setStringProperty("title", "test5189-2");
contentlet2.setStringProperty("body", "test5189-2");
contentlet2.setHost(host.getIdentifier());
contentlet2 = APILocator.getContentletAPI().checkin(contentlet2, systemUser,false);
if(APILocator.getPermissionAPI().doesUserHavePermission(contentlet2, PermissionAPI.PERMISSION_PUBLISH, systemUser))
APILocator.getVersionableAPI().setLive(contentlet2);
Contentlet contentlet3 = new Contentlet();
contentlet3.setStructureInode(structure.getInode());
contentlet3.setHost(host.getIdentifier());
contentlet3.setLanguageId(APILocator.getLanguageAPI().getDefaultLanguage().getId());
contentlet3.setStringProperty("title", "test5189-3");
contentlet3.setStringProperty("body", "test5189-3");
contentlet3.setHost(host.getIdentifier());
contentlet3 = APILocator.getContentletAPI().checkin(contentlet3, systemUser,false);
if(APILocator.getPermissionAPI().doesUserHavePermission(contentlet3, PermissionAPI.PERMISSION_PUBLISH, systemUser))
APILocator.getVersionableAPI().setLive(contentlet3);
/*
* Relating content to live page
*/
Identifier htmlPageIdentifier = APILocator.getIdentifierAPI().find(workinghtmlPageAsset);
Identifier containerIdentifier = APILocator.getIdentifierAPI().find(containerId);
Identifier contenletIdentifier1 = APILocator.getIdentifierAPI().find(contentlet1);
MultiTree multiTree = MultiTreeFactory.getMultiTree(htmlPageIdentifier, containerIdentifier,contenletIdentifier1);
int contentletCount = MultiTreeFactory.getMultiTree(htmlPageIdentifier).size();
if (!InodeUtils.isSet(multiTree.getParent1()) && !InodeUtils.isSet(multiTree.getParent2()) && !InodeUtils.isSet(multiTree.getChild())) {
MultiTree mTree = new MultiTree(htmlPageIdentifier.getInode(), containerIdentifier.getInode(),
contenletIdentifier1.getInode(),null,contentletCount);
MultiTreeFactory.saveMultiTree(mTree);
}
Identifier contenletIdentifier2 = APILocator.getIdentifierAPI().find(contentlet2);
multiTree = MultiTreeFactory.getMultiTree(htmlPageIdentifier, containerIdentifier,contenletIdentifier2);
contentletCount = MultiTreeFactory.getMultiTree(htmlPageIdentifier).size();
if (!InodeUtils.isSet(multiTree.getParent1()) && !InodeUtils.isSet(multiTree.getParent2()) && !InodeUtils.isSet(multiTree.getChild())) {
MultiTree mTree = new MultiTree(htmlPageIdentifier.getInode(), containerIdentifier.getInode(),
contenletIdentifier2.getInode(),null,contentletCount);
MultiTreeFactory.saveMultiTree(mTree);
}
Identifier contenletIdentifier3 = APILocator.getIdentifierAPI().find(contentlet3);
multiTree = MultiTreeFactory.getMultiTree(htmlPageIdentifier, containerIdentifier,contenletIdentifier3);
contentletCount = MultiTreeFactory.getMultiTree(htmlPageIdentifier).size();
if (!InodeUtils.isSet(multiTree.getParent1()) && !InodeUtils.isSet(multiTree.getParent2()) && !InodeUtils.isSet(multiTree.getChild())) {
MultiTree mTree = new MultiTree(htmlPageIdentifier.getInode(), containerIdentifier.getInode(),
contenletIdentifier3.getInode(),null,contentletCount);
MultiTreeFactory.saveMultiTree(mTree);
}
/*
* Validations
*/
assertTrue(workinghtmlPageAsset.isLive());
contentletCount = MultiTreeFactory.getMultiTree(htmlPageIdentifier).size();
assertTrue(contentletCount == 3);
/*
* Generate test environment
*/
//Preparing the url in order to push content
EnvironmentAPI environmentAPI = APILocator.getEnvironmentAPI();
PublishingEndPointAPI publisherEndPointAPI = APILocator.getPublisherEndPointAPI();
PublisherAPI publisherAPI = PublisherAPI.getInstance();
HttpServletRequest req = ServletTestRunner.localRequest.get();
Environment environment = new Environment();
environment.setName( "TestEnvironment_" + String.valueOf( new Date().getTime() ) );
environment.setPushToAll( false );
/*
* Find the roles of the admin user
*/
Role role = APILocator.getRoleAPI().loadRoleByKey( adminUser.getUserId() );
//Create the permissions for the environment
List<Permission> permissions = new ArrayList<Permission>();
Permission p = new Permission( environment.getId(), role.getId(), PermissionAPI.PERMISSION_USE );
permissions.add( p );
/*
* Create a environment
*/