Save point: [skip ci]

* Addition of AllInOneTransformControllerTest
This commit is contained in:
alandavis
2022-07-20 09:25:08 +01:00
parent 2763239538
commit 929b69384b
12 changed files with 483 additions and 83 deletions

View File

@@ -57,6 +57,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -114,13 +115,21 @@ public class TransformController
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------"); logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
if (transformEngines != null) 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("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
logger.info("Starting application components... Done"); 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. * @return a string that may be used in client debug.
*/ */

View File

@@ -46,7 +46,6 @@ import java.util.concurrent.atomic.AtomicLong;
import static org.alfresco.transform.base.fs.FileManager.TempFileProvider.createTempFile; import static org.alfresco.transform.base.fs.FileManager.TempFileProvider.createTempFile;
import static org.springframework.http.HttpStatus.INSUFFICIENT_STORAGE; import static org.springframework.http.HttpStatus.INSUFFICIENT_STORAGE;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; 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; import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS;
/** /**

View File

@@ -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()"));
}
}

View File

@@ -33,9 +33,9 @@ import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase; import ch.qos.logback.core.AppenderBase;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.alfresco.transform.base.components.TestTransformEngineTwoTransformers; import org.alfresco.transform.base.fakes.FakeTransformEngineWithTwoCustomTransformers;
import org.alfresco.transform.base.components.TestTransformerPdf2Png; import org.alfresco.transform.base.fakes.FakeTransformerPdf2Png;
import org.alfresco.transform.base.components.TestTransformerTxT2Pdf; import org.alfresco.transform.base.fakes.FakeTransformerTxT2Pdf;
import org.alfresco.transform.config.TransformConfig; import org.alfresco.transform.config.TransformConfig;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -84,14 +84,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
/** /**
* Testing base t-engine TransformController functionality. * Testing base t-engine TransformController functionality.
*
* Also see {@link AllInOneTransformControllerTest}.
*/ */
@AutoConfigureMockMvc @AutoConfigureMockMvc
@SpringBootTest(classes={org.alfresco.transform.base.Application.class}) @SpringBootTest(classes={org.alfresco.transform.base.Application.class})
@ContextConfiguration(classes = { @ContextConfiguration(classes = {
TestTransformEngineTwoTransformers.class, FakeTransformEngineWithTwoCustomTransformers.class,
TestTransformerTxT2Pdf.class, FakeTransformerTxT2Pdf.class,
TestTransformerPdf2Png.class}) FakeTransformerPdf2Png.class})
public class TransformControllerWithSingleEngineTest public class TransformControllerTest
{ {
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@@ -105,7 +107,7 @@ public class TransformControllerWithSingleEngineTest
@Test @Test
public void testInitEngine() throws Exception public void testInitEngine() throws Exception
{ {
assertEquals(TestTransformEngineTwoTransformers.class.getSimpleName(), assertEquals(FakeTransformEngineWithTwoCustomTransformers.class.getSimpleName(),
transformController.transformEngine.getClass().getSimpleName()); transformController.transformEngine.getClass().getSimpleName());
assertNotNull(transformController.probeTransform); assertNotNull(transformController.probeTransform);
} }
@@ -119,15 +121,15 @@ public class TransformControllerWithSingleEngineTest
assertEquals( assertEquals(
"--------------------------------------------------------------------------------------------------------------------------------------------------------------\n" "--------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
+ "Startup TwoTransformers\n" + "Startup TwoCustomTransformers\n"
+ "Line 2 TwoTransformers\n" + "Line 2 TwoCustomTransformers\n"
+ "Line 3\n" + "Line 3\n"
+ "--------------------------------------------------------------------------------------------------------------------------------------------------------------\n" + "--------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
+ "Starting application components... Done", + "Starting application components... Done",
controllerLogMessages.toString()); controllerLogMessages.toString());
} }
private StringJoiner getLogMessagesFor(Class classBeingLogged) static StringJoiner getLogMessagesFor(Class classBeingLogged)
{ {
StringJoiner logMessages = new StringJoiner("\n"); StringJoiner logMessages = new StringJoiner("\n");
Logger logger = (Logger) LoggerFactory.getLogger(classBeingLogged); Logger logger = (Logger) LoggerFactory.getLogger(classBeingLogged);
@@ -152,7 +154,7 @@ public class TransformControllerWithSingleEngineTest
{ {
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_VERSION)) mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_VERSION))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().string("TwoTransformers "+coreVersion+" available")); .andExpect(content().string("TwoCustomTransformers "+coreVersion+" available"));
} }
@Test @Test
@@ -160,7 +162,7 @@ public class TransformControllerWithSingleEngineTest
{ {
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_ROOT)) mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_ROOT))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().string(containsString("TwoTransformers Test Page"))); .andExpect(content().string(containsString("TwoCustomTransformers Test Page")));
} }
@Test @Test
@@ -168,7 +170,7 @@ public class TransformControllerWithSingleEngineTest
{ {
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_ERROR)) mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_ERROR))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().string(containsString("TwoTransformers Error Page"))); .andExpect(content().string(containsString("TwoCustomTransformers Error Page")));
} }
@Test @Test
@@ -176,7 +178,7 @@ public class TransformControllerWithSingleEngineTest
{ {
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_LOG)) mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_LOG))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().string(containsString("TwoTransformers Log Entries"))); .andExpect(content().string(containsString("TwoCustomTransformers Log Entries")));
} }
@Test @Test
@@ -206,7 +208,7 @@ public class TransformControllerWithSingleEngineTest
+ "TxT2Pdf,null,docOptions\n" + "TxT2Pdf,null,docOptions\n"
+ "Txt2JpgViaPdf,null,imageOptions\n" + "Txt2JpgViaPdf,null,imageOptions\n"
+ "Txt2PngViaPdf,null,imageOptions", + "Txt2PngViaPdf,null,imageOptions",
"docOptions,imageOptions"); "docOptions,imageOptions", mockMvc, objectMapper);
} }
@Test @Test
@@ -217,10 +219,11 @@ public class TransformControllerWithSingleEngineTest
+ "TxT2Pdf,"+coreVersion+",directAccessUrl,docOptions\n" + "TxT2Pdf,"+coreVersion+",directAccessUrl,docOptions\n"
+ "Txt2JpgViaPdf,null,imageOptions\n" + "Txt2JpgViaPdf,null,imageOptions\n"
+ "Txt2PngViaPdf,"+coreVersion+",directAccessUrl,imageOptions", + "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( TransformConfig config = objectMapper.readValue(
mockMvc.perform(MockMvcRequestBuilders.get(url)) mockMvc.perform(MockMvcRequestBuilders.get(url))
@@ -260,7 +263,7 @@ public class TransformControllerWithSingleEngineTest
mockMvc.perform(asyncDispatch(mvcResult)) mockMvc.perform(asyncDispatch(mvcResult))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(header().string("Content-Disposition", .andExpect(header().string("Content-Disposition",
"attachment; filename*=UTF-8''transform." + "pdf")) "attachment; filename*=UTF-8''transform.pdf"))
.andExpect(content().string("Start -> TxT2Pdf(page=1)")); .andExpect(content().string("Start -> TxT2Pdf(page=1)"));
} }
@@ -330,7 +333,7 @@ public class TransformControllerWithSingleEngineTest
mockMvc.perform(asyncDispatch(mvcResult)) mockMvc.perform(asyncDispatch(mvcResult))
.andExpect(status().isBadRequest()) .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"))); .andExpect(content().string(containsString("No transforms were able to handle the request")));
} }
} }

View File

@@ -24,27 +24,21 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #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.TransformEngine;
import org.alfresco.transform.base.probes.ProbeTransform;
import org.springframework.boot.test.context.TestComponent; 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 @TestComponent
public abstract class AbstractTestTransformEngine implements TransformEngine public abstract class AbstractFakeTransformEngine implements TransformEngine
{ {
@Override public String getTransformEngineName() @Override public String getTransformEngineName()
{ {
String simpleClassName = getClass().getSimpleName(); String simpleClassName = getClass().getSimpleName();
return simpleClassName.substring("TestTransformEngine".length()); return simpleClassName.substring("FakeTransformEngineWith".length());
} }
@Override public String getStartupMessage() @Override public String getStartupMessage()
@@ -53,12 +47,4 @@ public abstract class AbstractTestTransformEngine implements TransformEngine
"\nLine 2 "+getTransformEngineName()+ "\nLine 2 "+getTransformEngineName()+
"\nLine 3"; "\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);
}
} }

View File

@@ -24,14 +24,13 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.transform.base.components; package org.alfresco.transform.base.fakes;
import org.alfresco.transform.base.CustomTransformer; import org.alfresco.transform.base.CustomTransformer;
import org.alfresco.transform.base.TransformManager; import org.alfresco.transform.base.TransformManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.TestComponent; import org.springframework.boot.test.context.TestComponent;
import org.springframework.stereotype.Component;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; 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. * to the output. The output is always a String regardless of the stated mimetypes.
*/ */
@TestComponent @TestComponent
public abstract class AbstractTestTransformer implements CustomTransformer public abstract class AbstractFakeTransformer implements CustomTransformer
{ {
private final Logger logger = LoggerFactory.getLogger(getClass()); private final Logger logger = LoggerFactory.getLogger(getClass());

View File

@@ -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();
}
}

View File

@@ -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
}
}

View File

@@ -24,11 +24,12 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.transform.base.components; package org.alfresco.transform.base.fakes;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.alfresco.transform.base.probes.ProbeTransform;
import org.alfresco.transform.config.SupportedSourceAndTarget; import org.alfresco.transform.config.SupportedSourceAndTarget;
import org.alfresco.transform.config.TransformConfig; import org.alfresco.transform.config.TransformConfig;
import org.alfresco.transform.config.TransformOptionValue; 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_IMAGE_PNG;
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PDF; 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.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() @Override public TransformConfig getTransformConfig()
{ {
@@ -100,4 +102,12 @@ public class TestTransformEngineTwoTransformers extends AbstractTestTransformEng
.build())) .build()))
.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);
}
} }

View File

@@ -24,8 +24,8 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.transform.base.components; package org.alfresco.transform.base.fakes;
public class TestTransformerPdf2Png extends AbstractTestTransformer public class FakeTransformerPdf2Jpg extends AbstractFakeTransformer
{ {
} }

View File

@@ -24,8 +24,8 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.transform.base.components; package org.alfresco.transform.base.fakes;
public class TestTransformerTxT2Pdf extends AbstractTestTransformer public class FakeTransformerPdf2Png extends AbstractFakeTransformer
{ {
} }

View File

@@ -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
{
}