mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -103,6 +103,8 @@ public abstract class AbstractMetadataExtracterTest extends TestCase
|
||||
try
|
||||
{
|
||||
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
|
||||
testCommonMetadata(mimetype, properties);
|
||||
// check file-type specific metadata
|
||||
|
@@ -24,12 +24,14 @@
|
||||
*/
|
||||
package org.alfresco.repo.content.metadata;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
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.namespace.QName;
|
||||
|
||||
@@ -69,6 +71,11 @@ public class MailMetadataExtracterTest extends AbstractMetadataExtracterTest
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -78,10 +85,16 @@ public class MailMetadataExtracterTest extends AbstractMetadataExtracterTest
|
||||
*/
|
||||
protected void testCommonMetadata(String mimetype, Map<QName, Serializable> properties)
|
||||
{
|
||||
// Two equivalent ones
|
||||
assertEquals(
|
||||
"Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
|
||||
"Kevin Roast",
|
||||
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(
|
||||
"Property " + ContentModel.PROP_DESCRIPTION + " not found for mimetype " + mimetype,
|
||||
"Test the content transformer",
|
||||
|
@@ -120,6 +120,33 @@ public class TypeConverter
|
||||
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
|
||||
* type.
|
||||
|
Reference in New Issue
Block a user