REPO-5190 Remove Metadata Extractors that are been offloaded in 7.0.0 (#148)

Removed all the Extractors that now exist in the T-Engines:

    JodConnverterMetadataExtracter
    TikaPoweredMetadataExtracter – the abstract base class used by other extractors
    -- MailMetadataExtracter
    -- PoiMetadataExtracter
    -- TikaAutoMetadataExtracter
    -- MP3MetadataExtracter
    -- TikaSpringConfiguredMetadataExtracter - removed as it required Spring config and would run in process
    -- PdfBoxMetadataExtracter
    -- OpenDocumentMetadataExtracter
    -- OfficeMetadataExtracter
    -- DWGMetadataExtracter
    HtmlMetadataExtracter
    RFC822MetadataExtracter

XmlMetadataExtracter and XPathMetadataExtracter still exist but don't provide any extraction out of the box. The reason they still exist is to support custom transforms (in AMPs) to extract from XML. There are no XML extractors in the T-Engines at the moment, but that is where the custom transformer code really should be moved.

    There are new tests to ensure the async transforms take place as expected.
    Additionally many of the existing tests still exist (those not related to a specific extractor). Some of these have been modified to reflect that the extract is now async and to no longer check the modified value has not changed (it is now expected to change).
    There are also a number of new metadata extract smoke tests that ensure that a selected subset of extracts are supported by the OOTB T-Engines.
This commit is contained in:
Alan Davis
2020-11-12 14:08:04 +00:00
committed by GitHub
parent 374bf7aea8
commit d70790f0c2
54 changed files with 487 additions and 5640 deletions

View File

@@ -72,37 +72,24 @@ import org.springframework.context.ApplicationContext;
org.alfresco.repo.content.transform.AppleIWorksContentTransformerTest.class,
org.alfresco.repo.content.transform.ArchiveContentTransformerTest.class,
// Metadata tests
org.alfresco.repo.content.metadata.DWGMetadataExtracterTest.class,
org.alfresco.repo.content.metadata.HtmlMetadataExtracterTest.class,
org.alfresco.repo.content.metadata.MailMetadataExtracterTest.class,
org.alfresco.repo.content.metadata.MP3MetadataExtracterTest.class,
org.alfresco.repo.content.metadata.OfficeMetadataExtracterTest.class,
org.alfresco.repo.content.metadata.OpenDocumentMetadataExtracterTest.class,
org.alfresco.repo.content.metadata.JodMetadataExtractorOOoTest.class,
org.alfresco.repo.content.metadata.PdfBoxMetadataExtracterTest.class,
org.alfresco.repo.content.metadata.ConcurrencyPdfBoxMetadataExtracterTest.class,
org.alfresco.repo.content.metadata.PoiMetadataExtracterTest.class,
org.alfresco.repo.content.metadata.RFC822MetadataExtracterTest.class,
org.alfresco.repo.content.metadata.TikaAutoMetadataExtracterTest.class,
// Metadata tests - replaced with simplified test in LocalRenditionTest and ServiceRenditionTest
org.alfresco.repo.content.metadata.MappingMetadataExtracterTest.class,
// ----------------------------------------------------------------------
// Transformer/Rendition contexts
//
// The following tests can be extracted in a separate test suite
// if/when we decide to move the transformations in a separate component
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Transformer/Rendition contexts
//
// The following tests can be extracted in a separate test suite
// if/when we decide to move the transformations in a separate component
// ----------------------------------------------------------------------
// [classpath:alfresco/application-context.xml, classpath:org/alfresco/repo/thumbnail/test-thumbnail-context.xml]
// some tests fail locally - on windows
org.alfresco.repo.thumbnail.ThumbnailServiceImplTest.class,
// [classpath:alfresco/application-context.xml, classpath:org/alfresco/repo/thumbnail/test-thumbnail-context.xml]
// some tests fail locally - on windows
org.alfresco.repo.thumbnail.ThumbnailServiceImplTest.class,
// [classpath:/test/alfresco/test-renditions-context.xml, classpath:alfresco/application-context.xml,
// classpath:alfresco/test/global-integration-test-context.xml]
// this does NOT passes locally
org.alfresco.repo.rendition.RenditionServicePermissionsTest.class,
// [classpath:/test/alfresco/test-renditions-context.xml, classpath:alfresco/application-context.xml,
// classpath:alfresco/test/global-integration-test-context.xml]
// this does NOT passes locally
org.alfresco.repo.rendition.RenditionServicePermissionsTest.class,
// ----------------------------------------------------------------------
// Misc contexts

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -2175,7 +2175,7 @@ public class ContentDiskDriverTest extends TestCase
try
{
tran.doInTransaction(deleteGarbageDirCB);
transactionService.getRetryingTransactionHelper().doInTransaction(deleteGarbageDirCB);
}
catch (Exception e)
{
@@ -2205,8 +2205,8 @@ public class ContentDiskDriverTest extends TestCase
}
};
tran.doInTransaction(createTestDirCB);
};
transactionService.getRetryingTransactionHelper().doInTransaction(createTestDirCB);
logger.debug("Create rule on test dir");
RetryingTransactionCallback<Void> createRuleCB = new RetryingTransactionCallback<Void>() {
@@ -2235,7 +2235,7 @@ public class ContentDiskDriverTest extends TestCase
compAction.addActionCondition(noCondition2);
rule.setAction(compAction);
ruleService.saveRule(testContext.testDirNodeRef, rule);
logger.debug("rule created");
@@ -2243,7 +2243,7 @@ public class ContentDiskDriverTest extends TestCase
return null;
}
};
tran.doInTransaction(createRuleCB, false, true);
transactionService.getRetryingTransactionHelper().doInTransaction(createRuleCB, false, true);
/**
* Create a file in the test directory
@@ -2272,7 +2272,7 @@ public class ContentDiskDriverTest extends TestCase
return null;
}
};
tran.doInTransaction(createFileCB, false, true);
transactionService.getRetryingTransactionHelper().doInTransaction(createFileCB, false, true);
logger.debug("step b: write content to test file");
@@ -2294,16 +2294,16 @@ public class ContentDiskDriverTest extends TestCase
return null;
}
};
tran.doInTransaction(writeFileCB, false, true);
transactionService.getRetryingTransactionHelper().doInTransaction(writeFileCB, false, true);
Thread.sleep(3000); // Need to wait for the async extract
logger.debug("Step c: validate metadata has been extracted.");
/**
* c: check simple case of meta-data extraction has worked.
*/
RetryingTransactionCallback<Void> validateFirstExtractionCB = new RetryingTransactionCallback<Void>() {
@Override
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
Map<QName, Serializable> props = nodeService.getProperties(testContext.testNodeRef);
@@ -2318,14 +2318,11 @@ public class ContentDiskDriverTest extends TestCase
assertEquals("description is not correct", "This is a test file", nodeService.getProperty(testContext.testNodeRef, ContentModel.PROP_DESCRIPTION));
assertEquals("title is not correct", "ContentDiskDriverTest", nodeService.getProperty(testContext.testNodeRef, ContentModel.PROP_TITLE));
assertEquals("author is not correct", "mrogers", nodeService.getProperty(testContext.testNodeRef, ContentModel.PROP_AUTHOR));
return null;
}
};
tran.doInTransaction(validateFirstExtractionCB, false, true);
});
/**
* d: Save the new file as an update file in the test directory
@@ -2346,7 +2343,7 @@ public class ContentDiskDriverTest extends TestCase
return null;
}
};
tran.doInTransaction(createUpdateFileCB, false, true);
transactionService.getRetryingTransactionHelper().doInTransaction(createUpdateFileCB, false, true);
RetryingTransactionCallback<Void> writeFile2CB = new RetryingTransactionCallback<Void>() {
@@ -2379,7 +2376,7 @@ public class ContentDiskDriverTest extends TestCase
return null;
}
};
tran.doInTransaction(writeFile2CB, false, true);
transactionService.getRetryingTransactionHelper().doInTransaction(writeFile2CB, false, true);
/**
* rename the old file
@@ -2394,7 +2391,7 @@ public class ContentDiskDriverTest extends TestCase
return null;
}
};
tran.doInTransaction(renameOldFileCB, false, true);
transactionService.getRetryingTransactionHelper().doInTransaction(renameOldFileCB, false, true);
/**
* Check the old file has gone.
@@ -2416,7 +2413,7 @@ public class ContentDiskDriverTest extends TestCase
return null;
}
};
tran.doInTransaction(validateOldFileGoneCB, false, true);
transactionService.getRetryingTransactionHelper().doInTransaction(validateOldFileGoneCB, false, true);
// /**
// * Check metadata extraction on intermediate new file
@@ -2439,7 +2436,7 @@ public class ContentDiskDriverTest extends TestCase
// }
// };
//
// tran.doInTransaction(validateIntermediateCB, true, true);
// transactionService.getRetryingTransactionHelper().doInTransaction(validateIntermediateCB, true, true);
/**
* Move the new file into place, stuff should get shuffled
@@ -2454,8 +2451,8 @@ public class ContentDiskDriverTest extends TestCase
return null;
}
};
tran.doInTransaction(moveNewFileCB, false, true);
transactionService.getRetryingTransactionHelper().doInTransaction(moveNewFileCB, false, true);
logger.debug("validate update has run correctly.");
RetryingTransactionCallback<Void> validateUpdateCB = new RetryingTransactionCallback<Void>() {
@@ -2482,12 +2479,12 @@ public class ContentDiskDriverTest extends TestCase
return null;
}
};
tran.doInTransaction(validateUpdateCB, true, true);
transactionService.getRetryingTransactionHelper().doInTransaction(validateUpdateCB, true, true);
} // testScenarioShuffleMetadataExtraction
/**
* ALF-12812
*
@@ -2698,8 +2695,10 @@ public class ContentDiskDriverTest extends TestCase
};
tran.doInTransaction(moveNewFileCB, false, true);
logger.debug("Step c: validate metadata has been extracted.");
Thread.sleep(3000); // Need to wait for async extract
logger.debug("Step c: validate metadata has been extracted.");
/**
* c: check simple case of meta-data extraction has worked.
*/
@@ -2732,7 +2731,7 @@ public class ContentDiskDriverTest extends TestCase
};
tran.doInTransaction(validateFirstExtractionCB, false, true);
} // testScenarioMetadataExtractionForMac
public void testDirListing()throws Exception

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -26,6 +26,7 @@
package org.alfresco.repo.action;
import static java.lang.Thread.sleep;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -351,7 +352,16 @@ public class ActionServiceImpl2Test
Action action = actionService.createAction(ContentMetadataExtracter.EXECUTOR_NAME);
// Execute the action
actionService.executeAction(action, testNode);
return null;
}
});
Thread.sleep(3000); // Need to wait for the async extract
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
assertEquals("Gym class featuring a brown fox and lazy dog",
nodeService.getProperty(testNode, ContentModel.PROP_DESCRIPTION));
return null;

View File

@@ -93,8 +93,6 @@ public class ContentMetadataEmbedderTest extends BaseSpringTest
this.dictionaryService = (DictionaryService) this.applicationContext.getBean("dictionaryService");
this.mimetypeService = (MimetypeService) this.applicationContext.getBean("mimetypeService");
this.metadataExtracterRegistry = (MetadataExtracterRegistry) this.applicationContext.getBean("metadataExtracterRegistry");
metadataExtracterRegistry.setAsyncExtractEnabled(false);
metadataExtracterRegistry.setAsyncEmbedEnabled(false);
AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
authenticationComponent.setSystemUserAsCurrentUser();
@@ -124,13 +122,6 @@ public class ContentMetadataEmbedderTest extends BaseSpringTest
this.executer.setApplicableTypes(new String[] { ContentModel.TYPE_CONTENT.toString() });
}
@After
public void after()
{
metadataExtracterRegistry.setAsyncExtractEnabled(true);
metadataExtracterRegistry.setAsyncEmbedEnabled(true);
}
/**
* Test that a failing embedder does not destroy the original content
*/

View File

@@ -143,8 +143,6 @@ public class ContentMetadataExtracterTagMappingTest extends TestCase
this.nodeService = (NodeService) ctx.getBean("NodeService");
this.contentService = (ContentService) ctx.getBean("ContentService");
this.metadataExtracterRegistry = (MetadataExtracterRegistry) ctx.getBean("metadataExtracterRegistry");
metadataExtracterRegistry.setAsyncExtractEnabled(false);
metadataExtracterRegistry.setAsyncEmbedEnabled(false);
this.transactionService = (TransactionService)ctx.getBean("transactionComponent");
this.auditService = (AuditService)ctx.getBean("auditService");
@@ -209,9 +207,6 @@ public class ContentMetadataExtracterTagMappingTest extends TestCase
@Override
protected void tearDown() throws Exception
{
metadataExtracterRegistry.setAsyncExtractEnabled(true);
metadataExtracterRegistry.setAsyncEmbedEnabled(true);
if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
{
fail("Test is not transaction-safe. Fix up transaction handling and re-test.");

View File

@@ -47,10 +47,10 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.metadata.AbstractMappingMetadataExtracter;
import org.alfresco.repo.content.metadata.AsynchronousExtractor;
import org.alfresco.repo.content.metadata.MetadataExtracterRegistry;
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
@@ -59,13 +59,14 @@ import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.BaseSpringTestsCategory;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.test.context.transaction.TestTransaction;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
@@ -91,6 +92,7 @@ public class ContentMetadataExtracterTest extends BaseSpringTest
private NodeService nodeService;
private ContentService contentService;
private MetadataExtracterRegistry registry;
private TransactionService transactionService;
private StoreRef testStoreRef;
private NodeRef rootNodeRef;
private NodeRef nodeRef;
@@ -105,8 +107,7 @@ public class ContentMetadataExtracterTest extends BaseSpringTest
this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
this.contentService = (ContentService) this.applicationContext.getBean("contentService");
registry = (MetadataExtracterRegistry) applicationContext.getBean("metadataExtracterRegistry");
registry.setAsyncExtractEnabled(false);
registry.setAsyncEmbedEnabled(false);
transactionService = (TransactionService) this.applicationContext.getBean("transactionService");
AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
authenticationComponent.setSystemUserAsCurrentUser();
@@ -132,18 +133,11 @@ public class ContentMetadataExtracterTest extends BaseSpringTest
this.executer = (ContentMetadataExtracter) this.applicationContext.getBean("extract-metadata");
}
@After
public void after()
{
registry.setAsyncExtractEnabled(true);
registry.setAsyncEmbedEnabled(true);
}
/**
* Test execution of the extraction itself
*/
@Test
public void testFromBlanks()
public void testFromBlanks() throws Exception
{
// Test that the action writes properties when they don't exist or are
// unset
@@ -156,15 +150,34 @@ public class ContentMetadataExtracterTest extends BaseSpringTest
// be handled
this.nodeService.setProperties(this.nodeRef, props);
// Execute the action
ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null);
// Make the nodeRef visible to other transactions as it will need to be in async requests
TestTransaction.flagForCommit();
TestTransaction.end();
this.executer.execute(action, this.nodeRef);
// Execute the action
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null);
executer.execute(action, nodeRef);
return null;
}
});
Thread.sleep(3000); // Need to wait for the async extract
// Check that the properties have been set
assertEquals(QUICK_TITLE, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_TITLE));
assertEquals(QUICK_DESCRIPTION, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_DESCRIPTION));
assertEquals(QUICK_CREATOR, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_AUTHOR));
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
assertEquals(QUICK_TITLE, nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE));
assertEquals(QUICK_DESCRIPTION, nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION));
assertEquals(QUICK_CREATOR, nodeService.getProperty(nodeRef, ContentModel.PROP_AUTHOR));
return null;
}
});
}
private static final QName PROP_UNKNOWN_1 = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "unkown1");
@@ -304,7 +317,7 @@ public class ContentMetadataExtracterTest extends BaseSpringTest
* Test execution of the pragmatic approach
*/
@Test
public void testFromPartial()
public void testFromPartial() throws Exception
{
// Test that the action does not overwrite properties that are already
// set
@@ -318,16 +331,34 @@ public class ContentMetadataExtracterTest extends BaseSpringTest
props.remove(ContentModel.PROP_DESCRIPTION); // Allow this baby
this.nodeService.setProperties(this.nodeRef, props);
// Make the nodeRef visible to other transactions as it will need to be in async requests
TestTransaction.flagForCommit();
TestTransaction.end();
// Execute the action
ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null);
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null);
executer.execute(action, nodeRef);
return null;
}
});
this.executer.execute(action, this.nodeRef);
Thread.sleep(3000); // Need to wait for the async extract
// Check that the properties have been preserved
assertEquals(myTitle, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_TITLE));
assertEquals(myCreator, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_AUTHOR));
// Check that the properties have been preserved, but that description has been set
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
assertEquals(myTitle, nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE));
assertEquals(myCreator, nodeService.getProperty(nodeRef, ContentModel.PROP_AUTHOR));
// But this one should have been set
assertEquals(QUICK_DESCRIPTION, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_DESCRIPTION));
assertEquals(QUICK_DESCRIPTION, nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION));
return null;
}
});
}
}

View File

@@ -1,82 +0,0 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.content.metadata;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.joda.time.format.DateTimeFormat;
import org.junit.Test;
/**
* @deprecated OOTB extractors are being moved to T-Engines.
*
* MNT-8978
*/
@Deprecated
public class ConcurrencyOfficeMetadataExtracterTest
{
private OfficeMetadataExtracter extracter = new OfficeMetadataExtracter();
private final Date testDate = DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime("2010-10-22").toDate();
@Test
public void testDateFormatting() throws Exception
{
Callable<Date> task = new Callable<Date>()
{
public Date call() throws Exception
{
return extracter.makeDate("2010-10-22");
}
};
// pool with 5 threads
ExecutorService exec = Executors.newFixedThreadPool(5);
List<Future<Date>> results = new ArrayList<Future<Date>>();
// perform 10 date conversions
for (int i = 0; i < 10; i++)
{
results.add(exec.submit(task));
}
exec.shutdown();
for (Future<Date> result : results)
{
assertEquals(testDate, result.get());
}
}
}

View File

@@ -1,156 +0,0 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.content.metadata;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.namespace.QName;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @deprecated OOTB extractors are being moved to T-Engines.
*
* The test designed for testing the concurrent limitations in
* {@link AbstractMappingMetadataExtracter#extractRaw(ContentReader, MetadataExtracterLimits)}
*
* @author amukha
*/
@Deprecated
public class ConcurrencyPdfBoxMetadataExtracterTest extends AbstractMetadataExtracterTest
{
private SlowPdfBoxMetadataExtracter extracter;
private static final int MAX_CONCURENT_EXTRACTIONS = 5;
private static final double MAX_DOC_SIZE_MB = 0.03;
private static final int NUMBER_OF_CONCURRENT_THREADS = 11;
@Override
public void setUp() throws Exception
{
super.setUp();
extracter = new SlowPdfBoxMetadataExtracter();
extracter.setDictionaryService(dictionaryService);
MetadataExtracterLimits pdfLimit = new MetadataExtracterLimits();
pdfLimit.setMaxConcurrentExtractionsCount(MAX_CONCURENT_EXTRACTIONS);
pdfLimit.setMaxDocumentSizeMB(MAX_DOC_SIZE_MB);
Map<String,MetadataExtracterLimits> limits = new HashMap<>();
limits.put(MimetypeMap.MIMETYPE_PDF,pdfLimit);
extracter.setMimetypeLimits(limits);
extracter.setDelay(30*NUMBER_OF_CONCURRENT_THREADS);
extracter.register();
}
/**
* @return Returns the same transformer regardless - it is allowed
*/
protected MetadataExtracter getExtracter()
{
return extracter;
}
protected void testFileSpecificMetadata(String mimetype, Map<QName, Serializable> properties)
{
// not required
}
public void testConcurrentExtractions() throws InterruptedException
{
final Map<String, Boolean> threadResults = new ConcurrentHashMap<>();
for (int i = 0; i < NUMBER_OF_CONCURRENT_THREADS; i++)
{
new Thread(new Runnable()
{
@Override
public void run()
{
System.out.println(Thread.currentThread().getName() + " started " + System.currentTimeMillis());
try
{
Map<QName, Serializable> results = extractFromMimetype(MimetypeMap.MIMETYPE_PDF);
System.out.println(Thread.currentThread().getName() + " results are " + results);
threadResults.put(Thread.currentThread().getName(), !results.isEmpty());
}
catch (Exception e)
{
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName() + " finished " + System.currentTimeMillis());
}
}).start();
}
int numWaits = NUMBER_OF_CONCURRENT_THREADS*10;
while (numWaits > 0)
{
Thread.sleep(50);
if (threadResults.size() == NUMBER_OF_CONCURRENT_THREADS)
{
break;
}
numWaits--;
}
Map<Boolean, Integer> counted = new HashMap<>();
counted.put(Boolean.FALSE, 0);
counted.put(Boolean.TRUE, 0);
for (Boolean result : threadResults.values())
{
counted.put(result, counted.get(result)+1);
}
assertEquals("Wrong number of failed extractions.",
new Integer(NUMBER_OF_CONCURRENT_THREADS - MAX_CONCURENT_EXTRACTIONS),
counted.get(Boolean.FALSE));
assertEquals("Wrong number of successful extractions.",
new Integer(MAX_CONCURENT_EXTRACTIONS),
counted.get(Boolean.TRUE));
}
private class SlowPdfBoxMetadataExtracter extends PdfBoxMetadataExtracter
{
private long delay = 0;
public void setDelay(long delay)
{
this.delay = delay;
}
@Override
protected Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable
{
Thread.sleep(delay);
Map<String, Serializable> results = super.extractRaw(reader);
System.out.println(Thread.currentThread().getName() + " results are " + results);
return results;
}
}
}

View File

@@ -1,181 +0,0 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.content.metadata;
import java.io.File;
import java.io.Serializable;
import java.net.URL;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
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;
import org.apache.tika.metadata.Metadata;
/**
* @deprecated OOTB extractors are being moved to T-Engines.
*
* @see DWGMetadataExtracter
*
* @author Nick Burch
*/
@Deprecated
public class DWGMetadataExtracterTest extends AbstractMetadataExtracterTest
{
private DWGMetadataExtracter extracter;
private static final QName TIKA_LAST_AUTHOR_TEST_PROPERTY =
QName.createQName("TikaLastAuthorTestProp");
private static final QName TIKA_CUSTOM_TEST_PROPERTY =
QName.createQName("TikaCustomTestProp");
private static final String TIKA_CUSTOM_KEY = "customprop1";
@SuppressWarnings("deprecation")
@Override
public void setUp() throws Exception
{
super.setUp();
extracter = new DWGMetadataExtracter();
extracter.setDictionaryService(dictionaryService);
extracter.register();
// Attach some extra mappings, using the Tika
// metadata keys namespace
// These will be tested later
HashMap<String, Set<QName>> newMap = new HashMap<String, Set<QName>>(
extracter.getMapping()
);
Set<QName> tlaSet = new HashSet<QName>();
tlaSet.add(TIKA_LAST_AUTHOR_TEST_PROPERTY);
Set<QName> custSet = new HashSet<QName>();
custSet.add(TIKA_CUSTOM_TEST_PROPERTY);
newMap.put( Metadata.LAST_AUTHOR, tlaSet );
newMap.put( TIKA_CUSTOM_KEY, custSet );
extracter.setMapping(newMap);
}
/**
* @return Returns the same transformer regardless - it is allowed
*/
protected MetadataExtracter getExtracter()
{
return extracter;
}
public void testSupports() throws Exception
{
for (String mimetype : DWGMetadataExtracter.SUPPORTED_MIMETYPES)
{
boolean supports = extracter.isSupported(mimetype);
assertTrue("Mimetype should be supported: " + mimetype, supports);
}
}
/**
* Test all the supported files.
* Note - doesn't use extractFromMimetype
*/
public void testSupportedMimetypes() throws Exception
{
String mimetype = MimetypeMap.MIMETYPE_APP_DWG;
for (String version : new String[] {"2004","2007","2010"})
{
String filename = "quick" + version + ".dwg";
URL url = AbstractContentTransformerTest.class.getClassLoader().getResource("quick/" + filename);
File file = new File(url.getFile());
Map<QName, Serializable> properties = extractFromFile(file, mimetype);
// check we got something
assertFalse("extractFromMimetype should return at least some properties, none found for " + mimetype,
properties.isEmpty());
// check common metadata
testCommonMetadata(mimetype, properties);
// check file-type specific metadata
testFileSpecificMetadata(mimetype, properties);
}
}
@Override
protected boolean skipAuthorCheck(String mimetype) { return true; }
/**
* We also provide the creation date - check that
*/
protected void testFileSpecificMetadata(String mimetype,
Map<QName, Serializable> properties)
{
// Check for extra fields
assertEquals(
"Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
"Nevin Nollop",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_AUTHOR)));
// Ensure that we can also get things which are standard
// Tika metadata properties, if we so choose to
assertTrue(
"Test Property " + TIKA_LAST_AUTHOR_TEST_PROPERTY + " not found for mimetype " + mimetype,
properties.containsKey(TIKA_LAST_AUTHOR_TEST_PROPERTY)
);
assertEquals(
"Test Property " + TIKA_LAST_AUTHOR_TEST_PROPERTY + " incorrect for mimetype " + mimetype,
"paolon",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(TIKA_LAST_AUTHOR_TEST_PROPERTY)));
}
/**
* Test 2010 custom properties (ALF-16628)
*/
public void test2010CustomProperties() throws Exception
{
String mimetype = MimetypeMap.MIMETYPE_APP_DWG;
String filename = "quick2010CustomProps.dwg";
URL url = AbstractContentTransformerTest.class.getClassLoader().getResource("quick/" + filename);
File file = new File(url.getFile());
Map<QName, Serializable> properties = extractFromFile(file, mimetype);
// check we got something
assertFalse("extractFromMimetype should return at least some properties, none found for " + mimetype,
properties.isEmpty());
// check common metadata
testCommonMetadata(mimetype, properties);
assertEquals("Custom DWG property not found", "valueforcustomprop1", properties.get(TIKA_CUSTOM_TEST_PROPERTY));
}
}

View File

@@ -1,117 +0,0 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
/*
* Copyright (C) 2005 - 2020 Jesper Steen Møller
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.content.metadata;
import java.io.File;
import java.io.Serializable;
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;
/**
* @deprecated OOTB extractors are being moved to T-Engines.
*
* @author Jesper Steen Møller
*/
@Deprecated
public class HtmlMetadataExtracterTest extends AbstractMetadataExtracterTest
{
private static final String QUICK_TITLE_JAPANESE = "確認した結果を添付しますので、確認してください";
private HtmlMetadataExtracter extracter;
@Override
public void setUp() throws Exception
{
super.setUp();
extracter = new HtmlMetadataExtracter();
extracter.setDictionaryService(dictionaryService);
extracter.register();
}
/**
* @return Returns the same transformer regardless - it is allowed
*/
protected MetadataExtracter getExtracter()
{
return extracter;
}
public void testSupports() throws Exception
{
for (String mimetype : HtmlMetadataExtracter.MIMETYPES)
{
boolean supports = extracter.isSupported(mimetype);
assertTrue("Mimetype should be supported: " + mimetype, supports);
}
}
public void testHtmlExtraction() throws Exception
{
testExtractFromMimetype(MimetypeMap.MIMETYPE_HTML);
}
public void testHtmlExtractionJapanese() throws Exception
{
String mimetype = MimetypeMap.MIMETYPE_HTML;
File japaneseHtml = AbstractContentTransformerTest.loadNamedQuickTestFile("quick.japanese.html");
Map<QName, Serializable> properties = extractFromFile(japaneseHtml, mimetype);
assertFalse("extractFromMimetype should return at least some properties, none found for " + mimetype,
properties.isEmpty());
// Title and description
assertEquals(
"Property " + ContentModel.PROP_TITLE + " not found for mimetype " + mimetype,
QUICK_TITLE_JAPANESE,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_TITLE)));
}
/** Extractor only does the usual basic three properties */
public void testFileSpecificMetadata(String mimetype, Map<QName, Serializable> properties) {}
}

View File

@@ -1,144 +0,0 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.content.metadata;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.content.AbstractJodConverterBasedTest;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.filestore.FileContentReader;
import org.alfresco.repo.content.metadata.OpenOfficeMetadataWorker;
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
import org.junit.Ignore;
import org.junit.Test;
/**
* @deprecated OOTB extractors are being moved to T-Engines.
*
* @author Neil McErlean
* @since 3.2 SP1
*/
@Deprecated
public class JodMetadataExtractorOOoTest extends AbstractJodConverterBasedTest
{
protected static final String QUICK_TITLE = "The quick brown fox jumps over the lazy dog";
protected static final String QUICK_DESCRIPTION = "Gym class featuring a brown fox and lazy dog";
protected static final String QUICK_CREATOR = "Nevin Nollop";
protected static final String QUICK_CREATOR_EMAIL = "nevin.nollop@alfresco.com";
protected static final String QUICK_PREVIOUS_AUTHOR = "Derek Hulley";
@Test
@Ignore("The test was never run and fails on remote transformer")
public void metadataExtractionUsingJodConverter() throws Exception
{
// If OpenOffice is not available then we will ignore this test (by passing it).
// This is because not all the build servers have OOo installed.
if (!isOpenOfficeAvailable())
{
System.out.println("Did not run " + this.getClass().getSimpleName() + "thumbnailTransformationsUsingJodConverter" +
" because OOo is not available.");
return;
}
Map<QName, Serializable> properties = extractFromMimetype();
assertFalse("extractFromMimetype should return at least some properties, none found", properties.isEmpty());
String mimetype = MimetypeMap.MIMETYPE_WORD;
// One of Creator or Author
if (properties.containsKey(ContentModel.PROP_CREATOR))
{
assertEquals("Property " + ContentModel.PROP_CREATOR
+ " not found for mimetype " + mimetype, QUICK_CREATOR,
DefaultTypeConverter.INSTANCE.convert(String.class,
properties.get(ContentModel.PROP_CREATOR)));
} else if (properties.containsKey(ContentModel.PROP_AUTHOR))
{
assertEquals("Property " + ContentModel.PROP_AUTHOR
+ " not found for mimetype " + mimetype, QUICK_CREATOR,
DefaultTypeConverter.INSTANCE.convert(String.class,
properties.get(ContentModel.PROP_AUTHOR)));
} else
{
fail("Expected one Property out of " + ContentModel.PROP_CREATOR
+ " and " + ContentModel.PROP_AUTHOR
+ " but found neither of them.");
}
// Title and description
assertEquals("Property " + ContentModel.PROP_TITLE
+ " not found for mimetype " + mimetype, QUICK_TITLE,
DefaultTypeConverter.INSTANCE.convert(String.class, properties
.get(ContentModel.PROP_TITLE)));
assertEquals("Property " + ContentModel.PROP_DESCRIPTION
+ " not found for mimetype " + mimetype, QUICK_DESCRIPTION,
DefaultTypeConverter.INSTANCE.convert(String.class, properties
.get(ContentModel.PROP_DESCRIPTION)));
}
protected Map<QName, Serializable> extractFromMimetype() throws Exception
{
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
// attempt to get a source file for each mimetype
File sourceFile = AbstractContentTransformerTest.loadQuickTestFile("doc");
if (sourceFile == null)
{
throw new FileNotFoundException("No quick.doc file found for test");
}
// construct a reader onto the source file
ContentReader sourceReader = new FileContentReader(sourceFile);
sourceReader.setMimetype(MimetypeMap.MIMETYPE_WORD);
OpenOfficeMetadataWorker worker = (OpenOfficeMetadataWorker) ctx.getBean("extracter.worker.JodConverter");
Set<String> supportedTypes = new HashSet<String>();
supportedTypes.add(MimetypeMap.MIMETYPE_WORD);
JodConverterMetadataExtracter extracter = new JodConverterMetadataExtracter(supportedTypes);
extracter.setMimetypeService(serviceRegistry.getMimetypeService());
extracter.setDictionaryService(serviceRegistry.getDictionaryService());
extracter.setWorker(worker);
extracter.init();
extracter.extract(sourceReader, properties);
return properties;
}
}

View File

@@ -1,132 +0,0 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
/*
* Copyright (C) 2005 - 2020 Jesper Steen Møller
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.content.metadata;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
/**
* @deprecated OOTB extractors are being moved to T-Engines.
*
* Test for the MP3 metadata extraction from id3 tags.
*/
@Deprecated
public class MP3MetadataExtracterTest extends TikaAudioMetadataExtracterTest
{
private MP3MetadataExtracter extracter;
@Override
public void setUp() throws Exception
{
super.setUp();
extracter = (MP3MetadataExtracter)ctx.getBean("extracter.MP3");
extracter.register();
}
/**
* @return Returns the same transformer regardless - it is allowed
*/
protected MetadataExtracter getExtracter()
{
return extracter;
}
public void testSupports() throws Exception
{
for (String mimetype : MP3MetadataExtracter.SUPPORTED_MIMETYPES)
{
boolean supports = extracter.isSupported(mimetype);
assertTrue("Mimetype should be supported: " + mimetype, supports);
}
}
public void testMP3Extraction() throws Exception
{
testExtractFromMimetype(MimetypeMap.MIMETYPE_MP3);
}
@Override
public void testOggExtraction() throws Exception {}
@Override
public void testFlacExtraction() throws Exception {}
@Override
public void testMP4AudioExtraction() throws Exception {}
/**
* We don't have quite the usual metadata. Tests the descriptions one.
* Other tests in {@link #testFileSpecificMetadata(String, Map)}
*/
protected void testCommonMetadata(String mimetype, Map<QName, Serializable> properties)
{
// Title is as normal
assertEquals(
"Property " + ContentModel.PROP_TITLE + " not found for mimetype " + mimetype,
QUICK_TITLE,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_TITLE)));
// Has Author, not Creator, and is different
assertEquals(
"Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
"Hauskaz",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_AUTHOR)));
// Description is a composite
assertContains(
"Property " + ContentModel.PROP_DESCRIPTION + " didn't contain " + QUICK_TITLE + " for mimetype " + mimetype,
QUICK_TITLE,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_DESCRIPTION)));
// Check rest of it later
}
/**
* Tests for various MP3 specific bits of metadata
*/
public void testFileSpecificMetadata(String mimetype, Map<QName, Serializable> properties)
{
super.testFileSpecificMetadata(mimetype, properties);
}
}

View File

@@ -1,172 +0,0 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
/*
* Copyright (C) 2005 - 2020 Jesper Steen Møller
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
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;
/**
* @deprecated OOTB extractors are being moved to T-Engines.
*
* @author Derek Hulley
* @since 3.2
*/
@Deprecated
public class MailMetadataExtracterTest extends AbstractMetadataExtracterTest
{
private MailMetadataExtracter extracter;
@Override
public void setUp() throws Exception
{
super.setUp();
extracter = new MailMetadataExtracter();
extracter.setDictionaryService(dictionaryService);
extracter.register();
}
/**
* @return Returns the same transformer regardless - it is allowed
*/
protected MetadataExtracter getExtracter()
{
return extracter;
}
public void testSupports() throws Exception
{
for (String mimetype : MailMetadataExtracter.SUPPORTED_MIMETYPES)
{
boolean supports = extracter.isSupported(mimetype);
assertTrue("Mimetype should be supported: " + mimetype, supports);
}
}
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);
}
/**
* We have different things to normal, so
* do our own common tests.
*/
protected void testCommonMetadata(String mimetype, Map<QName, Serializable> properties)
{
// Two equivalent ones
assertEquals(
"Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
"Mark Rogers",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_AUTHOR)));
assertEquals(
"Property " + ContentModel.PROP_ORIGINATOR + " not found for mimetype " + mimetype,
"Mark Rogers",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_ORIGINATOR)));
// One other common bit
assertEquals(
"Property " + ContentModel.PROP_DESCRIPTION + " not found for mimetype " + mimetype,
"This is a quick test",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_DESCRIPTION)));
}
/**
* Test the outlook specific bits
*/
protected void testFileSpecificMetadata(String mimetype,
Map<QName, Serializable> properties) {
// TODO Sent Date should be a date/time as per the contentModel.xml
assertEquals(
"Property " + ContentModel.PROP_SENTDATE + " not found for mimetype " + mimetype,
"2013-01-18T13:44:20.000Z",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_SENTDATE)));
// Addressee
assertEquals(
"Property " + ContentModel.PROP_ADDRESSEE + " not found for mimetype " + mimetype,
"mark.rogers@alfresco.com",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_ADDRESSEE)));
// Addressees
assertTrue(
"Property " + ContentModel.PROP_ADDRESSEES + " not found for mimetype " + mimetype,
properties.get(ContentModel.PROP_ADDRESSEES) != null
);
Collection<String> addresses = DefaultTypeConverter.INSTANCE.getCollection(String.class,
properties.get(ContentModel.PROP_ADDRESSEES));
assertTrue(
"Property " + ContentModel.PROP_ADDRESSEES + " wrong content for mimetype " + mimetype + ", mark",
addresses.contains("mark.rogers@alfresco.com"));
assertTrue(
"Property " + ContentModel.PROP_ADDRESSEES + " wrong content for mimetype " + mimetype + ", mrquick",
addresses.contains("mrquick@nowhere.com"));
// Feature: metadata extractor has normalised internet address ... from "Whizz <speedy@quick.com>"
assertTrue(
"Property " + ContentModel.PROP_ADDRESSEES + " wrong content for mimetype " + mimetype + ", Whizz",
addresses.contains("speedy@quick.com"));
// Subject Line
assertEquals(
"Property " + ContentModel.PROP_SUBJECT + " not found for mimetype " + mimetype,
"This is a quick test",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_SUBJECT)));
}
}

View File

@@ -1,185 +0,0 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.content.metadata;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
/**
* @deprecated OOTB extractors are being moved to T-Engines.
*
* @see OfficeMetadataExtracter
*
* @author Jesper Steen Møller
*/
@Deprecated
public class OfficeMetadataExtracterTest extends AbstractMetadataExtracterTest
{
private OfficeMetadataExtracter extracter;
private static final QName WORD_COUNT_TEST_PROPERTY =
QName.createQName("WordCountTest");
private static final QName LAST_AUTHOR_TEST_PROPERTY =
QName.createQName("LastAuthorTest");
@Override
public void setUp() throws Exception
{
super.setUp();
extracter = new OfficeMetadataExtracter();
extracter.setDictionaryService(dictionaryService);
extracter.register();
// Attach a couple of extra mappings
// These will be tested later
HashMap<String, Set<QName>> newMap = new HashMap<String, Set<QName>>(
extracter.getMapping()
);
Set<QName> wcSet = new HashSet<QName>();
wcSet.add(WORD_COUNT_TEST_PROPERTY);
newMap.put( OfficeMetadataExtracter.KEY_WORD_COUNT, wcSet );
Set<QName> laSet = new HashSet<QName>();
laSet.add(LAST_AUTHOR_TEST_PROPERTY);
newMap.put( OfficeMetadataExtracter.KEY_LAST_AUTHOR, laSet );
extracter.setMapping(newMap);
}
/**
* @return Returns the same transformer regardless - it is allowed
*/
protected MetadataExtracter getExtracter()
{
return extracter;
}
public void testSupports() throws Exception
{
for (String mimetype : OfficeMetadataExtracter.SUPPORTED_MIMETYPES)
{
boolean supports = extracter.isSupported(mimetype);
assertTrue("Mimetype should be supported: " + mimetype, supports);
}
}
/**
* Test all the supported mimetypes
*/
public void testSupportedMimetypes() throws Exception
{
for (String mimetype : OfficeMetadataExtracter.SUPPORTED_MIMETYPES)
{
testExtractFromMimetype(mimetype);
}
}
/**
* We support all sorts of extra metadata. Check it all behaves.
*/
public void testFileSpecificMetadata(String mimetype, Map<QName, Serializable> properties) {
// Test the ones with a core alfresco mapping
if(mimetype.equals(MimetypeMap.MIMETYPE_WORD)) {
assertEquals(
"Property " + ContentModel.PROP_CREATED + " not found for mimetype " + mimetype,
"2005-05-26T12:57:00.000Z",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_CREATED)));
assertEquals(
"Property " + ContentModel.PROP_MODIFIED + " not found for mimetype " + mimetype,
"2005-09-20T17:25:00.000Z",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_MODIFIED)));
} else if(mimetype.equals(MimetypeMap.MIMETYPE_EXCEL)) {
assertEquals(
"Property " + ContentModel.PROP_CREATED + " not found for mimetype " + mimetype,
"1996-10-14T23:33:28.000Z",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_CREATED)));
assertEquals(
"Property " + ContentModel.PROP_MODIFIED + " not found for mimetype " + mimetype,
"2005-09-20T18:22:32.000Z",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_MODIFIED)));
} else if(mimetype.equals(MimetypeMap.MIMETYPE_PPT)) {
assertEquals(
"Property " + ContentModel.PROP_CREATED + " not found for mimetype " + mimetype,
"1601-01-01T00:00:00.000Z", // Seriously, that's what the file says!
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_CREATED)));
assertEquals(
"Property " + ContentModel.PROP_MODIFIED + " not found for mimetype " + mimetype,
"2005-09-20T18:23:41.000Z",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_MODIFIED)));
}
// Now check the non-standard ones we added in at test time
assertTrue(
"Test Property " + LAST_AUTHOR_TEST_PROPERTY + " not found for mimetype " + mimetype,
properties.containsKey(LAST_AUTHOR_TEST_PROPERTY)
);
if(mimetype.equals(MimetypeMap.MIMETYPE_WORD)) {
assertTrue(
"Test Property " + WORD_COUNT_TEST_PROPERTY + " not found for mimetype " + mimetype,
properties.containsKey(WORD_COUNT_TEST_PROPERTY)
);
assertEquals(
"Test Property " + WORD_COUNT_TEST_PROPERTY + " incorrect for mimetype " + mimetype,
"9",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(WORD_COUNT_TEST_PROPERTY)));
assertEquals(
"Test Property " + LAST_AUTHOR_TEST_PROPERTY + " incorrect for mimetype " + mimetype,
AbstractMetadataExtracterTest.QUICK_PREVIOUS_AUTHOR,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(LAST_AUTHOR_TEST_PROPERTY)));
} else if(mimetype.equals(MimetypeMap.MIMETYPE_EXCEL)) {
assertEquals(
"Test Property " + LAST_AUTHOR_TEST_PROPERTY + " not found for mimetype " + mimetype,
AbstractMetadataExtracterTest.QUICK_PREVIOUS_AUTHOR,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(LAST_AUTHOR_TEST_PROPERTY)));
} else if(mimetype.equals(MimetypeMap.MIMETYPE_PPT)) {
assertTrue(
"Test Property " + WORD_COUNT_TEST_PROPERTY + " not found for mimetype " + mimetype,
properties.containsKey(WORD_COUNT_TEST_PROPERTY)
);
assertEquals(
"Test Property " + WORD_COUNT_TEST_PROPERTY + " not found for mimetype " + mimetype,
"9",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(WORD_COUNT_TEST_PROPERTY)));
assertEquals(
"Test Property " + LAST_AUTHOR_TEST_PROPERTY + " not found for mimetype " + mimetype,
AbstractMetadataExtracterTest.QUICK_PREVIOUS_AUTHOR,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(LAST_AUTHOR_TEST_PROPERTY)));
}
}
}

View File

@@ -1,124 +0,0 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.content.metadata;
import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
/**
* @deprecated OOTB extractors are being moved to T-Engines.
*
* @see OpenDocumentMetadataExtracter
*
* @author Derek Hulley
*/
@Deprecated
public class OpenDocumentMetadataExtracterTest extends AbstractMetadataExtracterTest
{
private OpenDocumentMetadataExtracter extracter;
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
@Override
public void setUp() throws Exception
{
super.setUp();
extracter = new OpenDocumentMetadataExtracter();
extracter.setDictionaryService(dictionaryService);
extracter.register();
}
/**
* @return Returns the same transformer regardless - it is allowed
*/
protected MetadataExtracter getExtracter()
{
return extracter;
}
public void testSupports() throws Exception
{
for (String mimetype : OpenDocumentMetadataExtracter.SUPPORTED_MIMETYPES)
{
boolean supports = extracter.isSupported(mimetype);
assertTrue("Mimetype should be supported: " + mimetype, supports);
}
}
/**
* Test all the supported mimetypes
*/
public void testSupportedMimetypes() throws Exception
{
for (String mimetype : OpenDocumentMetadataExtracter.SUPPORTED_MIMETYPES)
{
testExtractFromMimetype(mimetype);
}
}
@Override
protected boolean skipAuthorCheck(String mimetype) { return true; }
/**
* We also provide the creation date - check that
*/
protected void testFileSpecificMetadata(String mimetype,
Map<QName, Serializable> properties)
{
try
{
// Check for two cases
if(mimetype.equals("application/vnd.oasis.opendocument.text"))
{
assertEquals(
"Property " + ContentModel.PROP_CREATED + " not found for mimetype " + mimetype,
DATE_FORMAT.parse("2005-09-06T23:34:00.000+0000"),
DefaultTypeConverter.INSTANCE.convert(Date.class, properties.get(ContentModel.PROP_CREATED)));
}
else if(mimetype.equals("application/vnd.oasis.opendocument.graphics"))
{
assertEquals(
"Property " + ContentModel.PROP_CREATED + " not found for mimetype " + mimetype,
DATE_FORMAT.parse("2006-01-27T11:46:11.000+0000"),
DefaultTypeConverter.INSTANCE.convert(Date.class, properties.get(ContentModel.PROP_CREATED)));
}
}
catch (ParseException e)
{
fail(e.getMessage());
}
}
}

View File

@@ -1,141 +0,0 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.content.metadata;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.Serializable;
import java.util.Calendar;
import java.util.HashMap;
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;
import org.apache.pdfbox.util.DateConverter;
/**
* @deprecated OOTB extractors are being moved to T-Engines.
*
* @see org.alfresco.repo.content.metadata.PdfBoxMetadataExtracter
*
* @author Jesper Steen Møller
*/
@Deprecated
public class PdfBoxMetadataExtracterTest extends AbstractMetadataExtracterTest
{
private PdfBoxMetadataExtracter extracter;
private static final int MAX_CONCURENT_EXTRACTIONS = 5;
private static final double MAX_DOC_SIZE_MB = 0.03;
@Override
public void setUp() throws Exception
{
super.setUp();
extracter = new PdfBoxMetadataExtracter();
extracter.setDictionaryService(dictionaryService);
MetadataExtracterLimits pdfLimit = new MetadataExtracterLimits();
pdfLimit.setMaxConcurrentExtractionsCount(MAX_CONCURENT_EXTRACTIONS);
pdfLimit.setMaxDocumentSizeMB(MAX_DOC_SIZE_MB);
Map<String,MetadataExtracterLimits> limits = new HashMap<>();
limits.put(MimetypeMap.MIMETYPE_PDF,pdfLimit);
extracter.setMimetypeLimits(limits);
extracter.register();
}
/**
* @return Returns the same transformer regardless - it is allowed
*/
protected MetadataExtracter getExtracter()
{
return extracter;
}
public void testSupports() throws Exception
{
for (String mimetype : PdfBoxMetadataExtracter.SUPPORTED_MIMETYPES)
{
boolean supports = extracter.isSupported(mimetype);
assertTrue("Mimetype should be supported: " + mimetype, supports);
}
}
public void testPdfExtraction() throws Exception
{
testExtractFromMimetype(MimetypeMap.MIMETYPE_PDF);
}
/**
* This test method extracts metadata from an Adobe Illustrator file (which in recent versions is a pdf file).
* @since 3.5.0
*/
public void testAiExtraction() throws Exception
{
testExtractFromMimetype(MimetypeMap.MIMETYPE_APPLICATION_ILLUSTRATOR);
}
/**
* We can also return a created date
*/
protected void testFileSpecificMetadata(String mimetype,
Map<QName, Serializable> properties) {
assertEquals(
"Property " + ContentModel.PROP_CREATED + " not found for mimetype " + mimetype,
"2005-05-26T19:52:58.000Z",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_CREATED)));
}
/**
* Test that will show when the workaround is in place.
*/
public void testDateConversion() throws Exception {
Calendar c = DateConverter.toCalendar("D:20050526205258+01'00'");
assertEquals(2005, c.get(Calendar.YEAR));
assertEquals(05-1, c.get(Calendar.MONTH));
assertEquals(26, c.get(Calendar.DAY_OF_MONTH));
assertEquals(20, c.get(Calendar.HOUR_OF_DAY));
assertEquals(52, c.get(Calendar.MINUTE));
assertEquals(58, c.get(Calendar.SECOND));
//assertEquals(0, c.get(Calendar.MILLISECOND));
}
public void testMaxDocumentSizeLimit() throws Exception
{
File sourceFile = AbstractContentTransformerTest.loadNamedQuickTestFile("quick-size-limit.pdf");
if (sourceFile == null)
{
throw new FileNotFoundException("No quick-size-limit.pdf file found for test");
}
Map<QName, Serializable> properties = extractFromFile(sourceFile, MimetypeMap.MIMETYPE_PDF);
assertTrue(properties.isEmpty());
}
}

View File

@@ -1,214 +0,0 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.content.metadata;
import java.io.File;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.filestore.FileContentReader;
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
/**
* @deprecated OOTB extractors are being moved to T-Engines.
*
* @see org.alfresco.repo.content.metadata.PoiMetadataExtracter
*
* @author Neil McErlean
* @author Dmitry Velichkevich
*/
@Deprecated
public class PoiMetadataExtracterTest extends AbstractMetadataExtracterTest
{
private static final int MINIMAL_EXPECTED_PROPERTIES_AMOUNT = 3;
private static final String ALL_MIMETYPES_FILTER = "*";
private static final String PROBLEM_FOOTNOTES_DOCUMENT_NAME = "problemFootnotes2.docx";
private PoiMetadataExtracter extracter;
private Long extractionTimeWithDefaultFootnotesLimit;
private Long extractionTimeWithLargeFootnotesLimit;
@Override
public void setUp() throws Exception
{
super.setUp();
extracter = new PoiMetadataExtracter();
extracter.setDictionaryService(dictionaryService);
extracter.register();
}
@Override
protected void tearDown() throws Exception
{
super.tearDown();
}
@Override
protected MetadataExtracter getExtracter()
{
return extracter;
}
public void testSupports() throws Exception
{
for (String mimetype : PoiMetadataExtracter.SUPPORTED_MIMETYPES)
{
boolean supports = extracter.isSupported(mimetype);
assertTrue("Mimetype should be supported: " + mimetype, supports);
}
}
public void testOffice2007Extraction() throws Exception
{
for (String mimetype : PoiMetadataExtracter.SUPPORTED_MIMETYPES)
{
testExtractFromMimetype(mimetype);
}
}
@Override
protected boolean skipDescriptionCheck(String mimetype)
{
// Our 3 OpenOffice 07 quick files have no description properties.
return true;
}
@Override
protected void testFileSpecificMetadata(String mimetype,
Map<QName, Serializable> properties)
{
// This test class is testing 3 files: quick.docx, quick.xlsx & quick.pptx.
// Their created times are hard-coded here for checking.
// Of course this means that if the files are updated, the test will break
// but those files are rarely modified - only added to.
if (MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING.equals(mimetype))
{
checkFileCreationDate(mimetype, properties, "2010-01-06T17:32:00.000Z");
}
else if (MimetypeMap.MIMETYPE_OPENXML_SPREADSHEET.equals(mimetype))
{
checkFileCreationDate(mimetype, properties, "1996-10-14T23:33:28.000Z");
}
else if (MimetypeMap.MIMETYPE_OPENXML_PRESENTATION.equals(mimetype))
{
// Extraordinary! This document predates Isaac Newton's Principia Mathematica by almost a century. ;)
checkFileCreationDate(mimetype, properties, "1601-01-01T00:00:00.000Z");
}
}
private void checkFileCreationDate(String mimetype, Map<QName, Serializable> properties, String date)
{
assertEquals("Property " + ContentModel.PROP_CREATED + " not found for mimetype " + mimetype, date,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_CREATED)));
}
/**
* Tests that metadata extraction from a somewhat corrupt file with several
* thousand footnotes times out properly.
*
* @throws Exception
*/
public void testProblemFootnotes() throws Exception
{
long timeoutMs = 2000;
MetadataExtracterLimits limits = new MetadataExtracterLimits();
limits.setTimeoutMs(timeoutMs);
HashMap<String, MetadataExtracterLimits> mimetypeLimits =
new HashMap<String, MetadataExtracterLimits>(1);
mimetypeLimits.put(ALL_MIMETYPES_FILTER, limits);
((PoiMetadataExtracter) getExtracter()).setMimetypeLimits(mimetypeLimits);
File sourceFile = AbstractContentTransformerTest.loadNamedQuickTestFile("problemFootnotes.docx");
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
// construct a reader onto the source file
ContentReader sourceReader = new FileContentReader(sourceFile);
sourceReader.setMimetype(MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING);
long startTime = System.currentTimeMillis();
getExtracter().extract(sourceReader, properties);
long extractionTime = System.currentTimeMillis() - startTime;
assertTrue("Metadata extraction took (" + extractionTime + "ms) " +
"but should have failed with a timeout at " + timeoutMs + "ms",
extractionTime < (timeoutMs + 100)); // bit of wiggle room for logging, cleanup, etc.
assertFalse("Reader was not closed", sourceReader.isChannelOpen());
}
/**
* Test for MNT-577: Alfresco is running 100% CPU for over 10 minutes while extracting metadata for Word office document
*
* @throws Exception
*/
public void testFootnotesLimitParameterUsingDefault() throws Exception
{
PoiMetadataExtracter extractor = (PoiMetadataExtracter) getExtracter();
File sourceFile = AbstractContentTransformerTest.loadNamedQuickTestFile(PROBLEM_FOOTNOTES_DOCUMENT_NAME);
ContentReader sourceReader = new FileContentReader(sourceFile);
sourceReader.setMimetype(MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING);
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
long startTime = System.currentTimeMillis();
extractor.extract(sourceReader, properties);
extractionTimeWithDefaultFootnotesLimit = System.currentTimeMillis() - startTime;
assertExtractedProperties(properties);
if (extractionTimeWithLargeFootnotesLimit != null)
{
assertTrue("The second metadata extraction operation must be longer!", extractionTimeWithLargeFootnotesLimit > extractionTimeWithDefaultFootnotesLimit);
}
}
/**
* Asserts extracted <code>properties</code>. At least {@link PoiMetadataExtracterTest#MINIMAL_EXPECTED_PROPERTIES_AMOUNT} properties are expected:
* {@link ContentModel#PROP_TITLE}, {@link ContentModel#PROP_AUTHOR} and {@link ContentModel#PROP_CREATED}
*
* @param properties - {@link Map}&lt;{@link QName}, {@link Serializable}&gt; instance which contains all extracted properties
*/
private void assertExtractedProperties(Map<QName, Serializable> properties)
{
assertNotNull("Properties were not extracted at all!", properties);
assertFalse("Extracted properties are empty!", properties.isEmpty());
assertTrue(("Expected 3 extracted properties but only " + properties.size() + " have been extracted!"), properties.size() >= MINIMAL_EXPECTED_PROPERTIES_AMOUNT);
assertTrue(("'" + ContentModel.PROP_TITLE + "' property is missing!"), properties.containsKey(ContentModel.PROP_TITLE));
assertTrue(("'" + ContentModel.PROP_AUTHOR + "' property is missing!"), properties.containsKey(ContentModel.PROP_AUTHOR));
assertTrue(("'" + ContentModel.PROP_CREATED + "' property is missing!"), properties.containsKey(ContentModel.PROP_CREATED));
}
}

View File

@@ -1,272 +0,0 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.content.metadata;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
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;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
/**
* @deprecated OOTB extractors are being moved to T-Engines.
*
* Test for the RFC822 (imap/mbox) extractor
*/
@Deprecated
public class RFC822MetadataExtracterTest extends AbstractMetadataExtracterTest
{
private RFC822MetadataExtracter extracter;
private static final QName MESSAGE_FROM_TEST_PROPERTY =
QName.createQName("MessageToTest");
private static final QName MESSAGE_TO_TEST_PROPERTY =
QName.createQName("MessageFromTest");
private static final QName MESSAGE_CC_TEST_PROPERTY =
QName.createQName("MessageCCTest");
@Override
public void setUp() throws Exception
{
super.setUp();
// Ask Spring for the extractor, so it
// gets its date formats populated
extracter = (RFC822MetadataExtracter)ctx.getBean("extracter.RFC822");
// Attach a couple of extra mappings
// These will be tested later
HashMap<String, Set<QName>> newMap = new HashMap<String, Set<QName>>(
extracter.getMapping()
);
Set<QName> fromSet = new HashSet<QName>();
fromSet.add(MESSAGE_FROM_TEST_PROPERTY);
fromSet.addAll( extracter.getCurrentMapping().get(RFC822MetadataExtracter.KEY_MESSAGE_FROM) );
newMap.put( RFC822MetadataExtracter.KEY_MESSAGE_FROM, fromSet );
Set<QName> toSet = new HashSet<QName>();
toSet.add(MESSAGE_TO_TEST_PROPERTY);
toSet.addAll( extracter.getCurrentMapping().get(RFC822MetadataExtracter.KEY_MESSAGE_TO) );
newMap.put( RFC822MetadataExtracter.KEY_MESSAGE_TO, toSet );
Set<QName> ccSet = new HashSet<QName>();
ccSet.add(MESSAGE_CC_TEST_PROPERTY);
ccSet.addAll( extracter.getCurrentMapping().get(RFC822MetadataExtracter.KEY_MESSAGE_CC) );
newMap.put( RFC822MetadataExtracter.KEY_MESSAGE_CC, ccSet );
extracter.setMapping(newMap);
}
/**
* @return Returns the same transformer regardless - it is allowed
*/
protected MetadataExtracter getExtracter()
{
return extracter;
}
// RFC822 has a non-standard date format. 1. EEE, d MMM yyyy HH:mm:ss Z
public void testHasDateFormats1() throws Exception
{
assertEquals("16 Aug 2012 15:13:29 GMT", extracter.makeDate("Thu, 16 Aug 2012 08:13:29 -0700").toGMTString());
}
// RFC822 has a non-standard date format. 2. EEE, d MMM yy HH:mm:ss Z
public void testHasDateFormats2() throws Exception
{
assertEquals("16 Aug 2012 15:13:29 GMT", extracter.makeDate("Thu, 16 Aug 12 08:13:29 -0700").toGMTString());
}
// RFC822 has a non-standard date format. 3. d MMM yyyy HH:mm:ss Z
public void testHasDateFormats3() throws Exception
{
assertEquals("16 Aug 2012 15:13:29 GMT", extracter.makeDate("16 Aug 2012 08:13:29 -0700").toGMTString());
}
// Check time zone names are ignored - these are not handled by org.joda.time.format.DateTimeFormat
public void testHasDateFormatsZoneName() throws Exception
{
assertEquals("16 Aug 2012 15:13:29 GMT", extracter.makeDate("Thu, 16 Aug 2012 08:13:29 -0700 (PDT)").toGMTString());
}
public void testJodaFormats()
{
String[][] testData = new String[][]
{
{ "a1", "EEE, d MMM yyyy HH:mm:ss Z", "Thu, 16 Aug 12 08:13:29 -0700", "Thu Aug 18 15:13:29 GMT 12", "0"}, // gets the year wrong
{ "a2a", "EEE, d MMM yy HH:mm:ss Z", "Thu, 16 Aug 12 08:13:29 -0700", "Thu Aug 16 15:13:29 GMT 2012", "20"},
{ "a2b", "EEE, d MMM yy HH:mm:ss Z", "Wed, 16 Aug 50 08:13:29 -0700", "Wed Aug 16 15:13:29 GMT 1950", "19"},
{ "a2c", "EEE, d MMM yy HH:mm:ss Z", "Sun, 16 Aug 20 08:13:29 -0700", "Sun Aug 16 15:13:29 GMT 2020", "20"},
{ "a3", "d MMM yyyy HH:mm:ss Z", "Thu, 16 Aug 12 08:13:29 -0700", null, null},
{ "b1", "EEE, d MMM yyyy HH:mm:ss Z", "Thu, 16 Aug 2012 08:13:29 -0700", "Thu Aug 16 15:13:29 GMT 2012", "20"},
{ "b2a", "EEE, d MMM yy HH:mm:ss Z", "Thu, 16 Aug 2012 08:13:29 -0700", "Thu Aug 16 15:13:29 GMT 2012", "20"},
{ "b2b", "EEE, d MMM yy HH:mm:ss Z", "Wed, 16 Aug 1950 08:13:29 -0700", "Wed Aug 16 15:13:29 GMT 1950", "19"},
{ "b2c", "EEE, d MMM yy HH:mm:ss Z", "Sun, 16 Aug 2020 08:13:29 -0700", "Sun Aug 16 15:13:29 GMT 2020", "20"},
{ "b3", "d MMM yyyy HH:mm:ss Z", "Thu, 16 Aug 2012 08:13:29 -0700", null, "20"},
{ "c1", "EEE, d MMM yyyy HH:mm:ss Z", "16 Aug 2012 08:13:29 -0700", null, null},
{ "c2", "EEE, d MMM yy HH:mm:ss Z", "16 Aug 2012 08:13:29 -0700", null, null},
{ "c3a", "d MMM yyyy HH:mm:ss Z", "16 Aug 2012 08:13:29 -0700", "Thu Aug 16 15:13:29 GMT 2012", "20"},
{ "c3b", "d MMM yyyy HH:mm:ss Z", "16 Aug 1950 08:13:29 -0700", "Wed Aug 16 15:13:29 GMT 1950", "19"},
{ "c3c", "d MMM yyyy HH:mm:ss Z", "16 Aug 2020 08:13:29 -0700", "Sun Aug 16 15:13:29 GMT 2020", "20"},
};
for (String[] data: testData)
{
String format = data[1];
String dateStr = data[2];
String context = data[0]+") \""+format+"\", \""+dateStr+"\"";
String expected = data[3];
int centuryOfEra = data[4] == null ? -1 : new Integer(data[4]);
// Need to set pivot year so it still works in 20 years time :)
DateTimeFormatter dateTimeFormater = DateTimeFormat.forPattern(format).withPivotYear(2000);
DateTime dateTime = null;
try
{
dateTime = dateTimeFormater.parseDateTime(dateStr);
}
catch (IllegalArgumentException e)
{
}
String actual = dateTime == null ? null : dateTime.toDate().toString();
assertEquals(context, expected, actual);
if (dateTime != null)
{
assertEquals(context, centuryOfEra, dateTime.getCenturyOfEra());
}
}
}
public void testSupports() throws Exception
{
for (String mimetype : RFC822MetadataExtracter.SUPPORTED_MIMETYPES)
{
boolean supports = extracter.isSupported(mimetype);
assertTrue("Mimetype should be supported: " + mimetype, supports);
}
}
public void testEmailExtraction() throws Exception
{
testExtractFromMimetype(MimetypeMap.MIMETYPE_RFC822);
}
public void testSpanishEmailExtraction() throws Exception
{
File spanishEml = AbstractContentTransformerTest.loadNamedQuickTestFile("quick.spanish.eml");
Map<QName, Serializable> properties = extractFromFile(spanishEml, MimetypeMap.MIMETYPE_RFC822);
testCommonMetadata(MimetypeMap.MIMETYPE_RFC822, properties);
}
/**
* We have no author, and have the same title and description
*/
protected void testCommonMetadata(String mimetype,
Map<QName, Serializable> properties) {
assertEquals(
"Property " + ContentModel.PROP_TITLE + " not found for mimetype " + mimetype,
QUICK_TITLE,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_TITLE)));
assertEquals(
"Property " + ContentModel.PROP_DESCRIPTION + " not found for mimetype " + mimetype,
QUICK_TITLE,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_DESCRIPTION)));
}
/**
* Test our extra IMAP properties
*/
public void testFileSpecificMetadata(String mimetype, Map<QName, Serializable> properties) {
// Check the other cm: ones
assertEquals(
"Property " + ContentModel.PROP_ORIGINATOR + " not found for mimetype " + mimetype,
QUICK_CREATOR + " <" + QUICK_CREATOR_EMAIL + ">",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_ORIGINATOR)));
// assertEquals(
// "Property " + ContentModel.PROP_SENTDATE + " not found for mimetype " + mimetype,
// "2004-06-04T13:23:22.000+01:00",
// DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_SENTDATE)));
// Check some imap: ones
assertEquals(
"Test Property " + MESSAGE_FROM_TEST_PROPERTY + " incorrect for mimetype " + mimetype,
"Nevin Nollop <nevin.nollop@alfresco.com>",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(MESSAGE_FROM_TEST_PROPERTY)));
assertEquals(
"Test Property " + MESSAGE_FROM_TEST_PROPERTY + " incorrect for mimetype " + mimetype,
"Nevin Nollop <nevin.nollop@alfresco.com>",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(MESSAGE_FROM_TEST_PROPERTY)));
assertEquals(
"Test Property " + MESSAGE_TO_TEST_PROPERTY + " incorrect for mimetype " + mimetype,
"Nevin Nollop <nevin.nollop@alfresco.com>",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(MESSAGE_TO_TEST_PROPERTY)));
// Finally check our non-standard ones we added in at test time
assertTrue(
"Test Property " + MESSAGE_FROM_TEST_PROPERTY + " not found for mimetype " + mimetype,
properties.containsKey(MESSAGE_FROM_TEST_PROPERTY)
);
assertTrue(
"Test Property " + MESSAGE_TO_TEST_PROPERTY + " not found for mimetype " + mimetype,
properties.containsKey(MESSAGE_TO_TEST_PROPERTY)
);
assertTrue(
"Test Property " + MESSAGE_CC_TEST_PROPERTY + " not found for mimetype " + mimetype,
properties.containsKey(MESSAGE_CC_TEST_PROPERTY)
);
assertEquals(
"Test Property " + MESSAGE_FROM_TEST_PROPERTY + " incorrect for mimetype " + mimetype,
"Nevin Nollop <nevin.nollop@alfresco.com>",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(MESSAGE_FROM_TEST_PROPERTY)));
assertEquals(
"Test Property " + MESSAGE_TO_TEST_PROPERTY + " incorrect for mimetype " + mimetype,
"Nevin Nollop <nevin.nollop@alfresco.com>",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(MESSAGE_TO_TEST_PROPERTY)));
assertEquals(
"Test Property " + MESSAGE_CC_TEST_PROPERTY + " incorrect for mimetype " + mimetype,
"Nevin Nollop <nevinn@alfresco.com>",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(MESSAGE_CC_TEST_PROPERTY)));
}
}

View File

@@ -1,172 +0,0 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
/*
* Copyright (C) 2005 - 2020 Jesper Steen Møller
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.content.metadata;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
/**
* @deprecated OOTB extractors are being moved to T-Engines.
*
* Test for the audio metadata extraction.
*/
@Deprecated
public class TikaAudioMetadataExtracterTest extends AbstractMetadataExtracterTest
{
private TikaAudioMetadataExtracter extracter;
private static final String ARTIST = "Hauskaz";
private static final String ALBUM = "About a dog and a fox";
private static final String GENRE = "Foxtrot";
@Override
public void setUp() throws Exception
{
super.setUp();
extracter = (TikaAudioMetadataExtracter)ctx.getBean("extracter.Audio");
extracter.register();
}
/**
* @return Returns the same transformer regardless - it is allowed
*/
protected MetadataExtracter getExtracter()
{
return extracter;
}
public void testSupports() throws Exception
{
for (String mimetype : TikaAudioMetadataExtracter.SUPPORTED_MIMETYPES)
{
boolean supports = extracter.isSupported(mimetype);
assertTrue("Mimetype should be supported: " + mimetype, supports);
}
}
public void testOggExtraction() throws Exception
{
testExtractFromMimetype(MimetypeMap.MIMETYPE_VORBIS);
}
public void testFlacExtraction() throws Exception
{
testExtractFromMimetype(MimetypeMap.MIMETYPE_FLAC);
}
public void testMP4AudioExtraction() throws Exception
{
testExtractFromMimetype(MimetypeMap.MIMETYPE_AUDIO_MP4);
}
/**
* We don't have quite the usual metadata. Tests the descriptions one.
* Other tests in {@link #testFileSpecificMetadata(String, Map)}
*/
protected void testCommonMetadata(String mimetype, Map<QName, Serializable> properties)
{
// Title is as normal
assertEquals(
"Property " + ContentModel.PROP_TITLE + " not found for mimetype " + mimetype,
QUICK_TITLE,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_TITLE)));
// Has Author, not Creator, and is different
assertEquals(
"Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
"Hauskaz",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_AUTHOR)));
// Description is a composite
assertContains(
"Property " + ContentModel.PROP_DESCRIPTION + " didn't contain " + QUICK_TITLE + " for mimetype " + mimetype,
QUICK_TITLE,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_DESCRIPTION)));
// Check rest of it later
}
/**
* Tests for various Audio specific bits of metadata
*/
public void testFileSpecificMetadata(String mimetype, Map<QName, Serializable> properties) {
QName album = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "album");
assertEquals(
"Property " + album + " not found for mimetype " + mimetype,
ALBUM,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(album)));
QName artist = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "artist");
assertEquals(
"Property " + artist + " not found for mimetype " + mimetype,
ARTIST,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(artist)));
QName genre = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "genre");
assertEquals(
"Property " + genre + " not found for mimetype " + mimetype,
GENRE,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(genre)));
QName releaseDate = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "releaseDate");
assertEquals(
"Property " + releaseDate + " not found for mimetype " + mimetype,
"2009-01-01T00:00:00.000Z",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(releaseDate)));
QName channels = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "channelType");
assertEquals(
"Property " + channels + " not found for mimetype " + mimetype,
"Stereo",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(channels)));
// Description is a composite - check the artist part
assertContains(
"Property " + ContentModel.PROP_DESCRIPTION + " didn't contain " + ARTIST + " for mimetype " + mimetype,
ARTIST,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_DESCRIPTION)));
}
}

View File

@@ -1,399 +0,0 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.content.metadata;
import java.io.File;
import java.io.Serializable;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.filestore.FileContentReader;
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tika.config.TikaConfig;
import org.apache.tika.io.TikaInputStream;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MediaType;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
import org.apache.tika.parser.microsoft.OfficeParser;
import org.apache.tika.parser.microsoft.ooxml.OOXMLParser;
import org.apache.tika.parser.mp3.Mp3Parser;
import org.apache.tika.parser.odf.OpenDocumentParser;
/**
* @deprecated OOTB extractors are being moved to T-Engines.
*
* @see TikaAutoMetadataExtracter
*
* @author Nick Burch
*/
@Deprecated
public class TikaAutoMetadataExtracterTest extends AbstractMetadataExtracterTest
{
private static Log logger = LogFactory.getLog(TikaAutoMetadataExtracterTest.class);
private TikaAutoMetadataExtracter extracter;
private static final QName TIKA_MIMETYPE_TEST_PROPERTY =
QName.createQName("TikaMimeTypeTestProp");
@Override
public void setUp() throws Exception
{
super.setUp();
TikaConfig config = (TikaConfig)ctx.getBean("tikaConfig");
extracter = new TikaAutoMetadataExtracter(config);
extracter.setDictionaryService(dictionaryService);
extracter.register();
// Attach some extra mappings, using the Tika
// metadata keys namespace
// These will be tested later
HashMap<String, Set<QName>> newMap = new HashMap<String, Set<QName>>(
extracter.getMapping()
);
Set<QName> tlaSet = new HashSet<QName>();
tlaSet.add(TIKA_MIMETYPE_TEST_PROPERTY);
newMap.put( Metadata.CONTENT_TYPE, tlaSet );
extracter.setMapping(newMap);
}
/**
* @return Returns the same transformer regardless - it is allowed
*/
protected MetadataExtracter getExtracter()
{
return extracter;
}
public void testSupports() throws Exception
{
ArrayList<String> mimeTypes = new ArrayList<String>();
for (Parser p : new Parser[] {
new OfficeParser(), new OpenDocumentParser(),
new Mp3Parser(), new OOXMLParser()
}) {
Set<MediaType> mts = p.getSupportedTypes(new ParseContext());
for (MediaType mt : mts)
{
mimeTypes.add(mt.toString());
}
}
for (String mimetype : mimeTypes)
{
boolean supports = extracter.isSupported(mimetype);
assertTrue("Mimetype should be supported: " + mimetype, supports);
}
}
/**
* Test several different files
* Note - doesn't use extractFromMimetype
*/
public void testSupportedMimetypes() throws Exception
{
String[] testFiles = new String[] {
".doc", ".docx", ".xls", ".xlsx",
".ppt", ".pptx",
//".vsd", // Our sample file lacks suitable metadata
"2010.dwg",
"2003.mpp", "2007.mpp",
".pdf",
".odt",
};
AutoDetectParser ap = new AutoDetectParser();
for (String fileBase : testFiles)
{
String filename = "quick" + fileBase;
URL url = AbstractContentTransformerTest.class.getClassLoader().getResource("quick/" + filename);
File file = new File(url.getFile());
// Cheat and ask Tika for the mime type!
Metadata metadata = new Metadata();
metadata.set(Metadata.RESOURCE_NAME_KEY, filename);
MediaType mt = ap.getDetector().detect(TikaInputStream.get(file), metadata);
String mimetype = mt.toString();
if (logger.isDebugEnabled())
{
logger.debug("Detected mimetype " + mimetype + " for quick test file " + filename);
}
// Have it processed
Map<QName, Serializable> properties = extractFromFile(file, mimetype);
// check we got something
assertFalse("extractFromMimetype should return at least some properties, " +
"none found for " + mimetype + " - " + filename,
properties.isEmpty());
// check common metadata
testCommonMetadata(mimetype, properties);
// check file-type specific metadata
testFileSpecificMetadata(mimetype, properties);
}
}
/**
* Test MNT-15219 Excel (.xlsx) containing xmls (shapes/drawings) with multi byte characters may
* cause OutOfMemory in Tika Note - doesn't use extractFromMimetype
*/
public void testParsingOfShapesInXLSXFiles() throws Exception
{
AutoDetectParser ap = new AutoDetectParser();
String filename = "dmsu1332-reproduced.xlsx";
URL url = AbstractContentTransformerTest.class.getClassLoader().getResource("quick/" + filename);
File file = new File(url.getFile());
// Cheat and ask Tika for the mime type!
Metadata metadata = new Metadata();
metadata.set(Metadata.RESOURCE_NAME_KEY, filename);
MediaType mt = ap.getDetector().detect(TikaInputStream.get(file), metadata);
String mimetype = mt.toString();
if (logger.isDebugEnabled())
{
logger.debug("Detected mimetype " + mimetype + " for quick test file " + filename);
}
// Have it processed
// see MNT-15219 and REPO-3251
Map<QName, Serializable> properties = extractFromFile(file, mimetype);
// check we got something
assertFalse("extractFromMimetype should return at least some properties, none found for " + mimetype + " - " + filename,
properties.isEmpty());
if (properties.containsKey(ContentModel.PROP_AUTHOR))
{
assertEquals("Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
"Udintsev, Anton (external - Project)",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_AUTHOR)));
}
else
{
fail("Expected one property out of " + ContentModel.PROP_CREATOR + " and " + ContentModel.PROP_AUTHOR + " but found neither of them for "
+ mimetype);
}
// Ensure that we can also get things which are standard
// Tika metadata properties, if we so choose to
assertTrue("Test Property " + TIKA_MIMETYPE_TEST_PROPERTY + " not found for mimetype " + mimetype,
properties.containsKey(TIKA_MIMETYPE_TEST_PROPERTY));
assertEquals("Test Property " + TIKA_MIMETYPE_TEST_PROPERTY + " incorrect for mimetype " + mimetype,
mimetype,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(TIKA_MIMETYPE_TEST_PROPERTY)));
}
@Override
protected boolean skipAuthorCheck(String mimetype) { return true; }
@Override
protected boolean skipDescriptionCheck(String mimetype)
{
if(mimetype.endsWith("/ogg"))
{
return true;
}
return false;
}
/**
* We also provide the creation date - check that
*/
protected void testFileSpecificMetadata(String mimetype,
Map<QName, Serializable> properties)
{
// Check for extra fields
// Author isn't there for the OpenDocument ones
if(mimetype.indexOf(".oasis.") == -1 && !mimetype.endsWith("/ogg") && !mimetype.endsWith("dwg"))
{
assertEquals(
"Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
"Nevin Nollop",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_AUTHOR)));
}
// Ensure that we can also get things which are standard
// Tika metadata properties, if we so choose to
assertTrue(
"Test Property " + TIKA_MIMETYPE_TEST_PROPERTY + " not found for mimetype " + mimetype,
properties.containsKey(TIKA_MIMETYPE_TEST_PROPERTY)
);
assertEquals(
"Test Property " + TIKA_MIMETYPE_TEST_PROPERTY + " incorrect for mimetype " + mimetype,
mimetype,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(TIKA_MIMETYPE_TEST_PROPERTY)));
// Extra media checks for music formats
if(mimetype.startsWith("audio"))
{
assertEquals(
"Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
"Hauskaz",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_AUTHOR)));
QName artistQ = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "artist");
assertEquals(
"Property " + artistQ + " not found for mimetype " + mimetype,
"Hauskaz",
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(artistQ)));
}
}
/**
* We don't have explicit extractors for most image and video formats.
* Instead, these will be handled by the Auto Tika Parser, and
* this test ensures that they are
*/
@SuppressWarnings("deprecation")
public void testImageVideo() throws Throwable {
Map<String, Serializable> p;
// Image
p = openAndCheck(".jpg", "image/jpeg");
assertEquals("409 pixels", p.get("Image Width"));
assertEquals("92 pixels", p.get("Image Height"));
assertEquals("8 bits", p.get("Data Precision"));
p = openAndCheck(".gif", "image/gif");
assertEquals("409", p.get("width"));
assertEquals("92", p.get("height"));
p = openAndCheck(".png", "image/png");
assertEquals("409", p.get("width"));
assertEquals("92", p.get("height"));
assertEquals("8 8 8", p.get("Data BitsPerSample"));
assertEquals("none", p.get("Transparency Alpha"));
p = openAndCheck(".bmp", "image/bmp");
assertEquals("409", p.get("width"));
assertEquals("92", p.get("height"));
assertEquals("8 8 8", p.get("Data BitsPerSample"));
// Image with wrong tiff:Width property. see MNT-13920
p = openAndCheck("SizeSample.jpg", "image/jpeg");
// Check raw EXIF properties
assertEquals("1535 pixels", p.get("Image Width"));
assertEquals("367 pixels", p.get("Image Height"));
// Map and check
Map<QName, Serializable> propsJPG = new HashMap<QName, Serializable>();
ContentReader readerJPG = new FileContentReader(open("SizeSample.jpg"));
readerJPG.setMimetype("image/jpeg");
extracter.extract(readerJPG, propsJPG);
assertEquals(1535, propsJPG.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "pixelXDimension")));
assertEquals(367, propsJPG.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "pixelYDimension")));
// Geo tagged image
p = openAndCheck("GEO.jpg", "image/jpeg");
// Check raw EXIF properties
assertEquals("100 pixels", p.get("Image Width"));
assertEquals("68 pixels", p.get("Image Height"));
assertEquals("8 bits", p.get("Data Precision"));
// Check regular Tika properties
assertEquals(QUICK_TITLE, p.get(Metadata.COMMENT));
assertEquals("canon-55-250, moscow-birds, serbor", p.get(Metadata.SUBJECT));
assertTrue(Arrays.equals(new String[] { "canon-55-250", "moscow-birds", "serbor" }, (String[]) p.get("dc:subject")));
// Check namespace'd Tika properties
assertEquals("12.54321", p.get("geo:lat"));
assertEquals("-54.1234", p.get("geo:long"));
assertEquals("100", p.get("tiff:ImageWidth"));
assertEquals("68", p.get("tiff:ImageLength"));
assertEquals("Canon", p.get("tiff:Make"));
assertEquals("5.6", p.get("exif:FNumber"));
// Map and check
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
ContentReader reader = new FileContentReader(open("GEO.jpg"));
reader.setMimetype("image/jpeg");
extracter.extract(reader, properties);
// Check the geo bits
assertEquals(12.54321, properties.get(ContentModel.PROP_LATITUDE));
assertEquals(-54.1234, properties.get(ContentModel.PROP_LONGITUDE));
// Check the exif bits
assertEquals(100, properties.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "pixelXDimension")));
assertEquals(68, properties.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "pixelYDimension")));
assertEquals(0.000625, properties.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "exposureTime")));
assertEquals(5.6, properties.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "fNumber")));
assertEquals(false, properties.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "flash")));
assertEquals(194.0, properties.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "focalLength")));
assertEquals("400", properties.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "isoSpeedRatings")));
assertEquals("Canon", properties.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "manufacturer")));
assertEquals("Canon EOS 40D", properties.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "model")));
assertEquals("Adobe Photoshop CS3 Macintosh", properties.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "software")));
assertEquals(null, properties.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "orientation")));
assertEquals(240.0, properties.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "xResolution")));
assertEquals(240.0, properties.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "yResolution")));
assertEquals("Inch", properties.get(QName.createQName(NamespaceService.EXIF_MODEL_1_0_URI, "resolutionUnit")));
}
private File open(String fileBase) throws Throwable {
String filename = "quick" + fileBase;
URL url = AbstractContentTransformerTest.class.getClassLoader().getResource("quick/" + filename);
File file = new File(url.getFile());
assertTrue(file.exists());
return file;
}
private Map<String, Serializable> openAndCheck(String fileBase, String expMimeType) throws Throwable {
// Get the mimetype via the MimeTypeMap
// (Uses Tika internally for the detection)
File file = open(fileBase);
ContentReader detectReader = new FileContentReader(file);
String mimetype = mimetypeMap.guessMimetype(fileBase, detectReader);
assertEquals("Wrong mimetype for " + fileBase, mimetype, expMimeType);
// Ensure the Tika Auto parser actually handles this
assertTrue("Mimetype should be supported but isn't: " + mimetype, extracter.isSupported(mimetype));
// Now create our proper reader
ContentReader sourceReader = new FileContentReader(file);
sourceReader.setMimetype(mimetype);
// And finally do the properties extraction
return extracter.extractRaw(sourceReader);
}
}

View File

@@ -28,12 +28,15 @@ package org.alfresco.repo.rendition2;
import junit.framework.AssertionFailedError;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.metadata.AsynchronousExtractor;
import org.alfresco.repo.content.metadata.MetadataExtracter;
import org.alfresco.repo.content.transform.LocalTransformServiceRegistry;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.thumbnail.ThumbnailRegistry;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.rendition.RenditionService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.MimetypeService;
@@ -59,7 +62,9 @@ import org.springframework.util.ResourceUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import static java.lang.Thread.sleep;
import static org.alfresco.model.ContentModel.PROP_CONTENT;
@@ -118,6 +123,9 @@ public abstract class AbstractRenditionIntegrationTest extends BaseSpringTest
@Autowired
protected TransformationOptionsConverter converter;
@Autowired
protected AsynchronousExtractor asynchronousExtractor;
static String PASSWORD = "password";
protected static final String ADMIN = "admin";
@@ -247,7 +255,7 @@ public abstract class AbstractRenditionIntegrationTest extends BaseSpringTest
fail("The " + renditionName + " rendition should NOT be supported for " + testFileName);
}
}
catch(UnsupportedOperationException e)
catch (UnsupportedOperationException e)
{
if (expectedToPass)
{
@@ -256,6 +264,27 @@ public abstract class AbstractRenditionIntegrationTest extends BaseSpringTest
}
}
protected void checkExtract(String testFileName, boolean expectedToPass)
{
try
{
NodeRef sourceNodeRef = createSource(ADMIN, testFileName);
extract(ADMIN, sourceNodeRef);
waitForExtract(ADMIN, sourceNodeRef, true);
if (!expectedToPass)
{
fail("The extract of metadata should NOT be supported for " + testFileName);
}
}
catch (AssertionFailedError e)
{
if (expectedToPass)
{
fail("The extract of metadata SHOULD be supported for " + testFileName);
}
}
}
// Creates a new source node as the given user in its own transaction.
protected NodeRef createSource(String user, String testFileName)
{
@@ -322,12 +351,31 @@ public abstract class AbstractRenditionIntegrationTest extends BaseSpringTest
}), user);
}
// Requests a new metadata extract as the given user in its own transaction.
protected void extract(String user, NodeRef sourceNode)
{
AuthenticationUtil.runAs((AuthenticationUtil.RunAsWork<Void>) () ->
transactionService.getRetryingTransactionHelper().doInTransaction(() ->
{
extract(sourceNode);
return null;
}), user);
}
// Requests a new rendition as the current user in the current transaction.
private void render(NodeRef sourceNodeRef, String renditionName)
{
renditionService2.render(sourceNodeRef, renditionName);
}
// Requests a new metadata extract as the current user in the current transaction.
private void extract(NodeRef sourceNodeRef)
{
ContentReader reader = contentService.getReader(sourceNodeRef, ContentModel.PROP_CONTENT);
asynchronousExtractor.extract(sourceNodeRef, reader, MetadataExtracter.OverwritePolicy.PRAGMATIC,
Collections.emptyMap(), Collections.emptyMap());
}
// As a given user waitForRendition for a rendition to appear. Creates new transactions to do this.
protected NodeRef waitForRendition(String user, NodeRef sourceNodeRef, String renditionName, boolean shouldExist) throws AssertionFailedError
{
@@ -346,6 +394,24 @@ public abstract class AbstractRenditionIntegrationTest extends BaseSpringTest
}
}
// As a given user waitForExtract to appear. Creates new transactions to do this.
protected void waitForExtract(String user, NodeRef sourceNodeRef, boolean nodePropsShouldChange) throws AssertionFailedError
{
try
{
AuthenticationUtil.runAs(() -> waitForExtract(sourceNodeRef, nodePropsShouldChange), user);
}
catch (RuntimeException e)
{
Throwable cause = e.getCause();
if (cause instanceof AssertionFailedError)
{
throw (AssertionFailedError)cause;
}
throw e;
}
}
// As the current user waitForRendition for a rendition to appear. Creates new transactions to do this.
private NodeRef waitForRendition(NodeRef sourceNodeRef, String renditionName, boolean shouldExist) throws InterruptedException
{
@@ -375,6 +441,38 @@ public abstract class AbstractRenditionIntegrationTest extends BaseSpringTest
}
}
// As the current user waitForRendition for a rendition to appear. Creates new transactions to do this.
private Object waitForExtract(NodeRef sourceNodeRef, boolean nodePropsShouldChange) throws InterruptedException
{
long maxMillis = 5000;
boolean nodeModified = true;
for (int i = (int)(maxMillis / 1000); i >= 0; i--)
{
// Must create a new transaction in order to see changes that take place after this method started.
nodeModified = transactionService.getRetryingTransactionHelper().doInTransaction(() ->
{
Serializable created = nodeService.getProperty(sourceNodeRef, ContentModel.PROP_CREATED);
Serializable modified = nodeService.getProperty(sourceNodeRef, ContentModel.PROP_MODIFIED);
return !created.equals(modified);
}, true, true);
if (nodeModified)
{
break;
}
logger.debug("waitForExtract sleep "+i);
sleep(1000);
}
if (nodePropsShouldChange)
{
assertTrue("Extract failed", nodeModified);
}
else
{
assertFalse("Extract did not fail", nodeModified);
}
return null;
}
protected String getTestFileName(String sourceMimetype) throws FileNotFoundException
{
String extension = mimetypeMap.getExtension(sourceMimetype);

View File

@@ -184,6 +184,57 @@ public abstract class AbstractRenditionTest extends AbstractRenditionIntegration
}
}
private void assertMetadataExtractsOkayFromSourceExtension(List<String> sourceExtensions, List<String> excludeList, List<String> expectedToFail,
int expectedExtractCount, int expectedFailedCount) throws Exception
{
int extractCount = 0;
int failedCount = 0;
int successCount = 0;
int excludedCount = 0;
RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
StringJoiner failures = new StringJoiner("\n");
StringJoiner successes = new StringJoiner("\n");
for (String sourceExtension : sourceExtensions)
{
String sourceMimetype = mimetypeMap.getMimetype(sourceExtension);
String testFileName = getTestFileName(sourceMimetype);
if (testFileName != null)
{
extractCount++;
if (excludeList.contains(sourceExtension))
{
excludedCount++;
}
else
{
try
{
checkExtract(testFileName, !expectedToFail.contains(sourceExtension));
successes.add(sourceExtension);
successCount++;
}
catch (AssertionFailedError e)
{
failures.add(sourceExtension);
failedCount++;
}
}
}
}
int expectedSuccessCount = expectedExtractCount - excludedCount - expectedFailedCount;
System.out.println("FAILURES:\n"+failures+"\n");
System.out.println("SUCCESSES:\n"+successes+"\n");
System.out.println("extractCount: "+extractCount+" expected "+expectedExtractCount);
System.out.println(" failedCount: "+failedCount+" expected "+expectedFailedCount);
System.out.println("successCount: "+successCount+" expected "+expectedSuccessCount);
assertEquals("Extract count has changed", expectedExtractCount, extractCount);
assertEquals("Failed extract count has changed", expectedFailedCount, failedCount);
assertEquals("Successful extract count has changed", expectedSuccessCount, successCount);
}
@Test
public void testExpectedNumberOfRenditions() throws Exception
{
@@ -242,6 +293,18 @@ public abstract class AbstractRenditionTest extends AbstractRenditionIntegration
Collections.emptyList(), Collections.emptyList(), expectedRenditionCount, expectedFailedCount);
}
@Test
public void testSelectedMetadataExtracts() throws Exception
{
internalTestSelectedMetadataExtracts(7, 0);
}
protected void internalTestSelectedMetadataExtracts(int expectedExtractCount, int expectedFailedCount) throws Exception
{
assertMetadataExtractsOkayFromSourceExtension(Arrays.asList("msg", "doc", "odt", "pdf", "docx", "mp4", "png"),
Collections.emptyList(), Collections.emptyList(), expectedExtractCount, expectedFailedCount);
}
/**
* Gets transforms combinations that are possible regardless of renditions.
*/

View File

@@ -27,6 +27,7 @@ package org.alfresco.repo.rendition2;
import org.alfresco.util.testing.category.DebugTests;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -47,9 +48,23 @@ public class LegacyRenditionTest extends AbstractRenditionTest
legacy();
}
@Override
@Before
public void setUp() throws Exception
{
super.setUp();
}
@AfterClass
public static void after()
{
AbstractRenditionIntegrationTest.after();
}
@Test
@Override
public void testSelectedMetadataExtracts() throws Exception
{
internalTestSelectedMetadataExtracts(7, 7);
}
}

View File

@@ -76,6 +76,13 @@ public class NoneRenditionTest extends AbstractRenditionTest
internalTestGifRenditions(0, 0);
}
@Test
@Override
public void testSelectedMetadataExtracts() throws Exception
{
internalTestSelectedMetadataExtracts(7, 7);
}
@Test
public void testAllTransformServiceConfigRenditions() throws Exception
{