mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-10-08 14:51:18 +00:00
ACS-930 Security update to spring boot 2.4.1 (#321)
* ACS-930 Upgrade to Junit5
This commit is contained in:
@@ -137,13 +137,6 @@
|
||||
<groupId>org.apache.pdfbox</groupId>
|
||||
<artifactId>pdfbox-tools</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Test dependenciues -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@@ -26,40 +26,6 @@
|
||||
*/
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
import org.alfresco.transformer.executors.RuntimeExec;
|
||||
import org.alfresco.transformer.model.FileRefEntity;
|
||||
import org.alfresco.transformer.model.FileRefResponse;
|
||||
import org.alfresco.transformer.probes.ProbeTestTransform;
|
||||
import org.apache.poi.ooxml.POIXMLProperties;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static java.nio.file.Files.readAllBytes;
|
||||
import static org.alfresco.transformer.executors.Tika.ARCHIVE;
|
||||
import static org.alfresco.transformer.executors.Tika.CSV;
|
||||
@@ -96,10 +62,10 @@ import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_XML;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_ZIP;
|
||||
import static org.alfresco.transformer.util.RequestParamMap.INCLUDE_CONTENTS;
|
||||
import static org.alfresco.transformer.util.RequestParamMap.NOT_EXTRACT_BOOKMARK_TEXT;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -116,12 +82,46 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.util.StringUtils.getFilenameExtension;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
import org.alfresco.transformer.executors.RuntimeExec;
|
||||
import org.alfresco.transformer.model.FileRefEntity;
|
||||
import org.alfresco.transformer.model.FileRefResponse;
|
||||
import org.alfresco.transformer.probes.ProbeTestTransform;
|
||||
import org.apache.poi.ooxml.POIXMLProperties;
|
||||
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.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
/**
|
||||
* Test the TikaController without a server.
|
||||
* Super class includes tests for the AbstractTransformerController.
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest(TikaController.class)
|
||||
// Specifying class for @WebMvcTest() will break AIO tests, without specifying it will use all controllers in the application context,
|
||||
// currently only TikaController.class
|
||||
@WebMvcTest()
|
||||
public class TikaControllerTest extends AbstractTransformerControllerTest
|
||||
{
|
||||
private static final String ENGINE_CONFIG_NAME = "tika_engine_config.json";
|
||||
@@ -148,7 +148,7 @@ public class TikaControllerTest extends AbstractTransformerControllerTest
|
||||
private String targetEncoding = "UTF-8";
|
||||
private String targetMimetype = MIMETYPE_TEXT_PLAIN;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before()
|
||||
{
|
||||
sourceExtension = "pdf";
|
||||
@@ -180,7 +180,7 @@ public class TikaControllerTest extends AbstractTransformerControllerTest
|
||||
when(mockTransformCommand.execute(any(), anyLong())).thenAnswer(
|
||||
(Answer<RuntimeExec.ExecutionResult>) invocation -> {
|
||||
Map<String, String> actualProperties = invocation.getArgument(0);
|
||||
assertEquals("There should be 3 properties", 3, actualProperties.size());
|
||||
assertEquals(3, actualProperties.size(),"There should be 3 properties");
|
||||
|
||||
String actualOptions = actualProperties.get("options");
|
||||
String actualSource = actualProperties.get("source");
|
||||
@@ -191,9 +191,8 @@ public class TikaControllerTest extends AbstractTransformerControllerTest
|
||||
assertNotNull(actualTarget);
|
||||
if (expectedSourceSuffix != null)
|
||||
{
|
||||
assertTrue(
|
||||
"The source file \"" + actualSource + "\" should have ended in \"" + expectedSourceSuffix + "\"",
|
||||
actualSource.endsWith(expectedSourceSuffix));
|
||||
assertTrue(actualSource.endsWith(expectedSourceSuffix),
|
||||
"The source file \"" + actualSource + "\" should have ended in \"" + expectedSourceSuffix + "\"");
|
||||
actualSource = actualSource.substring(0,
|
||||
actualSource.length() - expectedSourceSuffix.length());
|
||||
}
|
||||
@@ -201,14 +200,14 @@ public class TikaControllerTest extends AbstractTransformerControllerTest
|
||||
assertNotNull(actualOptions);
|
||||
if (expectedOptions != null)
|
||||
{
|
||||
assertEquals("expectedOptions", expectedOptions, actualOptions);
|
||||
assertEquals(expectedOptions, actualOptions, "expectedOptions");
|
||||
}
|
||||
|
||||
Long actualTimeout = invocation.getArgument(1);
|
||||
assertNotNull(actualTimeout);
|
||||
if (expectedTimeout != null)
|
||||
{
|
||||
assertEquals("expectedTimeout", expectedTimeout, actualTimeout);
|
||||
assertEquals(expectedTimeout, actualTimeout, "expectedTimeout");
|
||||
}
|
||||
|
||||
// Copy a test file into the target file location if it exists
|
||||
@@ -224,8 +223,8 @@ public class TikaControllerTest extends AbstractTransformerControllerTest
|
||||
|
||||
// Check the supplied source file has not been changed.
|
||||
byte[] actualSourceFileBytes = readAllBytes(new File(actualSource).toPath());
|
||||
assertArrayEquals("Source file is not the same", expectedSourceFileBytes,
|
||||
actualSourceFileBytes);
|
||||
assertArrayEquals(expectedSourceFileBytes, actualSourceFileBytes,
|
||||
"Source file is not the same");
|
||||
|
||||
return mockExecutionResult;
|
||||
});
|
||||
@@ -261,8 +260,8 @@ public class TikaControllerTest extends AbstractTransformerControllerTest
|
||||
"attachment; filename*= UTF-8''quick." + this.targetExtension)).
|
||||
andReturn();
|
||||
String content = result.getResponse().getContentAsString();
|
||||
assertTrue("The content did not include \"" + expectedContentContains,
|
||||
content.contains(expectedContentContains));
|
||||
assertTrue(content.contains(expectedContentContains),
|
||||
"The content did not include \"" + expectedContentContains);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Transform Core
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2019 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
@@ -28,19 +28,16 @@ package org.alfresco.transformer;
|
||||
|
||||
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
|
||||
/**
|
||||
* Tests TikaController with a server test harness.
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
public class TikaHttpRequestTest extends AbstractHttpRequestTest
|
||||
{
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Transform Core
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
@@ -26,13 +26,6 @@
|
||||
*/
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_APP_DWG;
|
||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_OUTLOOK_MSG;
|
||||
import static org.alfresco.transformer.TestFileInfo.testFile;
|
||||
@@ -74,21 +67,29 @@ import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_WORD;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_XML;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_ZIP;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Metadata integration tests in the Tika T-Engine.
|
||||
*
|
||||
* @author adavis
|
||||
* @author dedwards
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class TikaMetadataExtractsIT extends AbstractMetadataExtractsIT
|
||||
{
|
||||
public TikaMetadataExtractsIT(TestFileInfo testFileInfo)
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("engineTransformations")
|
||||
@Override
|
||||
public void testTransformation(TestFileInfo testFileInfo)
|
||||
{
|
||||
super(testFileInfo);
|
||||
super.testTransformation(testFileInfo);
|
||||
}
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static List<TestFileInfo> engineTransformations()
|
||||
private static Stream<TestFileInfo> engineTransformations()
|
||||
{
|
||||
// The following files are the ones tested in the content repository.
|
||||
// There are many more mimetypes supported by these extractors.
|
||||
@@ -528,6 +529,6 @@ public class TikaMetadataExtractsIT extends AbstractMetadataExtractsIT
|
||||
// cause OutOfMemory in Tika Note - doesn't use extractFromMimetype
|
||||
testFile(MIMETYPE_OPENXML_SPREADSHEET, "xlsx", "dmsu1332-reproduced.xlsx")
|
||||
|
||||
).collect(toList());
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Transform Core
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2019 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
@@ -32,15 +32,12 @@ import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* @author Lucian Tuca
|
||||
* created on 15/01/2019
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
properties = {"activemq.url=nio://localhost:61616"})
|
||||
public class TikaQueueTransformServiceIT extends AbstractQueueTransformServiceIT
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Transform Core
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2019 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
@@ -28,31 +28,27 @@ package org.alfresco.transformer;
|
||||
|
||||
import static java.text.MessageFormat.format;
|
||||
import static java.util.function.Function.identity;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
import static org.alfresco.transformer.EngineClient.sendTRequest;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* @author Cezar Leahu
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class TikaTransformationIT
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(TikaTransformationIT.class);
|
||||
@@ -63,15 +59,16 @@ public class TikaTransformationIT
|
||||
"xhtml", "application/xhtml+xml",
|
||||
"xml", "text/xml");
|
||||
|
||||
private final String sourceFile;
|
||||
private final String targetExtension;
|
||||
private final String targetMimetype;
|
||||
private final String sourceMimetype;
|
||||
|
||||
|
||||
public TikaTransformationIT(final Triple<String, String, String> entry)
|
||||
@ParameterizedTest
|
||||
@MethodSource("engineTransformations")
|
||||
public void testTransformation(Triple<String, String, String> entry)
|
||||
{
|
||||
sourceFile = entry.getLeft();
|
||||
targetExtension = entry.getMiddle();
|
||||
final String sourceFile = entry.getLeft();
|
||||
final String sourceMimetype = entry.getRight();
|
||||
final String targetExtension = entry.getMiddle();
|
||||
String targetMimetype;
|
||||
//Single test to cover pdf-->csv
|
||||
if (sourceFile.contains("pdf") && targetExtension.contains("csv"))
|
||||
{
|
||||
@@ -81,7 +78,31 @@ public class TikaTransformationIT
|
||||
{
|
||||
targetMimetype = extensionMimetype.get(entry.getMiddle());
|
||||
}
|
||||
sourceMimetype = entry.getRight();
|
||||
|
||||
|
||||
final String descriptor = format("Transform ({0}, {1} -> {2}, {3})",
|
||||
sourceFile, sourceMimetype, targetMimetype, targetExtension);
|
||||
try
|
||||
{
|
||||
final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile, null,
|
||||
targetMimetype, targetExtension, ImmutableMap.of(
|
||||
"targetEncoding", "UTF-8",
|
||||
"sourceMimetype", sourceMimetype));
|
||||
assertEquals(OK, response.getStatusCode(), descriptor);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
fail(descriptor + " exception: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static Stream<Triple<String, String, String>> allTargets(final String sourceFile,
|
||||
final String sourceMimetype)
|
||||
{
|
||||
return extensionMimetype
|
||||
.keySet()
|
||||
.stream()
|
||||
.map(k -> Triple.of(sourceFile, k, sourceMimetype));
|
||||
}
|
||||
|
||||
// TODO unit tests for the following file types (for which is difficult to find file samples):
|
||||
@@ -89,9 +110,7 @@ public class TikaTransformationIT
|
||||
// *.cpio (application/x-cpio)
|
||||
// *.cdf (application/x-netcdf)
|
||||
// *.hdf (application/x-hdf)
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Set<Triple<String, String, String>> engineTransformations()
|
||||
public static Stream<Triple<String, String, String>> engineTransformations()
|
||||
{
|
||||
return Stream
|
||||
.of(
|
||||
@@ -152,35 +171,6 @@ public class TikaTransformationIT
|
||||
allTargets("quick.z", "application/x-compress"),
|
||||
allTargets("quick.csv", "text/csv"),
|
||||
allTargets("quick.tar.gz", "application/x-gzip"))
|
||||
.flatMap(identity())
|
||||
.collect(toSet());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransformation()
|
||||
{
|
||||
final String descriptor = format("Transform ({0}, {1} -> {2}, {3})",
|
||||
sourceFile, sourceMimetype, targetMimetype, targetExtension);
|
||||
try
|
||||
{
|
||||
final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile, null,
|
||||
targetMimetype, targetExtension, ImmutableMap.of(
|
||||
"targetEncoding", "UTF-8",
|
||||
"sourceMimetype", sourceMimetype));
|
||||
assertEquals(descriptor, OK, response.getStatusCode());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
fail(descriptor + " exception: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static Stream<Triple<String, String, String>> allTargets(final String sourceFile,
|
||||
final String sourceMimetype)
|
||||
{
|
||||
return extensionMimetype
|
||||
.keySet()
|
||||
.stream()
|
||||
.map(k -> Triple.of(sourceFile, k, sourceMimetype));
|
||||
.flatMap(identity());
|
||||
}
|
||||
}
|
||||
|
@@ -47,6 +47,10 @@
|
||||
<groupId>org.quartz-scheduler</groupId>
|
||||
<artifactId>quartz</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>xml-apis</groupId>
|
||||
<artifactId>xml-apis</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
Reference in New Issue
Block a user