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.ContentImpl;
028: import org.jboss.portal.cms.impl.FileImpl;
029: import org.jboss.portal.cms.model.Content;
030: import org.jboss.portal.cms.model.File;
031:
032: import java.util.Locale;
033:
034: /**
035: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
036: * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
037: * @author <a href="mailto:sohil.shah@jboss.com">Sohil Shah</a>
038: */
039: public class TestFileCopy extends AbstractCommandTestCase {
040: String sFilePath = "/testdoc.gif";
041:
042: String sCopyToFilePath = "/testdoccopy.gif";
043:
044: // zip vars
045: String sZipPath = "/poop";
046:
047: String sZipFile = "resources/test/jcr/ziptest.zip";
048:
049: String sJPG = "/hibernate_logo.gif";
050:
051: String sText = "/training.txt";
052:
053: /**
054: *
055: *
056: */
057: public TestFileCopy() {
058: }
059:
060: /**
061: *
062: *
063: */
064: public static TestSuite suite() throws Exception {
065: return createTestSuite(TestFileCopy.class);
066: }
067:
068: /**
069: *
070: *
071: */
072: public void testFileCopy() throws CMSException {
073: createFile();
074: // copy file
075: Command copyCMD = service.getCommandFactory()
076: .createCopyCommand(sFilePath, sCopyToFilePath);
077: service.execute(copyCMD);
078:
079: Command getCMD = service.getCommandFactory()
080: .createFileGetCommand(sCopyToFilePath, Locale.ENGLISH);
081: File newfile = (File) service.execute(getCMD);
082: Content content = newfile.getContent();
083: assertEquals("Encoding Incorrect", content.getEncoding(),
084: "UTF-8");
085: assertEquals("Mimetype Incorrect", content.getMimeType(),
086: "image/gif");
087: assertEquals("Language Incorrect", content.getLocale()
088: .getLanguage(), "en");
089: assertEquals("Title Incorrect", content.getTitle(),
090: "English Title");
091: assertEquals("Desc Incorrect", content.getDescription(),
092: "English Description");
093:
094: Command getCMDSP = service
095: .getCommandFactory()
096: .createFileGetCommand(sCopyToFilePath, new Locale("es"));
097: File newfileSP = (File) service.execute(getCMDSP);
098: Content contentSP = newfileSP.getContent();
099: assertEquals("Encoding Incorrect", contentSP.getEncoding(),
100: "UTF-8");
101: assertEquals("Mimetype Incorrect", contentSP.getMimeType(),
102: "image/gif");
103: assertEquals("Language Incorrect", contentSP.getLocale()
104: .getLanguage(), "es");
105: assertEquals("Title Incorrect", contentSP.getTitle(),
106: "Spanish Title");
107: assertEquals("Desc Incorrect", contentSP.getDescription(),
108: "Spanish Description");
109: }
110:
111: /**
112: *
113: *
114: */
115: private void createFile() throws CMSException {
116: // create file english
117: File file = new FileImpl();
118: file.setBasePath(sFilePath);
119:
120: Content content = new ContentImpl();
121: content.setEncoding("UTF-8");
122: content.setTitle("English Title");
123: content.setDescription("English Description");
124: content.setBasePath(sFilePath + "/"
125: + Locale.ENGLISH.getLanguage());
126: content.setBytes("1234567890".getBytes());
127: content.setMimeType("image/gif");
128: file.setContent(Locale.ENGLISH, content);
129:
130: Command newFileCMD = service.getCommandFactory()
131: .createNewFileCommand(file, content);
132: service.execute(newFileCMD);
133:
134: // create content spanish
135: Content contentSP = new ContentImpl();
136: contentSP.setEncoding("UTF-8");
137: contentSP.setTitle("Spanish Title");
138: contentSP.setDescription("Spanish Description");
139: contentSP.setBasePath(sFilePath + "/es");
140: contentSP.setBytes("0987654321".getBytes());
141: contentSP.setMimeType("image/gif");
142: file.setContent(new Locale("es"), contentSP);
143:
144: Command newFileSPCMD = service.getCommandFactory()
145: .createNewFileCommand(file, contentSP);
146: service.execute(newFileSPCMD);
147: }
148: }
|