Improve the Mail metadata extractor test with more checks, and add a general metadata 'did we get something back' check to fail earlier with a more helpful error message. Also added an Array -> Collection TypeConverter that was missing from an early branch port

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18698 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2010-02-18 12:41:51 +00:00
parent bcabacb17d
commit c347025bae
3 changed files with 42 additions and 0 deletions

View File

@@ -103,6 +103,8 @@ public abstract class AbstractMetadataExtracterTest extends TestCase
try try
{ {
Map<QName, Serializable> properties = extractFromMimetype(mimetype); Map<QName, Serializable> properties = extractFromMimetype(mimetype);
// check we got something
assertFalse("extractFromMimetype should return at least some properties, none found", properties.isEmpty());
// check common metadata // check common metadata
testCommonMetadata(mimetype, properties); testCommonMetadata(mimetype, properties);
// check file-type specific metadata // check file-type specific metadata

View File

@@ -24,12 +24,14 @@
*/ */
package org.alfresco.repo.content.metadata; package org.alfresco.repo.content.metadata;
import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
@@ -69,6 +71,11 @@ public class MailMetadataExtracterTest extends AbstractMetadataExtracterTest
public void testOutlookMsgExtraction() throws Exception public void testOutlookMsgExtraction() throws Exception
{ {
// Check we can find the file
File sourceFile = AbstractContentTransformerTest.loadQuickTestFile("msg");
assertNotNull("quick.msg files should be available from Tests", sourceFile);
// Now test
testExtractFromMimetype(MimetypeMap.MIMETYPE_OUTLOOK_MSG); testExtractFromMimetype(MimetypeMap.MIMETYPE_OUTLOOK_MSG);
} }
@@ -78,10 +85,16 @@ public class MailMetadataExtracterTest extends AbstractMetadataExtracterTest
*/ */
protected void testCommonMetadata(String mimetype, Map<QName, Serializable> properties) protected void testCommonMetadata(String mimetype, Map<QName, Serializable> properties)
{ {
// Two equivalent ones
assertEquals( assertEquals(
"Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype, "Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
"Kevin Roast", "Kevin Roast",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_AUTHOR))); DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_AUTHOR)));
assertEquals(
"Property " + ContentModel.PROP_ORIGINATOR + " not found for mimetype " + mimetype,
"Kevin Roast",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_ORIGINATOR)));
// One other common bit
assertEquals( assertEquals(
"Property " + ContentModel.PROP_DESCRIPTION + " not found for mimetype " + mimetype, "Property " + ContentModel.PROP_DESCRIPTION + " not found for mimetype " + mimetype,
"Test the content transformer", "Test the content transformer",

View File

@@ -120,6 +120,33 @@ public class TypeConverter
return (T) converter.convert(value); return (T) converter.convert(value);
} }
/**
* General conversion method to convert collection contents to the specified
* type. Wrapper around the Collection version for arrays.
*
* @param propertyType - the target property type
* @param value - the value to be converted
* @return - the converted value as the correct type
* @throws DictionaryException if the property type's registered java class is invalid
* @throws TypeConversionException if the conversion cannot be performed
*/
@SuppressWarnings("unchecked")
public final Collection convert(DataTypeDefinition propertyType, Object[] values)
{
if(values == null) {
return convert(propertyType, (Collection)null);
} else {
// Turn the array into a Collection, then convert as that
ArrayList c = new ArrayList();
c.ensureCapacity(values.length);
for(Object v : values) {
c.add(v);
}
// Convert
return convert(propertyType, c);
}
}
/** /**
* General conversion method to convert collection contents to the specified * General conversion method to convert collection contents to the specified
* type. * type.