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.impl.jcr.util.VersionUtil;
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:
034: import javax.jcr.Node;
035: import javax.jcr.Property;
036: import javax.jcr.Session;
037: import java.util.Locale;
038:
039: /**
040: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
041: * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
042: * @author <a href="mailto:sohil.shah@jboss.com">Sohil Shah</a>
043: */
044: public class TestFileUpdate extends AbstractCommandTestCase {
045: String sFilePath = "/testdoc.gif";
046:
047: String sCopyToFilePath = "/testdoccopy.gif";
048:
049: // zip vars
050: String sZipPath = "/poop";
051:
052: String sZipFile = "resources/test/jcr/ziptest.zip";
053:
054: String sJPG = "/hibernate_logo.gif";
055:
056: String sText = "/training.txt";
057:
058: /**
059: *
060: *
061: */
062: public TestFileUpdate() {
063: }
064:
065: /**
066: *
067: *
068: */
069: public static TestSuite suite() throws Exception {
070: return createTestSuite(TestFileUpdate.class);
071: }
072:
073: /**
074: * Tests updating a file and its content.
075: *
076: * @throws Exception
077: */
078: public void testFileUpdate() throws Exception {
079: createFile();
080: Session session = RepositoryUtil.login(service.getRepository(),
081: "anonid", "");
082: Command getCMD = service.getCommandFactory()
083: .createFileGetCommand(sFilePath, Locale.ENGLISH);
084: File newfile = (File) service.execute(getCMD);
085: Content content = newfile.getContent();
086: content.setDescription("New English Description");
087: newfile.setContent(content.getLocale(), content);
088: // update file and make "LIVE"
089: Command cmdUpdate = service.getCommandFactory()
090: .createFileUpdateCommand(newfile);
091: service.execute(cmdUpdate);
092:
093: Command cmdVersion = service.getCommandFactory()
094: .createContentCreateNewVersionCommand(content, true);
095: service.execute(cmdVersion);
096:
097: boolean descriptionupdated = ((Property) session
098: .getItem("/testdoc.gif/en/portalcms:description"))
099: .getString().equals("New English Description");
100: assertTrue("Incorrect description for file object",
101: descriptionupdated);
102:
103: // version std out dump
104: VersionUtil
105: .print((Node) session.getItem(content.getBasePath()));
106: }
107:
108: /**
109: *
110: *
111: */
112: private void createFile() throws CMSException {
113: // create file english
114: File file = new FileImpl();
115: file.setBasePath(sFilePath);
116:
117: Content content = new ContentImpl();
118: content.setEncoding("UTF-8");
119: content.setTitle("English Title");
120: content.setDescription("English Description");
121: content.setBasePath(sFilePath + "/"
122: + Locale.ENGLISH.getLanguage());
123: content.setBytes("1234567890".getBytes());
124: content.setMimeType("image/gif");
125: file.setContent(Locale.ENGLISH, content);
126:
127: Command newFileCMD = service.getCommandFactory()
128: .createNewFileCommand(file, content);
129: service.execute(newFileCMD);
130:
131: // create content spanish
132: Content contentSP = new ContentImpl();
133: contentSP.setEncoding("UTF-8");
134: contentSP.setTitle("Spanish Title");
135: contentSP.setDescription("Spanish Description");
136: contentSP.setBasePath(sFilePath + "/es");
137: contentSP.setBytes("0987654321".getBytes());
138: contentSP.setMimeType("image/gif");
139: file.setContent(new Locale("es"), contentSP);
140:
141: Command newFileSPCMD = service.getCommandFactory()
142: .createNewFileCommand(file, contentSP);
143: service.execute(newFileSPCMD);
144: }
145: }
|