incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r293438 - in /incubator/graffito/trunk/jcr-mapping/src: test-config/ test/org/apache/portals/graffito/jcr/ test/org/apache/portals/graffito/jcr/persistence/impl/
Date Mon, 03 Oct 2005 19:19:32 GMT
Author: clombart
Date: Mon Oct  3 12:19:21 2005
New Revision: 293438

URL: http://svn.apache.org/viewcvs?rev=293438&view=rev
Log:
Add more unit tests

Added:
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleQueryTest.java
      - copied, changed from r292016, incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerQueryTest.java
Removed:
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerQueryTest.java
Modified:
    incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerAtomicQueryTest.java

Modified: incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml?rev=293438&r1=293437&r2=293438&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test-config/jcrmapping.xml Mon Oct  3 12:19:21
2005
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
-<!DOCTYPE graffito-jcr PUBLIC "-//The Apache Software Foundation//DTD Repository//EN"
"../dtd/graffito-jcr-mapping.dtd">
+<!DOCTYPE graffito-jcr PUBLIC "-//The Apache Software Foundation//DTD Repository//EN"
"./src/dtd/graffito-jcr-mapping.dtd">
 <graffito-jcr>
     
   

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java?rev=293438&r1=293437&r2=293438&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
Mon Oct  3 12:19:21 2005
@@ -19,26 +19,31 @@
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
-import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
 
 import javax.jcr.ImportUUIDBehavior;
-import javax.jcr.InvalidSerializedDataException;
-import javax.jcr.ItemExistsException;
-import javax.jcr.PathNotFoundException;
 import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.version.VersionException;
-
 
 import junit.framework.TestCase;
 
 import org.apache.portals.graffito.jcr.mapper.impl.DigesterMapperImpl;
 import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.BinaryTypeConverter;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.BooleanTypeConverter;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.ByteArrayTypeConverter;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.CalendarTypeConverter;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.DoubleTypeConverter;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.IntTypeConverter;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.LongTypeConverter;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.StringTypeConverter;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.TimestampTypeConverter;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.UtilDateTypeConverter;
 import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl;
 import org.apache.portals.graffito.jcr.query.QueryManager;
 import org.apache.portals.graffito.jcr.query.impl.QueryManagerImpl;
@@ -89,8 +94,27 @@
         Repository repository = RepositoryUtil.getRepository("repositoryTest");
         
         session = RepositoryUtil.login(repository, "superuser", "superuser");
+        
+        // TODO : After Spring integration, move the following code into the assembly script
         queryManager = new QueryManagerImpl(mapper);
-        persistenceManager = new PersistenceManagerImpl(mapper, queryManager, repository,
session);
+        
+        HashMap atomicTypeConverters = new HashMap();
+        atomicTypeConverters.put(String.class,  new StringTypeConverter(session.getValueFactory()));
+        atomicTypeConverters.put(InputStream.class,  new BinaryTypeConverter(session.getValueFactory()));
+        atomicTypeConverters.put(long.class,  new LongTypeConverter(session.getValueFactory()));
+        atomicTypeConverters.put(Long.class,  new LongTypeConverter(session.getValueFactory()));
+        atomicTypeConverters.put(int.class,  new IntTypeConverter(session.getValueFactory()));
+        atomicTypeConverters.put(Integer.class,  new IntTypeConverter(session.getValueFactory()));
+        atomicTypeConverters.put(double.class,  new DoubleTypeConverter(session.getValueFactory()));
+        atomicTypeConverters.put(Double.class,  new DoubleTypeConverter(session.getValueFactory()));
+        atomicTypeConverters.put(boolean.class,  new BooleanTypeConverter(session.getValueFactory()));
+        atomicTypeConverters.put(Boolean.class,  new BooleanTypeConverter(session.getValueFactory()));
+        atomicTypeConverters.put(Calendar.class,  new CalendarTypeConverter(session.getValueFactory()));
+        atomicTypeConverters.put(Date.class,  new UtilDateTypeConverter(session.getValueFactory()));
+        atomicTypeConverters.put(byte[].class,  new ByteArrayTypeConverter(session.getValueFactory()));
+        atomicTypeConverters.put(Timestamp.class,  new TimestampTypeConverter(session.getValueFactory()));
+                              
+        persistenceManager = new PersistenceManagerImpl(mapper, atomicTypeConverters, queryManager,
session);
         
         
         

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerAtomicQueryTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerAtomicQueryTest.java?rev=293438&r1=293437&r2=293438&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerAtomicQueryTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerAtomicQueryTest.java
Mon Oct  3 12:19:21 2005
@@ -49,6 +49,7 @@
 	public PersistenceManagerAtomicQueryTest(String testName) throws Exception
 	{
 		super(testName);
+		
 	}
 
 	public static Test suite()
@@ -78,7 +79,9 @@
 
 		try
 		{
-			this.importData();
+			Date date = new Date();
+			this.importData(date);
+			
 			PersistenceManager persistenceManager = this.getPersistenceManager();
 			
 			// Test Boolean value 
@@ -118,39 +121,64 @@
 			result = persistenceManager.getObjects(query);			
 			assertTrue("Invalid number of objects - should be = 36", result.size() == 36);
 
-			// Test double value
-//			filter = queryManager.createFilter(Atomic.class);
-//			filter.addEqualTo("doubleObject", new Double (202.12));
-//			query = queryManager.createQuery(filter);
-//			
-//			result = persistenceManager.getObjects(query);			
-//			assertTrue("Invalid number of objects - should be = 3", result.size() == 1);
-		
-//			filter = queryManager.createFilter(Atomic.class);
-//			filter.addLessOrEqualThan("doublePrimitive", new Double(602.12));
-//			query = queryManager.createQuery(filter);
-//			
-//			result = persistenceManager.getObjects(query);			
-//			assertTrue("Invalid number of objects - should be = 5", result.size() == 6);
 			
 			//Test Date & Calendar
-//			filter = queryManager.createFilter(Atomic.class);
-//			Calendar calendar = Calendar.getInstance();
-//			calendar.set(2012, 12, 01);
-//			filter.addLessThan("myCalendar", calendar);
-//			query = queryManager.createQuery(filter);
-//			
-//			result = persistenceManager.getObjects(query);			
-//			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);
-
-//			filter = queryManager.createFilter(Atomic.class);
-//			Calendar calendar = Calendar.getInstance();
-//			calendar.set(2012, 12, 01);
-//			filter.addLessThan("date", calendar);
-//			query = queryManager.createQuery(filter);
-//			
-//			result = persistenceManager.getObjects(query);			
-//			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);		

+			filter = queryManager.createFilter(Atomic.class);
+			Calendar calendar = Calendar.getInstance();
+			calendar.set(2012, 12, 01);
+			filter.addLessThan("calendar", calendar);
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);
+
+			filter = queryManager.createFilter(Atomic.class);
+			calendar = Calendar.getInstance();
+			calendar.set(1975, 12, 01);
+			filter.addLessThan("calendar", calendar);
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 0 ", result.size() == 0);
+			
+			filter = queryManager.createFilter(Atomic.class);			
+			filter.addEqualTo("date", date);
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);
+
+			filter = queryManager.createFilter(Atomic.class);			
+			filter.addBetween("date", date, new Date());
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);
+			
+			// Test contains method
+			filter = queryManager.createFilter(Atomic.class);			
+			filter.addContains(".", "JCR");
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 50 ", result.size() == 50);
+			
+			filter = queryManager.createFilter(Atomic.class);			
+			filter.addContains("byteArray", "Graffito");
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 50 ", result.size() == 50);
+			
+			filter = queryManager.createFilter(Atomic.class);			
+			filter.addContains("byteArray", "String");
+			query = queryManager.createQuery(filter);
+			
+			result = persistenceManager.getObjects(query);			
+			assertTrue("Invalid number of objects - should be = 0 ", result.size() == 0);
+
+		
+			
 			
 		}
 		catch (Exception e)
@@ -161,7 +189,7 @@
 
 	}
 
-	private void importData()
+	private void importData(Date date)
 	{
 		try
 		{
@@ -172,6 +200,8 @@
 				getPersistenceManager().remove("/test");
 			}
 
+			
+			
 			for (int i = 1; i <= 100; i++)
 			{
 				Atomic a = new Atomic();
@@ -180,7 +210,7 @@
 				a.setIntegerObject(new Integer(100 * i));
 				a.setIntPrimitive(200 + i);
 				a.setString("Test String " + i);
-				a.setDate(new Date());
+				a.setDate(date);
 				Calendar calendar = Calendar.getInstance();
 				calendar.set(1976, 4, 20, 15, 40);
 				a.setCalendar(calendar);
@@ -188,6 +218,14 @@
 				a.setDoublePrimitive(1.23 + i);
 				long now = System.currentTimeMillis();
 				a.setTimestamp(new Timestamp(now));
+				if ((i % 2) == 0)
+				{
+				     a.setByteArray("This is small object stored in a JCR repository".getBytes());
+				}
+				else
+				{
+					 a.setByteArray("This is small object stored in a Graffito repository".getBytes());
+				}
 				getPersistenceManager().insert("/test" + i, a);
 			}
 

Copied: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleQueryTest.java
(from r292016, 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/PersistenceManagerSimpleQueryTest.java?p2=incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleQueryTest.java&p1=incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerQueryTest.java&r1=292016&r2=293438&rev=293438&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerQueryTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleQueryTest.java
Mon Oct  3 12:19:21 2005
@@ -40,15 +40,15 @@
  *
  * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
  */
-public class PersistenceManagerQueryTest extends TestBase
+public class PersistenceManagerSimpleQueryTest extends TestBase
 {
-    private final static Log log = LogFactory.getLog(PersistenceManagerQueryTest.class);
+    private final static Log log = LogFactory.getLog(PersistenceManagerSimpleQueryTest.class);
 
     /**
      * <p>Defines the test case name for junit.</p>
      * @param testName The test case name.
      */
-    public PersistenceManagerQueryTest(String testName)  throws Exception
+    public PersistenceManagerSimpleQueryTest(String testName)  throws Exception
     {
         super(testName);
     }
@@ -56,7 +56,7 @@
     public static Test suite()
     {
         // All methods starting with "test" will be executed in the test suite.
-        return new TestSuite(PersistenceManagerQueryTest.class);
+        return new TestSuite(PersistenceManagerSimpleQueryTest.class);
     }
 
     



Mime
View raw message