mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
Save point: [skip ci]
* Addition of AllInOneTransformControllerTest
This commit is contained in:
@@ -57,6 +57,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -114,13 +115,21 @@ public class TransformController
|
||||
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
if (transformEngines != null)
|
||||
{
|
||||
Arrays.stream(transformEngine.getStartupMessage().split("\\n")).forEach(logger::info);
|
||||
logSplitMessage(transformEngine.getStartupMessage());
|
||||
transformEngines.stream()
|
||||
.filter(te -> te != transformEngine)
|
||||
.sorted(Comparator.comparing(TransformEngine::getTransformEngineName))
|
||||
.forEach(te -> logSplitMessage(te.getStartupMessage()));
|
||||
}
|
||||
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
|
||||
logger.info("Starting application components... Done");
|
||||
}
|
||||
|
||||
private void logSplitMessage(String message)
|
||||
{
|
||||
Arrays.stream(message.split("\\n")).forEach(logger::info);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a string that may be used in client debug.
|
||||
*/
|
||||
|
@@ -46,7 +46,6 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
import static org.alfresco.transform.base.fs.FileManager.TempFileProvider.createTempFile;
|
||||
import static org.springframework.http.HttpStatus.INSUFFICIENT_STORAGE;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS;
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Core
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 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.transform.base;
|
||||
|
||||
import org.alfresco.transform.base.fakes.FakeTransformEngineWithAllInOne;
|
||||
import org.alfresco.transform.base.fakes.FakeTransformEngineWithOneCustomTransformer;
|
||||
import org.alfresco.transform.base.fakes.FakeTransformEngineWithTwoCustomTransformers;
|
||||
import org.alfresco.transform.base.fakes.FakeTransformerPdf2Jpg;
|
||||
import org.alfresco.transform.base.fakes.FakeTransformerPdf2Png;
|
||||
import org.alfresco.transform.base.fakes.FakeTransformerTxT2Pdf;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import static org.alfresco.transform.base.TransformControllerTest.assertConfig;
|
||||
import static org.alfresco.transform.base.TransformControllerTest.getLogMessagesFor;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_IMAGE_JPEG;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PDF;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_ERROR;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_LIVE;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_LOG;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_READY;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_ROOT;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG_LATEST;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_VERSION;
|
||||
import static org.alfresco.transform.common.RequestParamMap.PAGE_REQUEST_PARAM;
|
||||
import static org.alfresco.transform.common.RequestParamMap.SOURCE_MIMETYPE;
|
||||
import static org.alfresco.transform.common.RequestParamMap.TARGET_MIMETYPE;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* Testing base t-engine TransformController functionality where there are multiple TransformEngines brought together
|
||||
* in a single t-engine.
|
||||
*
|
||||
* Contains a subset of tests also in {@link TransformControllerTest}.
|
||||
*/
|
||||
@AutoConfigureMockMvc
|
||||
@SpringBootTest(classes={org.alfresco.transform.base.Application.class})
|
||||
@ContextConfiguration(classes = {
|
||||
FakeTransformEngineWithAllInOne.class,
|
||||
FakeTransformEngineWithTwoCustomTransformers.class,
|
||||
FakeTransformerTxT2Pdf.class,
|
||||
FakeTransformerPdf2Png.class,
|
||||
FakeTransformEngineWithOneCustomTransformer.class,
|
||||
FakeTransformerPdf2Jpg.class})
|
||||
public class AllInOneTransformControllerTest
|
||||
{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private TransformController transformController;
|
||||
@Autowired
|
||||
protected ObjectMapper objectMapper;
|
||||
@Autowired
|
||||
private String coreVersion;
|
||||
|
||||
@Test
|
||||
public void testInitEngine() throws Exception
|
||||
{
|
||||
assertEquals(FakeTransformEngineWithAllInOne.class.getSimpleName(),
|
||||
transformController.transformEngine.getClass().getSimpleName());
|
||||
assertNotNull(transformController.probeTransform);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartupLogsIncludeEngineMessages()
|
||||
{
|
||||
StringJoiner controllerLogMessages = getLogMessagesFor(TransformController.class);
|
||||
|
||||
transformController.startup();
|
||||
|
||||
assertEquals(
|
||||
"--------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
|
||||
+ "Startup AllInOne\n"
|
||||
+ "Line 2 AllInOne\n"
|
||||
+ "Line 3\n"
|
||||
+ "Startup OneCustomTransformer\n"
|
||||
+ "Line 2 OneCustomTransformer\n"
|
||||
+ "Line 3\n"
|
||||
+ "Startup TwoCustomTransformers\n"
|
||||
+ "Line 2 TwoCustomTransformers\n"
|
||||
+ "Line 3\n"
|
||||
+ "--------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
|
||||
+ "Starting application components... Done",
|
||||
controllerLogMessages.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVersionEndpointIncludesAvailable() throws Exception
|
||||
{
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_VERSION))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string("AllInOne "+coreVersion+" available"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRootEndpointReturnsTestPage() throws Exception
|
||||
{
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_ROOT))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("AllInOne Test Page")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorEndpointReturnsErrorPage() throws Exception
|
||||
{
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_ERROR))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("AllInOne Error Page")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogEndpointReturnsLogPage() throws Exception
|
||||
{
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_LOG))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("AllInOne Log Entries")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadyEndpointReturnsSuccessful() throws Exception
|
||||
{
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_READY))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("Success - ")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiveEndpointReturnsSuccessful() throws Exception
|
||||
{
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_LIVE))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("Success - ")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigEndpointReturnsOriginalConfigFormat() throws Exception
|
||||
{
|
||||
// The transformer's options should not include directAccessUrl as this is the default version of config
|
||||
assertConfig(ENDPOINT_TRANSFORM_CONFIG,
|
||||
"Pdf2Jpg,null,imageOptions\n"
|
||||
+ "Pdf2Png,null,imageOptions\n"
|
||||
+ "TxT2Pdf,null,docOptions\n"
|
||||
+ "Txt2JpgViaPdf,null,imageOptions\n"
|
||||
+ "Txt2PngViaPdf,null,imageOptions",
|
||||
"docOptions,imageOptions", mockMvc, objectMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigLatestEndpointReturnsCoreVersionAndDirectAccessUrlOption() throws Exception
|
||||
{
|
||||
assertConfig(ENDPOINT_TRANSFORM_CONFIG_LATEST,
|
||||
"Pdf2Jpg,2.6.1,directAccessUrl,imageOptions\n"
|
||||
+ "Pdf2Png,"+coreVersion+",directAccessUrl,imageOptions\n"
|
||||
+ "TxT2Pdf,"+coreVersion+",directAccessUrl,docOptions\n"
|
||||
+ "Txt2JpgViaPdf,"+coreVersion+",directAccessUrl,imageOptions\n"
|
||||
+ "Txt2PngViaPdf,"+coreVersion+",directAccessUrl,imageOptions",
|
||||
"directAccessUrl,docOptions,imageOptions", mockMvc, objectMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransformEndpointUsingTransformEngineWithTwoCustomTransformers() throws Exception
|
||||
{
|
||||
MvcResult mvcResult = mockMvc.perform(
|
||||
MockMvcRequestBuilders.multipart(ENDPOINT_TRANSFORM)
|
||||
.file(new MockMultipartFile("file", null, MIMETYPE_TEXT_PLAIN,
|
||||
"Start".getBytes(StandardCharsets.UTF_8)))
|
||||
.param(SOURCE_MIMETYPE, MIMETYPE_TEXT_PLAIN)
|
||||
.param(TARGET_MIMETYPE, MIMETYPE_PDF)
|
||||
.param(PAGE_REQUEST_PARAM, "1"))
|
||||
.andExpect(request().asyncStarted())
|
||||
.andReturn();
|
||||
|
||||
mockMvc.perform(asyncDispatch(mvcResult))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
"attachment; filename*=UTF-8''transform.pdf"))
|
||||
.andExpect(content().string("Start -> TxT2Pdf(page=1)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransformEndpointUsingTransformEngineWithOneCustomTransformer() throws Exception
|
||||
{
|
||||
MvcResult mvcResult = mockMvc.perform(
|
||||
MockMvcRequestBuilders.multipart(ENDPOINT_TRANSFORM)
|
||||
.file(new MockMultipartFile("file", null, MIMETYPE_PDF,
|
||||
"Start".getBytes(StandardCharsets.UTF_8)))
|
||||
.param(SOURCE_MIMETYPE, MIMETYPE_PDF)
|
||||
.param(TARGET_MIMETYPE, MIMETYPE_IMAGE_JPEG))
|
||||
.andExpect(request().asyncStarted())
|
||||
.andReturn();
|
||||
|
||||
mockMvc.perform(asyncDispatch(mvcResult))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
"attachment; filename*=UTF-8''transform.jpeg"))
|
||||
.andExpect(content().string("Start -> Pdf2Jpg()"));
|
||||
}
|
||||
}
|
@@ -33,9 +33,9 @@ import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.core.AppenderBase;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.alfresco.transform.base.components.TestTransformEngineTwoTransformers;
|
||||
import org.alfresco.transform.base.components.TestTransformerPdf2Png;
|
||||
import org.alfresco.transform.base.components.TestTransformerTxT2Pdf;
|
||||
import org.alfresco.transform.base.fakes.FakeTransformEngineWithTwoCustomTransformers;
|
||||
import org.alfresco.transform.base.fakes.FakeTransformerPdf2Png;
|
||||
import org.alfresco.transform.base.fakes.FakeTransformerTxT2Pdf;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -84,14 +84,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
|
||||
/**
|
||||
* Testing base t-engine TransformController functionality.
|
||||
*
|
||||
* Also see {@link AllInOneTransformControllerTest}.
|
||||
*/
|
||||
@AutoConfigureMockMvc
|
||||
@SpringBootTest(classes={org.alfresco.transform.base.Application.class})
|
||||
@ContextConfiguration(classes = {
|
||||
TestTransformEngineTwoTransformers.class,
|
||||
TestTransformerTxT2Pdf.class,
|
||||
TestTransformerPdf2Png.class})
|
||||
public class TransformControllerWithSingleEngineTest
|
||||
FakeTransformEngineWithTwoCustomTransformers.class,
|
||||
FakeTransformerTxT2Pdf.class,
|
||||
FakeTransformerPdf2Png.class})
|
||||
public class TransformControllerTest
|
||||
{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@@ -105,7 +107,7 @@ public class TransformControllerWithSingleEngineTest
|
||||
@Test
|
||||
public void testInitEngine() throws Exception
|
||||
{
|
||||
assertEquals(TestTransformEngineTwoTransformers.class.getSimpleName(),
|
||||
assertEquals(FakeTransformEngineWithTwoCustomTransformers.class.getSimpleName(),
|
||||
transformController.transformEngine.getClass().getSimpleName());
|
||||
assertNotNull(transformController.probeTransform);
|
||||
}
|
||||
@@ -119,15 +121,15 @@ public class TransformControllerWithSingleEngineTest
|
||||
|
||||
assertEquals(
|
||||
"--------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
|
||||
+ "Startup TwoTransformers\n"
|
||||
+ "Line 2 TwoTransformers\n"
|
||||
+ "Startup TwoCustomTransformers\n"
|
||||
+ "Line 2 TwoCustomTransformers\n"
|
||||
+ "Line 3\n"
|
||||
+ "--------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
|
||||
+ "Starting application components... Done",
|
||||
controllerLogMessages.toString());
|
||||
}
|
||||
|
||||
private StringJoiner getLogMessagesFor(Class classBeingLogged)
|
||||
static StringJoiner getLogMessagesFor(Class classBeingLogged)
|
||||
{
|
||||
StringJoiner logMessages = new StringJoiner("\n");
|
||||
Logger logger = (Logger) LoggerFactory.getLogger(classBeingLogged);
|
||||
@@ -152,7 +154,7 @@ public class TransformControllerWithSingleEngineTest
|
||||
{
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_VERSION))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string("TwoTransformers "+coreVersion+" available"));
|
||||
.andExpect(content().string("TwoCustomTransformers "+coreVersion+" available"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -160,7 +162,7 @@ public class TransformControllerWithSingleEngineTest
|
||||
{
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_ROOT))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("TwoTransformers Test Page")));
|
||||
.andExpect(content().string(containsString("TwoCustomTransformers Test Page")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -168,7 +170,7 @@ public class TransformControllerWithSingleEngineTest
|
||||
{
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_ERROR))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("TwoTransformers Error Page")));
|
||||
.andExpect(content().string(containsString("TwoCustomTransformers Error Page")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,7 +178,7 @@ public class TransformControllerWithSingleEngineTest
|
||||
{
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_LOG))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("TwoTransformers Log Entries")));
|
||||
.andExpect(content().string(containsString("TwoCustomTransformers Log Entries")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -206,7 +208,7 @@ public class TransformControllerWithSingleEngineTest
|
||||
+ "TxT2Pdf,null,docOptions\n"
|
||||
+ "Txt2JpgViaPdf,null,imageOptions\n"
|
||||
+ "Txt2PngViaPdf,null,imageOptions",
|
||||
"docOptions,imageOptions");
|
||||
"docOptions,imageOptions", mockMvc, objectMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -217,10 +219,11 @@ public class TransformControllerWithSingleEngineTest
|
||||
+ "TxT2Pdf,"+coreVersion+",directAccessUrl,docOptions\n"
|
||||
+ "Txt2JpgViaPdf,null,imageOptions\n"
|
||||
+ "Txt2PngViaPdf,"+coreVersion+",directAccessUrl,imageOptions",
|
||||
"directAccessUrl,docOptions,imageOptions");
|
||||
"directAccessUrl,docOptions,imageOptions", mockMvc, objectMapper);
|
||||
}
|
||||
|
||||
private void assertConfig(String url, String expectedTransformers, String expectedOptions) throws Exception
|
||||
static void assertConfig(String url, String expectedTransformers, String expectedOptions,
|
||||
MockMvc mockMvc, ObjectMapper objectMapper) throws Exception
|
||||
{
|
||||
TransformConfig config = objectMapper.readValue(
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(url))
|
||||
@@ -260,7 +263,7 @@ public class TransformControllerWithSingleEngineTest
|
||||
mockMvc.perform(asyncDispatch(mvcResult))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
"attachment; filename*=UTF-8''transform." + "pdf"))
|
||||
"attachment; filename*=UTF-8''transform.pdf"))
|
||||
.andExpect(content().string("Start -> TxT2Pdf(page=1)"));
|
||||
}
|
||||
|
||||
@@ -330,7 +333,7 @@ public class TransformControllerWithSingleEngineTest
|
||||
|
||||
mockMvc.perform(asyncDispatch(mvcResult))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().string(containsString("TwoTransformers Error Page")))
|
||||
.andExpect(content().string(containsString("TwoCustomTransformers Error Page")))
|
||||
.andExpect(content().string(containsString("No transforms were able to handle the request")));
|
||||
}
|
||||
}
|
@@ -24,27 +24,21 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.base.components;
|
||||
package org.alfresco.transform.base.fakes;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.alfresco.transform.base.TransformEngine;
|
||||
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||
import org.springframework.boot.test.context.TestComponent;
|
||||
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PDF;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transform.common.RequestParamMap.SOURCE_ENCODING;
|
||||
|
||||
/**
|
||||
* Subclass MUST be named TestTransformEngine\<something>.
|
||||
* Subclass MUST be named FakeTransformEngineWith\<something>.
|
||||
*/
|
||||
@TestComponent
|
||||
public abstract class AbstractTestTransformEngine implements TransformEngine
|
||||
public abstract class AbstractFakeTransformEngine implements TransformEngine
|
||||
{
|
||||
@Override public String getTransformEngineName()
|
||||
{
|
||||
String simpleClassName = getClass().getSimpleName();
|
||||
return simpleClassName.substring("TestTransformEngine".length());
|
||||
return simpleClassName.substring("FakeTransformEngineWith".length());
|
||||
}
|
||||
|
||||
@Override public String getStartupMessage()
|
||||
@@ -53,12 +47,4 @@ public abstract class AbstractTestTransformEngine implements TransformEngine
|
||||
"\nLine 2 "+getTransformEngineName()+
|
||||
"\nLine 3";
|
||||
}
|
||||
|
||||
@Override public ProbeTransform getProbeTransform()
|
||||
{
|
||||
return new ProbeTransform("quick.txt", "quick.pdf",
|
||||
MIMETYPE_TEXT_PLAIN, MIMETYPE_PDF, ImmutableMap.of(SOURCE_ENCODING, "UTF-8"),
|
||||
46, 0, 150, 1024, 1,
|
||||
60 * 2);
|
||||
}
|
||||
}
|
@@ -24,14 +24,13 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.base.components;
|
||||
package org.alfresco.transform.base.fakes;
|
||||
|
||||
import org.alfresco.transform.base.CustomTransformer;
|
||||
import org.alfresco.transform.base.TransformManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.test.context.TestComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -44,7 +43,7 @@ import java.util.stream.Collectors;
|
||||
* to the output. The output is always a String regardless of the stated mimetypes.
|
||||
*/
|
||||
@TestComponent
|
||||
public abstract class AbstractTestTransformer implements CustomTransformer
|
||||
public abstract class AbstractFakeTransformer implements CustomTransformer
|
||||
{
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Core
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 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.transform.base.fakes;
|
||||
|
||||
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class FakeTransformEngineWithAllInOne extends AbstractFakeTransformEngine
|
||||
{
|
||||
@Autowired
|
||||
private FakeTransformEngineWithTwoCustomTransformers oneOfTheTransformEngines;
|
||||
|
||||
@Override public TransformConfig getTransformConfig()
|
||||
{
|
||||
// Has no config of its own. The combined config of the others is returned from the t-engine.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public ProbeTransform getProbeTransform()
|
||||
{
|
||||
return oneOfTheTransformEngines.getProbeTransform();
|
||||
}
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Core
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 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.transform.base.fakes;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.alfresco.transform.config.TransformOptionValue;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_IMAGE_JPEG;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PDF;
|
||||
|
||||
public class FakeTransformEngineWithOneCustomTransformer extends AbstractFakeTransformEngine
|
||||
{
|
||||
@Override public TransformConfig getTransformConfig()
|
||||
{
|
||||
String imageOptions = "imageOptions";
|
||||
return TransformConfig.builder()
|
||||
.withTransformOptions(ImmutableMap.of(
|
||||
imageOptions, ImmutableSet.of(
|
||||
new TransformOptionValue(false, "width"),
|
||||
new TransformOptionValue(false, "height"))))
|
||||
.withTransformers(ImmutableList.of(
|
||||
Transformer.builder()
|
||||
.withTransformerName("Pdf2Jpg")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(MIMETYPE_PDF)
|
||||
.withTargetMediaType(MIMETYPE_IMAGE_JPEG)
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of(imageOptions))
|
||||
.build()))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override public ProbeTransform getProbeTransform()
|
||||
{
|
||||
return null; // Not used in tests
|
||||
}
|
||||
}
|
@@ -24,11 +24,12 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.base.components;
|
||||
package org.alfresco.transform.base.fakes;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.alfresco.transform.config.TransformOptionValue;
|
||||
@@ -41,8 +42,9 @@ import static org.alfresco.transform.common.Mimetype.MIMETYPE_IMAGE_JPEG;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_IMAGE_PNG;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PDF;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transform.common.RequestParamMap.SOURCE_ENCODING;
|
||||
|
||||
public class TestTransformEngineTwoTransformers extends AbstractTestTransformEngine
|
||||
public class FakeTransformEngineWithTwoCustomTransformers extends AbstractFakeTransformEngine
|
||||
{
|
||||
@Override public TransformConfig getTransformConfig()
|
||||
{
|
||||
@@ -65,39 +67,47 @@ public class TestTransformEngineTwoTransformers extends AbstractTestTransformEng
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of(docOptions))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("Pdf2Png")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(MIMETYPE_PDF)
|
||||
.withTargetMediaType(MIMETYPE_IMAGE_PNG)
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of(imageOptions))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("Txt2PngViaPdf")
|
||||
.withTransformerPipeline(List.of(
|
||||
new TransformStep("TxT2Pdf", MIMETYPE_PDF),
|
||||
new TransformStep("Pdf2Png", null)))
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(MIMETYPE_TEXT_PLAIN)
|
||||
.withTargetMediaType(MIMETYPE_IMAGE_PNG)
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of(imageOptions))
|
||||
.build(),
|
||||
Transformer.builder() // Unavailable until Pdf2Jpg is added
|
||||
.withTransformerName("Txt2JpgViaPdf")
|
||||
.withTransformerPipeline(List.of(
|
||||
new TransformStep("TxT2Pdf", MIMETYPE_PDF),
|
||||
new TransformStep("Pdf2Jpg", null)))
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(MIMETYPE_TEXT_PLAIN)
|
||||
.withTargetMediaType(MIMETYPE_IMAGE_JPEG)
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of(imageOptions))
|
||||
.build()))
|
||||
Transformer.builder()
|
||||
.withTransformerName("Pdf2Png")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(MIMETYPE_PDF)
|
||||
.withTargetMediaType(MIMETYPE_IMAGE_PNG)
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of(imageOptions))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("Txt2PngViaPdf")
|
||||
.withTransformerPipeline(List.of(
|
||||
new TransformStep("TxT2Pdf", MIMETYPE_PDF),
|
||||
new TransformStep("Pdf2Png", null)))
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(MIMETYPE_TEXT_PLAIN)
|
||||
.withTargetMediaType(MIMETYPE_IMAGE_PNG)
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of(imageOptions))
|
||||
.build(),
|
||||
Transformer.builder() // Unavailable until Pdf2Jpg is added
|
||||
.withTransformerName("Txt2JpgViaPdf")
|
||||
.withTransformerPipeline(List.of(
|
||||
new TransformStep("TxT2Pdf", MIMETYPE_PDF),
|
||||
new TransformStep("Pdf2Jpg", null)))
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(MIMETYPE_TEXT_PLAIN)
|
||||
.withTargetMediaType(MIMETYPE_IMAGE_JPEG)
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of(imageOptions))
|
||||
.build()))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override public ProbeTransform getProbeTransform()
|
||||
{
|
||||
return new ProbeTransform("quick.txt", "quick.pdf",
|
||||
MIMETYPE_TEXT_PLAIN, MIMETYPE_PDF, ImmutableMap.of(SOURCE_ENCODING, "UTF-8"),
|
||||
46, 0, 150, 1024, 1,
|
||||
60 * 2);
|
||||
}
|
||||
}
|
@@ -24,8 +24,8 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.base.components;
|
||||
package org.alfresco.transform.base.fakes;
|
||||
|
||||
public class TestTransformerPdf2Png extends AbstractTestTransformer
|
||||
public class FakeTransformerPdf2Jpg extends AbstractFakeTransformer
|
||||
{
|
||||
}
|
@@ -24,8 +24,8 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.base.components;
|
||||
package org.alfresco.transform.base.fakes;
|
||||
|
||||
public class TestTransformerTxT2Pdf extends AbstractTestTransformer
|
||||
public class FakeTransformerPdf2Png extends AbstractFakeTransformer
|
||||
{
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Core
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 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.transform.base.fakes;
|
||||
|
||||
public class FakeTransformerTxT2Pdf extends AbstractFakeTransformer
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user