incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r291715 - in /incubator/graffito/trunk/jcr-mapping/src: test-data/ test-data/data-import.xml test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerQueryTest.java
Date Mon, 26 Sep 2005 19:10:58 GMT
Author: clombart
Date: Mon Sep 26 12:10:51 2005
New Revision: 291715

URL: http://svn.apache.org/viewcvs?rev=291715&view=rev
Log:
Continue my work on the Query service. This is not yet finished. 
The PersistenceManagerQueryTest contains a good API example.

Added:
    incubator/graffito/trunk/jcr-mapping/src/test-data/
    incubator/graffito/trunk/jcr-mapping/src/test-data/data-import.xml
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerQueryTest.java

Added: incubator/graffito/trunk/jcr-mapping/src/test-data/data-import.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test-data/data-import.xml?rev=291715&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test-data/data-import.xml (added)
+++ incubator/graffito/trunk/jcr-mapping/src/test-data/data-import.xml Mon Sep 26 12:10:51
2005
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<test jcr:primaryType="nt:unstructured" title="Page_x0020_Title"
+	xmlns:jcr="http://www.jcp.org/jcr/1.0"
+	xmlns:graffito="http://incubator.apache.org/graffito"
+	xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:rep="internal"
+	xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+	xmlns:xs="http://www.w3.org/2001/XMLSchema"
+	xmlns:fn="http://www.w3.org/2004/10/xpath-functions"
+	xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns="">
+	<collection-element1 jcr:primaryType="graffito:paragraph"
+		jcr:uuid="60ff5b3d-cd00-4cce-9374-20860dbffac6"
+		jcr:isCheckedOut="true"
+		jcr:versionHistory="4c39a5cc-0e64-4627-8151-3425733cd555"
+		graffito:text="Para_x0020_1"
+		jcr:baseVersion="60302342-93db-482c-80cc-1881407ba9bc"
+		jcr:predecessors="60302342-93db-482c-80cc-1881407ba9bc" />
+	<collection-element2 jcr:primaryType="graffito:paragraph"
+		jcr:uuid="2524f2fc-1f1d-4d60-940f-53d503ef2847"
+		jcr:isCheckedOut="true"
+		jcr:versionHistory="3f68a72c-661a-445d-a336-648783addcbf"
+		graffito:text="Para_x0020_2"
+		jcr:baseVersion="25101f16-33d2-4770-bb3d-7fdd4e767a01"
+		jcr:predecessors="25101f16-33d2-4770-bb3d-7fdd4e767a01" />
+	<collection-element3 jcr:primaryType="graffito:paragraph"
+		jcr:uuid="09a5a1c4-5c1e-40d0-b11c-637197400be0"
+		jcr:isCheckedOut="true"
+		jcr:versionHistory="740c05d1-77dc-415a-8613-870a4f86c2fa"
+		graffito:text="Para_x0020_4"
+		jcr:baseVersion="f533756d-05e7-4ea2-b894-74d6fba4978d"
+		jcr:predecessors="f533756d-05e7-4ea2-b894-74d6fba4978d" />
+	<collection-element4 jcr:primaryType="graffito:paragraph"
+		jcr:uuid="cd182817-15e3-4a74-8a7a-56ff6d342549"
+		jcr:isCheckedOut="true"
+		jcr:versionHistory="9e08be9d-3fa8-40f5-8aad-144184d1b490"
+		graffito:text="Para_x0020_5"
+		jcr:baseVersion="6a4b7e76-76d3-42e4-8a38-51359d4cd47f"
+		jcr:predecessors="6a4b7e76-76d3-42e4-8a38-51359d4cd47f" />
+</test>
\ No newline at end of file

Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerQueryTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerQueryTest.java?rev=291715&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerQueryTest.java
(added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerQueryTest.java
Mon Sep 26 12:10:51 2005
@@ -0,0 +1,114 @@
+/* ========================================================================
+ * 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.persistence.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+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.jcr.TestBase;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.query.Filter;
+import org.apache.portals.graffito.jcr.query.Query;
+import org.apache.portals.graffito.jcr.query.QueryManager;
+import org.apache.portals.graffito.jcr.testmodel.C;
+import org.apache.portals.graffito.jcr.testmodel.Page;
+import org.apache.portals.graffito.jcr.testmodel.Paragraph;
+
+
+/**
+ * Test QueryManagerImpl Query methods
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerQueryTest extends TestBase
+{
+    private final static Log log = LogFactory.getLog(PersistenceManagerQueryTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public PersistenceManagerQueryTest(String testName)  throws Exception
+    {
+        super(testName);
+    }
+
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new TestSuite(PersistenceManagerQueryTest.class);
+    }
+
+    
+    public void testGetObjects()
+    {
+
+    	try
+    	{
+    		
+    		  importData();
+    		  
+    		  // Build the Query Object
+    	      QueryManager queryManager = this.getQueryManager();
+    	      Filter filter = queryManager.createFilter(Paragraph.class);
+    	      filter.addEqualTo("text", "Para 1");    	          	     
+    	      filter.setScope("/test");
+    	      
+    	      Query query = queryManager.createQuery(filter);
+    	      
+    	      PersistenceManager persistenceManager = this.getPersistenceManager();
+    	      Collection result = persistenceManager.getObjects(query);
+    	      assertTrue("Invalid number of objects - should be = 1", result.size() == 1);
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+    
+    private void importData() throws JcrMappingException 
+    {
+        
+    	if (getPersistenceManager().itemExists("/test"))
+        {
+            getPersistenceManager().remove("/test");
+        }
+
+        Page page = new Page();
+        page.setTitle("Page Title");
+        
+        ArrayList paragraphs = new ArrayList();
+        
+        paragraphs.add(new Paragraph("Para 1"));
+        paragraphs.add(new Paragraph("Para 2"));
+        paragraphs.add(new Paragraph("Para 3"));
+        page.setParagraphs(paragraphs);
+        
+        getPersistenceManager().insert("/test", page);            
+                
+
+    }
+}
\ No newline at end of file



Mime
View raw message