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.Command;
026: import org.jboss.portal.cms.impl.ContentImpl;
027: import org.jboss.portal.cms.impl.FileImpl;
028: import org.jboss.portal.cms.impl.jcr.JCRCompositeCommand;
029: import org.jboss.portal.cms.impl.jcr.composite.NewFileCommand;
030: import org.jboss.portal.cms.model.Content;
031: import org.jboss.portal.cms.model.File;
032: import org.jboss.portal.cms.util.RepositoryUtil;
033: import org.jboss.portal.test.cms.mock.RuntimeExceptionCommand;
034:
035: import javax.jcr.Item;
036: import javax.jcr.Node;
037: import javax.jcr.Session;
038: import java.util.Locale;
039:
040: /**
041: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
042: * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
043: * @author <a href="mailto:sohil.shah@jboss.com">Sohil Shah</a>
044: */
045: public class TestFileCreateFailed extends AbstractCommandTestCase {
046: String sFilePath = "/testdoc.gif";
047:
048: String sCopyToFilePath = "/testdoccopy.gif";
049:
050: // zip vars
051: String sZipPath = "/poop";
052:
053: String sZipFile = "resources/test/jcr/ziptest.zip";
054:
055: String sJPG = "/hibernate_logo.gif";
056:
057: String sText = "/training.txt";
058:
059: /**
060: *
061: *
062: */
063: public TestFileCreateFailed() {
064: }
065:
066: /**
067: *
068: *
069: */
070: public static TestSuite suite() throws Exception {
071: return createTestSuite(TestFileCreateFailed.class);
072: }
073:
074: /**
075: *
076: *
077: */
078: public void testFileCreateFailed() throws Exception {
079: Session session = null;
080:
081: session = RepositoryUtil.login(service.getRepository(),
082: "anonid", "");
083:
084: if (session.itemExists(sFilePath)) {
085: Item item = session.getItem(sFilePath);
086: Node parentNode = item.getParent();
087: item.remove();
088: parentNode.save();
089: }
090:
091: // create file english
092: File file = new FileImpl();
093: file.setBasePath(sFilePath);
094:
095: Content content = new ContentImpl();
096: content.setEncoding("UTF-8");
097: content.setTitle("English Title");
098: content.setDescription("English Description");
099: content.setBasePath(sFilePath + "/"
100: + Locale.ENGLISH.getLanguage());
101: content.setBytes("1234567890".getBytes());
102: content.setMimeType("image/gif");
103: file.setContent(Locale.ENGLISH, content);
104:
105: // save english file
106:
107: class TestCommand extends JCRCompositeCommand {
108: /** The serialVersionUID */
109: private static final long serialVersionUID = -4206026300826187649L;
110:
111: public TestCommand(File file, Content content) {
112: Command newFileCMD = new NewFileCommand(file, content);
113: commands.add(newFileCMD);
114: Command runtimeExceptionCMD = new RuntimeExceptionCommand();
115: commands.add(runtimeExceptionCMD);
116: }
117: }
118:
119: Command newFileCMD = new TestCommand(file, content);
120:
121: try {
122: service.execute(newFileCMD);
123: } catch (RuntimeException e) {
124: // Ignore
125: }
126:
127: assertFalse("File has been copied and not rolledback", session
128: .itemExists(sFilePath));
129: }
130: }
|