01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.test.cms.commands;
23:
24: import junit.framework.TestSuite;
25: import org.jboss.portal.cms.Command;
26: import org.jboss.portal.cms.impl.FolderImpl;
27: import org.jboss.portal.cms.model.Folder;
28: import org.jboss.portal.cms.util.RepositoryUtil;
29:
30: import javax.jcr.Node;
31: import javax.jcr.Property;
32: import javax.jcr.Session;
33: import java.util.Date;
34:
35: /**
36: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
37: * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
38: * @author <a href="mailto:sohil.shah@jboss.com">Sohil Shah</a>
39: */
40: public class TestFolderCreate extends AbstractCommandTestCase {
41: /** A test folder path * */
42: String sFolderPath = "/alpha";
43:
44: /** A test folder path for copied folder trees * */
45: String sCopyToFolderPath = "/alpha/beta";
46:
47: /**
48: *
49: *
50: */
51: public TestFolderCreate() {
52: }
53:
54: /**
55: *
56: *
57: */
58: public static TestSuite suite() throws Exception {
59: return createTestSuite(TestFolderCreate.class);
60: }
61:
62: /**
63: *
64: *
65: */
66: public void testFolderCreate() throws Exception {
67: // create folder object
68: Folder folder = new FolderImpl();
69: folder.setCreationDate(new Date());
70: folder.setDescription("Folder description");
71: folder.setTitle("Folder Title");
72: folder.setLastModified(new Date());
73: folder.setName("Alpha Folder");
74: folder.setBasePath(sFolderPath);
75:
76: // save folder
77: Command saveCMD = service.getCommandFactory()
78: .createFolderSaveCommand(folder);
79: service.execute(saveCMD);
80:
81: // get folder - RAW
82: Session session = RepositoryUtil.login(service.getRepository(),
83: "anonid", "");
84: Node folderNode = (Node) session.getItem(sFolderPath);
85: assertNotNull("FolderNodeis null", folderNode);
86: assertTrue("Incorrect primarynodetype", folderNode
87: .getPrimaryNodeType().getName().equals(
88: "portalcms:folder"));
89: assertTrue("Incorrect Name for " + sFolderPath, folderNode
90: .getName().equals("alpha"));
91: session.save();
92:
93: Property description = folderNode
94: .getProperty("portalcms:description");
95: assertNotNull("Folder description is null", description);
96: assertTrue("Incorrect description for " + sFolderPath,
97: description.getString().equals("Folder description"));
98: }
99: }
|