ACS-930 Security update to spring boot 2.4.1 (#321)

* ACS-930 Upgrade to Junit5
This commit is contained in:
David Edwards
2021-01-15 10:31:25 +00:00
committed by GitHub
parent 0060461695
commit ef21365e00
55 changed files with 647 additions and 836 deletions

View File

@@ -67,11 +67,6 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@@ -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.
* -
@@ -26,15 +26,14 @@
*/
package org.alfresco.transformer;
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_PDF;
import static org.alfresco.transformer.util.RequestParamMap.SOURCE_MIMETYPE;
import static org.alfresco.transformer.util.RequestParamMap.TARGET_EXTENSION;
import static org.alfresco.transformer.util.RequestParamMap.TARGET_MIMETYPE;
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_PDF;
import static org.alfresco.transformer.executors.RuntimeExec.ExecutionResult;
import static org.hamcrest.Matchers.containsString;
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.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.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
@@ -55,15 +54,17 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.UUID;
import javax.annotation.PostConstruct;
import org.alfresco.transform.client.model.TransformReply;
import org.alfresco.transform.client.model.TransformRequest;
import org.alfresco.transformer.executors.LibreOfficeJavaExecutor;
import org.alfresco.transformer.executors.RuntimeExec.ExecutionResult;
import org.alfresco.transformer.model.FileRefEntity;
import org.alfresco.transformer.model.FileRefResponse;
import org.artofsolving.jodconverter.office.OfficeException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
@@ -74,18 +75,16 @@ 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.request.MockMvcRequestBuilders;
import javax.annotation.PostConstruct;
/**
* Test the LibreOfficeController without a server.
* Super class includes tests for the AbstractTransformerController.
*/
@RunWith(SpringRunner.class)
@WebMvcTest(LibreOfficeController.class)
// Specifying class for @WebMvcTest() will break AIO tests, without specifying it will use all controllers in the application context,
// currently only LibreOfficeController.class
@WebMvcTest()
public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
{
@@ -124,7 +123,7 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
@Autowired
protected AbstractTransformerController controller;
@Before
@BeforeEach
public void before() throws IOException
{
sourceExtension = "doc";
@@ -164,8 +163,7 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
// Check the supplied source file has not been changed.
byte[] actualSourceFileBytes = Files.readAllBytes(sourceFile.toPath());
assertTrue("Source file is not the same",
Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes));
assertTrue(Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes), "Source file is not the same");
return null;
}).when(javaExecutor).convert(any(), any());

View File

@@ -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.
* -
@@ -26,14 +26,11 @@
*/
package org.alfresco.transformer;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Tests LibreOfficeController with a server test harness.
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class LibreOfficeHttpRequestTest extends AbstractHttpRequestTest
{

View File

@@ -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.
* -
@@ -31,15 +31,12 @@ import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_OPENXML_WORD
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 LibreOfficeQueueTransformServiceIT extends AbstractQueueTransformServiceIT

View File

@@ -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.
* -
@@ -29,7 +29,6 @@ package org.alfresco.transformer;
import static java.text.MessageFormat.format;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.toSet;
import static org.alfresco.transformer.EngineClient.sendTRequest;
import static org.alfresco.transformer.TestFileInfo.testFile;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_EXCEL;
@@ -63,8 +62,8 @@ import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_SXC;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_STW;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_STI;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_STC;
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;
@@ -74,9 +73,8 @@ import java.util.stream.Stream;
import com.google.common.collect.ImmutableSet;
import org.apache.commons.lang3.tuple.Pair;
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;
@@ -85,7 +83,6 @@ import org.springframework.http.ResponseEntity;
/**
* @author Cezar Leahu
*/
@RunWith(Parameterized.class)
public class LibreOfficeTransformationIT
{
private static final Logger logger = LoggerFactory.getLogger(LibreOfficeTransformationIT.class);
@@ -127,11 +124,6 @@ public class LibreOfficeTransformationIT
testFile(MIMETYPE_TEXT_PLAIN,"txt",null)
);
private final String sourceFile;
private final String targetExtension;
private final String sourceMimetype;
private final String targetMimetype;
private static final Map<String,TestFileInfo> TEST_FILES = Stream.of(
testFile(MIMETYPE_WORD ,"doc" ,"quick.doc"),
testFile(MIMETYPE_OPENXML_WORDPROCESSING ,"docx" ,"quick.docx"),
@@ -164,16 +156,7 @@ public class LibreOfficeTransformationIT
testFile(MIMETYPE_TSV ,"tsv" ,"sample.tsv")
).collect(toMap(TestFileInfo::getPath, identity()));
public LibreOfficeTransformationIT(final Pair<TestFileInfo, TestFileInfo> entry)
{
sourceFile = entry.getLeft().getPath();
targetExtension = entry.getRight().getExtension();
sourceMimetype = entry.getLeft().getMimeType();
targetMimetype = entry.getRight().getMimeType();
}
@Parameterized.Parameters
public static Set<Pair<TestFileInfo, TestFileInfo>> engineTransformations()
public static Stream<Pair<TestFileInfo, TestFileInfo>> engineTransformations()
{
return Stream
.of(
@@ -213,20 +196,24 @@ public class LibreOfficeTransformationIT
allTargets("quick.msg", txtTarget)
)
.flatMap(identity())
.collect(toSet());
.flatMap(identity());
}
@Test
public void testTransformation()
@ParameterizedTest
@MethodSource("engineTransformations")
public void testTransformation(final Pair<TestFileInfo, TestFileInfo> entry)
{
final String sourceFile = entry.getLeft().getPath();
final String targetExtension = entry.getRight().getExtension();
final String sourceMimetype = entry.getLeft().getMimeType();
final String targetMimetype = entry.getRight().getMimeType();
final String descriptor = format("Transform ({0}, {1} -> {2}, {3})",
sourceFile, sourceMimetype, targetMimetype, targetExtension);
try
{
final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile, sourceMimetype,
targetMimetype, targetExtension);
assertEquals(descriptor, OK, response.getStatusCode());
assertEquals(OK, response.getStatusCode(), descriptor);
}
catch (Exception e)
{