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 TestFileGet 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 TestFileGet() {
058: }
059:
060: /**
061: *
062: *
063: */
064: public static TestSuite suite() throws Exception {
065: return createTestSuite(TestFileGet.class);
066: }
067:
068: /** Tests retrieval of the version labeled LIVE. */
069: public void testFileGet() throws CMSException {
070: createFile();
071: Command getCMD = service.getCommandFactory()
072: .createFileGetCommand(sFilePath, Locale.ENGLISH);
073: File newfile = (File) service.execute(getCMD);
074:
075: Content content = newfile.getContent();
076: assertEquals("Encoding Incorrect", content.getEncoding(),
077: "UTF-8");
078: assertEquals("Mimetype Incorrect", content.getMimeType(),
079: "image/gif");
080: assertEquals("Language Incorrect", content.getLocale()
081: .getLanguage(), "en");
082: assertEquals("Title Incorrect", content.getTitle(),
083: "English Title");
084: assertEquals("Desc Incorrect", content.getDescription(),
085: "English Description");
086: }
087:
088: /**
089: *
090: *
091: */
092: private void createFile() throws CMSException {
093: // create file english
094: File file = new FileImpl();
095: file.setBasePath(sFilePath);
096:
097: Content content = new ContentImpl();
098: content.setEncoding("UTF-8");
099: content.setTitle("English Title");
100: content.setDescription("English Description");
101: content.setBasePath(sFilePath + "/"
102: + Locale.ENGLISH.getLanguage());
103: content.setBytes("1234567890".getBytes());
104: content.setMimeType("image/gif");
105: file.setContent(Locale.ENGLISH, content);
106:
107: Command newFileCMD = service.getCommandFactory()
108: .createNewFileCommand(file, content);
109: service.execute(newFileCMD);
110:
111: // create content spanish
112: Content contentSP = new ContentImpl();
113: contentSP.setEncoding("UTF-8");
114: contentSP.setTitle("Spanish Title");
115: contentSP.setDescription("Spanish Description");
116: contentSP.setBasePath(sFilePath + "/es");
117: contentSP.setBytes("0987654321".getBytes());
118: contentSP.setMimeType("image/gif");
119: file.setContent(new Locale("es"), contentSP);
120:
121: Command newFileSPCMD = service.getCommandFactory()
122: .createNewFileCommand(file, contentSP);
123: service.execute(newFileSPCMD);
124: }
125: }
|