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: import org.jboss.portal.cms.util.RepositoryUtil;
032:
033: import javax.jcr.Session;
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 TestFileDelete 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: /**
056: *
057: *
058: */
059: public TestFileDelete() {
060: }
061:
062: /**
063: *
064: *
065: */
066: public static TestSuite suite() throws Exception {
067: return createTestSuite(TestFileDelete.class);
068: }
069:
070: /**
071: *
072: *
073: */
074: public void testFileDelete() throws Exception {
075: createFile();
076:
077: // delete old test nodes
078: Command deleteCMD = service.getCommandFactory()
079: .createDeleteCommand(sFilePath);
080: service.execute(deleteCMD);
081: Command deleteToCMD = service.getCommandFactory()
082: .createDeleteCommand(sCopyToFilePath);
083: service.execute(deleteToCMD);
084:
085: // zip deletes
086: Command deleteZipCMD = service.getCommandFactory()
087: .createDeleteCommand(sZipPath);
088: service.execute(deleteZipCMD);
089: Command deleteZipJCMD = service.getCommandFactory()
090: .createDeleteCommand(sJPG);
091: service.execute(deleteZipJCMD);
092: Command deleteZipTCMD = service.getCommandFactory()
093: .createDeleteCommand(sText);
094: service.execute(deleteZipTCMD);
095:
096: Session session = RepositoryUtil.login(service.getRepository(),
097: "anonid", "");
098: assertFalse(sFilePath + " not Deleted", session
099: .itemExists(sFilePath));
100: assertFalse(sCopyToFilePath + " not Deleted", session
101: .itemExists(sCopyToFilePath));
102: assertFalse(sZipPath + " not Deleted", session
103: .itemExists(sZipPath));
104: assertFalse(sJPG + " not Deleted", session.itemExists(sJPG));
105: assertFalse(sText + " not Deleted", session.itemExists(sText));
106:
107: RepositoryUtil.safeLogout(session);
108: }
109:
110: /**
111: *
112: *
113: */
114: private void createFile() throws CMSException {
115: // create file english
116: File file = new FileImpl();
117: file.setBasePath(sFilePath);
118:
119: Content content = new ContentImpl();
120: content.setEncoding("UTF-8");
121: content.setTitle("English Title");
122: content.setDescription("English Description");
123: content.setBasePath(sFilePath + "/"
124: + Locale.ENGLISH.getLanguage());
125: content.setBytes("1234567890".getBytes());
126: content.setMimeType("image/gif");
127: file.setContent(Locale.ENGLISH, content);
128:
129: Command newFileCMD = service.getCommandFactory()
130: .createNewFileCommand(file, content);
131: service.execute(newFileCMD);
132:
133: // create content spanish
134: Content contentSP = new ContentImpl();
135: contentSP.setEncoding("UTF-8");
136: contentSP.setTitle("Spanish Title");
137: contentSP.setDescription("Spanish Description");
138: contentSP.setBasePath(sFilePath + "/es");
139: contentSP.setBytes("0987654321".getBytes());
140: contentSP.setMimeType("image/gif");
141: file.setContent(new Locale("es"), contentSP);
142:
143: Command newFileSPCMD = service.getCommandFactory()
144: .createNewFileCommand(file, contentSP);
145: service.execute(newFileSPCMD);
146: }
147: }
|