[lsc-changes] r527 - lsc/trunk/src/test/java/org/lsc/beans

jclarke at lsc-project.org jclarke at lsc-project.org
Mon Nov 30 23:36:24 CET 2009


Author: jclarke
Date: 2009-11-30 23:36:24 +0100 (Mon, 30 Nov 2009)
New Revision: 527

Modified:
   lsc/trunk/src/test/java/org/lsc/beans/BeanComparatorTest.java
Log:
Rewrite BeanComparator.calculateModificationType method to avoid cloning object unless necessary and optimize cloning. Add test to cover this method (in trunk and 1.1 branch)

Modified: lsc/trunk/src/test/java/org/lsc/beans/BeanComparatorTest.java
===================================================================
--- lsc/trunk/src/test/java/org/lsc/beans/BeanComparatorTest.java	2009-11-30 21:59:41 UTC (rev 526)
+++ lsc/trunk/src/test/java/org/lsc/beans/BeanComparatorTest.java	2009-11-30 22:36:24 UTC (rev 527)
@@ -71,6 +71,40 @@
 public class BeanComparatorTest extends TestCase
 {
 
+	/**
+	 * Test method for {@link org.lsc.beans.BeanComparator#calculateModificationType(ISyncOptions, IBean, IBean, Object)}.
+	 */
+	public void testCalculateModificationType() {
+		dummySyncOptions syncOptions = new dummySyncOptions();
+		IBean srcBean = new SimpleBean();
+		IBean dstBean = new SimpleBean();
+
+		try {
+			// test null and null --> null
+			assertNull(BeanComparator.calculateModificationType(syncOptions, null, null, null));
+			
+			// test not null and null --> add
+			assertEquals(JndiModificationType.ADD_ENTRY, BeanComparator.calculateModificationType(syncOptions, srcBean, null, null));
+			
+			// test null and not null --> delete
+			assertEquals(JndiModificationType.DELETE_ENTRY, BeanComparator.calculateModificationType(syncOptions, null, dstBean, null));
+			
+			// test both not null, and syncoptions to make DNs identical --> modify
+			syncOptions.setDn("\"destination DN\"");
+			dstBean.setDistinguishName("destination DN");
+			assertEquals(JndiModificationType.MODIFY_ENTRY, BeanComparator.calculateModificationType(syncOptions, srcBean, dstBean, null));
+
+			// test both not null, with different DNs and no DN in syncoptions --> modrdn
+			syncOptions.setDn(null);
+			srcBean.setDistinguishName("source DN");
+			dstBean.setDistinguishName("destination DN");
+			assertEquals(JndiModificationType.MODRDN_ENTRY, BeanComparator.calculateModificationType(syncOptions, srcBean, dstBean, null));
+		}
+		catch (CloneNotSupportedException e) {
+			assertTrue(e.toString(), false);
+		}
+	}
+	
     /**
      * This test ensures that a source bean containing fields with only
      * empty string values is not output as a modification to be applied 
@@ -328,6 +362,7 @@
 		Map<String, List<String>> defaultValuesMap; 
 		Map<String, List<String>> forceValuesMap;
 		Map<String, STATUS_TYPE> statusMap;
+		String dn;
 		
 		public dummySyncOptions(Map<String, List<String>> createValuesMap,
 				Map<String, List<String>> defaultValuesMap, 
@@ -348,6 +383,10 @@
 
 		}
 		
+		public dummySyncOptions() {
+			// TODO Auto-generated constructor stub
+		}
+
 		public String getCondition(JndiModificationType operation)
 		{
 			// TODO Auto-generated method stub
@@ -388,10 +427,14 @@
 			return null;
 		}
 
+		public void setDn(String dn)
+		{
+			this.dn = dn;
+		}
+
 		public String getDn()
 		{
-			// TODO Auto-generated method stub
-			return null;
+			return dn;
 		}
 
 		public Set<String> getForceValuedAttributeNames()



More information about the lsc-changes mailing list