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