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.Command;
026: import org.jboss.portal.cms.impl.ContentImpl;
027: import org.jboss.portal.cms.impl.FileImpl;
028: import org.jboss.portal.cms.impl.FolderImpl;
029: import org.jboss.portal.cms.model.Content;
030: import org.jboss.portal.cms.model.File;
031: import org.jboss.portal.cms.model.Folder;
032:
033: import java.util.Date;
034: import java.util.Locale;
035:
036: /**
037: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
038: * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
039: * @author <a href="mailto:sohil.shah@jboss.com">Sohil Shah</a>
040: */
041: public class TestFolderCopy extends AbstractCommandTestCase {
042: /** A test folder path * */
043: String sFolderPath = "/alpha";
044:
045: /** A test folder path for copied folder trees * */
046: String sCopyToFolderPath = "/alpha/beta";
047:
048: /**
049: *
050: *
051: */
052: public TestFolderCopy() {
053: }
054:
055: /**
056: *
057: *
058: */
059: public static TestSuite suite() throws Exception {
060: return createTestSuite(TestFolderCopy.class);
061: }
062:
063: /** Copy test data from repo */
064: public void testFolderCopy() throws Exception {
065: // create folder object
066: Folder folder = new FolderImpl();
067: folder.setCreationDate(new Date());
068: folder.setDescription("Folder description");
069: folder.setTitle("Folder Title");
070: folder.setLastModified(new Date());
071: folder.setName("Alpha Folder");
072: folder.setBasePath("/alpha1");
073:
074: // save folder
075: Command saveCMD = service.getCommandFactory()
076: .createFolderSaveCommand(folder);
077: service.execute(saveCMD);
078:
079: // create file english
080: File file = new FileImpl();
081: file.setBasePath("/alpha1/toto.txt");
082:
083: Content content = new ContentImpl();
084: content.setEncoding("UTF-8");
085: content.setTitle("English Title");
086: content.setDescription("English Description");
087: content.setBasePath("/alpha1/toto.txt/"
088: + Locale.ENGLISH.getLanguage());
089: content.setBytes("1234567890".getBytes());
090: content.setMimeType("image/gif");
091:
092: file.setContent(Locale.ENGLISH, content);
093:
094: // save english file
095: Command saveFileCMD = service.getCommandFactory()
096: .createNewFileCommand(file, content);
097: service.execute(saveFileCMD);
098:
099: Folder folder2 = new FolderImpl();
100: folder2.setCreationDate(new Date());
101: folder2.setDescription("Folder description");
102: folder2.setTitle("Folder Title");
103: folder2.setLastModified(new Date());
104: folder2.setName("Beta Folder");
105: folder2.setBasePath("/beta1");
106:
107: // save folder
108: Command saveCMD2 = service.getCommandFactory()
109: .createFolderSaveCommand(folder2);
110: service.execute(saveCMD2);
111:
112: Command copyFolderCMD = service.getCommandFactory()
113: .createCopyCommand("/alpha1", "/beta1/test");
114: service.execute(copyFolderCMD);
115:
116: Command getLiveCMD = service.getCommandFactory()
117: .createFileGetCommand("/alpha1/toto.txt",
118: Locale.ENGLISH);
119: File fileOrig = (File) service.execute(getLiveCMD);
120:
121: assertNotNull("Content of the original file is null", fileOrig
122: .getContent());
123:
124: getLiveCMD = service.getCommandFactory().createFileGetCommand(
125: "/beta1/test/toto.txt", Locale.ENGLISH);
126: File fileCopy = (File) service.execute(getLiveCMD);
127:
128: assertNotNull("Content of the copied file is null", fileCopy
129: .getContent());
130: }
131: }
|