Patch from Jasper on August 23.

This commit is contained in:
Ulrik Sandberg
2007-08-23 19:04:59 +00:00
parent 6afb32ea94
commit da97ce4b2c
12 changed files with 170 additions and 267 deletions

View File

@@ -1,169 +0,0 @@
<project name="odm" basedir="." xmlns:ivy="antlib:fr.jayasoft.ivy.ant" default="info">
<xmlproperty file="build-properties.xml" keeproot="false" semanticattributes="true" collapseattributes="true"/>
<target name="-info">
<echoproperties/>
</target>
<taskdef resource="fr/jayasoft/ivy/ant/antlib.xml" uri="antlib:fr.jayasoft.ivy.ant">
<classpath>
<fileset dir="${config.ivy}">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
<target name="-coverage.init" unless="coverage.init.done">
<path id="coverage.classpath">
<fileset dir="${build.lib.tasks}" includes="**/*.jar"/>
</path>
<delete dir="${build.coverage.instrumented}"/>
<delete dir="${build.coverage.output}"/>
<delete dir="${build.coverage.reports}"/>
<delete file="${build.coverage.datafile}"/>
<mkdir dir="${build.coverage.instrumented}"/>
<mkdir dir="${build.coverage}"/>
<mkdir dir="${build.coverage.output}"/>
<mkdir dir="${build.coverage.reports}"/>
<delete dir="${build.coverage}"/>
<mkdir dir="${build.coverage}"/>
<property name="coverage.init.done" value="true"/>
</target>
<target name="-coverage.instrument">
<fail unless="build.coverage.datafile"/>
<fail unless="build.main.classes"/>
<fail unless="build.coverage.instrumented"/>
<mkdir dir="${build.main.classes}"/>
<mkdir dir="${build.coverage.instrumented}"/>
<cobertura-instrument datafile="${build.coverage.datafile}"
toDir="${build.coverage.instrumented}">
<fileset dir="${build.main.classes}"
includes="**/*.class"/>
</cobertura-instrument>
</target>
<target name="-clean">
<mkdir dir="${build}"/>
<delete includeemptydirs="true" failonerror="false">
<fileset dir="${build}">
<include name="**/*"/>
</fileset>
</delete>
</target>
<target name="-taskdef">
<path id="tasks.lib">
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>
<taskdef resource="checkstyletask.properties" classpathref="tasks.lib"/>
<taskdef resource="tasks.properties" classpathref="tasks.lib"/>
<taskdef resource="testngtasks" classpathref="tasks.lib"/>
</target>
<target name="-checkstyle">
<mkdir dir="${build.checkstyle.reports}"/>
<checkstyle config="${config.checkstyle}/main-checkstyle.xml" failonviolation="true">
<formatter type="plain" toFile="${build.checkstyle.reports}/main-checkstyle-report.txt"/>
<fileset dir="${source.main.java}">
<include name="**/*.java"/>
</fileset>
<property key="checkstyle.import.control.file" value="main-import-control.xml"/>
</checkstyle>
<checkstyle config="${config.checkstyle}/test-checkstyle.xml" failonviolation="true">
<formatter type="plain" toFile="${build.checkstyle.reports}/test-checkstyle-report.txt"/>
<fileset dir="${source.test.java}">
<include name="**/*.java"/>
</fileset>
</checkstyle>
</target>
<target name="-compile">
<mkdir dir="${build.main.classes}"/>
<mkdir dir="${build.test.classes}"/>
<javac srcdir="${source.main.java}" destdir="${build.main.classes}" debug="true" fork="true" source="1.5"
target="1.5">
<classpath>
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</classpath>
</javac>
<javac srcdir="${source.test.java}" destdir="${build.test.classes}" debug="true" fork="true" source="1.5"
target="1.5">
<classpath>
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
<pathelement location="${build.main.classes}"/>
</classpath>
</javac>
</target>
<target name="-unit-test">
<testng outputdir="${build.test.reports}" haltonfailure="false"
failureproperty="unit.tests.failed">
<sysproperty key="net.sourceforge.cobertura.datafile" file="${build.coverage.datafile}"/>
<classpath>
<pathelement location="${build.coverage.instrumented}"/>
<pathelement location="${build.main.classes}"/>
<pathelement location="${build.test.classes}"/>
<pathelement location="${source.main.config}"/>
<fileset dir="lib" includes="*.jar"/>
</classpath>
<xmlfileset dir="${source.test.config}/testng" includes="unittest.xml"/>
</testng>
<junitreport todir="${build.test.reports}">
<fileset dir="${build.test.reports}/unit-tests" includes="*xml"/>
<report format="noframes" todir="${build.test.reports}/unit-tests"/>
</junitreport>
</target>
<target name="-cobertura-report">
<cobertura-report datafile="${build.coverage.datafile}"
srcdir="${source.main.java}"
destdir="${build.coverage.reports}"/>
</target>
<target name="-evaluate-build">
<fail if="unit.tests.failed"/>
<fail if="functional.tests.failed"/>
</target>
<target name="-package">
<mkdir dir="${build.main.artifacts}"/>
<zip file="${build.main.artifacts}/odm-source.zip">
<fileset dir="${source.main.java}" includes="**/*.java"/>
</zip>
<jar file="${build.main.artifacts}/odm.jar">
<fileset dir="${build.main.classes}" includes="**/*.class"/>
</jar>
</target>
<!-- private targets -->
<target name="--info" depends="-info"/>
<target name="--build"
depends="-clean, -taskdef, -checkstyle, -compile, -package, -coverage.init, -coverage.instrument, -unit-test, -cobertura-report, -evaluate-build"/>
<!-- public targets -->
<target name="info" depends="--info" description="-- echo the common and user specified build properties"/>
<target name="build" depends="--build"
description="-- clean, configure, compile and produce build artifacts"/>
</project>

View File

@@ -30,7 +30,7 @@ public class LdapDaoITest extends AbstractLdapTemplateIntegrationTest
LOGGER.debug("********************INIT TEST CLASS**************************");
return new String[]{"beans.xml"};
}
protected void onSetUp() throws Exception
{
super.onSetUp();

View File

@@ -12,10 +12,10 @@ import org.springframework.beans.TypeMismatchException;
import org.springframework.core.MethodParameter;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.odm.typeconversion.ConversionType;
import org.springframework.ldap.odm.typeconversion.LdapTypeConverter;
import org.springframework.ldap.odm.typeconversion.MultiValueType;
import org.springframework.ldap.odm.typeconversion.ReferencedEntryEditorFactory;
import org.springframework.ldap.odm.typeconversion.ValidConversionType;
import org.springframework.ldap.odm.typeconversion.ValidContainerType;
import org.springframework.ldap.odm.util.AttributeWrapper;
import org.springframework.util.StringUtils;
@@ -108,7 +108,7 @@ public class ObjectDirectoryMapperImpl implements ObjectDirectoryMapper
{
ctxAdapter.setAttributeValue(attributeName, beanPropertyValue);
}
else if (ValidContainerType.isImplementedBy(beanPropertyValue.getClass()))
else if (MultiValueType.isAssignableTo(beanPropertyValue.getClass()))
{
ctxAdapter.setAttributeValues(attributeName,
typeConverter.getAllAsText(beanPropertyValue));
@@ -211,7 +211,7 @@ public class ObjectDirectoryMapperImpl implements ObjectDirectoryMapper
{
for (Method getter : propertyGetters.values())
{
if (!ValidConversionType.isValidConversionType(getter.getReturnType()))
if (!ConversionType.isConversionType(getter.getReturnType()))
{
try
{
@@ -225,8 +225,8 @@ public class ObjectDirectoryMapperImpl implements ObjectDirectoryMapper
+ getter.getName()
+ "() has invalid return type. Return type must be a directory " +
"mapped object, or one of the following: \n\n"
+ ValidConversionType.listTypes() + "\n\n"
+ ValidContainerType.listTypes(), e);
+ ConversionType.listTypes() + "\n\n"
+ MultiValueType.listTypes(), e);
}
}
}

View File

@@ -12,7 +12,7 @@ import java.util.Date;
/** This list of types supported for mapping between ldap attributes and bean properties. */
public enum ValidConversionType
public enum ConversionType
{
BYTE_ARRAY(byte[].class),
BOOLEAN(Boolean.class),
@@ -32,9 +32,9 @@ public enum ValidConversionType
private final Class clazz;
ValidConversionType(Class validType)
ConversionType(Class type)
{
this.clazz = validType;
this.clazz = type;
}
@@ -42,13 +42,13 @@ public enum ValidConversionType
public static String listTypes()
{
StringBuilder sb = new StringBuilder();
sb.append("VALID CONVERSION TYPES: ");
for (int i = 0; i < ValidConversionType.values().length; i++)
sb.append("CONVERSION TYPES: ");
for (int i = 0; i < values().length; i++)
{
ValidConversionType validType = ValidConversionType.values()[i];
ConversionType type = values()[i];
sb.append("\n");
sb.append(validType.clazz.getSimpleName());
if (i != ValidConversionType.values().length - 1)
sb.append(type.clazz.getSimpleName());
if (i != values().length - 1)
{
sb.append(",");
}
@@ -57,11 +57,11 @@ public enum ValidConversionType
}
/** Returns true if the argument is a member of this enumeration. */
public static boolean isValidConversionType(Class returnType)
public static boolean isConversionType(Class candidate)
{
for (ValidConversionType type : ValidConversionType.values())
for (ConversionType type : values())
{
if (returnType.equals(type.clazz))
if (candidate.equals(type.clazz))
{
return true;
}

View File

@@ -69,6 +69,7 @@ public class LdapTypeConverter extends SimpleTypeConverter
}
}
/** Convert a collection or Array of objects to their string representation */
public String[] getAllAsText(Object values)
{
if (values instanceof Collection)
@@ -80,10 +81,7 @@ public class LdapTypeConverter extends SimpleTypeConverter
return getAllAsText((Object[]) values);
}
}
/**
* Convert Object array to String array
*/
private String[] getAllAsText(Object[] values)
{
String[] textValues = new String[values.length];

View File

@@ -10,3 +10,9 @@ public enum LoadPolicy
{
THROW_REFERENTIAL_INTEGRITY_EXCEPTIONS, SUPPRESS_REFERENTIAL_INTEGRITY_EXCEPTIONS
}
/*
* Copyright 2005 by Majitek. All Rights Reserved.
*
* This software is the proprietary information of Majitek. Use is subject to license terms.
*/

View File

@@ -10,7 +10,7 @@ import java.util.List;
import java.util.Set;
import java.util.Collection;
public enum ValidContainerType
public enum MultiValueType
{
ARRAY(Object[].class),
COLLECTION(Collection.class),
@@ -19,7 +19,7 @@ public enum ValidContainerType
private final Class clazz;
ValidContainerType(Class clazz)
MultiValueType(Class clazz)
{
this.clazz = clazz;
}
@@ -30,10 +30,10 @@ public enum ValidContainerType
public static String listTypes()
{
StringBuilder sb = new StringBuilder();
sb.append("VALID MULTI-VALUE CONTAINER TYPES:");
sb.append("MULTI-VALUE TYPES:");
for (int i = 0; i < values().length; i++)
{
ValidContainerType validType = values()[i];
MultiValueType validType = values()[i];
sb.append("\n");
sb.append(validType.clazz.getSimpleName());
if (i != values().length - 1)
@@ -47,9 +47,9 @@ public enum ValidContainerType
/**
* Returns true if the argument is a member of this enumeration.
*/
public static boolean isValidContainerType(Class returnType)
public static boolean isMultiValueType(Class returnType)
{
for (ValidContainerType type : values())
for (MultiValueType type : values())
{
if (returnType.equals(type.clazz))
{
@@ -59,9 +59,9 @@ public enum ValidContainerType
return false;
}
public static boolean isImplementedBy(Class returnType)
public static boolean isAssignableTo(Class returnType)
{
for (ValidContainerType type : values())
for (MultiValueType type : values())
{
if (type.clazz.isAssignableFrom(returnType))
{

View File

@@ -18,3 +18,10 @@ public class ReferentialIntegrityException extends RuntimeException
super(message, cause);
}
}
/*
* Copyright 2005 by Majitek. All Rights Reserved.
*
* This software is the proprietary information of Majitek. Use is subject to license terms.
*/

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2005 by Majitek. All Rights Reserved.
*
* This software is the proprietary information of Majitek. Use is subject to license terms.
*/
package org.springframework.ldap.odm.typeconversion;
import junit.framework.TestCase;
import junit.framework.Assert;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ldap.core.DistinguishedName;
import javax.naming.ldap.LdapName;
import java.util.Date;
import java.util.List;
public class ConversionTypeTest extends TestCase
{
private static final Log LOGGER = LogFactory.getLog(ConversionTypeTest.class);
public void testListTypes()
{
LOGGER.debug(ConversionType.listTypes());
}
public void testIsConversionType()
{
Assert.assertFalse(ConversionType.isConversionType(List.class));
Assert.assertTrue(ConversionType.isConversionType(byte[].class));
Assert.assertTrue(ConversionType.isConversionType(Boolean.class));
Assert.assertTrue(ConversionType.isConversionType(String.class));
Assert.assertTrue(ConversionType.isConversionType(String[].class));
Assert.assertTrue(ConversionType.isConversionType(Date.class));
Assert.assertTrue(ConversionType.isConversionType(Date[].class));
Assert.assertTrue(ConversionType.isConversionType(LdapName.class));
Assert.assertTrue(ConversionType.isConversionType(LdapName[].class));
Assert.assertTrue(ConversionType.isConversionType(DistinguishedName.class));
Assert.assertTrue(ConversionType.isConversionType(DistinguishedName[].class));
Assert.assertTrue(ConversionType.isConversionType(Integer.class));
Assert.assertTrue(ConversionType.isConversionType(Integer[].class));
Assert.assertTrue(ConversionType.isConversionType(Long.class));
Assert.assertTrue(ConversionType.isConversionType(Long[].class));
}
}

View File

@@ -12,6 +12,7 @@ import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
import java.lang.reflect.Method;
import javax.naming.InvalidNameException;
@@ -40,7 +41,7 @@ public class LdapTypeConverterTest extends TestCase
typeConverter = new LdapTypeConverter();
}
public void testConvertToByteArray()
public void testPassthroughOfByteArray()
{
byte[] objectToTranslate = "fred".getBytes();
@@ -57,7 +58,7 @@ public class LdapTypeConverterTest extends TestCase
}
}
public void testConvertToBoolean()
public void testConvertStringToBoolean()
{
String objectToTranslate = "true";
try
@@ -73,7 +74,7 @@ public class LdapTypeConverterTest extends TestCase
}
}
public void testConvertFromBoolean()
public void testConvertBooleanToString()
{
boolean objectToTranslate = false;
try
@@ -88,7 +89,7 @@ public class LdapTypeConverterTest extends TestCase
}
}
public void testConvertToString()
public void testPassthroughOfString()
{
String objectToTranslate = "onetwothree";
try
@@ -103,7 +104,7 @@ public class LdapTypeConverterTest extends TestCase
}
}
public void testConvertToStringArray()
public void testPassthroughOfStringArray()
{
String object1 = "onetwothree";
String object2 = "fourfivesix";
@@ -122,7 +123,7 @@ public class LdapTypeConverterTest extends TestCase
}
}
public void testConvertToListOfStrings()
public void testConvertStringArrayToListOfStrings()
{
String object1 = "onetwothree";
String object2 = "fourfivesix";
@@ -142,7 +143,7 @@ public class LdapTypeConverterTest extends TestCase
}
public void testConvertToSetOfStrings()
public void testConvertStringArrayToSetOfStrings()
{
String object1 = "onetwothree";
String object2 = "fourfivesix";
@@ -164,7 +165,7 @@ public class LdapTypeConverterTest extends TestCase
public void testConvertToDate() throws ParseException
public void testConvertStringToDate() throws ParseException
{
String object1 = "19700101100000.000+1000";
@@ -181,7 +182,7 @@ public class LdapTypeConverterTest extends TestCase
}
}
public void testConvertFromDate()
public void testConvertDateToString()
{
Date source = new Date(1184283822285L); //Friday July 13, 2007 9:43:42 AM GMT+1000
LOGGER.debug(typeConverter.getAsText(source));
@@ -190,7 +191,7 @@ public class LdapTypeConverterTest extends TestCase
.matches("20070713\\d\\d\\d\\d42.285\\+\\d\\d\\d\\d"));
}
public void testConvertToDateArray() throws ParseException
public void testConvertStringArrayToDateArray() throws ParseException
{
String object1 = "20071105093655.0+1000";
String object2 = "19700101100000.0+1000";
@@ -210,7 +211,7 @@ public class LdapTypeConverterTest extends TestCase
}
}
public void testGeneralizedTimeToListOfDates() throws ParseException, NoSuchMethodException
public void testConvertGeneralizedTimeArrayToListOfDates() throws ParseException, NoSuchMethodException
{
String object1 = "20071105093655.0+1000";
String object2 = "19700101100000.0+1000";
@@ -234,7 +235,7 @@ public class LdapTypeConverterTest extends TestCase
}
public void testConvertFromDateArray()
public void testConvertDateArrayToStringArray()
{
Date date1 = new Date(1184283822285L); //Friday July 13, 2007 9:43:42 AM + GMT+1000
Date date2 = new Date(0); //epoch + GMT + 1000
@@ -245,7 +246,21 @@ public class LdapTypeConverterTest extends TestCase
Assert.assertTrue(converted[1].matches("19700101\\d\\d\\d\\d00.000\\+\\d\\d\\d\\d"));
}
public void testConvertToLdapName()
public void testConvertDateCollectionToStringArray()
{
Date date1 = new Date(1184283822285L); //Friday July 13, 2007 9:43:42 AM + GMT+1000
Date date2 = new Date(0); //epoch + GMT + 1000
Set<Date> dates = new HashSet<Date>();
dates.add(date1);
dates.add(date2);
String[] converted = typeConverter.getAllAsText(dates);
Assert.assertTrue(converted[0].matches("20070713\\d\\d\\d\\d42.285\\+\\d\\d\\d\\d"));
Assert.assertTrue(converted[1].matches("19700101\\d\\d\\d\\d00.000\\+\\d\\d\\d\\d"));
}
public void testConvertStringToLdapName()
{
String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com";
try
@@ -264,7 +279,7 @@ public class LdapTypeConverterTest extends TestCase
}
}
public void testConvertToLdapNameArray()
public void testConvertStringArrayToLdapNameArray()
{
String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com";
String object2 = "uid=fred, ou = people, dc = myretsu,dc=com";
@@ -286,7 +301,7 @@ public class LdapTypeConverterTest extends TestCase
}
}
public void testConvertToDistinguishedName()
public void testConvertStringToDistinguishedName()
{
String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com";
try
@@ -301,7 +316,7 @@ public class LdapTypeConverterTest extends TestCase
}
}
public void testConvertToDistinguishedNameArray()
public void testConvertStringArrayToDistinguishedNameArray()
{
String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com";
String object2 = "uid=fred, ou = people, dc = myretsu,dc=com";
@@ -319,7 +334,7 @@ public class LdapTypeConverterTest extends TestCase
}
}
public void testConvertToLong()
public void testConvertStringToLong()
{
String object1 = "9887342";
try
@@ -334,7 +349,7 @@ public class LdapTypeConverterTest extends TestCase
}
}
public void testConvertToLongArray()
public void testConvertStringArrayToLongArray()
{
String object1 = "878787";
String object2 = "23948787";
@@ -353,7 +368,7 @@ public class LdapTypeConverterTest extends TestCase
}
}
public void testConvertToInteger()
public void testConvertStringToInteger()
{
String object1 = "9887342";
@@ -369,7 +384,7 @@ public class LdapTypeConverterTest extends TestCase
}
}
public void testConvertToIntegerArray()
public void testConvertStringArrayToIntegerArray()
{
String object1 = "878787";
String object2 = "23948787";

View File

@@ -0,0 +1,46 @@
/*
* Copyright 2005 by Majitek. All Rights Reserved.
*
* This software is the proprietary information of Majitek. Use is subject to license terms.
*/
package org.springframework.ldap.odm.typeconversion;
import junit.framework.TestCase;
import junit.framework.Assert;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
import java.util.ArrayList;
public class MultiValueTypeTest extends TestCase
{
private static final Log LOGGER = LogFactory.getLog(MultiValueTypeTest.class);
public void testListTypes()
{
LOGGER.debug(MultiValueType.listTypes());
}
public void testIsMultiValueType()
{
Assert.assertFalse(MultiValueType.isMultiValueType(String.class));
Assert.assertTrue(MultiValueType.isMultiValueType(Object[].class));
Assert.assertTrue(MultiValueType.isMultiValueType(Collection.class));
Assert.assertTrue(MultiValueType.isMultiValueType(List.class));
Assert.assertTrue(MultiValueType.isMultiValueType(Set.class));
}
public void testIsAssignableTo()
{
Assert.assertFalse(MultiValueType.isAssignableTo(String.class));
Assert.assertTrue(MultiValueType.isAssignableTo(ArrayList.class));
Assert.assertTrue(MultiValueType.isAssignableTo(HashSet.class));
}
}

View File

@@ -1,48 +0,0 @@
/*
* Copyright 2005 by Majitek. All Rights Reserved.
*
* This software is the proprietary information of Majitek. Use is subject to license terms.
*/
package org.springframework.ldap.odm.typeconversion;
import junit.framework.TestCase;
import junit.framework.Assert;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ldap.core.DistinguishedName;
import javax.naming.ldap.LdapName;
import java.util.Date;
import java.util.List;
public class ValidConversionTypeTest extends TestCase
{
private static final Log LOGGER = LogFactory.getLog(ValidConversionTypeTest.class);
public void testListTypes()
{
LOGGER.debug(ValidConversionType.listTypes());
}
public void testIsValidConversionType()
{
Assert.assertFalse(ValidConversionType.isValidConversionType(List.class));
Assert.assertTrue(ValidConversionType.isValidConversionType(byte[].class));
Assert.assertTrue(ValidConversionType.isValidConversionType(Boolean.class));
Assert.assertTrue(ValidConversionType.isValidConversionType(String.class));
Assert.assertTrue(ValidConversionType.isValidConversionType(String[].class));
Assert.assertTrue(ValidConversionType.isValidConversionType(Date.class));
Assert.assertTrue(ValidConversionType.isValidConversionType(Date[].class));
Assert.assertTrue(ValidConversionType.isValidConversionType(LdapName.class));
Assert.assertTrue(ValidConversionType.isValidConversionType(LdapName[].class));
Assert.assertTrue(ValidConversionType.isValidConversionType(DistinguishedName.class));
Assert.assertTrue(ValidConversionType.isValidConversionType(DistinguishedName[].class));
Assert.assertTrue(ValidConversionType.isValidConversionType(Integer.class));
Assert.assertTrue(ValidConversionType.isValidConversionType(Integer[].class));
Assert.assertTrue(ValidConversionType.isValidConversionType(Long.class));
Assert.assertTrue(ValidConversionType.isValidConversionType(Long[].class));
}
}