incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r159469 [2/2] - in incubator/graffito/trunk/jcr-mapping: ./ repotest/ repotest/repository/ repotest/repository/meta/ repotest/repository/namespaces/ repotest/repository/nodetypes/ repotest/versions/ repotest/versions/blobs/ repotest/versions/data/ repotest/versions/data/face/ repotest/versions/data/face/face/ repotest/versions/data/face/face/ab3b48a9b31be7d0a9c1c3b1/ repotest/workspaces/ repotest/workspaces/default/ repotest/workspaces/default/blobs/ repotest/workspaces/default/data/ repotest/workspaces/default/data/0b0d/ repotest/workspaces/default/data/0b0d/3027/ repotest/workspaces/default/data/0b0d/3027/7aea4a428ef08cb5da4876fe/ repotest/workspaces/default/data/cafe/ repotest/workspaces/default/data/cafe/babe/ repotest/workspaces/default/data/cafe/babe/cafebabecafebabecafebabe/ repotest/workspaces/default/data/dead/ repotest/workspaces/default/data/dead/beef/ repotest/workspaces/default/data/dead/beef/cafebabecafebabecafebabe/ repotest/workspaces/default/data/dead/beef/cafecafecafebabecafebabe/ repotest/workspaces/default/data/dead/beef/facebabecafebabecafebabe/ repotest/workspaces/default/index/ src/ src/conf/ src/conf/convertertest/ src/conf/repotest/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/portals/ src/java/org/apache/portals/graffito/ src/java/org/apache/portals/graffito/jcr/ src/java/org/apache/portals/graffito/jcr/converter/ src/java/org/apache/portals/graffito/jcr/converter/impl/ src/java/org/apache/portals/graffito/jcr/exception/ src/java/org/apache/portals/graffito/jcr/repository/ src/java/org/apache/portals/graffito/jcr/session/ src/java/org/apache/portals/graffito/jcr/session/impl/ src/test/ src/test/org/ src/test/org/apache/ src/test/org/apache/portals/ src/test/org/apache/portals/graffito/ src/test/org/apache/portals/graffito/jcr/ src/test/org/apache/portals/graffito/jcr/converter/ src/test/org/apache/portals/graffito/jcr/converter/impl/ src/test/org/apache/portals/graffito/jcr/repository/ src/test/org/apache/portals/graffito/jcr/session/ src/test/org/apache/portals/graffito/jcr/session/impl/ src/test/org/apache/portals/graffito/jcr/testconverter/ src/test/org/apache/portals/graffito/jcr/testmodel/
Date Wed, 30 Mar 2005 08:32:07 GMT
Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/session/impl/JcrSessionTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/session/impl/JcrSessionTest.java?view=auto&rev=159469
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/session/impl/JcrSessionTest.java
(added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/session/impl/JcrSessionTest.java
Wed Mar 30 00:31:54 2005
@@ -0,0 +1,153 @@
+/* ========================================================================
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.apache.portals.graffito.jcr.session.impl;
+
+import java.util.Date;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.converter.ConverterManager;
+import org.apache.portals.graffito.jcr.converter.impl.ConverterManagerImpl;
+import org.apache.portals.graffito.jcr.repository.RepositoryUtil;
+import org.apache.portals.graffito.jcr.session.JcrSession;
+import org.apache.portals.graffito.jcr.session.impl.JcrSessionImpl;
+import org.apache.portals.graffito.jcr.testmodel.Folder;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test JcrSession
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class JcrSessionTest extends TestCase
+{
+    private final static Log log = LogFactory.getLog(JcrSessionTest.class);
+
+    private JcrSession jcrSession;
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public JcrSessionTest(String testName)
+    {
+        super(testName);
+    }
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        ConverterManager converterManager = new ConverterManagerImpl("src/conf/convertertest/converters.xml");
+
+        RepositoryUtil.registerRepository("repositoryTest", "repotest/repository.xml", "repotest");
+        Repository repository = RepositoryUtil.getRepository("repositoryTest");
+        Session session = RepositoryUtil.login(repository, "anonymous", "");
+        jcrSession = new JcrSessionImpl(converterManager, repository, session);
+
+    }
+
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {
+        super.tearDown();
+
+    }
+
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new TestSuite(JcrSessionTest.class);
+    }
+
+    /**
+     * 
+     * Test for insert,update,retrieve POJO from/to jcr repository 
+     *
+     */
+    public void testInsertUpdateRetrieve()
+    {
+        try
+        {
+
+            if (jcrSession.itemExists("/test"))
+            {
+                jcrSession.remove("/test");
+            }
+
+            // --------------------------------------------------------------------------------
+            // Create and store a folder in the repository
+            // --------------------------------------------------------------------------------
+            Folder folder = new Folder();
+            folder.setCreationDate(new Date());
+            folder.setDescription("Folder description");
+            folder.setLastModified(new Date());
+            folder.setName("TestFolder");
+            folder.setTitle("Folder Title");
+
+            jcrSession.insert("/test", folder);
+
+            // --------------------------------------------------------------------------------
+            // Check the jcr node structure
+            // --------------------------------------------------------------------------------
+            Session session = jcrSession.getSession();
+            Node folderNode = (Node) session.getItem("/test");
+            assertNotNull("Folder node is null", folderNode);
+            assertTrue("Incorrect primary type", folderNode.getPrimaryNodeType().getName().equals("graffito:folder"));
+            assertTrue("Incorrect Name for '/test'", folderNode.getName().equals("test"));
+
+            Property description = folderNode.getProperty("graffito:description");
+            assertNotNull("Folder description  is null", description);
+            assertTrue("Incorrect description for '/test'", description.getString().equals("Folder
description"));
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
          
+            folder = (Folder) jcrSession.getObject(Folder.class, "/test");
+            assertNotNull("Folder object is null", folder);
+            assertTrue("Incorrect description for folder object", folder.getDescription().equals("Folder
description"));
+
+            // --------------------------------------------------------------------------------
+            // Update the object
+            // --------------------------------------------------------------------------------
          
+            folder.setDescription("new folder description");
+            jcrSession.update("/test", folder);
+
+            assertTrue("Incorrect description for folder object", ((Property) session.getItem("/test/graffito:description"))
+                    .getString().equals("new folder description"));
+
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Unable to find the repository : " + e);
+        }
+
+    }
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/DocumentConverter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/DocumentConverter.java?view=auto&rev=159469
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/DocumentConverter.java
(added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/DocumentConverter.java
Wed Mar 30 00:31:54 2005
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.apache.portals.graffito.jcr.testconverter;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+import javax.jcr.StringValue;
+
+import org.apache.portals.graffito.jcr.converter.Converter;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.repository.RepositoryUtil;
+import org.apache.portals.graffito.jcr.testmodel.Folder;
+
+/**
+ * Converter for a test folder
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe
</a>
+ * @version $Id: Exp $
+ */
+public class DocumentConverter implements Converter
+{
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.converter.Converter#insert(javax.jcr.Session,
java.lang.String, java.lang.Object)
+     */
+    public void insert(Session session, String path, Object object)  throws JcrMappingException
+    {
+        try 
+        {
+           Folder folder = (Folder) object; 
+           String parentPath = RepositoryUtil.getParentPath(path);
+           String nodeName = RepositoryUtil.getNodeName(path);
+               
+           Node parentNode = (Node) session.getItem(parentPath);
+           Node folderNode = parentNode.addNode(nodeName,"graffito:folder");
+           folderNode.setProperty("graffito:description", new StringValue(folder.getDescription()));
+           parentNode.save();
+            
+        }
+        catch(Exception e)
+        {
+            throw new JcrMappingException("Impossible to store the object at " + path, e);
+        }
+
+    }
+    
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.converter.Converter#update(javax.jcr.Session,
java.lang.String, java.lang.Object)
+     */
+    public void update(Session session, String path, Object object) throws JcrMappingException
+    {
+        try 
+        {
+           Folder folder = (Folder) object; 
+           Node folderNode = (Node) session.getItem(path);               
+           folderNode.setProperty("graffito:description", new StringValue(folder.getDescription()));
+           
+           folderNode.save();
+            
+        }
+        catch(Exception e)
+        {
+            throw new JcrMappingException("Impossible to store the object at " + path, e);
+        }
+    }
+    
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.converter.Converter#getObject(javax.jcr.Session,
java.lang.String)
+     */
+    public Object getObject(Session session, String path)  throws JcrMappingException
+    {
+        try 
+        {
+           Folder folder = new Folder(); 
+               
+           Node folderNode = (Node) session.getItem(path);
+           folder.setDescription(folderNode.getProperty("graffito:description").getString());
+           folder.setCreationDate(folderNode.getProperty("jcr:created").getDate().getTime());
+           return folder;
+           
+            
+        }
+        catch(Exception e)
+        {
+            throw new JcrMappingException("Impossible to store the object at " + path, e);
+        }
+    }
+
+}

Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/FolderConverter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/FolderConverter.java?view=auto&rev=159469
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/FolderConverter.java
(added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/FolderConverter.java
Wed Mar 30 00:31:54 2005
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.apache.portals.graffito.jcr.testconverter;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+import javax.jcr.StringValue;
+
+import org.apache.portals.graffito.jcr.converter.Converter;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.repository.RepositoryUtil;
+import org.apache.portals.graffito.jcr.testmodel.Folder;
+
+/**
+ * Converter for a test folder
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe
</a>
+ * @version $Id: Exp $
+ */
+public class FolderConverter implements Converter
+{
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.converter.Converter#insert(javax.jcr.Session,
java.lang.String, java.lang.Object)
+     */
+    public void insert(Session session, String path, Object object)  throws JcrMappingException
+    {
+        try 
+        {
+           Folder folder = (Folder) object; 
+           String parentPath = RepositoryUtil.getParentPath(path);
+           String nodeName = RepositoryUtil.getNodeName(path);
+               
+           Node parentNode = (Node) session.getItem(parentPath);
+           Node folderNode = parentNode.addNode(nodeName,"graffito:folder");
+           folderNode.setProperty("graffito:description", new StringValue(folder.getDescription()));
+           parentNode.save();
+            
+        }
+        catch(Exception e)
+        {
+            throw new JcrMappingException("Impossible to store the object at " + path, e);
+        }
+
+    }
+    
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.converter.Converter#update(javax.jcr.Session,
java.lang.String, java.lang.Object)
+     */
+    public void update(Session session, String path, Object object) throws JcrMappingException
+    {
+        try 
+        {
+           Folder folder = (Folder) object; 
+           Node folderNode = (Node) session.getItem(path);               
+           folderNode.setProperty("graffito:description", new StringValue(folder.getDescription()));
+           
+           folderNode.save();
+            
+        }
+        catch(Exception e)
+        {
+            throw new JcrMappingException("Impossible to store the object at " + path, e);
+        }
+    }
+    
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.converter.Converter#getObject(javax.jcr.Session,
java.lang.String)
+     */
+    public Object getObject(Session session, String path)  throws JcrMappingException
+    {
+        try 
+        {
+           Folder folder = new Folder(); 
+               
+           Node folderNode = (Node) session.getItem(path);
+           folder.setDescription(folderNode.getProperty("graffito:description").getString());
+           folder.setCreationDate(folderNode.getProperty("jcr:created").getDate().getTime());
+           return folder;
+           
+            
+        }
+        catch(Exception e)
+        {
+            throw new JcrMappingException("Impossible to store the object at " + path, e);
+        }
+    }
+
+}

Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/CmsObject.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/CmsObject.java?view=auto&rev=159469
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/CmsObject.java
(added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/CmsObject.java
Wed Mar 30 00:31:54 2005
@@ -0,0 +1,197 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.apache.portals.graffito.jcr.testmodel;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * CmsObject test
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ * 
+ * 
+ */
+public class CmsObject
+{
+    public static final long serialVersionUID = 1;
+    
+    protected Long objectId;
+        
+    protected Long parentId;  //parent folder id
+    protected Folder parentFolder;
+    
+    protected String name;
+    
+    protected String description;
+    protected String title;
+    protected Date creationDate;
+    protected Date lastModified;
+    
+    /** 
+     * Special attribute telling OJB the object's concrete type.
+     *  
+     */    
+    protected String ojbConcreteClass; 
+       
+    /**
+     * Constructor
+     */
+    public CmsObject()
+    {
+        ojbConcreteClass = this.getClass().getName();       
+    }
+    
+    
+        
+    /**
+     * @return Returns the parentFolder.
+     */
+    public Folder getParentFolder()
+    {
+        return parentFolder;
+    }
+
+    /**
+     * @param parentFolder The parentFolder to set.
+     */
+    public void setParentFolder(Folder parentFolder)
+    {
+        this.parentFolder = parentFolder;
+    }
+
+    /**
+     * @param parentId The parentId to set.
+     */
+    public void setParentId(Long parentId)
+    {
+        this.parentId = parentId;
+    }
+
+    /**
+     * @return Returns the parentId.
+     */
+    public Long getParentId()
+    {
+        return parentId;
+    }
+       
+    
+    /**
+     * @return Returns the objectId.
+     */
+    public Long getObjectId()
+    {
+        return objectId;
+    }
+
+    /**
+     * @param objectId The objectId to set.
+     */
+    public void setObjectId(Long objectId)
+    {
+        this.objectId = objectId;
+    }
+    
+
+    /* 
+     * @see org.apache.portals.graffito.model.CmsObject#getName()
+     */
+    public String getName()
+    {
+        return this.name;
+    }
+
+    /* 
+     * @see org.apache.portals.graffito.model.CmsObject#setName(java.lang.String)
+     */
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    
+    /* 
+     * @see org.apache.portals.graffito.model.CmsObject#getCreationDate()
+     */
+    public Date getCreationDate()
+    {
+        return this.creationDate;
+    }
+
+    /* 
+     * @see org.apache.portals.graffito.model.CmsObject#setCreationDate(java.util.Date)
+     */
+    public void setCreationDate(Date creationDate)
+    {
+        this.creationDate = creationDate;
+    }
+
+    /* 
+     * @see org.apache.portals.graffito.model.CmsObject#getLastModified()
+     */
+    public Date getLastModified()
+    {
+        return this.lastModified;
+    }
+
+    /* 
+     * @see org.apache.portals.graffito.model.CmsObject#setLastModified(java.util.Date)
+     */
+    public void setLastModified(Date lastModified)
+    {
+        this.lastModified = lastModified;
+    }
+
+    /* 
+     * @see org.apache.portals.graffito.model.CmsObject#getDescription()
+     */
+    public String getDescription()
+    {
+        return this.description;
+    }
+
+    /* 
+     * @see org.apache.portals.graffito.model.CmsObject#setDescription(java.lang.String)
+     */
+    public void setDescription(String v)
+    {
+        this.description = v;
+    }
+
+    /** 
+     * @see org.apache.portals.graffito.model.CmsObject#getTitle()
+     */
+    public String getTitle()
+    {
+        return this.title;
+    }
+
+    /** 
+     * @see org.apache.portals.graffito.model.CmsObject#setTitle(java.lang.String)
+     */    
+    public void setTitle(String title)
+    {
+        this.title = title;
+    }
+    
+    
+ 
+    
+    
+}

Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Folder.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Folder.java?view=auto&rev=159469
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Folder.java
(added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Folder.java
Wed Mar 30 00:31:54 2005
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.apache.portals.graffito.jcr.testmodel;
+
+import java.util.List;
+
+
+
+
+/**
+ * CMS Folder Test
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ * @version $Id: Folder.java,v 1.1 2004/12/22 20:36:59 christophe Exp $
+ */
+public class Folder extends CmsObject 
+{
+
+    protected List folders;
+    protected List documents;
+    
+    /**
+     * @see org.apache.portals.graffito.model.Folder#getDocuments()
+     */
+    public List getDocuments()
+    {
+        return documents;
+    }
+
+    /**
+     * @see org.apache.portals.graffito.model.Folder#getFolders()
+     */
+    public List getFolders()
+    {
+        return folders;
+    }
+    
+}
+



Mime
View raw message