[skip ci] options in test page

This commit is contained in:
alandavis
2022-08-06 14:25:35 +01:00
parent 9838d5cc44
commit 29b053eaa1
11 changed files with 367 additions and 201 deletions

View File

@@ -26,8 +26,8 @@
*/
package org.alfresco.transform.base;
import org.alfresco.transform.base.html.OptionLister;
import org.alfresco.transform.base.logging.LogEntry;
import org.alfresco.transform.base.probes.ProbeTransform;
import org.alfresco.transform.base.transform.TransformHandler;
import org.alfresco.transform.client.model.TransformReply;
import org.alfresco.transform.client.model.TransformRequest;
@@ -102,6 +102,8 @@ public class TransformController
@Autowired TransformHandler transformHandler;
@Autowired
private String coreVersion;
@Autowired
private OptionLister optionLister;
TransformEngine transformEngine;
@@ -149,6 +151,9 @@ public class TransformController
public String test(Model model)
{
model.addAttribute("title", transformEngine.getTransformEngineName() + " Test Page");
TransformConfig transformConfig = ((TransformRegistry) transformRegistry).getTransformConfig();
transformConfig = setOrClearCoreVersion(transformConfig, 0);
model.addAttribute("transformOptions", optionLister.getOptionNames(transformConfig.getTransformOptions()));
return "test"; // display test.html
}

View File

@@ -0,0 +1,71 @@
/*
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2022 - 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.html;
import org.alfresco.transform.config.TransformOption;
import org.alfresco.transform.config.TransformOptionGroup;
import org.alfresco.transform.config.TransformOptionValue;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
@Component
public class OptionLister
{
public Set<String> getOptionNames(Map<String, Set<TransformOption>> transformOptionsByName)
{
Set<String> set = new TreeSet<>();
transformOptionsByName.forEach(((optionName, optionSet) -> {
optionSet.stream().forEach(option -> addToList(set, option));
}));
return set;
}
private void addToList(Set<String> set, TransformOption option)
{
if (option instanceof TransformOptionGroup)
{
addGroupToList(set, (TransformOptionGroup)option);
}
else
{
addValueToList(set, (TransformOptionValue)option);
}
}
private void addGroupToList(Set<String> set, TransformOptionGroup group)
{
group.getTransformOptions().stream().forEach(option -> addToList(set, option));
}
private void addValueToList(Set<String> set, TransformOptionValue value)
{
set.add(value.getName());
}
}

View File

@@ -111,9 +111,8 @@ public abstract class StreamHandler
{
inputStream.close();
}
catch (IOException e)
catch (IOException ignore)
{
throw new RuntimeException(e);
}
}
}

View File

@@ -5,7 +5,7 @@
<form method="POST" enctype="multipart/form-data" action="/test">
<table>
<tr><td><div style="text-align:right">file</div></td><td><input type="file" name="file" /></td></tr>
<tr><td><div style="text-align:right">Direct Url</div></td><td><input type="text" name="directAccessUrl"/></td></tr>
<tr><td><div style="text-align:right">directAccessUrl</div></td><td><input type="text" name="directAccessUrl"/></td></tr>
<tr><td><div style="text-align:right">sourceMimetype</div></td><td><input type="text" name="sourceMimetype" value="" /></td>
<td><select name="_sourceMimetype">
<option value="" >-- file extension --</option>
@@ -28,166 +28,20 @@
<option value="text/html">html</option>
<option value="text/plain">txt</option>
</select></td></tr>
<tr><td><select name="name0">
<option value="sourceEncoding" >sourceEncoding</option>
<option value="targetEncoding">targetEncoding</option>
<option value="page">page</option>
<option value="width">width</option>
<option value="height">height</option>
<option value="allowPdfEnlargement">allowPdfEnlargement</option>
<option value="maintainPdfAspectRatio">maintainPdfAspectRatio</option>
<option value="startPage">startPage</option>
<option value="endPage">endPage</option>
<option value="alphaRemove">alphaRemove</option>
<option value="autoOrient">autoOrient</option>
<option value="cropGravity">cropGravity</option>
<option value="cropWidth">cropWidth</option>
<option value="cropHeight">cropHeight</option>
<option value="cropPercentage">cropPercentage</option>
<option value="cropXOffset">cropXOffset</option>
<option value="cropYOffset">cropYOffset</option>
<option value="thumbnail">thumbnail</option>
<option value="resizeWidth">resizeWidth</option>
<option value="resizeHeight">resizeHeight</option>
<option value="resizePercentage">resizePercentage</option>
<option value="allowEnlargement">allowEnlargement</option>
<option value="maintainAspectRatio">maintainAspectRatio</option>
<option value="commandOptions">commandOptions</option>
<option value="timeout">timeout</option>
<option value="includeContents">includeContents</option>
<option value="notExtractBookmarksText">notExtractBookmarksText</option>
<option value="pageLimit">pageLimit</option>
</select></td><td><input type="text" name="value0" /></td></tr>
<tr><td><select name="name1">
<option value="sourceEncoding">sourceEncoding</option>
<option value="targetEncoding">targetEncoding</option>
<option value="page">page</option>
<option value="width">width</option>
<option value="height">height</option>
<option value="allowPdfEnlargement">allowPdfEnlargement</option>
<option value="maintainPdfAspectRatio">maintainPdfAspectRatio</option>
<option value="startPage">startPage</option>
<option value="endPage">endPage</option>
<option value="alphaRemove">alphaRemove</option>
<option value="autoOrient">autoOrient</option>
<option value="cropGravity">cropGravity</option>
<option value="cropWidth">cropWidth</option>
<option value="cropHeight">cropHeight</option>
<option value="cropPercentage">cropPercentage</option>
<option value="cropXOffset">cropXOffset</option>
<option value="cropYOffset">cropYOffset</option>
<option value="thumbnail">thumbnail</option>
<option value="resizeWidth" selected="selected">resizeWidth</option>
<option value="resizeHeight">resizeHeight</option>
<option value="resizePercentage">resizePercentage</option>
<option value="allowEnlargement">allowEnlargement</option>
<option value="maintainAspectRatio">maintainAspectRatio</option>
<option value="commandOptions">commandOptions</option>
<option value="timeout">timeout</option>
<option value="includeContents">includeContents</option>
<option value="notExtractBookmarksText">notExtractBookmarksText</option>
<option value="pageLimit">pageLimit</option>
</select></td><td><input type="text" name="value1" value="" /></td></tr>
<tr><td><select name="name2">
<option value="sourceEncoding">sourceEncoding</option>
<option value="targetEncoding">targetEncoding</option>
<option value="page">page</option>
<option value="width">width</option>
<option value="height">height</option>
<option value="allowPdfEnlargement">allowPdfEnlargement</option>
<option value="maintainPdfAspectRatio">maintainPdfAspectRatio</option>
<option value="startPage">startPage</option>
<option value="endPage">endPage</option>
<option value="alphaRemove">alphaRemove</option>
<option value="autoOrient">autoOrient</option>
<option value="cropGravity">cropGravity</option>
<option value="cropWidth">cropWidth</option>
<option value="cropHeight">cropHeight</option>
<option value="cropPercentage">cropPercentage</option>
<option value="cropXOffset">cropXOffset</option>
<option value="cropYOffset">cropYOffset</option>
<option value="thumbnail">thumbnail</option>
<option value="resizeWidth">resizeWidth</option>
<option value="resizeHeight" selected="selected">resizeHeight</option>
<option value="resizePercentage">resizePercentage</option>
<option value="allowEnlargement">allowEnlargement</option>
<option value="maintainAspectRatio">maintainAspectRatio</option>
<option value="commandOptions">commandOptions</option>
<option value="timeout">timeout</option>
<option value="includeContents">includeContents</option>
<option value="notExtractBookmarksText">notExtractBookmarksText</option>
<option value="pageLimit">pageLimit</option>
</select></td><td><input type="text" name="value2" value="" /></td></tr>
<tr><td><select name="name3">
<option value="sourceEncoding">sourceEncoding</option>
<option value="targetEncoding">targetEncoding</option>
<option value="page">page</option>
<option value="width">width</option>
<option value="height">height</option>
<option value="allowPdfEnlargement">allowPdfEnlargement</option>
<option value="maintainPdfAspectRatio">maintainPdfAspectRatio</option>
<option value="startPage">startPage</option>
<option value="endPage">endPage</option>
<option value="alphaRemove">alphaRemove</option>
<option value="autoOrient">autoOrient</option>
<option value="cropGravity">cropGravity</option>
<option value="cropWidth">cropWidth</option>
<option value="cropHeight">cropHeight</option>
<option value="cropPercentage">cropPercentage</option>
<option value="cropXOffset">cropXOffset</option>
<option value="cropYOffset">cropYOffset</option>
<option value="thumbnail" selected="selected">thumbnail</option>
<option value="resizeWidth">resizeWidth</option>
<option value="resizeHeight">resizeHeight</option>
<option value="resizePercentage">resizePercentage</option>
<option value="allowEnlargement">allowEnlargement</option>
<option value="maintainAspectRatio">maintainAspectRatio</option>
<option value="commandOptions">commandOptions</option>
<option value="timeout">timeout</option>
<option value="includeContents">includeContents</option>
<option value="notExtractBookmarksText">notExtractBookmarksText</option>
<option value="pageLimit">pageLimit</option>
</select></td><td><input type="text" name="value3" value="" /></td></tr>
<tr><td><select name="name4">
<option value="sourceEncoding">sourceEncoding</option>
<option value="targetEncoding">targetEncoding</option>
<option value="page">page</option>
<option value="width">width</option>
<option value="height">height</option>
<option value="allowPdfEnlargement">allowPdfEnlargement</option>
<option value="maintainPdfAspectRatio">maintainPdfAspectRatio</option>
<option value="startPage">startPage</option>
<option value="endPage">endPage</option>
<option value="alphaRemove">alphaRemove</option>
<option value="autoOrient">autoOrient</option>
<option value="cropGravity">cropGravity</option>
<option value="cropWidth">cropWidth</option>
<option value="cropHeight">cropHeight</option>
<option value="cropPercentage">cropPercentage</option>
<option value="cropXOffset">cropXOffset</option>
<option value="cropYOffset">cropYOffset</option>
<option value="thumbnail">thumbnail</option>
<option value="resizeWidth">resizeWidth</option>
<option value="resizeHeight">resizeHeight</option>
<option value="resizePercentage">resizePercentage</option>
<option value="allowEnlargement">allowEnlargement</option>
<option value="maintainAspectRatio">maintainAspectRatio</option>
<option value="commandOptions">commandOptions</option>
<option value="timeout">timeout</option>
<option value="includeContents">includeContents</option>
<option value="notExtractBookmarksText">notExtractBookmarksText</option>
<option value="pageLimit">pageLimit</option>
</select></td><td><input type="text" name="value4" value="" /></td></tr>
<tr><td><input type="text" name="name5" value="" /></td><td><input type="text" name="value5" value="" /></td></tr>
<tr><td><input type="text" name="name6" value="" /></td><td><input type="text" name="value6" value="" /></td></tr>
<tr><td><input type="text" name="name7" value="" /></td><td><input type="text" name="value7" value="" /></td></tr>
<tr><td><input type="text" name="name8" value="" /></td><td><input type="text" name="value8" value="" /></td></tr>
<tr><td><input type="text" name="name9" value="" /></td><td><input type="text" name="value9" value="" /></td></tr>
<tr><td><input type="text" name="name10" value="" /></td><td><input type="text" name="value10" value="" /></td></tr>
<tr><td><input type="text" name="name11" value="" /></td><td><input type="text" name="value11" value="" /></td></tr>
<tr><td><input type="text" name="name12" value="" /></td><td><input type="text" name="value12" value="" /></td></tr>
<tr><td><input type="text" name="name13" value="" /></td><td><input type="text" name="value13" value="" /></td></tr>
<tr><td><input type="text" name="name14" value="" /></td><td><input type="text" name="value14" value="" /></td></tr>
<th:block th:each="i: ${#numbers.sequence(0, T(java.lang.Math).min(18, transformOptions.size) - 1)}">
<tr><td><select th:name="${'name'+i}">
<option th:each="transformOption, iStat: ${transformOptions}"
th:value="${transformOption}" th:text="${transformOption}"
th:selected="${iStat.index eq i}"/>
</select></td><td><input type="text" th:name="${'value'+i}" /></td></tr>
</th:block>
<th:block th:each="i: ${#numbers.sequence(T(java.lang.Math).min(18, transformOptions.size), T(java.lang.Math).min(18, transformOptions.size) + 2)}">
<tr><td><input type="text" th:name="${'name'+i}" value="" /></td>
<td><input type="text" th:name="${'value'+i}" value="" /></td></tr>
</th:block>
<tr><td><div style="text-align:right">timeout</div></td><td><input type="text" name="timeout" value="" /></td></tr>
<tr><td></td><td><input type="submit" value="Transform" /></td></tr>
</table>

View File

@@ -0,0 +1,189 @@
/*
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2022 - 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.http;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.alfresco.transform.base.html.OptionLister;
import org.alfresco.transform.config.TransformOption;
import org.alfresco.transform.config.TransformOptionGroup;
import org.alfresco.transform.config.TransformOptionValue;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Used in the html test page.
*/
public class OptionListerTest
{
OptionLister optionLister = new OptionLister();
@Test
public void emptyListTest()
{
Map<String, Set<TransformOption>> transformOptionsByName = Collections.emptyMap();
assertEquals(Collections.emptySet(), optionLister.getOptionNames(transformOptionsByName));
}
@Test
public void singleOptionNameWithSingleValue()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("Dummy", ImmutableSet.of(
new TransformOptionValue(true, "startPage")));
assertEquals(ImmutableSet.of("startPage"), optionLister.getOptionNames(transformOptionsByName));
}
@Test
public void whenOptionNameEndsInOptions_stripIt()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("DummyOptions", ImmutableSet.of(
new TransformOptionValue(true, "startPage")));
assertEquals(ImmutableSet.of("startPage"), optionLister.getOptionNames(transformOptionsByName));
}
@Test
public void singleOptionNameWithASingleRequiredValue()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("DummyOptions", ImmutableSet.of(
new TransformOptionValue(true, "startPage")));
assertEquals(ImmutableSet.of("startPage"), optionLister.getOptionNames(transformOptionsByName));
}
@Test
public void singleOptionNameWithACoupleOfValues()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("DummyOptions", ImmutableSet.of(
new TransformOptionValue(false, "startPage"),
new TransformOptionValue(true, "endPage")));
assertEquals(ImmutableSet.of("startPage", "endPage"), optionLister.getOptionNames(transformOptionsByName));
}
@Test
public void sortedValues()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("DummyOptions", ImmutableSet.of(
new TransformOptionValue(false, "a"),
new TransformOptionValue(false, "n"),
new TransformOptionValue(false, "k"),
new TransformOptionValue(false, "f"),
new TransformOptionValue(true, "z")));
assertEquals(ImmutableList.of("a", "f", "k", "n", "z"), new ArrayList<>(optionLister.getOptionNames(transformOptionsByName)));
}
@Test
public void multipleOptionNames()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("DummyOptions", ImmutableSet.of(
new TransformOptionValue(false, "startPage"),
new TransformOptionValue(true, "endPage")),
"Another", ImmutableSet.of(
new TransformOptionValue(false, "scale")),
"YetAnother", ImmutableSet.of(
new TransformOptionValue(false, "x"),
new TransformOptionValue(false, "y"),
new TransformOptionValue(true, "ratio"))
);
assertEquals(ImmutableSet.of(
"startPage",
"endPage",
"scale",
"x",
"y",
"ratio"),
optionLister.getOptionNames(transformOptionsByName));
}
@Test
public void multipleOptionNamesWithDuplicates()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("DummyOptions", ImmutableSet.of(
new TransformOptionValue(false, "startPage"),
new TransformOptionValue(true, "endPage")),
"Another", ImmutableSet.of(
new TransformOptionValue(false, "scale")),
"YetAnother", ImmutableSet.of(
new TransformOptionValue(false, "x"),
new TransformOptionValue(false, "y"),
new TransformOptionValue(true, "scale"))
);
assertEquals(ImmutableSet.of(
"startPage",
"endPage",
"scale",
"x",
"y"),
optionLister.getOptionNames(transformOptionsByName));
}
@Test
public void nestedGroups()
{
Map<String, Set<TransformOption>> transformOptionsByName = ImmutableMap.of("DummyOptions", ImmutableSet.of(
new TransformOptionValue(false, "1"),
new TransformOptionValue(true, "2"),
new TransformOptionGroup(false, ImmutableSet.of(
new TransformOptionValue(false, "3.1"),
new TransformOptionValue(true, "3.2"),
new TransformOptionValue(false, "3.3"))),
new TransformOptionGroup(true, ImmutableSet.of(
new TransformOptionValue(false, "4.1"),
new TransformOptionGroup(false, ImmutableSet.of(
new TransformOptionValue(false, "4.2.1"),
new TransformOptionGroup(true, ImmutableSet.of(
new TransformOptionValue(false, "4.2.2.1"))),
new TransformOptionValue(true, "4.2.3"))),
new TransformOptionValue(false, "4.3")))));
assertEquals(ImmutableSet.of(
"1",
"2",
"3.1",
"3.2",
"3.3",
"4.1",
"4.2.1",
"4.2.2.1",
"4.2.3",
"4.3"),
optionLister.getOptionNames(transformOptionsByName));
}
}

View File

@@ -38,7 +38,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.springframework.http.HttpHeaders.ACCEPT;
import static org.springframework.http.HttpHeaders.CONTENT_DISPOSITION;

View File

@@ -26,12 +26,14 @@
*/
package org.alfresco.transform.misc;
import com.google.common.collect.ImmutableSet;
import org.alfresco.transform.base.AbstractBaseTest;
import org.alfresco.transform.client.model.TransformRequest;
import org.alfresco.transform.base.html.OptionLister;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.junit.jupiter.api.BeforeEach;
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.MvcResult;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
@@ -63,6 +65,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/
public class MiscTest extends AbstractBaseTest
{
@Autowired OptionLister optionLister;
protected final String sourceEncoding = "UTF-8";
protected final String targetEncoding = "UTF-8";
protected final String targetMimetype = MIMETYPE_TEXT_PLAIN;
@@ -499,4 +503,14 @@ public class MiscTest extends AbstractBaseTest
super.targetMimetype = this.targetMimetype;
super.queueTransformRequestUsingDirectAccessUrlTest();
}
@Test
public void optionListTest()
{
assertEquals(ImmutableSet.of(
"pageLimit",
"targetEncoding",
"extractMapping"),
optionLister.getOptionNames(controller.transformConfig(0).getBody().getTransformOptions()));
}
}

View File

@@ -26,8 +26,10 @@
*/
package org.alfresco.transform.tika;
import com.google.common.collect.ImmutableSet;
import org.alfresco.transform.base.AbstractBaseTest;
import org.alfresco.transform.base.executors.RuntimeExec;
import org.alfresco.transform.base.html.OptionLister;
import org.alfresco.transform.base.model.FileRefEntity;
import org.alfresco.transform.base.model.FileRefResponse;
import org.alfresco.transform.client.model.TransformReply;
@@ -37,6 +39,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
@@ -116,6 +119,8 @@ public class TikaTest extends AbstractBaseTest
"The quick brown fox jumps over the lazy dogs";
private static final String EXPECTED_CSV_CONTENT_CONTAINS = "\"The\",\"quick\",\"brown\",\"fox\"";
@Autowired OptionLister optionLister;
@Mock
private RuntimeExec.ExecutionResult mockExecutionResult;
@@ -480,4 +485,16 @@ public class TikaTest extends AbstractBaseTest
expectedTargetFileBytes = readTestFile(targetExtension);
super.httpTransformRequestUsingDirectAccessUrlTest();
}
@Test
public void optionListTest()
{
assertEquals(ImmutableSet.of(
"includeContents",
"targetEncoding",
"extractMapping",
"notExtractBookmarksText",
"metadata"),
optionLister.getOptionNames(controller.transformConfig(0).getBody().getTransformOptions()));
}
}

View File

@@ -56,27 +56,5 @@ public class Origin<T>
{
return readFrom;
}
public static <T> Set<T> setOf(Collection<Origin<T>> originCollection)
{
Set<T> tSet = new HashSet<>(originCollection.size());
originCollection.forEach(element -> tSet.add(element.get()));
return tSet;
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Origin<?> origin = (Origin<?>)o;
return t.equals(origin.t);
}
@Override
public int hashCode()
{
return Objects.hash(t);
}
}

View File

@@ -26,6 +26,7 @@
*/
package org.alfresco.transform.registry;
import com.google.common.collect.ImmutableMap;
import org.alfresco.transform.common.TransformException;
import org.junit.jupiter.api.Test;
@@ -34,6 +35,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import static java.util.Arrays.asList;
import static java.util.Collections.emptySet;
import static org.alfresco.transform.common.RequestParamMap.TIMEOUT;
import static org.alfresco.transform.registry.TransformRegistryHelper.retrieveTransformListBySize;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -181,4 +183,16 @@ public class TransformRegistryHelperTest
retrieveTransformListBySize(data, "text/plain", null, null, null);
});
}
@Test
public void filterTimeoutTest()
{
// Almost identical to buildTransformListTargetMimeTypeNullErrorTest
TransformCache data = new TransformCache();
assertThrows(TransformException.class, () ->
{
retrieveTransformListBySize(data, "text/plain", null, ImmutableMap.of(TIMEOUT, "1234"), null);
});
}
}

View File

@@ -42,6 +42,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.google.common.collect.ImmutableList;
import org.alfresco.transform.config.CoreFunction;
import org.alfresco.transform.config.SupportedSourceAndTarget;
import org.alfresco.transform.config.TransformConfig;
import org.alfresco.transform.config.TransformOption;
@@ -130,7 +132,7 @@ public class TransformRegistryTest
}
// transformOptionNames are upper case if required.
private void assertIsSupported(final Set<String> actualOptionNames,
private void assertOptionsMatch(final Set<String> actualOptionNames,
final Set<String> transformOptionNames, final String unsupportedMsg)
{
final Map<String, Boolean> transformOptions = transformOptionNames
@@ -384,22 +386,22 @@ public class TransformRegistryTest
}
@Test
public void testRegistryIsSupportedMethod()
public void testRegistryOptionsMatchMethod()
{
assertIsSupported(set("a"), set("a", "B", "c"), "required option B is missing");
assertIsSupported(emptySet(), set("a", "B", "c"), "required option B is missing");
assertIsSupported(set("B"), set("a", "B", "c"), null);
assertIsSupported(set("B", "c"), set("a", "B", "c"), null);
assertIsSupported(set("B", "a", "c"), set("a", "B", "c"), null);
assertOptionsMatch(set("a"), set("a", "B", "c"), "required option B is missing");
assertOptionsMatch(emptySet(), set("a", "B", "c"), "required option B is missing");
assertOptionsMatch(set("B"), set("a", "B", "c"), null);
assertOptionsMatch(set("B", "c"), set("a", "B", "c"), null);
assertOptionsMatch(set("B", "a", "c"), set("a", "B", "c"), null);
assertIsSupported(set("B", "d"), set("a", "B", "c"), "there is an extra option d");
assertIsSupported(set("B", "c", "d"), set("a", "B", "c"), "there is an extra option d");
assertIsSupported(set("d"), set("a", "B", "c"),
assertOptionsMatch(set("B", "d"), set("a", "B", "c"), "there is an extra option d");
assertOptionsMatch(set("B", "c", "d"), set("a", "B", "c"), "there is an extra option d");
assertOptionsMatch(set("d"), set("a", "B", "c"),
"required option B is missing and there is an extra option d");
assertIsSupported(set("a"), set("a", "b", "c"), null);
assertIsSupported(emptySet(), set("a", "b", "c"), null);
assertIsSupported(set("a", "b", "c"), set("a", "b", "c"), null);
assertOptionsMatch(set("a"), set("a", "b", "c"), null);
assertOptionsMatch(emptySet(), set("a", "b", "c"), null);
assertOptionsMatch(set("a", "b", "c"), set("a", "b", "c"), null);
}
@Test
@@ -613,4 +615,28 @@ public class TransformRegistryTest
}
return ImmutableSet.copyOf(elements);
}
@Test
public void testIsSupportedCoreFunction() throws Exception
{
Transformer t1 = newTransformer("transformer1", MSG, GIF, 100, 50);
Transformer t2 = newTransformer("transformer2", MSG, GIF, 200, 60);
Transformer t3 = newTransformer("transformer3", MSG, GIF, 200, 40);
t2.setCoreVersion("1.0");
t3.setCoreVersion("2.5.7");
buildAndPopulateRegistry(new Transformer[] {t1, t2, t3});
assertTrue(registry.isSupported(CoreFunction.HTTP, "transformer1"));
assertTrue(registry.isSupported(CoreFunction.HTTP, "transformer2"));
assertTrue(registry.isSupported(CoreFunction.HTTP, "transformer3"));
assertFalse(registry.isSupported(CoreFunction.ACTIVE_MQ, "transformer1"));
assertTrue(registry.isSupported(CoreFunction.ACTIVE_MQ, "transformer2"));
assertTrue(registry.isSupported(CoreFunction.ACTIVE_MQ, "transformer3"));
assertFalse(registry.isSupported(CoreFunction.DIRECT_ACCESS_URL, "transformer1"));
assertFalse(registry.isSupported(CoreFunction.DIRECT_ACCESS_URL, "transformer2"));
assertTrue(registry.isSupported(CoreFunction.DIRECT_ACCESS_URL, "transformer3"));
}
}