001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.test.cms.commands;
023:
024: import junit.framework.TestSuite;
025: import org.jboss.portal.cms.CMSException;
026: import org.jboss.portal.cms.Command;
027: import org.jboss.portal.cms.impl.FolderImpl;
028: import org.jboss.portal.cms.model.Folder;
029: import org.jboss.portal.cms.util.RepositoryUtil;
030:
031: import javax.jcr.Property;
032: import javax.jcr.Session;
033: import java.util.Date;
034:
035: /**
036: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
037: * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
038: * @author <a href="mailto:sohil.shah@jboss.com">Sohil Shah</a>
039: */
040: public class TestFolderUpdate extends AbstractCommandTestCase {
041: /** A test folder path * */
042: String sFolderPath = "/alpha";
043:
044: /** A test folder path for copied folder trees * */
045: String sCopyToFolderPath = "/alpha/beta";
046:
047: /**
048: *
049: *
050: */
051: public TestFolderUpdate() {
052: }
053:
054: /**
055: *
056: *
057: */
058: public static TestSuite suite() throws Exception {
059: return createTestSuite(TestFolderUpdate.class);
060: }
061:
062: /**
063: *
064: *
065: */
066: public void testFolderUpdate() throws Exception {
067: createFolder();
068: // get folder
069: Command getCMD = service.getCommandFactory()
070: .createFolderGetCommand(sFolderPath);
071: Folder newFolder = (Folder) service.execute(getCMD);
072:
073: // update folder
074: newFolder.setDescription("new folder description");
075: Command cmdUpdate = service.getCommandFactory()
076: .createFolderUpdateCommand(newFolder);
077: service.execute(cmdUpdate);
078:
079: Session session = RepositoryUtil.login(service.getRepository(),
080: "anonid", "");
081: Property prop = (Property) session
082: .getItem("/alpha/portalcms:description");
083: System.out.println(prop.getString());
084: boolean descriptionupdated = ((Property) session
085: .getItem("/alpha/portalcms:description")).getString()
086: .equals("new folder description");
087: assertTrue("Incorrect description for folder: ",
088: descriptionupdated);
089: session.save();
090: }
091:
092: /**
093: *
094: *
095: */
096: public void createFolder() throws CMSException {
097: // create folder object
098: Folder folder = new FolderImpl();
099: folder.setCreationDate(new Date());
100: folder.setDescription("Folder description");
101: folder.setTitle("Folder Title");
102: folder.setLastModified(new Date());
103: folder.setName("Alpha Folder");
104: folder.setBasePath(sFolderPath);
105:
106: // save folder
107: Command saveCMD = service.getCommandFactory()
108: .createFolderSaveCommand(folder);
109: service.execute(saveCMD);
110: }
111: }
|