incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r225708 - in /incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services: ./ core/ core/impl/ dm/ dm/impl/
Date Thu, 28 Jul 2005 05:46:25 GMT
Author: clombart
Date: Wed Jul 27 22:46:20 2005
New Revision: 225708

URL: http://svn.apache.org/viewcvs?rev=225708&view=rev
Log:
Review object model (see GRFT-25)

Added:
    incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/
    incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/
    incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/
    incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentModelService.java
    incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentSearchService.java
    incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentServerService.java
    incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentVersionService.java
    incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/dm/
    incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/dm/impl/
    incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/dm/impl/TestDocumentModelService.java

Added: incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentModelService.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentModelService.java?rev=225708&view=auto
==============================================================================
--- incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentModelService.java (added)
+++ incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentModelService.java Wed Jul 27 22:46:20 2005
@@ -0,0 +1,571 @@
+/*
+ * 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.services.core.impl;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.exception.ContentManagementException;
+import org.apache.portals.graffito.model.core.CmsObject;
+import org.apache.portals.graffito.model.core.Content;
+import org.apache.portals.graffito.model.core.Folder;
+import org.apache.portals.graffito.model.core.Link;
+import org.apache.portals.graffito.persistence.impl.PersistenceSupportedTestCase;
+import org.apache.portals.graffito.services.core.ContentModelService;
+import org.apache.portals.graffito.util.StreamUtil;
+
+
+/**
+ * Test Persistence Service
+ * 
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ * 
+ * @version $Id: TestContentModelService.java,v 1.1 2004/12/22 20:37:02 christophe Exp $
+ *  
+ */
+public class TestContentModelService extends PersistenceSupportedTestCase
+{
+    private final static Log log = LogFactory.getLog(TestContentModelService.class);
+
+    private static final int MAX_SUB_LEVEL = 3;
+
+    private static final int NUMBER_OF_FOLDERS = 5;
+
+    private static final int NUMBER_OF_CONTENTS = 15;
+
+    private ContentModelService modelService;
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {        
+    	super.setUp();    	
+    	modelService = (ContentModelService) ctx.getBean("org.apache.portals.graffito.services.core.ContentModelService");
+    	
+    }
+    
+   
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {        
+        super.tearDown();
+    }
+
+    /** 
+     * @return The tes suite
+     */
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new TestSuite(TestContentModelService.class);
+    }
+
+
+    /**
+     * Simple unit on Folder objects : create, add, get, update, remove
+     * 
+     * @throws Exception generate by one of the unit test method calls
+     */
+    public void testFolder() throws Exception
+    {
+
+        
+        log.info("  ************************ Testing Content Model service - Folder  Object ****************************");
+        // ---------------------------------------------------------------------------------------
+        // Create a folder
+        // ---------------------------------------------------------------------------------------
+        Folder folder = modelService.createFolder();
+        folder.setCreationDate(new Timestamp(System.currentTimeMillis()));
+        folder.setLastModified(new Timestamp(System.currentTimeMillis()));
+        folder.setName("folder1");
+        folder.setUri("/graffitotest/folder1");
+
+        // ---------------------------------------------------------------------------------------
+        // Add a folder
+        // ---------------------------------------------------------------------------------------        
+        log.info("Add folder");
+        modelService.addFolder(folder);
+
+        // ---------------------------------------------------------------------------------------
+        // Get a folder
+        // ---------------------------------------------------------------------------------------                
+        log.info("Get folder");
+        folder = modelService.getFolder("/graffitotest/folder1");
+        assertNotNull("/graffitotest/folder1 is null", folder);
+        assertTrue("Invalid name for /graffitotest/folder1", folder.getName().equals("folder1"));
+
+        // ---------------------------------------------------------------------------------------
+        // Update a folder
+        // ---------------------------------------------------------------------------------------        
+        log.info("Update folder");
+        folder.setProperty("test", "test value");
+        modelService.updateFolder(folder);
+        
+        // ---------------------------------------------------------------------------------------
+        // Get a modified folder
+        // ---------------------------------------------------------------------------------------                
+        log.info("Get modified folder");
+        folder = modelService.getFolder("/graffitotest/folder1");
+        assertNotNull("/graffitotest/folder1 is null", folder);
+        assertTrue("Invalid title for /folder1", folder.getProperty("test").equals("test value"));
+
+        // ---------------------------------------------------------------------------------------
+        // Get folders
+        // ---------------------------------------------------------------------------------------                
+        log.info("Get folders");
+        Collection folders = modelService.getFolders("/graffitotest");
+        assertNotNull("Folders is null", folders);
+        assertTrue("Invalid number of folders in  /graffitotest",  folders.size() == 1);
+        
+        // ---------------------------------------------------------------------------------------
+        // Remove a folder
+        // ---------------------------------------------------------------------------------------                
+        log.info("Remove folder");
+        modelService.removeFolder(folder);
+
+    }
+
+    
+    /**
+     * 
+     * Simple unit on Link objects : create, add, get, update, remove
+     * 
+     */
+    public void testLink() throws Exception
+    {
+
+        log.info("  ************************ Testing Content Model service - Link  Object ****************************");
+
+        // ---------------------------------------------------------------------------------------
+        // Create a folder
+        // ---------------------------------------------------------------------------------------
+        Folder folder = modelService.createFolder();
+        folder.setCreationDate(new Timestamp(System.currentTimeMillis()));
+        folder.setLastModified(new Timestamp(System.currentTimeMillis()));
+        
+        folder.setName("folder1");
+        folder.setUri("/graffitotest/folder1");
+
+        // ---------------------------------------------------------------------------------------
+        // Add a folder
+        // ---------------------------------------------------------------------------------------        
+        log.info("Add folder");
+        modelService.addFolder(folder);
+
+        // ---------------------------------------------------------------------------------------
+        // Create a Link
+        // ---------------------------------------------------------------------------------------
+        Link link = modelService.createLink();
+        link.setCreationDate(new Timestamp(System.currentTimeMillis()));
+        link.setLastModified(new Timestamp(System.currentTimeMillis()));
+
+        link.setName("Link1");
+        link.setUri("/graffitotest/link1");
+        link.setTargetCmsObject(folder);
+
+        // ---------------------------------------------------------------------------------------
+        // Add a Link
+        // ---------------------------------------------------------------------------------------        
+        log.info("Add Link");
+        modelService.addLink(link);        
+                
+        // ---------------------------------------------------------------------------------------
+        // Get a link
+        // ---------------------------------------------------------------------------------------                
+        log.info("Get Link");
+        link = modelService.getLink("/graffitotest/link1");
+        assertNotNull("/graffitotest/link1 is null", link);      
+        assertTrue("Invalid linked object for /graffitotest/link1", link.getTargetCmsObject().getUri().equals("/graffitotest/folder1"));
+        
+        // ---------------------------------------------------------------------------------------
+        // Update a link
+        // ---------------------------------------------------------------------------------------        
+        log.info("Update link");
+        link.setProperty("test","test value");
+        modelService.updateLink(link);
+
+        // ---------------------------------------------------------------------------------------
+        // Get a modified link
+        // ---------------------------------------------------------------------------------------                
+        log.info("Get modified link");
+        link = modelService.getLink("/graffitotest/link1");
+        assertNotNull("/graffitotest/link1 is null", link);
+        assertTrue("Invalid title for /graffitotest/link1", link.getProperty("test").equals("test value"));
+
+        // ---------------------------------------------------------------------------------------
+        // Remove folder & link
+        // ---------------------------------------------------------------------------------------                
+        log.info("Remove folder & link");
+        modelService.removeFolder(folder);
+        modelService.removeLink(link);
+        
+    }
+    
+    /**
+     * Simple test on content object
+     *
+     */
+    public void testContent()
+    {
+
+        try
+        {
+            log.info(
+            "  ************************ Testing Content Model service - Content object  ****************************");
+            
+
+            // ---------------------------------------------------------------------------------------
+            // Create a content
+            // ---------------------------------------------------------------------------------------
+            
+            Content content = modelService.createContent();
+            content.setProperty("description", "this is the content description");
+            content.setCreationDate(new Timestamp(System.currentTimeMillis()));
+            content.setLastModified(new Timestamp(System.currentTimeMillis()));            
+            content.setName("content1");            
+            content.setUri("/graffitotest/content1");
+
+            log.info("Add Content");
+            modelService.addContent(content);
+
+
+            // ---------------------------------------------------------------------------------------
+            // Get a content
+            // ---------------------------------------------------------------------------------------
+            content = null;            
+
+            log.info("Get Content");
+            content = modelService.getContent("/graffitotest/content1");
+            assertNotNull("/graffitotest/content1 is null", content);
+            assertTrue("Invalid property for /graffitotest/content1", content.getProperty("description").equals("this is the content description"));
+            
+            
+            // ---------------------------------------------------------------------------------------
+            // Update a content
+            // ---------------------------------------------------------------------------------------            
+            log.info("Update content");
+            content.setProperty("description", "Update - this is the content description");
+            modelService.updateContent(content);
+
+            // ---------------------------------------------------------------------------------------
+            // Get the modified content
+            // ---------------------------------------------------------------------------------------
+            log.info("Get modified  content");
+            content = modelService.getContent("/graffitotest/content1");
+            assertNotNull("/graffitotest/content1 is null", content);
+            assertTrue("Invalid description for /graffitotest/content1", content.getProperty("description").equals("Update - this is the content description"));
+
+            
+            // ---------------------------------------------------------------------------------------
+            // Get a all contents
+            // ---------------------------------------------------------------------------------------                      
+            log.info("Get all contents");
+            Collection contents = modelService.getContents("/graffitotest");
+            assertNotNull("/graffitotest is null", contents);
+            assertTrue("Invalid number of contents in /graffitotest", contents.size() == 1);
+            content = (Content) contents.iterator().next();
+            assertNotNull("Content is null", content);
+                        
+            // ---------------------------------------------------------------------------------------
+            // Remove a content
+            // ---------------------------------------------------------------------------------------        
+            log.info("Remove Content");
+            modelService.removeContent(content);     
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs :" + e.toString());
+        }
+    }
+    
+    /**
+     * Test content exception 
+     *
+     */
+    public void testContentExceptions()
+    {
+
+        log.info(
+        "  ************************ Testing Content Model service - exception  ****************************");
+        Content content = null;
+        try
+        {
+            
+            // ---------------------------------------------------------------------------------------
+            // Create a content object
+            // ---------------------------------------------------------------------------------------            
+            content = modelService.createContent();
+            content.setCreationDate(new Timestamp(System.currentTimeMillis()));
+            content.setLastModified(new Timestamp(System.currentTimeMillis()));
+            content.setName("content1");            
+            content.setUri("/graffitotest/content1");
+
+            log.info("Add Content");
+            modelService.addContent(content);
+            
+            // ---------------------------------------------------------------------------------------
+            // Create a second time the same content uri in order to check if an exception is throw
+            // ---------------------------------------------------------------------------------------
+            Content content2 = modelService.createContent();
+            
+            content2.setCreationDate(new Timestamp(System.currentTimeMillis()));
+            content2.setLastModified(new Timestamp(System.currentTimeMillis()));            
+            content2.setName("contentxx");           
+            content2.setUri("/graffitotest/content1");
+
+            log.info("Add Content");
+            modelService.addContent(content2);
+            fail("Exception doesn't occur for duplicate content uri");
+        
+            
+        }
+        catch (Exception e)
+        {
+            // ---------------------------------------------------------------------------------------
+            // Remove a content
+            // ---------------------------------------------------------------------------------------
+            
+            log.info("Exception  - Impossible to add a new content with the same uri");
+            try 
+            {
+                modelService.removeContent(content);
+            }
+            catch(Exception e1) {/* Not necessary to manage this ex for this unit test */}
+//            persistenceBroker.commitTransaction();            
+            
+        }
+    }
+    
+       
+    /**
+     * 
+     * Unit test for CmsObject associations (create, get, update, remove a complete content tree)
+     * 
+     */
+
+    public void testContentTree() throws Exception
+    {
+
+        log.info("  ************************ Testing Content Model service - Test Content Tree ****************************");
+
+        // ---------------------------------------------------------------------------------------
+        // Create the root folder
+        // ---------------------------------------------------------------------------------------
+        
+        Folder root = modelService.createFolder();
+        root.setCreationDate(new Timestamp(System.currentTimeMillis()));
+        root.setLastModified(new Timestamp(System.currentTimeMillis()));
+        root.setName("root");        
+        root.setUri("/graffitotest/root");
+
+        // ---------------------------------------------------------------------------------------
+        // Add the root folder & its children
+        // ---------------------------------------------------------------------------------------                                    
+        log.info("Add root folder");
+        modelService.addFolder(root);
+
+        addChildren(root, modelService, 1);
+
+        // ---------------------------------------------------------------------------------------
+        // Get root children info
+        // ---------------------------------------------------------------------------------------
+        log.info("Check root children");
+        root = null;
+        root = modelService.getFolder("/graffitotest/root/folder1");
+        
+        assertTrue("Invalid number of content children", root.getContents().size() == NUMBER_OF_CONTENTS);
+        assertTrue("Invalid number of folder children", root.getFolders().size() == NUMBER_OF_FOLDERS);
+        // ---------------------------------------------------------------------------------------
+        // Test getChildren method
+        // ---------------------------------------------------------------------------------------        
+        Collection children = modelService.getChildren(root);
+
+        assertTrue("Invalid number of children for '/graffitotest/root/folder1' - should be " + ( NUMBER_OF_FOLDERS + NUMBER_OF_CONTENTS),
+                   children.size() == (NUMBER_OF_FOLDERS + NUMBER_OF_CONTENTS));
+        
+        Iterator iterator = children.iterator();
+        while (iterator.hasNext())
+        {
+            CmsObject cmsObject = (CmsObject) iterator.next();
+            log.info("children found in the folder root : " + cmsObject.getUri());
+        }        
+        Content doc = modelService.getContent("/graffitotest/root/folder1/content5");
+        assertTrue("Invalid parent folder for /graffitotest/root/folder1/content5", doc.getParentFolder().getUri().equals(root.getUri()));
+        
+        // ---------------------------------------------------------------------------------------
+        // Test getContents method
+        // ---------------------------------------------------------------------------------------        
+
+        children = modelService.getContents("/graffitotest");
+        assertTrue("Invalid number of contents for '/graffitotest' - should be 0",
+                   children.size() == 0);
+        
+        children = modelService.getContents("/graffitotest/root");
+        assertTrue("Invalid number of contents for '/graffitotest/root/folder1' - should be " + NUMBER_OF_CONTENTS,
+                   children.size() == NUMBER_OF_CONTENTS);
+
+        // ---------------------------------------------------------------------------------------
+        // Test getFolders method
+        // ---------------------------------------------------------------------------------------        
+        children = modelService.getFolders("/graffitotest");
+        assertTrue("Invalid number of folders for '/graffitotest' - should be 1",
+                   children.size() == 1);
+
+        children = modelService.getFolders("/graffitotest/root");
+        assertTrue("Invalid number of contents for '/graffitotest/root/folder1' - should be " + NUMBER_OF_FOLDERS,
+                   children.size() == NUMBER_OF_FOLDERS);
+        
+        // ---------------------------------------------------------------------------------------
+        // Remove the root folder and all its children content
+        // ---------------------------------------------------------------------------------------                                    
+        
+        log.info("Remove root folder and its children");        
+        root = modelService.getFolder("/graffitotest/root");
+        modelService.removeFolder(root);
+        root = modelService.getFolder("/graffitotest/root");
+        assertNull("root folder is not deleted", root);
+
+    }
+
+    
+    /**
+     * 
+     * Unit test on Exception or specific cases
+     * @throws Exception an exception which is not checked in this unit test 
+     */
+
+    public void testExceptions() throws Exception
+    {
+      log.info("  ************************ Testing Content Model service - Test Exceptions ****************************");
+      
+      // ---------------------------------------------------------------------------------------
+      // Retrieve a folder with an uri = a server.scrope
+      // ---------------------------------------------------------------------------------------
+      log.info("Retrieve folder with uri = server.scope - Should return null - use getServer");
+      Folder folder = modelService.getFolder("/graffitotest");
+      assertNull("Folder /graffitotest is not null", folder);
+ 
+      // ---------------------------------------------------------------------------------------
+      // Create a folder & Add a folder with uri = server.scrope
+      // ---------------------------------------------------------------------------------------
+      folder = modelService.createFolder();
+      folder.setCreationDate(new Timestamp(System.currentTimeMillis()));
+      folder.setLastModified(new Timestamp(System.currentTimeMillis()));
+      
+      folder.setName("folder1");
+      folder.setUri("/graffitotest");
+      
+      log.info("Add folder with uri = server.scope - Should generate an exception");
+      try 
+      {
+         modelService.addFolder(folder);
+         fail("No excpetion has been throw when adding a folder with an uri = sever.scrope");
+      }
+      catch (ContentManagementException e)
+      {
+          log.info("Exception : cannot add a folder with an uri = sever.scrope");           
+      }
+           
+      // ---------------------------------------------------------------------------------------
+      // Create a content with uri = server.scope
+      // ---------------------------------------------------------------------------------------
+      
+      log.info("Add content with uri = server.scope - Should generate an exception");
+      Content content = modelService.createContent();
+
+      content.setCreationDate(new Timestamp(System.currentTimeMillis()));
+      content.setLastModified(new Timestamp(System.currentTimeMillis()));
+      content.setName("content1");      
+      content.setUri("/graffitotest");
+
+      try 
+      {
+         modelService.addContent(content);
+         fail("No excpetion has been throw when adding a content with an uri = sever.scrope");
+      }
+      catch (ContentManagementException e)
+      {
+          log.info("Exception : cannot add a content with an uri = sever.scrope");           
+      }      
+    }
+    
+    
+    private void addChildren(Folder parent, ContentModelService modelService, int level) throws Exception
+    {
+
+        // ---------------------------------------------------------------------------------------
+        // Create the children folders
+        // ---------------------------------------------------------------------------------------
+        for (int i = 1; i <= NUMBER_OF_FOLDERS; i++)
+        {
+            Folder folder = modelService.createFolder();
+            folder.setCreationDate(new Timestamp(System.currentTimeMillis()));
+            folder.setLastModified(new Timestamp(System.currentTimeMillis()));
+
+            folder.setName("Folder" + i);
+            folder.setUri(parent.getUri() + "/folder" + i);
+            folder.setParentFolder(parent);
+            log.info("Add folder : " + folder.getUri());
+            modelService.addFolder(folder);
+            if (level < MAX_SUB_LEVEL)
+            {
+                addChildren(folder, modelService, level + MAX_SUB_LEVEL);
+            }
+
+        }
+
+        // ---------------------------------------------------------------------------------------
+        // Create the children contents
+        // ---------------------------------------------------------------------------------------
+        for (int i = 1; i <= NUMBER_OF_CONTENTS; i++)
+        {
+            Content content = modelService.createContent();
+            content.setCreationDate(new Timestamp(System.currentTimeMillis()));
+            content.setLastModified(new Timestamp(System.currentTimeMillis()));
+
+            content.setName("Content" + i);
+            content.setUri(parent.getUri() + "/content" + i);
+
+            content.setParentFolder(parent);
+            log.info("Add content : " + content.getUri());
+            modelService.addContent(content);
+        }
+
+    }
+    
+    protected String[] getConfigurations()
+    {        
+        String[] confs = super.getConfigurations();
+        List confList = new ArrayList(Arrays.asList(confs));
+        confList.add("META-INF/graffito-without-access-control.xml");        
+        return (String[]) confList.toArray(new String[confList.size()]);        
+    }     
+}

Added: incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentSearchService.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentSearchService.java?rev=225708&view=auto
==============================================================================
--- incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentSearchService.java (added)
+++ incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentSearchService.java Wed Jul 27 22:46:20 2005
@@ -0,0 +1,208 @@
+/*
+ * 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.services.core.impl;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.model.core.CmsObject;
+import org.apache.portals.graffito.model.core.Content;
+import org.apache.portals.graffito.model.core.Folder;
+import org.apache.portals.graffito.persistence.impl.PersistenceSupportedTestCase;
+import org.apache.portals.graffito.services.core.ContentModelService;
+import org.apache.portals.graffito.services.search.ContentSearchService;
+import org.apache.portals.graffito.services.search.Filter;
+import org.apache.portals.graffito.services.search.SearchResults;
+
+/**
+ * Test Persistence Service
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ * 
+ * @version $Id: TestContentSearchService.java,v 1.1 2004/12/22 20:37:02 christophe Exp $
+ *  
+ */
+public class TestContentSearchService extends PersistenceSupportedTestCase
+{
+    private final static Log log = LogFactory.getLog(TestContentSearchService.class);
+
+    private static final int MAX_SUB_LEVEL = 3;
+
+    private static final int NUMBER_OF_FOLDERS = 5;
+
+    private static final int NUMBER_OF_DOCUMENTS = 15;
+
+    private static String XML_FILE = "./test/article.xml";
+
+    private ContentSearchService searchService;
+
+    private ContentModelService modelService;
+      
+
+    /* (non-Javadoc)
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {        
+    	super.setUp();
+    	searchService = (ContentSearchService) ctx.getBean("org.apache.portals.graffito.services.search.ContentSearchService");    	
+    	modelService = (ContentModelService) ctx.getBean("org.apache.portals.graffito.services.core.ContentModelService");
+    	
+    }
+    
+   
+    /**
+     * @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(TestContentSearchService.class);
+    }
+
+    /**
+     * 
+     * Simple unit on Folder objects : create, add, get, update, remove
+     * 
+     */
+    public void testSearch() throws Exception
+    {
+        
+        log.info("  ************************ Testing Content Model service - Test Content Tree ****************************");
+        // ---------------------------------------------------------------------------------------
+        // Create the root folder
+        // ---------------------------------------------------------------------------------------                            
+        Folder root = modelService.createFolder();
+        root.setCreationDate(new Timestamp(System.currentTimeMillis()));
+        root.setLastModified(new Timestamp(System.currentTimeMillis()));
+
+        root.setName("root");
+        root.setUri("/graffitotest/root");
+
+        // ---------------------------------------------------------------------------------------
+        // Add the root folder & its children
+        // ---------------------------------------------------------------------------------------                                    
+        log.info("Add root folder");
+        modelService.addFolder(root);
+
+        addChildren(root, modelService, 1);
+
+        // ---------------------------------------------------------------------------------------
+        // Search Cms object
+        // ---------------------------------------------------------------------------------------        
+        log.info("Search Cms Object on uri");
+
+        Filter filter = searchService.newFilter();
+        filter.addEqualTo("uri", "/graffitotest/root/folder3/content1");
+        SearchResults results = searchService.searchCmsObjects(filter);
+        assertNotNull("Search result is null", results);
+        assertTrue("Search result size is != 1", results.size() == 1);
+
+        
+        log.info("Search Cms Object on different cms object attributes");
+
+        filter = searchService.newFilter();
+        filter.addEqualTo("name", "Content1");
+        filter.addEqualTo("parentFolder.uri", "/graffitotest/root/folder4");
+        
+        results = searchService.searchCmsObjects(filter);
+        assertNotNull("Search result is null", results);
+        for(int i = 0; i < results.size();i++)
+        {
+            CmsObject cmsObject = results.get(i);
+            System.out.println("Cms object found : " + cmsObject.getUri());
+        }
+        assertTrue("Search result size is != 1 / size = " + results.size() ,  results.size() == 1);
+        
+        
+        // ---------------------------------------------------------------------------------------
+        // Remove all 
+        // ---------------------------------------------------------------------------------------
+        root = modelService.getFolder("/graffitotest/root");
+        modelService.removeFolder(root);
+
+
+
+
+    }
+
+    private void addChildren(Folder parent, ContentModelService service, int level) throws Exception
+    {
+
+        // ---------------------------------------------------------------------------------------
+        // Create the children folders
+        // ---------------------------------------------------------------------------------------
+        for (int i = 1; i <= NUMBER_OF_FOLDERS; i++)
+        {
+            Folder folder = service.createFolder();
+            folder.setCreationDate(new Timestamp(System.currentTimeMillis()));
+            folder.setLastModified(new Timestamp(System.currentTimeMillis()));
+
+
+            folder.setName("Folder" + i);
+
+            folder.setUri(parent.getUri() + "/folder" + i);
+            folder.setParentFolder(parent);
+            log.info("Add folder : " + folder.getUri());
+            service.addFolder(folder);
+            if (level < MAX_SUB_LEVEL)
+            {
+                addChildren(folder, service, level + MAX_SUB_LEVEL);
+            }
+
+        }
+
+        // ---------------------------------------------------------------------------------------
+        // Create the children documents
+        // ---------------------------------------------------------------------------------------
+        for (int i = 1; i <= NUMBER_OF_DOCUMENTS; i++)
+        {
+            Content content = modelService.createContent();
+            content.setCreationDate(new Timestamp(System.currentTimeMillis()));
+            content.setLastModified(new Timestamp(System.currentTimeMillis()));
+
+            content.setName("Content" + i);
+            content.setUri(parent.getUri() + "/content" + i);
+
+            content.setParentFolder(parent);
+            log.info("Add Content: " + content.getUri());
+            modelService.addContent(content);
+            
+            
+        }
+
+    }
+    protected String[] getConfigurations()
+    {        
+        String[] confs = super.getConfigurations();
+        List confList = new ArrayList(Arrays.asList(confs));
+        confList.add("META-INF/graffito-without-access-control.xml");        
+        return (String[]) confList.toArray(new String[confList.size()]);        
+    } 
+
+}

Added: incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentServerService.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentServerService.java?rev=225708&view=auto
==============================================================================
--- incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentServerService.java (added)
+++ incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentServerService.java Wed Jul 27 22:46:20 2005
@@ -0,0 +1,260 @@
+/*
+ * 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.services.core.impl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.exception.ContentManagementException;
+import org.apache.portals.graffito.model.server.FileSystemServer;
+import org.apache.portals.graffito.model.server.GraffitoServer;
+import org.apache.portals.graffito.model.server.Server;
+import org.apache.portals.graffito.persistence.impl.PersistenceSupportedTestCase;
+import org.apache.portals.graffito.services.core.ContentServerService;
+
+
+
+
+
+/**
+ * Test Content Server Service.
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ * 
+ * @version $Id: TestContentServerService.java,v 1.1 2004/12/22 20:37:02 christophe Exp $
+ *  
+ */
+public class TestContentServerService extends PersistenceSupportedTestCase
+{
+    private final static Log log = LogFactory.getLog(TestContentServerService.class);
+
+    private ContentServerService serverService;
+    
+
+    /* (non-Javadoc)
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {        
+    	super.setUp();        	
+        serverService = (ContentServerService) ctx.getBean("org.apache.portals.graffito.services.core.ContentServerService");
+    	
+    }
+    
+   
+    /**
+     * @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(TestContentServerService.class);
+    }
+
+    
+    /**
+     * Simple unit on Graffito Server objects : create, add, get, update, remove
+     * 
+     * @throws ContentManagementException - throws when one of the operations fails (insert, remove,...)
+     */
+    public void testGraffitoServer() throws ContentManagementException
+    {
+
+        log.info("  ************************ Testing Content Server service  ****************************");
+        
+        // ----------------------------------------------------------------------------------------
+        // Add Server
+        // --------------------------------------------------------------------------------------                        
+        GraffitoServer server = serverService.createGraffitoServer();
+        server.setAlias("test"); 
+        server.setDbAlias("//localhost/graffitostore");
+        server.setDescription("Graffito Test 2 Zerver");        
+        server.setDriver("com.mysql.jdbc.Driver");
+        server.setJdbcLevel("2.0");
+        server.setLogin("user");
+        server.setPassword("password");
+        server.setPlateform("MySQL");
+        server.setProtocol("jdbc");
+        server.setScope("/test");
+        server.setSubProtocol("mysql");
+        server.setTitle("Graffito Test Server");
+        
+        server.setStoreClassName("org.apache.portals.graffito.store.impl.ojb.GraffitoOJBStore");
+        
+        log.info("Add Graffito Store Server");
+        serverService.addServer(server);     
+
+        // ---------------------------------------------------------------------------------------
+        // Get  server
+        // ---------------------------------------------------------------------------------------         
+        log.info("Get server");
+        server = (GraffitoServer) serverService.getServer("/test");
+        assertTrue("Incorrect alias for server '/test", server.getAlias().equals("test"));
+
+        // ---------------------------------------------------------------------------------------
+        // Update server
+        // ---------------------------------------------------------------------------------------         
+        log.info("Update server");
+        server.setDescription("Graffito Server Test 2 server modified");
+        serverService.updateServer(server);        
+
+        
+        // ---------------------------------------------------------------------------------------
+        // Get the modified server
+        // ---------------------------------------------------------------------------------------         
+        log.info("Get the modified server");
+        server = (GraffitoServer) serverService.getServer("/test");
+        assertTrue("Incorrect alias for server '/test", server.getDescription().equals("Graffito Server Test 2 server modified"));  
+
+        // ---------------------------------------------------------------------------------------
+        // Try to add another with the same scope
+        // ---------------------------------------------------------------------------------------           
+        server = serverService.createGraffitoServer();
+        server.setAlias("test2"); 
+        server.setDbAlias("//localhost/graffitostore");
+        server.setDescription("Graffito Server Test 2");        
+        server.setDriver("com.mysql.jdbc.Driver");
+        server.setJdbcLevel("2.0");
+        server.setLogin("user");
+        server.setPassword("password");
+        server.setPlateform("MySQL");
+        server.setProtocol("jdbc");
+        server.setScope("/test");
+        server.setSubProtocol("mysql");
+        server.setTitle("Graffito Test Server");        
+        server.setStoreClassName("org.apache.portals.graffito.store.GraffitoOJBStore");
+        
+        log.info("Add Graffito Store Server");
+        try 
+        {
+           serverService.addServer(server);
+           fail("Adding another server with the same scope doesn't failed");
+        }
+        catch (ContentManagementException e)
+        {
+            log.info("Impossible to add another server with the same scope");
+        }        
+        // ---------------------------------------------------------------------------------------
+        // Remove  server
+        // ---------------------------------------------------------------------------------------         
+        log.info("Remove server");
+
+        server = (GraffitoServer) serverService.getServer("/test");
+        serverService.removeServer(server);
+
+
+    }
+
+    /**
+     * Simple unit on File System Server objects : create, add, get, update, remove
+     * 
+     * @throws ContentManagementException - throws when one of the operations fails (insert, remove,...)
+     */
+    public void testFileSystemServer() throws ContentManagementException
+    {
+
+        log.info("  ************************ Testing File System with Content Server service  ****************************");
+        
+        // ----------------------------------------------------------------------------------------
+        // Add Server
+        // --------------------------------------------------------------------------------------                        
+        FileSystemServer server = serverService.createFileSystemServer();
+        server.setAlias("share2"); 
+        server.setDescription("Graffito File System Test 2 Zerver");        
+        server.setScope("/share2");
+        server.setTitle("Graffito FS Test Server");
+        server.setRoot("/home/dtaylor/shares/two/");
+                                 
+        server.setStoreClassName("org.apache.portals.graffito.store.impl.fs.FileSystemContentStore");
+        
+        log.info("Add FS Store Server");
+        serverService.addServer(server);     
+
+        // ---------------------------------------------------------------------------------------
+        // Get  server
+        // ---------------------------------------------------------------------------------------         
+        log.info("Get FS server");
+        server = (FileSystemServer) serverService.getServer("/share2");
+        assertTrue("Incorrect alias for server 'share2", server.getAlias().equals("share2"));
+        assertTrue("Incorrect root for server 'share2", server.getRoot().equals("/home/dtaylor/shares/two/"));
+
+        // ---------------------------------------------------------------------------------------
+        // Update server
+        // ---------------------------------------------------------------------------------------
+        final String MODIFIED_MESSAGE = "Graffito File System Server Test 2 server modified";
+        log.info("Update FS server");
+        server.setDescription(MODIFIED_MESSAGE);
+        serverService.updateServer(server);        
+
+        
+        // ---------------------------------------------------------------------------------------
+        // Get the modified server
+        // ---------------------------------------------------------------------------------------         
+        log.info("Get the modified FS server");
+        server = (FileSystemServer) serverService.getServer("/share2");
+        assertTrue("Incorrect alias for server '/share2", server.getDescription().equals(MODIFIED_MESSAGE));  
+
+        // ---------------------------------------------------------------------------------------
+        // Remove  server
+        // ---------------------------------------------------------------------------------------         
+        log.info("Remove FS server");
+
+        server = (FileSystemServer) serverService.getServer("/share2");
+        serverService.removeServer(server);
+    }
+
+    /**
+     * Simple unit on Master Graffito Server objects
+     * 
+     * @throws ContentManagementException - throws when one of the operations fails (insert, remove,...)
+     */
+    public void testMasterGraffitoServer() throws ContentManagementException
+    {
+
+        log.info("  ************************ Testing Master Content Server ********************************");
+        
+        // ---------------------------------------------------------------------------------------
+        // Get  server
+        // ---------------------------------------------------------------------------------------         
+        log.info("Get server");
+        Server server = (GraffitoServer) serverService.getServer("/graffitotest"); // graffitotest is the scope assigned to the Master Store Server
+        assertNotNull("Graffito Master Server is null", server);
+        assertTrue("Incorrect Master Server store", server.getScope().equals("/graffitotest"));
+
+    }
+    
+    
+    protected String[] getConfigurations()
+    {        
+        String[] confs = super.getConfigurations();
+        List confList = new ArrayList(Arrays.asList(confs));
+        confList.add("META-INF/graffito-without-access-control.xml");        
+        return (String[]) confList.toArray(new String[confList.size()]);        
+    }     
+}

Added: incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentVersionService.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentVersionService.java?rev=225708&view=auto
==============================================================================
--- incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentVersionService.java (added)
+++ incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/core/impl/TestContentVersionService.java Wed Jul 27 22:46:20 2005
@@ -0,0 +1,203 @@
+/*
+ * 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.services.core.impl;
+
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.model.core.HistoryElement;
+import org.apache.portals.graffito.model.core.VersionnedContent;
+import org.apache.portals.graffito.persistence.impl.PersistenceSupportedTestCase;
+import org.apache.portals.graffito.services.core.ContentModelService;
+import org.apache.portals.graffito.services.core.ContentVersionService;
+
+
+
+/**
+ * Test Persistence Service
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ * 
+ * @version $Id: TestContentVersionService.java,v 1.1 2004/12/22 20:37:02 christophe Exp $
+ *  
+ */
+public class TestContentVersionService extends PersistenceSupportedTestCase
+{
+    private final static Log log = LogFactory.getLog(TestContentVersionService.class);
+
+
+    private ContentModelService modelService;
+
+    private ContentVersionService versionService;
+        
+
+    /* (non-Javadoc)
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {        
+    	super.setUp();
+    	
+    	versionService =  (ContentVersionService) ctx.getBean("org.apache.portals.graffito.services.core.ContentVersionService");
+    	modelService = (ContentModelService) ctx.getBean("org.apache.portals.graffito.services.core.ContentModelService");
+    }
+    
+   
+    /**
+     * @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(TestContentVersionService.class);
+    }
+
+
+    /**
+     * Test on VersionnedContent and ContentVersionService
+     *
+     */
+    public void testVersion()
+    {
+
+        try
+        {
+            log.info(
+            "  ************************ Testing Content Version service  ****************************");
+
+            // ---------------------------------------------------------------------------------------
+            // Create a generic versionned content object
+            // ---------------------------------------------------------------------------------------
+            
+            VersionnedContent content = modelService.createVersionnedContent();                        
+            content.setCreationDate(new Timestamp(System.currentTimeMillis()));
+            content.setLastModified(new Timestamp(System.currentTimeMillis()));
+            content.setName("content1");            
+            content.setUri("/graffitotest/content1");
+
+            log.info("Add Versionned Content");
+            modelService.addVersionnedContent(content);
+           
+
+            // ---------------------------------------------------------------------------------------
+            // Get a generic versionned content object
+            // ---------------------------------------------------------------------------------------
+            log.info("Get Versionned Content");
+            content = modelService.getVersionnedContent("/graffitotest/content1");
+            assertNotNull("/graffitotest/content1 is null", content);
+            assertTrue("Invalid version number for /graffitotest/content1", content.getVersionNumber().equals("1.0"));
+            
+            
+            // ---------------------------------------------------------------------------------------
+            // Create a new major version
+            // ---------------------------------------------------------------------------------------            
+            log.info("Create a new major version");
+            VersionnedContent newContent = versionService.createMajorVersion(content.getUri());
+            assertNotNull("/graffitotest/content1 is null", newContent);
+            assertTrue("Invalid version number for /graffitotest/content1", newContent.getVersionNumber().equals("2.0"));             
+
+            
+            // ---------------------------------------------------------------------------------------
+            // Create a new minor version 
+            // ---------------------------------------------------------------------------------------            
+            log.info("Create a new minor version");
+            newContent = versionService.createMinorVersion(content.getUri());
+            assertNotNull("/graffitotest/content1 is null", newContent);
+            assertTrue("Invalid version number for /graffitotest/content1", newContent.getVersionNumber().equals("2.1"));
+            
+            // ---------------------------------------------------------------------------------------
+            // Get versions
+            // ---------------------------------------------------------------------------------------
+            VersionnedContent lastVersion = modelService.getVersionnedContent("/graffitotest/content1");
+            assertNotNull("/graffitotest/content1 is null", lastVersion);
+            assertTrue("Invalid version number for /graffitotest/content1", lastVersion.getVersionNumber().equals("2.1"));  
+            assertTrue("Invalid last version flag", lastVersion.isLastVersion());
+            
+            VersionnedContent v20 = modelService.getVersionnedContent("/graffitotest/content1", "2.0");
+            assertNotNull("/graffitotest/content1 is null", v20);
+            assertTrue("Invalid version number for /graffitotest/content1", v20.getVersionNumber().equals("2.0"));   
+            assertFalse("Invalid last version flag", v20.isLastVersion());
+            
+            VersionnedContent v10 = modelService.getVersionnedContent("/graffitotest/content1", "1.0");
+            assertNotNull("/graffitotest/content1 is null", v10);
+            assertTrue("Invalid version number for /graffitotest/content1", v10.getVersionNumber().equals("1.0"));            
+            assertFalse("Invalid last version flag", v10.isLastVersion());
+
+            // ---------------------------------------------------------------------------------------
+            // Get History
+            // ---------------------------------------------------------------------------------------        
+            HistoryElement historyElement = versionService.getHistory("/graffitotest/content1");
+            assertNotNull("History Element is null", historyElement );
+            content = historyElement.getVersionnedContent();
+            assertTrue("Invalid version number in the last history Element", content.getVersionNumber().equals("2.1"));            
+            assertTrue("Invalid last version flag", content.isLastVersion());
+            
+            historyElement = historyElement.getPrevious();
+            assertNotNull("History Element is null", historyElement );
+            content = historyElement.getVersionnedContent();
+            assertTrue("Invalid version number in the last history Element", content.getVersionNumber().equals("2.0"));            
+            assertFalse("Invalid last version flag", content.isLastVersion());
+            
+            historyElement = historyElement.getPrevious();
+            assertNotNull("History Element is null", historyElement );
+            content = historyElement.getVersionnedContent();
+            assertTrue("Invalid version number in the last history Element", content.getVersionNumber().equals("1.0"));            
+            assertFalse("Invalid last version flag", content.isLastVersion());
+            
+            historyElement = historyElement.getPrevious();
+            assertNull("History Element is not null", historyElement );
+            
+            // ---------------------------------------------------------------------------------------
+            // Remove contents
+            // ---------------------------------------------------------------------------------------        
+            log.info("Remove versionned content objects");
+            modelService.removeVersionnedContent(lastVersion);
+            modelService.removeVersionnedContent(v20);
+            modelService.removeVersionnedContent(v10);
+
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs :" + e.toString());
+        }
+    }
+    
+    protected String[] getConfigurations()
+    {        
+        String[] confs = super.getConfigurations();
+        List confList = new ArrayList(Arrays.asList(confs));
+        confList.add("META-INF/graffito-without-access-control.xml");        
+        return (String[]) confList.toArray(new String[confList.size()]);        
+    }     
+       
+ 
+}

Added: incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/dm/impl/TestDocumentModelService.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/dm/impl/TestDocumentModelService.java?rev=225708&view=auto
==============================================================================
--- incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/dm/impl/TestDocumentModelService.java (added)
+++ incubator/graffito/trunk/components/src/test/org/apache/portals/graffito/services/dm/impl/TestDocumentModelService.java Wed Jul 27 22:46:20 2005
@@ -0,0 +1,185 @@
+/*
+ * 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.services.dm.impl;
+
+import java.io.FileInputStream;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.model.dm.Document;
+import org.apache.portals.graffito.persistence.impl.PersistenceSupportedTestCase;
+import org.apache.portals.graffito.services.dm.DocumentModelService;
+import org.apache.portals.graffito.util.StreamUtil;
+
+
+/**
+ * Test Persistence Service
+ * 
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ * 
+ * @version $Id: TestContentModelService.java,v 1.1 2004/12/22 20:37:02 christophe Exp $
+ *  
+ */
+public class TestDocumentModelService extends PersistenceSupportedTestCase
+{
+    private final static Log log = LogFactory.getLog(TestDocumentModelService.class);
+
+    private static final int MAX_SUB_LEVEL = 3;
+
+    private static final int NUMBER_OF_FOLDERS = 5;
+
+    private static final int NUMBER_OF_DOCUMENTS = 15;
+
+    private static String XML_FILE = "./test/article.xml";    
+
+    private static String WORD_FILE = "./test/word.doc";
+
+    private DocumentModelService modelService;
+
+
+                   
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {        
+    	super.setUp();    	
+    	modelService = (DocumentModelService) ctx.getBean("org.apache.portals.graffito.services.dm.DocumentModelService");
+    	
+    }
+    
+   
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {        
+        super.tearDown();
+    }
+
+    /** 
+     * @return The tes suite
+     */
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new TestSuite(TestDocumentModelService.class);
+    }
+
+
+    
+    /**
+     * Simple test on Document object
+     *
+     */
+    public void testDocument()
+    {
+
+        try
+        {
+            log.info(
+            "  ************************ Testing Document Model service - Simple Document (with one version)  ****************************");
+            FileInputStream file = new FileInputStream(XML_FILE);
+            byte[] xmlContent = StreamUtil.getContentByte(file);
+
+            // ---------------------------------------------------------------------------------------
+            // Create a document & its content object
+            // ---------------------------------------------------------------------------------------
+            
+            Document document = modelService.createDocument();
+            document.setVersionNumber("1.0");            
+            document.setContentType("text/xml");            
+            document.setSize(xmlContent.length);
+            document.getDocumentStream().setIsoCode("EN");
+            document.getDocumentStream().setContent(xmlContent);
+
+            document.setCreationDate(new Timestamp(System.currentTimeMillis()));
+            document.setLastModified(new Timestamp(System.currentTimeMillis()));
+            document.setName("document1");
+            document.setUri("/graffitotest/document1");
+
+            log.info("Add Document");
+            modelService.addDocument(document);
+
+
+            // ---------------------------------------------------------------------------------------
+            // Get a document
+            // ---------------------------------------------------------------------------------------
+            document = null;            
+
+            log.info("Get Document");
+            document = modelService.getDocument("/graffitotest/document1");
+            assertNotNull("/graffitotest/document1 is null", document);
+            assertTrue("Invalid title for /graffitotest/document1", document.getName().equals("document1"));
+            assertNotNull("Document content is null", document.getDocumentStream().getContentByte());
+            
+            // ---------------------------------------------------------------------------------------
+            // Update a document and its last version
+            // ---------------------------------------------------------------------------------------            
+            log.info("Update document");
+            document.setProperty("description", "description for Document 1");
+
+            file = new FileInputStream(WORD_FILE);
+            xmlContent = StreamUtil.getContentByte(file);
+            
+            document.setContentType("application/msword");
+            document.getDocumentStream().setContent(xmlContent);
+            document.getDocumentStream().setIsoCode("FR");
+            modelService.updateDocument(document);
+
+            // ---------------------------------------------------------------------------------------
+            // Get the modified document
+            // ---------------------------------------------------------------------------------------
+            log.info("Get modified  document");
+            document = modelService.getDocument("/graffitotest/document1");
+            assertNotNull("/graffitotest/document1 is null", document);
+            assertTrue("Invalid description for /graffitotest/document1", document.getProperty("description").equals("description for Document 1"));
+            assertTrue("Invalid content type for /graffitotest/document1", document.getContentType().equals("application/msword"));
+            assertTrue("Invalid Iso code for /graffitotest/document1", document.getDocumentStream().getIsoCode().equals("FR"));
+            
+                        
+            // ---------------------------------------------------------------------------------------
+            // Remove a  document and its versions
+            // ---------------------------------------------------------------------------------------        
+            log.info("Remove document and its content");
+            modelService.removeDocument(document);     
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs :" + e.toString());
+        }
+    }
+    
+    
+    
+    protected String[] getConfigurations()
+    {        
+        String[] confs = super.getConfigurations();
+        List confList = new ArrayList(Arrays.asList(confs));
+        confList.add("META-INF/graffito-without-access-control.xml");        
+        return (String[]) confList.toArray(new String[confList.size()]);        
+    }     
+}



Mime
View raw message