Merged 5.2.N (5.2.1) to HEAD (5.2)

128569 adavis: MNT-16381 Transformers must validate the content stream mimetype
      - Ensure error when indexer is the caller includes the file name rather than null.
        NodeContentGet now calls transform method with TransformationOptions parameter and the original
        transformer method was deprecated as it should be been when this extra parameter was added.
      - Set the strictMimeTypeCheck and retryTransformOnDifferentMimeType properties on dynamically created
        pipeline and fail over transformers from global properties as is don for static transformers.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@129293 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alexandru Epure
2016-08-09 13:57:13 +00:00
parent 72032949f5
commit 36c251afff
5 changed files with 154 additions and 60 deletions

View File

@@ -25,28 +25,23 @@
*/
package org.alfresco.repo.content.transform;
import static org.alfresco.repo.content.transform.TransformerPropertyNameExtractorTest.mockMimetypes;
import static org.alfresco.repo.content.transform.TransformerPropertyNameExtractorTest.mockProperties;
import static org.junit.Assert.*;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Date;
import org.alfresco.service.cmr.module.ModuleDetails;
import org.alfresco.service.cmr.module.ModuleService;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.TransformationOptionLimits;
import org.alfresco.service.cmr.repository.TransformationOptions;
import org.alfresco.service.descriptor.Descriptor;
import org.alfresco.service.descriptor.DescriptorService;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import static org.alfresco.repo.content.transform.TransformerPropertyNameExtractorTest.mockMimetypes;
import static org.alfresco.repo.content.transform.TransformerPropertyNameExtractorTest.mockProperties;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import java.util.Properties;
import org.alfresco.service.cmr.module.ModuleDetails;
import org.alfresco.service.cmr.module.ModuleService;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.TransformationOptions;
import org.alfresco.service.descriptor.Descriptor;
import org.alfresco.service.descriptor.DescriptorService;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
@@ -121,7 +116,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerA.pipeline", "transformer1|pdf|transformer2|png|transformer3");
assertEquals(0, new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null).getErrorCount());
transformerRegistry, transformerDebug, null, null, null).getErrorCount());
assertEquals(4, transformerRegistry.getAllTransformers().size());
assertEquals(1, transformerRegistry.getTransformers().size());
@@ -141,9 +136,9 @@ public class TransformerConfigDynamicTransformersTest
assertEquals("transformer.transformer3", transformer.getIntermediateTransformers().get(2).getName());
//
transformer.isTransformable("application/pdf", -1, "text/txt", new TransformationOptions());
}
transformer.isTransformable("application/pdf", -1, "text/txt", new TransformationOptions());
}
@Test
// Pipeline - too few components in the value
public void pipelineTooFewCompsTest()
@@ -152,7 +147,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerA.pipeline", "transformer1|pdf");
assertEquals(1, new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null).getErrorCount());
transformerRegistry, transformerDebug, null, null, null).getErrorCount());
}
@Test
@@ -163,7 +158,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerA.pipeline", "transformer1|pdf|transformer2|png");
assertEquals(1, new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null).getErrorCount());
transformerRegistry, transformerDebug, null, null, null).getErrorCount());
}
@Test
@@ -174,7 +169,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformer3.pipeline", "transformer1|pdf|transformer2");
assertEquals(1, new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null).getErrorCount());
transformerRegistry, transformerDebug, null, null, null).getErrorCount());
}
@Test
@@ -185,7 +180,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerA.pipeline", "transformer1|*|transformer2|png|transformer3");
new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null);
transformerRegistry, transformerDebug, null, null, null);
transformerRegistry.getTransformer("transformer.transformerA");
}
@@ -198,7 +193,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerA.pipeline", "transformer1|pdf|*|png|transformer3");
new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null);
transformerRegistry, transformerDebug, null, null, null);
transformerRegistry.getTransformer("transformer.transformerA");
}
@@ -211,7 +206,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerA.pipeline", "unknown1|pdf|unknown2|png|unknown3");
assertEquals(1, new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null).getErrorCount());
transformerRegistry, transformerDebug, null, null, null).getErrorCount());
}
@Test
@@ -223,7 +218,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerA.available", "false");
new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null);
transformerRegistry, transformerDebug, null, null, null);
assertEquals(4, transformerRegistry.getAllTransformers().size());
assertEquals(0, transformerRegistry.getTransformers().size()); // << note 0 rather than 1
@@ -241,7 +236,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerA.failover", "transformer1|transformer2|transformer3");
assertEquals(0, new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null).getErrorCount());
transformerRegistry, transformerDebug, null, null, null).getErrorCount());
assertEquals(4, transformerRegistry.getAllTransformers().size());
assertEquals(1, transformerRegistry.getTransformers().size());
@@ -258,7 +253,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerA.failover", "transformer1");
assertEquals(1, new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null).getErrorCount());
transformerRegistry, transformerDebug, null, null, null).getErrorCount());
}
@Test
@@ -269,7 +264,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformer3.failover", "transformer1|transformer2");
assertEquals(1, new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null).getErrorCount());
transformerRegistry, transformerDebug, null, null, null).getErrorCount());
}
@Test
@@ -280,7 +275,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerA.failover", "transformer1|*|transformer3");
new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null);
transformerRegistry, transformerDebug, null, null, null);
transformerRegistry.getTransformer("transformer.transformerA");
}
@@ -293,7 +288,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerA.failover", "unknown1|unknown2|unknown3");
assertEquals(1, new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null).getErrorCount());
transformerRegistry, transformerDebug, null, null, null).getErrorCount());
}
@Test
@@ -305,7 +300,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerA.available", "false");
new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null);
transformerRegistry, transformerDebug, null, null, null);
assertEquals(4, transformerRegistry.getAllTransformers().size());
assertEquals(0, transformerRegistry.getTransformers().size()); // << note 0 rather than 1
@@ -325,7 +320,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerE.failover", "transformer1|transformer1");
new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null);
transformerRegistry, transformerDebug, null, null, null);
assertEquals(5, transformerRegistry.getTransformers().size());
@@ -344,7 +339,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerE.failover", "transformer1|transformerC");
new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null);
transformerRegistry, transformerDebug, null, null, null);
assertEquals(2, transformerRegistry.getTransformers().size());
@@ -361,7 +356,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerA.edition", "Enterprise");
new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, descriptorService);
transformerRegistry, transformerDebug, null, descriptorService, null);
}
private void ampTransformer(String moduleId)
@@ -373,7 +368,7 @@ public class TransformerConfigDynamicTransformersTest
"content.transformer.transformerA.amp", moduleId);
new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, moduleService, null);
transformerRegistry, transformerDebug, moduleService, null, null);
}
@Test
@@ -409,5 +404,82 @@ public class TransformerConfigDynamicTransformersTest
ampTransformer("testAmp");
assertEquals(4, transformerRegistry.getAllTransformers().size());
}
}
// for MNT-16381
@Test
public void failoverPropertyFFTest()
{
internalProprtyTest(false, false, false);
}
@Test
public void failoverPropertyFTTest()
{
internalProprtyTest(false, false, true);
}
@Test
public void failoverPropertyTFTest()
{
internalProprtyTest(false, true, false);
}
@Test
public void failoverPropertyTTTest()
{
internalProprtyTest(false, true, true);
}
@Test
public void pipelinePropertyFFTest()
{
internalProprtyTest(true, false, false);
}
@Test
public void pipelinePropertyFTTest()
{
internalProprtyTest(true, false, true);
}
@Test
public void pipelinePropertyTFTest()
{
internalProprtyTest(true, true, false);
}
@Test
public void pipelinePropertyTTTest()
{
internalProprtyTest(true, true, true);
}
private void internalProprtyTest(boolean pipeline, boolean expectedRetry, boolean expectedCheck)
{
String[] transformerNamesAndValues = pipeline
? new String[] {"content.transformer.transformerA.pipeline", "transformer1|pdf|transformer2"}
: new String[] {"content.transformer.transformerA.failover", "transformer1|transformer2|transformer3"};
Properties properties = new Properties();
if (expectedRetry)
{
properties.setProperty("content.transformer.retryOn.different.mimetype", "true");
}
if (expectedCheck)
{
properties.setProperty("content.transformer.strict.mimetype.check", "true");
}
mockProperties(transformerProperties, transformerNamesAndValues);
assertEquals(0, new TransformerConfigDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, contentService,
transformerRegistry, transformerDebug, null, null, properties).getErrorCount());
// Throws an exception if it does not exist
AbstractContentTransformer2 transformer = (AbstractContentTransformer2)transformerRegistry.getTransformer("transformer.transformerA");
assertEquals("retryTransformOnDifferentMimeType was not set", expectedRetry, transformer.getRetryTransformOnDifferentMimeType());
assertEquals("strictMimetypeCheck was not set", expectedCheck, transformer.getStrictMimeTypeCheck());
}
}