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.List;
033: import java.util.Locale;
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 TestFileGetList extends AbstractCommandTestCase {
041: String sFilePath = "/testdoc.gif";
042:
043: String sCopyToFilePath = "/testdoccopy.gif";
044:
045: // zip vars
046: String sZipPath = "/poop";
047:
048: String sZipFile = "resources/test/jcr/ziptest.zip";
049:
050: String sJPG = "/hibernate_logo.gif";
051:
052: String sText = "/training.txt";
053:
054: /**
055: *
056: *
057: */
058: public TestFileGetList() {
059: }
060:
061: /**
062: *
063: *
064: */
065: public static TestSuite suite() throws Exception {
066: return createTestSuite(TestFileGetList.class);
067: }
068:
069: /** Tests retrieving a list of contents under a file and the versions for contents. */
070: public void testFileList() throws CMSException {
071: createFile();
072: Command getFileListCMD = service.getCommandFactory()
073: .createFileGetListCommand(sFilePath);
074: List contentList = (List) service.execute(getFileListCMD);
075: assertTrue("Incorrect list size", contentList.size() == 2);
076:
077: for (int i = 0; i < contentList.size(); i++) {
078: Content content = (Content) contentList.get(i);
079: Command getContentVersionsCMD = service.getCommandFactory()
080: .createContentGetVersionsCommand(
081: content.getBasePath());
082: List versionList = (List) service
083: .execute(getContentVersionsCMD);
084: }
085: }
086:
087: /**
088: *
089: *
090: */
091: private void createFile() throws CMSException {
092: // create file english
093: File file = new FileImpl();
094: file.setBasePath(sFilePath);
095:
096: Content content = new ContentImpl();
097: content.setEncoding("UTF-8");
098: content.setTitle("English Title");
099: content.setDescription("English Description");
100: content.setBasePath(sFilePath + "/"
101: + Locale.ENGLISH.getLanguage());
102: content.setBytes("1234567890".getBytes());
103: content.setMimeType("image/gif");
104: file.setContent(Locale.ENGLISH, content);
105:
106: Command newFileCMD = service.getCommandFactory()
107: .createNewFileCommand(file, content);
108: service.execute(newFileCMD);
109:
110: // create content spanish
111: Content contentSP = new ContentImpl();
112: contentSP.setEncoding("UTF-8");
113: contentSP.setTitle("Spanish Title");
114: contentSP.setDescription("Spanish Description");
115: contentSP.setBasePath(sFilePath + "/es");
116: contentSP.setBytes("0987654321".getBytes());
117: contentSP.setMimeType("image/gif");
118: file.setContent(new Locale("es"), contentSP);
119:
120: Command newFileSPCMD = service.getCommandFactory()
121: .createNewFileCommand(file, contentSP);
122: service.execute(newFileSPCMD);
123: }
124: }
|