mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
Save point: [skip ci]
* Split TransformStream and TransformProcess out of TransformHandler * TestFileInfo to FileInfo * Removed HttpRequestTests as it adds nothing now the controller is in the base * Initialised the internal context to TranformRequest tests
This commit is contained in:
@@ -21,11 +21,18 @@
|
||||
*/
|
||||
package org.alfresco.transform.client.model;
|
||||
|
||||
import org.alfresco.transform.common.ExtensionService;
|
||||
import org.alfresco.transform.messages.TransformStack;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.alfresco.transform.messages.TransformStack.PIPELINE_FLAG;
|
||||
import static org.alfresco.transform.messages.TransformStack.levelBuilder;
|
||||
import static org.alfresco.transform.messages.TransformStack.setInitialTransformRequestOptions;
|
||||
|
||||
// This class is in the package org.alfresco.transform.messages in HxP because that is more readable, but in
|
||||
// org.alfresco.transform.client.model in Alfresco for backward compatibility.
|
||||
public class TransformRequest implements Serializable
|
||||
@@ -189,6 +196,25 @@ public class TransformRequest implements Serializable
|
||||
'}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the internal context structure when a client request is initially received by the router,
|
||||
* so that we don't have to keep checking if bits of it are initialised. Prior to making this call,
|
||||
* the id, sourceMimetypes, targetMimetype, transformRequestOptions and sourceReference should have
|
||||
* been set, if they are to be set.
|
||||
*/
|
||||
public TransformRequest initialiseContextWhenReceivedByRouter()
|
||||
{
|
||||
setInternalContext(InternalContext.initialise(getInternalContext()));
|
||||
setTargetExtension(ExtensionService.getExtensionForTargetMimetype(getTargetMediaType(),
|
||||
getSourceMediaType()));
|
||||
getInternalContext().getMultiStep().setInitialRequestId(getRequestId());
|
||||
getInternalContext().getMultiStep().setInitialSourceMediaType(getSourceMediaType());
|
||||
getInternalContext().setTransformRequestOptions(getTransformRequestOptions());
|
||||
setInitialTransformRequestOptions(getInternalContext(), getTransformRequestOptions());
|
||||
TransformStack.setInitialSourceReference(getInternalContext(), getSourceReference());
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
{
|
||||
return new Builder();
|
||||
@@ -267,6 +293,14 @@ public class TransformRequest implements Serializable
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withInternalContextForTransformEngineTests()
|
||||
{
|
||||
request.initialiseContextWhenReceivedByRouter();
|
||||
TransformStack.addTransformLevel(request.internalContext, levelBuilder(PIPELINE_FLAG)
|
||||
.withStep("dummyTransformerName", request.sourceMediaType, request.targetMediaType));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TransformRequest build()
|
||||
{
|
||||
return request;
|
||||
|
@@ -88,7 +88,7 @@ class TransformStackTest
|
||||
{
|
||||
MockitoAnnotations.openMocks(this);
|
||||
|
||||
// Repeat what is done by Router.initialiseContext
|
||||
// Repeat what is done by Router.initialiseContextWhenReceivedByRouter
|
||||
internalContext.setMultiStep(new MultiStep());
|
||||
internalContext.getMultiStep().setTransformsToBeDone(new ArrayList<>());
|
||||
TransformStack.setInitialTransformRequestOptions(internalContext, options);
|
||||
|
@@ -21,15 +21,20 @@
|
||||
*/
|
||||
package org.alfresco.transform.registry;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.alfresco.transform.config.TransformStep;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -201,7 +206,16 @@ public class CombinedTransformConfigTest
|
||||
}
|
||||
};
|
||||
|
||||
private final TestTransformRegistry registry = new TestTransformRegistry();
|
||||
private final FakeTransformRegistry registry = new FakeTransformRegistry();
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private TransformConfig readTransformConfigFromResource(String filename) throws IOException
|
||||
{
|
||||
return objectMapper.readValue(
|
||||
getClass().getClassLoader().getResourceAsStream(filename),
|
||||
TransformConfig.class);
|
||||
}
|
||||
|
||||
private String expectedWildcardError(String errorReason)
|
||||
{
|
||||
@@ -889,8 +903,62 @@ public class CombinedTransformConfigTest
|
||||
config.addTransformConfig(transformConfig, READ_FROM_B, BASE_URL_B, registry);
|
||||
config.combineTransformerConfig(registry);
|
||||
|
||||
String expected = expectedWildcardError("the step transforms don't support any");
|
||||
assertEquals(expectedWildcardError("the step transforms don't support any"), registry.errorMessages.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonComplete() throws Exception
|
||||
{
|
||||
TransformConfig transformConfig = readTransformConfigFromResource("engine_config_complete.json");
|
||||
|
||||
config.addTransformConfig(transformConfig, READ_FROM_B, BASE_URL_B, registry);
|
||||
config.combineTransformerConfig(registry);
|
||||
TransformConfig combinedTransformConfig = config.buildTransformConfig();
|
||||
|
||||
assertEquals(0, registry.errorMessages.size());
|
||||
assertEquals(1, combinedTransformConfig.getTransformers().size());
|
||||
assertEquals(1, combinedTransformConfig.getTransformOptions().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonDuplicateOptionsAndSupportedMimetypes() throws Exception
|
||||
{
|
||||
TransformConfig transformConfig = readTransformConfigFromResource("engine_config_with_duplicates.json");
|
||||
|
||||
config.addTransformConfig(transformConfig, READ_FROM_B, BASE_URL_B, registry);
|
||||
config.combineTransformerConfig(registry);
|
||||
TransformConfig combinedTransformConfig = config.buildTransformConfig();
|
||||
|
||||
assertEquals(0, registry.errorMessages.size());
|
||||
assertEquals(1, combinedTransformConfig.getTransformers().size());
|
||||
assertEquals(1, combinedTransformConfig.getTransformOptions().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonNoOptions() throws Exception
|
||||
{
|
||||
TransformConfig transformConfig = readTransformConfigFromResource("engine_config_no_transform_options.json");
|
||||
|
||||
config.addTransformConfig(transformConfig, READ_FROM_B, BASE_URL_B, registry);
|
||||
config.combineTransformerConfig(registry);
|
||||
TransformConfig combinedTransformConfig = config.buildTransformConfig();
|
||||
|
||||
assertEquals(0, registry.errorMessages.size());
|
||||
assertEquals(1, combinedTransformConfig.getTransformers().size());
|
||||
assertEquals(0, combinedTransformConfig.getTransformOptions().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonIncompleteNoTransformName() throws Exception
|
||||
{
|
||||
TransformConfig transformConfig = readTransformConfigFromResource("engine_config_incomplete.json");
|
||||
|
||||
config.addTransformConfig(transformConfig, READ_FROM_B, BASE_URL_B, registry);
|
||||
config.combineTransformerConfig(registry);
|
||||
TransformConfig combinedTransformConfig = config.buildTransformConfig();
|
||||
|
||||
assertEquals(1, registry.errorMessages.size());
|
||||
assertEquals(expected, registry.errorMessages.get(0));
|
||||
assertEquals("Transformer names may not be null. Read from readFromB", registry.errorMessages.get(0));
|
||||
assertEquals(0, combinedTransformConfig.getTransformers().size());
|
||||
}
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Helper class for testing an {@link AbstractTransformRegistry}.
|
||||
*/
|
||||
public class TestTransformRegistry extends AbstractTransformRegistry
|
||||
public class FakeTransformRegistry extends AbstractTransformRegistry
|
||||
{
|
||||
private static final String READ_FROM_A = "readFromA";
|
||||
private static final String BASE_URL_B = "baseUrlB";
|
@@ -96,7 +96,7 @@ public class OverrideTransformConfigTests
|
||||
|
||||
private final CombinedTransformConfig config = new CombinedTransformConfig();
|
||||
|
||||
private final TestTransformRegistry registry = new TestTransformRegistry();
|
||||
private final FakeTransformRegistry registry = new FakeTransformRegistry();
|
||||
|
||||
@Test
|
||||
public void testRemoveTransformers()
|
||||
|
22
model/src/test/resources/engine_config_complete.json
Normal file
22
model/src/test/resources/engine_config_complete.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"transformOptions": {
|
||||
"engineXOptions": [
|
||||
{"value": {"name": "page"}},
|
||||
{"value": {"name": "width"}},
|
||||
{"group": {"transformOptions": [
|
||||
{"value": {"name": "cropGravity"}}
|
||||
]}}
|
||||
]
|
||||
},
|
||||
"transformers": [
|
||||
{
|
||||
"transformerName": "engineX",
|
||||
"supportedSourceAndTargetList": [
|
||||
{"sourceMediaType": "application/pdf", "targetMediaType": "image/png" }
|
||||
],
|
||||
"transformOptions": [
|
||||
"engineXOptions"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
10
model/src/test/resources/engine_config_incomplete.json
Normal file
10
model/src/test/resources/engine_config_incomplete.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"transformOptions": {},
|
||||
"transformers": [
|
||||
{
|
||||
"supportedSourceAndTargetList": [
|
||||
{"sourceMediaType": "application/pdf", "targetMediaType": "image/png" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"transformers": [
|
||||
{
|
||||
"transformerName": "engineX",
|
||||
"supportedSourceAndTargetList": [
|
||||
{"sourceMediaType": "application/pdf", "targetMediaType": "image/png" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
26
model/src/test/resources/engine_config_with_duplicates.json
Normal file
26
model/src/test/resources/engine_config_with_duplicates.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"transformOptions": {
|
||||
"engineXOptions": [
|
||||
{"value": {"name": "page"}},
|
||||
{"value": {"name": "page"}},
|
||||
{"value": {"name": "width"}},
|
||||
{"group": {"transformOptions": [
|
||||
{"value": {"name": "cropGravity"}}
|
||||
]}}
|
||||
]
|
||||
},
|
||||
"transformers": [
|
||||
{
|
||||
"transformerName": "engineX",
|
||||
"supportedSourceAndTargetList": [
|
||||
{"sourceMediaType": "application/pdf", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "application/pdf", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "application/pdf", "targetMediaType": "image/png" }
|
||||
],
|
||||
"transformOptions": [
|
||||
"engineXOptions",
|
||||
"engineXOptions"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user