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.model.Folder;
028: import org.jboss.portal.common.io.IOTools;
029:
030: import java.io.FileInputStream;
031: import java.io.IOException;
032: import java.io.InputStream;
033: import java.util.List;
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 TestFileArchiveUpload extends AbstractCommandTestCase {
042: String sFilePath = "/testdoc.gif";
043:
044: String sCopyToFilePath = "/testdoccopy.gif";
045:
046: // zip vars
047: String sZipPath = "/poop";
048:
049: String sZipFile = "resources/test/jcr/ziptest.zip";
050:
051: String sJPG = "/hibernate_logo.gif";
052:
053: String sText = "/training.txt";
054:
055: String foreignArchive = "resources/test/jcr/prueba.zip";
056:
057: /**
058: *
059: *
060: */
061: public TestFileArchiveUpload() {
062: }
063:
064: /**
065: *
066: *
067: */
068: public static TestSuite suite() throws Exception {
069: return createTestSuite(TestFileArchiveUpload.class);
070: }
071:
072: public void testArchiveUpload() throws CMSException, IOException {
073: service.setDefaultLocale(Locale.ENGLISH.getLanguage());
074: InputStream is = IOTools
075: .safeBufferedWrapper(new FileInputStream(sZipFile));
076: Command storearchiveCMD = service.getCommandFactory()
077: .createStoreArchiveCommand("", is, "en");
078: List contentsToVersion = (List) service
079: .execute(storearchiveCMD);
080: is.close();
081:
082: Command createVersions = service.getCommandFactory()
083: .createContentCreateNewVersionCommand(
084: contentsToVersion, true);
085: service.execute(createVersions);
086:
087: // retrieve list
088: Command listCMD = service.getCommandFactory()
089: .createFolderGetListCommand("/ziptest/poop");
090: Folder whopper = (Folder) service.execute(listCMD);
091: List folders = whopper.getFolders();
092: List files = whopper.getFiles();
093: assertEquals("Folder Size incorrect", folders.size(), 1);
094: assertEquals("File Size incorrect", files.size(), 1);
095:
096: // retrieve list
097: Command listCMD2 = service.getCommandFactory()
098: .createFolderGetListCommand("/ziptest/poop/music");
099: Folder whopper2 = (Folder) service.execute(listCMD2);
100: List folders2 = whopper2.getFolders();
101: List files2 = whopper2.getFiles();
102: assertEquals("Folder Size incorrect", folders2.size(), 0);
103: assertEquals("File Size incorrect", files2.size(), 1);
104:
105: // retrieve list
106: Command listCMD3 = service.getCommandFactory()
107: .createFolderGetListCommand("/");
108: Folder whopper3 = (Folder) service.execute(listCMD3);
109: List folders3 = whopper3.getFolders();
110: List files3 = whopper3.getFiles();
111:
112: //Create and Test an archive containing foreign files
113: is = IOTools.safeBufferedWrapper(new FileInputStream(
114: this .foreignArchive));
115: storearchiveCMD = service.getCommandFactory()
116: .createStoreArchiveCommand("", is, "en");
117: contentsToVersion = (List) service.execute(storearchiveCMD);
118: assertTrue(
119: "Foreign Archive Creation Failed",
120: (contentsToVersion != null
121: && !contentsToVersion.isEmpty() && contentsToVersion
122: .size() == 2));
123: is.close();
124: }
125: }
|