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;
023:
024: import junit.framework.TestSuite;
025: import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
026: import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
027: import org.apache.jackrabbit.name.QName;
028: import org.jboss.portal.cms.impl.jcr.jackrabbit.JackrabbitJCRService;
029: import org.jboss.portal.cms.util.RepositoryUtil;
030: import org.jboss.portal.common.util.CLResourceLoader;
031: import org.jboss.portal.common.util.LoaderResource;
032:
033: import javax.jcr.Node;
034: import javax.jcr.Repository;
035: import javax.jcr.Session;
036: import javax.jcr.Workspace;
037: import javax.jcr.nodetype.NodeTypeManager;
038:
039: /**
040: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
041: * @version $Revision: 6653 $
042: */
043: public class JackrabbitTestCase extends AbstractCMSTestCase {
044:
045: public JackrabbitTestCase() {
046: }
047:
048: private JackrabbitJCRService jcr;
049:
050: public void setUp() throws Exception {
051: super .setUp();
052:
053: // Load config
054: LoaderResource res = new CLResourceLoader()
055: .getResource("jcr/repository.xml");
056: String config = res.asString();
057:
058: jcr = new JackrabbitJCRService();
059: jcr.setRepositoryName("repo");
060: jcr.setConfig(config);
061: jcr.setHomeDir("repotest");
062: jcr.start();
063: }
064:
065: public void tearDown() throws Exception {
066: jcr.stop();
067: jcr = null;
068: super .tearDown();
069: }
070:
071: public void testRepository() throws Exception {
072: Repository repo = jcr.getRepository();
073: assertNotNull(repo);
074:
075: //
076: Session session = null;
077: try {
078: session = jcr.login("anonid", "");
079: Workspace wosp = session.getWorkspace();
080: NodeTypeManager mgr = wosp.getNodeTypeManager();
081: NodeTypeRegistry reg = ((NodeTypeManagerImpl) mgr)
082: .getNodeTypeRegistry();
083: assertTrue(reg.isRegistered(new QName(
084: "http://jboss.org/jcr/portalcms", "folder")));
085: assertTrue(reg.isRegistered(new QName(
086: "http://jboss.org/jcr/portalcms", "file")));
087: assertTrue(reg.isRegistered(new QName(
088: "http://jboss.org/jcr/portalcms", "content")));
089:
090: //
091: Node node = session.getRootNode();
092: assertNotNull(node);
093: } finally {
094: RepositoryUtil.safeLogout(session);
095: }
096:
097: //
098: try {
099: session = jcr.login("anonid", "");
100:
101: //
102: Node node = session.getRootNode();
103: assertNotNull(node);
104:
105: //
106: node.setProperty("abc", "abc");
107: session.save();
108: } finally {
109: RepositoryUtil.safeLogout(session);
110: }
111:
112: //
113: try {
114: session = jcr.login("anonid", "");
115:
116: //
117: Node node = session.getRootNode();
118: assertEquals("abc", node.getProperty("abc").getString());
119: } finally {
120: RepositoryUtil.safeLogout(session);
121: }
122: }
123:
124: public static TestSuite suite() throws Exception {
125: return createTestSuite(TestRepositoryBootStrap.class);
126: }
127: }
|