mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-05-12 17:04:48 +00:00
ATS-434 : Implement /info
endpoint in T-Engines (#44)
- implement '/info' endpoint - add engine_config files - use SNAPSHOT transform-model with new Transform Config models (TODO update after transform-model release) - remove 'tests' from travis stages - add new junits - add test resources
This commit is contained in:
parent
9e0042e767
commit
d2292f94a0
@ -28,7 +28,6 @@ branches:
|
||||
|
||||
stages:
|
||||
- build
|
||||
- tests
|
||||
- release
|
||||
- company_release
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
{
|
||||
"transformOptions": {
|
||||
"pdfRendererOptions": [
|
||||
{"value": {"name": "page"}},
|
||||
{"value": {"name": "width"}},
|
||||
{"value": {"name": "height"}},
|
||||
{"value": {"name": "allowPdfEnlargement"}},
|
||||
{"value": {"name": "maintainPdfAspectRatio"}}
|
||||
]
|
||||
},
|
||||
"transformers": [
|
||||
{
|
||||
"transformerName": "pdfrenderer",
|
||||
"supportedSourceAndTargetList": [
|
||||
{"sourceMediaType": "application/pdf", "targetMediaType": "image/png" }
|
||||
],
|
||||
"transformOptions": [
|
||||
"pdfRendererOptions"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
{
|
||||
"transformOptions": {
|
||||
"imageMagickOptions": [
|
||||
{"value": {"name": "alphaRemove"}},
|
||||
{"value": {"name": "autoOrient"}},
|
||||
{"value": {"name": "startPage"}},
|
||||
{"value": {"name": "endPage"}},
|
||||
{"group": {"transformOptions": [
|
||||
{"value": {"name": "cropGravity"}},
|
||||
{"value": {"name": "cropWidth"}},
|
||||
{"value": {"name": "cropHeight"}},
|
||||
{"value": {"name": "cropPercentage"}},
|
||||
{"value": {"name": "cropXOffset"}},
|
||||
{"value": {"name": "cropYOffset"}}
|
||||
]}},
|
||||
{"group": {"transformOptions": [
|
||||
{"value": {"name": "thumbnail"}},
|
||||
{"value": {"name": "resizeHeight"}},
|
||||
{"value": {"name": "resizeWidth"}},
|
||||
{"value": {"name": "resizePercentage"}},
|
||||
{"value": {"name": "allowEnlargement"}},
|
||||
{"value": {"name": "maintainAspectRatio"}}
|
||||
]}}
|
||||
]
|
||||
},
|
||||
"transformers": [
|
||||
{
|
||||
"transformerName": "imagemagick",
|
||||
"supportedSourceAndTargetList": [
|
||||
{"sourceMediaType": "image/gif", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "image/gif", "targetMediaType": "image/jpeg"},
|
||||
{"sourceMediaType": "image/gif", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "image/gif", "targetMediaType": "image/tiff"},
|
||||
|
||||
{"sourceMediaType": "image/jpeg", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "image/jpeg", "targetMediaType": "image/jpeg"},
|
||||
{"sourceMediaType": "image/jpeg", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "image/jpeg", "targetMediaType": "image/tiff"},
|
||||
|
||||
{"sourceMediaType": "image/png", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "image/png", "targetMediaType": "image/jpeg"},
|
||||
{"sourceMediaType": "image/png", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "image/png", "targetMediaType": "image/tiff"},
|
||||
|
||||
{"sourceMediaType": "image/tiff", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "image/tiff", "targetMediaType": "image/tiff"}
|
||||
],
|
||||
"transformOptions": [
|
||||
"imageMagickOptions"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
{
|
||||
"transformers": [
|
||||
{
|
||||
"transformerName": "libreoffice",
|
||||
"supportedSourceAndTargetList": [
|
||||
{"sourceMediaType": "application/msword", "targetMediaType": "application/msword" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "targetMediaType": "application/msword" },
|
||||
{"sourceMediaType": "application/msword", "maxSourceSizeBytes": 10485760, "targetMediaType": "application/pdf" },
|
||||
{"sourceMediaType": "application/vnd.ms-excel", "maxSourceSizeBytes": 10485760, "targetMediaType": "application/pdf"},
|
||||
{"sourceMediaType": "application/vnd.ms-powerpoint", "maxSourceSizeBytes": 6291456, "targetMediaType": "application/pdf" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "maxSourceSizeBytes": 786432, "targetMediaType": "application/pdf" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "maxSourceSizeBytes": 1572864, "targetMediaType": "application/pdf"},
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.presentation", "maxSourceSizeBytes": 4194304, "targetMediaType": "application/pdf" },
|
||||
{"sourceMediaType": "application/vnd.ms-outlook", "targetMediaType": "application/pdf"}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
29
alfresco-docker-tika/src/main/resources/engine_config.json
Normal file
29
alfresco-docker-tika/src/main/resources/engine_config.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"transformOptions": {
|
||||
"tikaOptions": [
|
||||
{"value": {"name": "transform"}},
|
||||
{"value": {"name": "includeContents"}},
|
||||
{"value": {"name": "notExtractBookmarksText"}},
|
||||
{"value": {"name": "targetMimetype"}},
|
||||
{"value": {"name": "targetEncoding"}}
|
||||
]
|
||||
},
|
||||
"transformers": [
|
||||
{
|
||||
"transformerName": "tika",
|
||||
"supportedSourceAndTargetList": [
|
||||
{"sourceMediaType": "application/pdf", "maxSourceSizeBytes": 26214400, "targetMediaType": "text/plain" },
|
||||
{"sourceMediaType": "application/msword", "targetMediaType": "text/plain"},
|
||||
{"sourceMediaType": "application/vnd.ms-excel", "targetMediaType": "text/plain" },
|
||||
{"sourceMediaType": "application/vnd.ms-powerpoint", "targetMediaType": "text/plain" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "targetMediaType": "text/plain"},
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "targetMediaType": "text/plain" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.presentation", "targetMediaType": "text/plain" },
|
||||
{"sourceMediaType": "application/vnd.ms-outlook", "targetMediaType": "text/plain"}
|
||||
],
|
||||
"transformOptions": [
|
||||
"tikaOptions"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
|
||||
import static org.alfresco.transformer.fs.FileManager.buildFile;
|
||||
import static org.alfresco.transformer.fs.FileManager.createTargetFileName;
|
||||
import static org.alfresco.transformer.fs.FileManager.deleteFile;
|
||||
@ -28,14 +29,18 @@ import static org.alfresco.transformer.fs.FileManager.getFilenameFromContentDisp
|
||||
import static org.alfresco.transformer.fs.FileManager.save;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
import org.alfresco.transform.client.model.TransformRequestValidator;
|
||||
import org.alfresco.transform.client.model.config.TransformConfig;
|
||||
import org.alfresco.transformer.clients.AlfrescoSharedFileStoreClient;
|
||||
import org.alfresco.transform.exceptions.TransformException;
|
||||
import org.alfresco.transformer.logging.LogEntry;
|
||||
@ -44,6 +49,7 @@ import org.alfresco.util.TempFileProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@ -53,6 +59,7 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.DirectFieldBindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
@ -89,6 +96,7 @@ import org.springframework.web.client.HttpClientErrorException;
|
||||
public abstract class AbstractTransformerController implements TransformController
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(AbstractTransformerController.class);
|
||||
private static String ENGINE_CONFIG = "engine_config.json";
|
||||
|
||||
@Autowired
|
||||
private AlfrescoSharedFileStoreClient alfrescoSharedFileStoreClient;
|
||||
@ -96,6 +104,29 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
@Autowired
|
||||
private TransformRequestValidator transformRequestValidator;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@GetMapping(value = "/info")
|
||||
public ResponseEntity<TransformConfig> info()
|
||||
{
|
||||
logger.info("GET Transform Config.");
|
||||
try
|
||||
{
|
||||
ClassPathResource classPathResource = new ClassPathResource(ENGINE_CONFIG);
|
||||
File engineConfigFile = classPathResource.getFile();
|
||||
|
||||
TransformConfig transformConfig = objectMapper.setSerializationInclusion(NON_NULL)
|
||||
.readValue(engineConfigFile, TransformConfig.class);
|
||||
return new ResponseEntity<>(transformConfig, OK);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
"Could not read Transform Config file.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* '/transform' endpoint which consumes and produces 'application/json'
|
||||
*
|
||||
|
@ -0,0 +1 @@
|
||||
{}
|
@ -23,6 +23,7 @@ package org.alfresco.transformer;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
@ -38,23 +39,36 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
import org.alfresco.transform.client.model.config.SupportedSourceAndTarget;
|
||||
import org.alfresco.transform.client.model.config.TransformConfig;
|
||||
import org.alfresco.transform.client.model.config.TransformOption;
|
||||
import org.alfresco.transform.client.model.config.TransformOptionGroup;
|
||||
import org.alfresco.transform.client.model.config.TransformOptionValue;
|
||||
import org.alfresco.transform.client.model.config.Transformer;
|
||||
import org.alfresco.transformer.clients.AlfrescoSharedFileStoreClient;
|
||||
import org.alfresco.transformer.probes.ProbeTestTransform;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Super class for testing controllers without a server. Includes tests for the AbstractTransformerController itself.
|
||||
@ -287,4 +301,134 @@ public abstract class AbstractTransformerControllerTest
|
||||
// Assert the reply
|
||||
assertEquals(BAD_REQUEST.value(), transformReply.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTransformConfigInfo() throws Exception
|
||||
{
|
||||
TransformConfig expectedTransformConfig = objectMapper
|
||||
.readValue(new ClassPathResource("engine_config.json").getFile(),
|
||||
TransformConfig.class);
|
||||
|
||||
ReflectionTestUtils
|
||||
.setField(AbstractTransformerController.class, "ENGINE_CONFIG", "engine_config.json");
|
||||
|
||||
String response = mockMvc.perform(MockMvcRequestBuilders.get("/info"))
|
||||
.andExpect(status().is(OK.value())).andExpect(
|
||||
header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
|
||||
TransformConfig transformConfig = objectMapper.readValue(response, TransformConfig.class);
|
||||
|
||||
assertEquals(expectedTransformConfig, transformConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInfoFromConfigWithDuplicates() throws Exception
|
||||
{
|
||||
TransformConfig expectedResult = buildCompleteTransformConfig();
|
||||
|
||||
ReflectionTestUtils.setField(AbstractTransformerController.class, "ENGINE_CONFIG",
|
||||
"engine_config_with_duplicates.json");
|
||||
|
||||
String response = mockMvc.perform(MockMvcRequestBuilders.get("/info"))
|
||||
.andExpect(status().is(OK.value())).andExpect(
|
||||
header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
|
||||
TransformConfig transformConfig = objectMapper.readValue(response, TransformConfig.class);
|
||||
|
||||
assertNotNull(transformConfig);
|
||||
assertEquals(expectedResult, transformConfig);
|
||||
assertEquals(3, transformConfig.getTransformOptions().get("engineXOptions").size());
|
||||
assertEquals(1,
|
||||
transformConfig.getTransformers().get(0).getSupportedSourceAndTargetList().size());
|
||||
assertEquals(1,
|
||||
transformConfig.getTransformers().get(0).getTransformOptions().size());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInfoFromConfigWithEmptyTransformOptions() throws Exception
|
||||
{
|
||||
Transformer transformer = buildTransformer("application/pdf", "image/png");
|
||||
TransformConfig expectedResult = new TransformConfig();
|
||||
expectedResult.setTransformers(ImmutableList.of(transformer));
|
||||
|
||||
ReflectionTestUtils.setField(AbstractTransformerController.class, "ENGINE_CONFIG",
|
||||
"engine_config_incomplete.json");
|
||||
|
||||
String response = mockMvc.perform(MockMvcRequestBuilders.get("/info"))
|
||||
.andExpect(status().is(OK.value())).andExpect(
|
||||
header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
|
||||
TransformConfig transformConfig = objectMapper.readValue(response, TransformConfig.class);
|
||||
|
||||
assertNotNull(transformConfig);
|
||||
assertEquals(expectedResult, transformConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInfoFromConfigWithNoTransformOptions() throws Exception
|
||||
{
|
||||
Transformer transformer = buildTransformer("application/pdf", "image/png");
|
||||
transformer.setTransformerName("engineX");
|
||||
TransformConfig expectedResult = new TransformConfig();
|
||||
expectedResult.setTransformers(ImmutableList.of(transformer));
|
||||
|
||||
ReflectionTestUtils.setField(AbstractTransformerController.class, "ENGINE_CONFIG",
|
||||
"engine_config_no_transform_options.json");
|
||||
|
||||
String response = mockMvc.perform(MockMvcRequestBuilders.get("/info"))
|
||||
.andExpect(status().is(OK.value())).andExpect(
|
||||
header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
|
||||
TransformConfig transformConfig = objectMapper.readValue(response, TransformConfig.class);
|
||||
|
||||
assertNotNull(transformConfig);
|
||||
assertEquals(expectedResult, transformConfig);
|
||||
}
|
||||
|
||||
private TransformConfig buildCompleteTransformConfig()
|
||||
{
|
||||
TransformConfig expectedResult = new TransformConfig();
|
||||
|
||||
Set<TransformOption> transformOptionGroup = ImmutableSet.of(
|
||||
new TransformOptionValue(false, "cropGravity"));
|
||||
Set<TransformOption> transformOptions = ImmutableSet.of(
|
||||
new TransformOptionValue(false, "page"),
|
||||
new TransformOptionValue(false, "width"),
|
||||
new TransformOptionGroup(false, transformOptionGroup));
|
||||
Map<String, Set<TransformOption>> transformOptionsMap = ImmutableMap.of("engineXOptions", transformOptions);
|
||||
|
||||
Transformer transformer = buildTransformer("application/pdf", "image/png", "engineXOptions",
|
||||
"engineX");
|
||||
List<Transformer> transformers = ImmutableList.of(transformer);
|
||||
|
||||
expectedResult.setTransformOptions(transformOptionsMap);
|
||||
expectedResult.setTransformers(transformers);
|
||||
|
||||
return expectedResult;
|
||||
}
|
||||
|
||||
private Transformer buildTransformer(String sourceMediaType, String targetMediaType,
|
||||
String transformOptions, String transformerName)
|
||||
{
|
||||
Transformer transformer = buildTransformer(sourceMediaType, targetMediaType);
|
||||
transformer.setTransformerName(transformerName);
|
||||
transformer.setTransformOptions(ImmutableSet.of(transformOptions));
|
||||
|
||||
return transformer;
|
||||
}
|
||||
|
||||
private Transformer buildTransformer(String sourceMediaType, String targetMediaType)
|
||||
{
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargetList = ImmutableSet.of(
|
||||
new SupportedSourceAndTarget(sourceMediaType, targetMediaType, -1));
|
||||
|
||||
Transformer transformer = new Transformer();
|
||||
transformer.setSupportedSourceAndTargetList(supportedSourceAndTargetList);
|
||||
return transformer;
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
3
pom.xml
3
pom.xml
@ -23,7 +23,8 @@
|
||||
<dependency.alfresco-data-model.version>8.8</dependency.alfresco-data-model.version>
|
||||
<dependency.alfresco-jodconverter-core.version>3.0.1.1</dependency.alfresco-jodconverter-core.version>
|
||||
<env.project_version>${project.version}</env.project_version>
|
||||
<dependency.alfresco-transform-model.version>1.0.2.2</dependency.alfresco-transform-model.version>
|
||||
<!-- TODO: update after transform-model release -->
|
||||
<dependency.alfresco-transform-model.version>1.0.2.3-SNAPSHOT</dependency.alfresco-transform-model.version>
|
||||
<dependency.activemq.version>5.15.9</dependency.activemq.version>
|
||||
<dependency.jackson.version>2.9.9</dependency.jackson.version>
|
||||
</properties>
|
||||
|
Loading…
x
Reference in New Issue
Block a user