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.Locale;
033:
034: /**
035: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
036: * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
037: * @author <a href="mailto:sohil.shah@jboss.com">Sohil Shah</a>
038: */
039: public class TestFileGetVersion extends AbstractCommandTestCase {
040: String sFilePath = "/testdoc.gif";
041:
042: String sCopyToFilePath = "/testdoccopy.gif";
043:
044: // zip vars
045: String sZipPath = "/poop";
046:
047: String sZipFile = "resources/test/jcr/ziptest.zip";
048:
049: String sJPG = "/hibernate_logo.gif";
050:
051: String sText = "/training.txt";
052:
053: /**
054: *
055: *
056: */
057: public TestFileGetVersion() {
058: }
059:
060: /**
061: *
062: *
063: */
064: public static TestSuite suite() throws Exception {
065: return createTestSuite(TestFileGetVersion.class);
066: }
067:
068: /** Tests retrieval of a specific version by version number. */
069: public void testFileGetVersion() throws CMSException {
070: createFile();
071:
072: // get specific file version
073: Command getCMDV = service.getCommandFactory()
074: .createFileGetCommand(sFilePath, "1.0", Locale.ENGLISH);
075: File Vnewfile = (File) service.execute(getCMDV);
076: assertTrue("Incorrect version number for file object", Vnewfile
077: .getContent().getVersionNumber().equals("1.0"));
078:
079: //Update this file and create a new version that goes "LIVE"
080: this .updateFile(Vnewfile);
081:
082: //Make sure a new version 1.1 is created and thats the one that is "LIVE"
083: getCMDV = service.getCommandFactory().createFileGetCommand(
084: sFilePath, Locale.ENGLISH);
085: Vnewfile = (File) service.execute(getCMDV);
086: assertTrue("Incorrect version number for file object", Vnewfile
087: .getContent().getVersionNumber().equals("1.1"));
088:
089: //Now switch to 1.0 as being the "LIVE" version
090: Command makeLiveCommand = service.getCommandFactory()
091: .createMakeLiveVersionCommand(sFilePath,
092: Locale.ENGLISH.getLanguage(), "1.0");
093: String liveVersion = (String) service.execute(makeLiveCommand);
094: assertEquals("Incorrect version number is 'LIVE'", liveVersion,
095: "1.0");
096:
097: //Verify that 1.0 is the "LIVE" version and not 1.1
098: getCMDV = service.getCommandFactory().createFileGetCommand(
099: sFilePath, Locale.ENGLISH);
100: Vnewfile = (File) service.execute(getCMDV);
101: assertEquals("Incorrect version number for file object ("
102: + liveVersion + ")", Vnewfile.getContent()
103: .getVersionNumber(), liveVersion);
104: }
105:
106: /**
107: *
108: *
109: */
110: private void createFile() throws CMSException {
111: // create file english
112: File file = new FileImpl();
113: file.setBasePath(sFilePath);
114:
115: Content content = new ContentImpl();
116: content.setEncoding("UTF-8");
117: content.setTitle("English Title");
118: content.setDescription("English Description");
119: content.setBasePath(sFilePath + "/"
120: + Locale.ENGLISH.getLanguage());
121: content.setBytes("1234567890".getBytes());
122: content.setMimeType("image/gif");
123: file.setContent(Locale.ENGLISH, content);
124:
125: Command newFileCMD = service.getCommandFactory()
126: .createNewFileCommand(file, content);
127: service.execute(newFileCMD);
128:
129: // create content spanish
130: Content contentSP = new ContentImpl();
131: contentSP.setEncoding("UTF-8");
132: contentSP.setTitle("Spanish Title");
133: contentSP.setDescription("Spanish Description");
134: contentSP.setBasePath(sFilePath + "/es");
135: contentSP.setBytes("0987654321".getBytes());
136: contentSP.setMimeType("image/gif");
137: file.setContent(new Locale("es"), contentSP);
138:
139: Command newFileSPCMD = service.getCommandFactory()
140: .createNewFileCommand(file, contentSP);
141: service.execute(newFileSPCMD);
142: }
143:
144: /** @throws CMSException */
145: private void updateFile(File updatedFile) throws CMSException {
146: Command updateFileCMD = service.getCommandFactory()
147: .createUpdateFileCommand(updatedFile,
148: updatedFile.getContent(), true);
149: service.execute(updateFileCMD);
150: }
151: }
|