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.model.Content;
029: import org.jboss.portal.cms.model.File;
030: import org.jboss.portal.cms.util.NodeUtil;
031: import org.jboss.portal.cms.util.RepositoryUtil;
032:
033: import javax.jcr.Node;
034: import javax.jcr.Session;
035: import java.util.Locale;
036:
037: /**
038: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
039: * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
040: * @author <a href="mailto:sohil.shah@jboss.com">Sohil Shah</a>
041: */
042: public class TestFileCreate extends AbstractCommandTestCase {
043: String sFilePath = "/testdoc.gif";
044:
045: String sCopyToFilePath = "/testdoccopy.gif";
046:
047: // zip vars
048: String sZipPath = "/poop";
049:
050: String sZipFile = "resources/test/jcr/ziptest.zip";
051:
052: String sJPG = "/hibernate_logo.gif";
053:
054: String sText = "/training.txt";
055:
056: /**
057: *
058: *
059: */
060: public TestFileCreate() {
061: }
062:
063: /**
064: *
065: *
066: */
067: public static TestSuite suite() throws Exception {
068: return createTestSuite(TestFileCreate.class);
069: }
070:
071: /**
072: *
073: *
074: */
075: public void testFileCreate() throws Exception {
076: // create file english
077: File file = new FileImpl();
078: file.setBasePath(sFilePath);
079:
080: Content content = new ContentImpl();
081: content.setEncoding("UTF-8");
082: content.setTitle("English Title");
083: content.setDescription("English Description");
084: content.setBasePath(sFilePath + "/"
085: + Locale.ENGLISH.getLanguage());
086: content.setBytes("1234567890".getBytes());
087: content.setMimeType("image/gif");
088: file.setContent(Locale.ENGLISH, content);
089:
090: // save english file
091: Command saveFileCMD = service.getCommandFactory()
092: .createFileSaveCommand(file);
093: service.execute(saveFileCMD);
094:
095: //save english content
096: Command saveContentCMD = service.getCommandFactory()
097: .createContentSaveCommand(file);
098: service.execute(saveContentCMD);
099:
100: // version the english content node
101: Command verCMD = service.getCommandFactory()
102: .createContentCreateNewVersionCommand(content, true);
103: service.execute(verCMD);
104:
105: // create content spanish
106: Content contentSP = new ContentImpl();
107: contentSP.setEncoding("UTF-8");
108: contentSP.setTitle("Spanish Title");
109: contentSP.setDescription("Spanish Description");
110: contentSP.setBasePath(sFilePath + "/es");
111: contentSP.setBytes("0987654321".getBytes());
112: contentSP.setMimeType("image/gif");
113: file.setContent(new Locale("es"), contentSP);
114:
115: //save spanish content
116: Command saveSPContentCMD = service.getCommandFactory()
117: .createContentSaveCommand(file);
118: service.execute(saveSPContentCMD);
119:
120: // version the spanish content node
121: Command verSPCMD = service.getCommandFactory()
122: .createContentCreateNewVersionCommand(contentSP, true);
123: service.execute(verSPCMD);
124:
125: Session session = null;
126:
127: session = RepositoryUtil.login(service.getRepository(),
128: "anonid", "");
129: Node fileNode = (Node) session.getItem(sFilePath);
130: assertEquals("Name incorrect", NodeUtil.getNodeName(file
131: .getBasePath()), fileNode.getName());
132:
133: Node contentNodeEN = fileNode.getNode(Locale.ENGLISH
134: .getLanguage());
135: assertEquals("Encoding Incorrect", content.getEncoding(),
136: contentNodeEN.getProperty("jcr:encoding").getString());
137: assertEquals("Mimetype Incorrect", content.getMimeType(),
138: contentNodeEN.getProperty("jcr:mimeType").getString());
139: assertEquals("Language Incorrect", content.getLocale()
140: .getLanguage(), contentNodeEN.getProperty(
141: "portalcms:language").getString());
142: assertEquals("Title Incorrect", content.getTitle(),
143: contentNodeEN.getProperty("portalcms:title")
144: .getString());
145: assertEquals("Desc Incorrect", content.getDescription(),
146: contentNodeEN.getProperty("portalcms:description")
147: .getString());
148:
149: Node contentNodeSP = fileNode.getNode("es");
150: assertEquals("Encoding Incorrect", contentSP.getEncoding(),
151: contentNodeSP.getProperty("jcr:encoding").getString());
152: assertEquals("Mimetype Incorrect", contentSP.getMimeType(),
153: contentNodeSP.getProperty("jcr:mimeType").getString());
154: assertEquals("Language Incorrect", contentSP.getLocale()
155: .getLanguage(), contentNodeSP.getProperty(
156: "portalcms:language").getString());
157: assertEquals("Title Incorrect", contentSP.getTitle(),
158: contentNodeSP.getProperty("portalcms:title")
159: .getString());
160: assertEquals("Desc Incorrect", contentSP.getDescription(),
161: contentNodeSP.getProperty("portalcms:description")
162: .getString());
163:
164: session.logout();
165: }
166: }
|