mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
ClientDataTests + tidy up
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
package org.alfresco.transform.aio;
|
||||
|
||||
import org.alfresco.transform.base.AbstractBaseTest;
|
||||
import org.alfresco.transform.base.TransformController;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -36,11 +37,14 @@ import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import static org.alfresco.transform.base.TransformControllerTest.getLogMessagesFor;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_HTML;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transform.common.RequestParamMap.CONFIG_VERSION_DEFAULT;
|
||||
import static org.alfresco.transform.common.RequestParamMap.CONFIG_VERSION_LATEST;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
@@ -94,4 +98,29 @@ public class AIOTest extends AbstractBaseTest
|
||||
" should have had a coreValue but was null. Should have been " + coreVersion);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartupLogsIncludeEngineMessages()
|
||||
{
|
||||
StringJoiner controllerLogMessages = getLogMessagesFor(TransformController.class);
|
||||
|
||||
controller.startup();
|
||||
|
||||
assertEquals(
|
||||
"--------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
|
||||
+ "If the Alfresco software was purchased under a paid Alfresco license, the terms of the paid license agreement \n"
|
||||
+ "will prevail. Otherwise, the software is provided under terms of the GNU LGPL v3 license. \n"
|
||||
+ "See the license at http://www.gnu.org/licenses/lgpl-3.0.txt. or in /LICENSE.txt \n"
|
||||
+ "\n"
|
||||
+ "This transformer uses ImageMagick from ImageMagick Studio LLC. See the license at http://www.imagemagick.org/script/license.php or in /ImageMagick-license.txt\n"
|
||||
+ "This transformer uses LibreOffice from The Document Foundation. See the license at https://www.libreoffice.org/download/license/ or in /libreoffice.txt\n"
|
||||
+ "This transformer uses libraries from Apache. See the license at http://www.apache.org/licenses/LICENSE-2.0. or in /Apache\\\\ 2.0.txt\n"
|
||||
+ "This transformer uses htmlparser. See the license at http://htmlparser.sourceforge.net/license.html\n"
|
||||
+ "This transformer uses alfresco-pdf-renderer which uses the PDFium library from Google Inc. See the license at https://pdfium.googlesource.com/pdfium/+/master/LICENSE or in /pdfium.txt\n"
|
||||
+ "This transformer uses Tika from Apache. See the license at http://www.apache.org/licenses/LICENSE-2.0. or in /Apache\\ 2.0.txt\n"
|
||||
+ "This transformer uses ExifTool by Phil Harvey. See license at https://exiftool.org/#license. or in /Perl-Artistic-License.txt\n"
|
||||
+ "--------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
|
||||
+ "Starting application components... Done",
|
||||
controllerLogMessages.toString());
|
||||
}
|
||||
}
|
@@ -120,10 +120,6 @@ public class TransformController
|
||||
if (transformEngines != null)
|
||||
{
|
||||
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");
|
||||
|
@@ -195,9 +195,9 @@ abstract class ProcessHandler extends FragmentHandler
|
||||
if (transformerName == null)
|
||||
{
|
||||
throw new TransformException(BAD_REQUEST, "No transforms for: "+
|
||||
sourceMimetype+" -> "+targetMimetype+transformOptions.entrySet().stream()
|
||||
.map(entry -> entry.getKey()+"="+entry.getValue())
|
||||
.collect(Collectors.joining(", ", " ", "")));
|
||||
sourceMimetype+" -> "+targetMimetype+transformOptions.entrySet().stream()
|
||||
.map(entry -> entry.getKey()+"="+entry.getValue())
|
||||
.collect(Collectors.joining(", ", " ", "")));
|
||||
}
|
||||
return transformerName;
|
||||
}
|
||||
|
@@ -114,12 +114,6 @@ public class TransformControllerAllInOneTest
|
||||
+ "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());
|
||||
|
@@ -40,12 +40,10 @@ import org.alfresco.transform.base.fakes.FakeTransformerTxT2Pdf;
|
||||
import org.alfresco.transform.base.model.FileRefEntity;
|
||||
import org.alfresco.transform.base.model.FileRefResponse;
|
||||
import org.alfresco.transform.base.transform.TransformHandler;
|
||||
import org.alfresco.transform.base.transform.FragmentTest;
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.stubbing.Answer;
|
||||
@@ -130,25 +128,6 @@ public class TransformControllerTest
|
||||
@MockBean
|
||||
protected AlfrescoSharedFileStoreClient fakeSfsClient;
|
||||
|
||||
private void fakeSfsClient()
|
||||
{
|
||||
final Map<String,File> sfsRef2File = new HashMap<>();
|
||||
when(fakeSfsClient.saveFile(any())).thenAnswer((Answer) invocation -> {
|
||||
File originalFile = (File) invocation.getArguments()[0];
|
||||
|
||||
// Make a copy as the original might get deleted
|
||||
File fileCopy = new File(tempDir, originalFile.getName()+"copy");
|
||||
FileUtils.copyFile(originalFile, fileCopy);
|
||||
|
||||
String fileRef = UUID.randomUUID().toString();
|
||||
sfsRef2File.put(fileRef, fileCopy);
|
||||
return new FileRefResponse(new FileRefEntity(fileRef));
|
||||
});
|
||||
when(fakeSfsClient.retrieveFile(any())).thenAnswer((Answer) invocation ->
|
||||
ResponseEntity.ok().header(CONTENT_DISPOSITION,"attachment; filename*=UTF-8''transform.tmp")
|
||||
.body((Resource) new UrlResource(sfsRef2File.get(invocation.getArguments()[0]).toURI())));
|
||||
}
|
||||
|
||||
static void resetProbeForTesting(TransformController transformController)
|
||||
{
|
||||
transformController.transformHandler.getProbeTransform().resetForTesting();
|
||||
@@ -178,7 +157,7 @@ public class TransformControllerTest
|
||||
controllerLogMessages.toString());
|
||||
}
|
||||
|
||||
static StringJoiner getLogMessagesFor(Class classBeingLogged)
|
||||
public static StringJoiner getLogMessagesFor(Class classBeingLogged)
|
||||
{
|
||||
StringJoiner logMessages = new StringJoiner("\n");
|
||||
Logger logger = (Logger) LoggerFactory.getLogger(classBeingLogged);
|
||||
@@ -302,7 +281,23 @@ public class TransformControllerTest
|
||||
@Test
|
||||
public void testTransformEndpointThatUsesTransformRequests() throws Exception
|
||||
{
|
||||
fakeSfsClient();
|
||||
final Map<String,File> sfsRef2File = new HashMap<>();
|
||||
when(fakeSfsClient.saveFile(any())).thenAnswer((Answer) invocation -> {
|
||||
File originalFile = (File) invocation.getArguments()[0];
|
||||
|
||||
// Make a copy as the original might get deleted
|
||||
File fileCopy = new File(tempDir, originalFile.getName()+"copy");
|
||||
FileUtils.copyFile(originalFile, fileCopy);
|
||||
|
||||
String fileRef = UUID.randomUUID().toString();
|
||||
sfsRef2File.put(fileRef, fileCopy);
|
||||
return new FileRefResponse(new FileRefEntity(fileRef));
|
||||
});
|
||||
|
||||
when(fakeSfsClient.retrieveFile(any())).thenAnswer((Answer) invocation ->
|
||||
ResponseEntity.ok().header(CONTENT_DISPOSITION,"attachment; filename*=UTF-8''transform.tmp")
|
||||
.body((Resource) new UrlResource(sfsRef2File.get(invocation.getArguments()[0]).toURI())));
|
||||
|
||||
File sourceFile = getTestFile("original.txt", true, tempDir);
|
||||
String sourceFileRef = fakeSfsClient.saveFile(sourceFile).getEntry().getFileRef();
|
||||
|
||||
|
@@ -68,7 +68,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
@@ -79,7 +78,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
@ContextConfiguration(classes = {
|
||||
FakeTransformEngineWithFragments.class,
|
||||
FakeTransformerFragments.class})
|
||||
public class FragmentTest
|
||||
public class FragmentHandlerTest
|
||||
{
|
||||
@Autowired
|
||||
private TransformHandler transformHandler;
|
@@ -30,16 +30,17 @@ import java.util.stream.Stream;
|
||||
*/
|
||||
public class RepositoryClientData
|
||||
{
|
||||
private static final String CLIENT_DATA_SEPARATOR = "\u23D0";
|
||||
public static final String CLIENT_DATA_SEPARATOR = "\u23D0";
|
||||
public static final String DEBUG_SEPARATOR = "\u23D1";
|
||||
static final String REPO_ID = "Repo";
|
||||
public static final String DEBUG = "debug:";
|
||||
|
||||
private static final String REPO_ID = "Repo";
|
||||
private static final String DEBUG = "debug:";
|
||||
|
||||
private final String origClientData;
|
||||
private final String[] split;
|
||||
|
||||
public RepositoryClientData(String clientData)
|
||||
{
|
||||
origClientData = clientData;
|
||||
split = clientData == null ? null : clientData.split(CLIENT_DATA_SEPARATOR);
|
||||
}
|
||||
|
||||
@@ -88,7 +89,7 @@ public class RepositoryClientData
|
||||
{
|
||||
if (split == null)
|
||||
{
|
||||
return null;
|
||||
return origClientData;
|
||||
}
|
||||
StringJoiner sj = new StringJoiner(CLIENT_DATA_SEPARATOR);
|
||||
Stream.of(split).forEach(element -> sj.add(element));
|
||||
|
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Model
|
||||
* %%
|
||||
* Copyright (C) 2022 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 General Lesser Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Lesser Public
|
||||
* License along with this program. If not, see
|
||||
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.common;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import static org.alfresco.transform.common.RepositoryClientData.CLIENT_DATA_SEPARATOR;
|
||||
import static org.alfresco.transform.common.RepositoryClientData.DEBUG;
|
||||
import static org.alfresco.transform.common.RepositoryClientData.DEBUG_SEPARATOR;
|
||||
import static org.alfresco.transform.common.RepositoryClientData.REPO_ID;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class RepositoryClientDataTest
|
||||
{
|
||||
RepositoryClientData repositoryClientData;
|
||||
|
||||
@Test
|
||||
void AcsClientDataWithDebugTest()
|
||||
{
|
||||
String clientData = new StringJoiner(CLIENT_DATA_SEPARATOR)
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add(DEBUG)
|
||||
.toString();
|
||||
repositoryClientData = new RepositoryClientData(clientData);
|
||||
|
||||
assertEquals("ACS1234", repositoryClientData.getAcsVersion());
|
||||
assertEquals("renditionName", repositoryClientData.getRenditionName());
|
||||
assertEquals(54321, repositoryClientData.getRequestId());
|
||||
assertTrue(repositoryClientData.isDebugRequested());
|
||||
assertEquals(clientData, repositoryClientData.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void AcsClientDataWithoutDebugTest()
|
||||
{
|
||||
String clientData = new StringJoiner(CLIENT_DATA_SEPARATOR)
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add("9")
|
||||
.toString();
|
||||
repositoryClientData = new RepositoryClientData(clientData);
|
||||
|
||||
assertEquals("ACS1234", repositoryClientData.getAcsVersion());
|
||||
assertEquals("renditionName", repositoryClientData.getRenditionName());
|
||||
assertEquals(54321, repositoryClientData.getRequestId());
|
||||
assertFalse(repositoryClientData.isDebugRequested());
|
||||
assertEquals(clientData, repositoryClientData.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void noLeadingRepoTest()
|
||||
{
|
||||
String clientData = new StringJoiner(CLIENT_DATA_SEPARATOR)
|
||||
.add("ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add("9")
|
||||
.toString();
|
||||
repositoryClientData = new RepositoryClientData(clientData);
|
||||
|
||||
assertEquals("", repositoryClientData.getAcsVersion());
|
||||
assertEquals("", repositoryClientData.getRenditionName());
|
||||
assertEquals(-1, repositoryClientData.getRequestId());
|
||||
assertFalse(repositoryClientData.isDebugRequested());
|
||||
assertEquals(clientData, repositoryClientData.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tooFewElementsTest()
|
||||
{
|
||||
String clientData = new StringJoiner(CLIENT_DATA_SEPARATOR)
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.toString();
|
||||
repositoryClientData = new RepositoryClientData(clientData);
|
||||
|
||||
assertEquals("", repositoryClientData.getAcsVersion());
|
||||
assertEquals("", repositoryClientData.getRenditionName());
|
||||
assertEquals(-1, repositoryClientData.getRequestId());
|
||||
assertFalse(repositoryClientData.isDebugRequested());
|
||||
assertEquals(clientData, repositoryClientData.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tooManyElementsTest()
|
||||
{
|
||||
String clientData = new StringJoiner(CLIENT_DATA_SEPARATOR)
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add(DEBUG)
|
||||
.add("10")
|
||||
.toString();
|
||||
repositoryClientData = new RepositoryClientData(clientData);
|
||||
assertEquals("", repositoryClientData.getAcsVersion());
|
||||
assertEquals("", repositoryClientData.getRenditionName());
|
||||
assertEquals(-1, repositoryClientData.getRequestId());
|
||||
assertFalse(repositoryClientData.isDebugRequested());
|
||||
assertEquals(clientData, repositoryClientData.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullClientDataTest()
|
||||
{
|
||||
repositoryClientData = new RepositoryClientData(null);
|
||||
assertEquals(null, repositoryClientData.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void noElementsClientDataTest()
|
||||
{
|
||||
String clientData = "There are no CLIENT_DATA_SEPARATOR chars";
|
||||
repositoryClientData = new RepositoryClientData(clientData);
|
||||
assertEquals(clientData, repositoryClientData.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void debugTest()
|
||||
{
|
||||
String clientData = new StringJoiner(CLIENT_DATA_SEPARATOR)
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("2")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("6")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add(DEBUG)
|
||||
.toString();
|
||||
repositoryClientData = new RepositoryClientData(clientData);
|
||||
|
||||
assertEquals(clientData, repositoryClientData.toString());
|
||||
|
||||
repositoryClientData.appendDebug("Some debug");
|
||||
assertEquals(clientData+DEBUG_SEPARATOR+"Some debug",
|
||||
repositoryClientData.toString());
|
||||
|
||||
repositoryClientData.appendDebug("Some other debug");
|
||||
assertEquals(clientData+DEBUG_SEPARATOR+"Some debug"+DEBUG_SEPARATOR+"Some other debug",
|
||||
repositoryClientData.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidRequestIdTest()
|
||||
{
|
||||
String clientData = new StringJoiner(CLIENT_DATA_SEPARATOR)
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("abc")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add(DEBUG)
|
||||
.toString();
|
||||
repositoryClientData = new RepositoryClientData(clientData);
|
||||
|
||||
assertEquals(-1, repositoryClientData.getRequestId());
|
||||
assertEquals(clientData, repositoryClientData.toString());
|
||||
}
|
||||
}
|
@@ -39,6 +39,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -500,6 +501,31 @@ public class TransformRegistryTest
|
||||
assertEquals(999999L, registry.findMaxSize(DOC, GIF, emptyMap(), "doclib"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransformCacheGetTransforms() // Used in the Alfresco Repo tests
|
||||
{
|
||||
TransformConfig transformConfig = TransformConfig.builder()
|
||||
.withTransformers(ImmutableList.of(new Transformer("transformer1", emptySet(), set(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(GIF)
|
||||
.withTargetMediaType(PDF)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(GIF)
|
||||
.withTargetMediaType(JPEG)
|
||||
.build()))))
|
||||
.build();
|
||||
|
||||
assertEquals(0, registry.getData().getTransforms().size());
|
||||
assertEquals("", registry.getData().toString());
|
||||
|
||||
CombinedTransformConfig.combineAndRegister(transformConfig, "readFrom", "baseUrl", registry);
|
||||
|
||||
assertEquals(1, registry.getData().getTransforms().size());
|
||||
assertEquals(2, registry.getData().getTransforms().get(GIF).size());
|
||||
assertEquals("(transformers: 1 transforms: 2)", registry.getData().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTransformerName() throws Exception
|
||||
{
|
||||
|
Reference in New Issue
Block a user