Author: sascharodekamp
Date: Thu Aug 11 10:59:22 2011 New Revision: 1156568 URL: http://svn.apache.org/viewvc?rev=1156568&view=rev Log: Update the JCR Test implementation Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JcrTests.java (with props) Removed: ofbiz/branches/jackrabbit20100709/applications/content/src/org/ofbiz/content/test/JcrTests.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/NodePropertiesJackrabbit.java Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/JcrUtil.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JcrUtilJackrabbit.java ofbiz/branches/jackrabbit20100709/framework/jcr/testdef/jcrtests.xml Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java?rev=1156568&r1=1156567&r2=1156568&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java Thu Aug 11 10:59:22 2011 @@ -17,10 +17,18 @@ public class ContentWriterJackrabbit imp private ObjectContentManager ocm = null; + /** + * + * @param ocm + */ public ContentWriterJackrabbit(ObjectContentManager ocm) { this.ocm = ocm; } + /* + * (non-Javadoc) + * @see org.ofbiz.jcr.access.ContentWriter#storeContentObject(org.ofbiz.jcr.orm.OfbizRepositoryMapping) + */ @Override public void storeContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException { if (orm == null) { @@ -83,12 +91,20 @@ public class ContentWriterJackrabbit imp this.saveState(); } + /* + * (non-Javadoc) + * @see org.ofbiz.jcr.access.ContentWriter#updateContentObject(org.ofbiz.jcr.orm.OfbizRepositoryMapping) + */ @Override public void updateContentObject(OfbizRepositoryMapping orm) throws ObjectContentManagerException { ocm.update(orm); this.saveState(); } + /* + * (non-Javadoc) + * @see org.ofbiz.jcr.access.ContentWriter#removeContentObject(java.lang.String) + */ @Override public void removeContentObject(String nodePath) throws ObjectContentManagerException { ocm.remove(nodePath); Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java?rev=1156568&r1=1156567&r2=1156568&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java Thu Aug 11 10:59:22 2011 @@ -79,7 +79,7 @@ public class RepositoryAccessJackrabbit */ @Override public void closeAccess() { - if (this.ocm != null) { + if (this.ocm != null && this.ocm.getSession().isLive()) { this.ocm.logout(); } this.ocm = null; Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JcrTests.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JcrTests.java?rev=1156568&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JcrTests.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JcrTests.java Thu Aug 11 10:59:22 2011 @@ -0,0 +1,122 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. + */ +package org.ofbiz.jcr.test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.jcr.access.RepositoryAccess; +import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit; +import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFile; +import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFolder; +import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitNews; +import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitResource; +import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit; +import org.ofbiz.service.testtools.OFBizTestCase; + +public class JcrTests extends OFBizTestCase { + + protected GenericValue userLogin = null; + RepositoryAccess repositoryAccess = null; + + public JcrTests(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system")); + repositoryAccess = new RepositoryAccessJackrabbit(userLogin); + } + + @Override + protected void tearDown() throws Exception { + repositoryAccess.closeAccess(); + } + + public void testRepositoryConstructor() throws Exception { + assertNotNull(repositoryAccess); + } + + public void testCreateRepositoryNewsNode() throws Exception { + OfbizRepositoryMappingJackrabbitNews orm = new OfbizRepositoryMappingJackrabbitNews(); + assertNotNull(orm); + orm.setPath("/news/today"); + orm.setLanguage("en"); + orm.setContent("Hello World"); + orm.setTitle("News of Today"); + + repositoryAccess.storeContentObject(orm); + } + + public void testReadRepositoryNewsNode() throws Exception { + OfbizRepositoryMappingJackrabbitNews orm = (OfbizRepositoryMappingJackrabbitNews) repositoryAccess.getContentObject("/news/today"); + assertNotNull(orm); + + assertEquals(orm.getContent(), "Hello World"); + } + + public void testUpdateRepositoryNewsNode() throws Exception { + OfbizRepositoryMappingJackrabbitNews orm = (OfbizRepositoryMappingJackrabbitNews) repositoryAccess.getContentObject("/news/today"); + assertNotNull(orm); + + orm.setContent("Hello Visitors"); + repositoryAccess.updateContentObject(orm); + } + + public void testRemoveRepositoryNewsNode() throws Exception { + repositoryAccess.removeContentObject("/news/today"); + } + + /* + * Test the File upload + */ + public void testCreateRepositoryFileNode() throws Exception { + File f = new File("stopofbiz.sh"); + assertTrue(f.exists()); + + InputStream file = new FileInputStream(f); + + OfbizRepositoryMappingJackrabbitResource ormResource = new OfbizRepositoryMappingJackrabbitResource(); + ormResource.setData(file); + + OfbizRepositoryMappingJackrabbitFile ormFile = new OfbizRepositoryMappingJackrabbitFile(); + ormFile.setResource(ormResource); + // have to be relative + ormFile.setPath("testFile"); + + OfbizRepositoryMappingJackrabbitFolder ormFolder = new OfbizRepositoryMappingJackrabbitFolder(); + ormFolder.setPath("/fileHome"); + ormFolder.addChild(ormFile); + + repositoryAccess.storeContentObject(ormFolder); + } + + public void testRemoveRepositoryFileNode() throws Exception { + repositoryAccess.removeContentObject("/fileHome"); + } + + public void testListRepositoryNodes() throws Exception { + assertNotNull(JcrUtilJackrabbit.getRepositoryNodes(userLogin, null)); + } + +} \ No newline at end of file Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JcrTests.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/JcrUtil.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/JcrUtil.java?rev=1156568&r1=1156567&r2=1156568&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/JcrUtil.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/JcrUtil.java Thu Aug 11 10:59:22 2011 @@ -1,5 +1,12 @@ package org.ofbiz.jcr.util; +import java.util.List; +import java.util.Map; + +import javax.jcr.RepositoryException; + +import org.ofbiz.entity.GenericValue; + public interface JcrUtil { } Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JcrUtilJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JcrUtilJackrabbit.java?rev=1156568&r1=1156567&r2=1156568&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JcrUtilJackrabbit.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/util/jackrabbit/JcrUtilJackrabbit.java Thu Aug 11 10:59:22 2011 @@ -18,72 +18,73 @@ import org.ofbiz.jcr.util.JcrUtil; public class JcrUtilJackrabbit implements JcrUtil { - public static final String module = JcrUtilJackrabbit.class.getName(); + public static final String module = JcrUtilJackrabbit.class.getName(); - /** - * Just a dummy method to list all nodes in the repository. - * - * @param startNodePath - * @return - * @throws RepositoryException - */ - public static List<Map<String, String>> getRepositoryNodes(GenericValue userLogin, String startNodePath) throws RepositoryException { - List<Map<String, String>> returnList = null; - Session session = JCRFactoryUtil.getSession(); - - try { - returnList = getRepositoryNodes(session, startNodePath); - } catch (RepositoryException e) { - throw new RepositoryException(e); - } finally { - session.logout(); - } - - return returnList; - } - - /** - * Just a dummy method to list all nodes in the repository. - * - * @param startNodePath - * @return - * @throws RepositoryException - */ - private static List<Map<String, String>> getRepositoryNodes(Session session, String startNodePath) throws RepositoryException { - Node node = null; - - List<Map<String, String>> nodeList = FastList.newInstance(); - if (UtilValidate.isEmpty(startNodePath)) { - node = session.getRootNode(); - } else { - node = session.getNode(startNodePath); - } - - NodeIterator nodeIterator = node.getNodes(); - Map<String, String> nodeEntry = null; - while (nodeIterator.hasNext()) { - Node n = nodeIterator.nextNode(); - - // recursion - get all subnodes and add the results to our nodeList - if (n.getNodes().hasNext()) { - nodeList.addAll(getRepositoryNodes(session, n.getPath())); - } - - nodeEntry = FastMap.newInstance(); - - // if the node path is a jcr:system node than ignore this - // entry - if (n.getPath().startsWith("/jcr:system")) { - continue; - } - - nodeEntry.put("path", n.getPath()); + /** + * A method to list all nodes in the repository. The result List contains + * the node path and the node type. + * + * @param startNodePath + * @return + * @throws RepositoryException + */ + public static List<Map<String, String>> getRepositoryNodes(GenericValue userLogin, String startNodePath) throws RepositoryException { + List<Map<String, String>> returnList = null; + Session session = JCRFactoryUtil.getSession(); + + try { + returnList = getRepositoryNodes(session, startNodePath); + } catch (RepositoryException e) { + throw new RepositoryException(e); + } finally { + session.logout(); + } + + return returnList; + } + + /** + * Just a dummy method to list all nodes in the repository. + * + * @param startNodePath + * @return + * @throws RepositoryException + */ + private static List<Map<String, String>> getRepositoryNodes(Session session, String startNodePath) throws RepositoryException { + Node node = null; + + List<Map<String, String>> nodeList = FastList.newInstance(); + if (UtilValidate.isEmpty(startNodePath)) { + node = session.getRootNode(); + } else { + node = session.getNode(startNodePath); + } + + NodeIterator nodeIterator = node.getNodes(); + Map<String, String> nodeEntry = null; + while (nodeIterator.hasNext()) { + Node n = nodeIterator.nextNode(); + + // recursion - get all subnodes and add the results to our nodeList + if (n.getNodes().hasNext()) { + nodeList.addAll(getRepositoryNodes(session, n.getPath())); + } + + nodeEntry = FastMap.newInstance(); + + // if the node path is a jcr:system node than ignore this + // entry + if (n.getPath().startsWith("/jcr:system")) { + continue; + } + + nodeEntry.put("path", n.getPath()); - nodeEntry.put("primaryNodeType", n.getPrimaryNodeType().getName()); + nodeEntry.put("primaryNodeType", n.getPrimaryNodeType().getName()); - nodeList.add(nodeEntry); - } + nodeList.add(nodeEntry); + } - return nodeList; - } + return nodeList; + } } Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/testdef/jcrtests.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/testdef/jcrtests.xml?rev=1156568&r1=1156567&r2=1156568&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/testdef/jcrtests.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/testdef/jcrtests.xml Thu Aug 11 10:59:22 2011 @@ -29,6 +29,8 @@ --> - <test-case case-name="jcr-tests"><junit-test-suite class-name="org.ofbiz.content.test.JcrTests"/></test-case> + <test-case case-name="jcr-tests"> + <junit-test-suite class-name="org.ofbiz.jcr.test.JcrTests"/> + </test-case> </test-suite> \ No newline at end of file |
Free forum by Nabble | Edit this page |