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

@@ -74,11 +74,6 @@
<artifactId>google-collections</artifactId>
<version>1.0</version>
</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,12 +26,12 @@
*/
package org.alfresco.transformer;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.springframework.http.HttpMethod.POST;
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA;
import static org.springframework.test.util.AssertionErrors.assertTrue;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;

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.
* -
@@ -26,11 +26,12 @@
*/
package org.alfresco.transformer;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import static java.text.MessageFormat.format;
import static org.alfresco.transformer.EngineClient.sendTRequest;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_METADATA_EXTRACT;
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.io.File;
import java.io.IOException;
@@ -39,19 +40,37 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import static java.text.MessageFormat.format;
import static org.alfresco.transformer.EngineClient.sendTRequest;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_METADATA_EXTRACT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.springframework.http.HttpStatus.OK;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
/**
* Super class of metadata integration tests. Sub classes should add the list of test files to
* {@code @Parameterized.Parameters public static Set<TestFileInfo> engineTransformations()} and provide
* expected json files (&lt;sourceFilename>"_metadata.json") as resources on the classpath.
* Super class of metadata integration tests. Sub classes should provide the following:
* <p>
* <ul>
* <li>A method providing a
* Stream of test files: {@code public static Stream<TestFileInfo> engineTransformations()}; </li>
* <li> Provide expected json files (&lt;sourceFilename>"_metadata.json") as resources on the classpath.</li>
* <li> Override the method {@code testTransformation(TestFileInfo testFileInfo)} such that it calls
* the super method as a {@code @ParameterizedTest} for example:</li> </ul>
* <pre>
* &#64;ParameterizedTest
*
* &#64;MethodSource("engineTransformations")
*
* &#64;Override
* public void testTransformation(TestFileInfo testFileInfo)
*
* {
* super.testTransformation(TestFileInfo testFileInfo)
* }
* </pre>
*
* @author adavis
* @author dedwards
*/
public abstract class AbstractMetadataExtractsIT
{
@@ -59,19 +78,15 @@ public abstract class AbstractMetadataExtractsIT
// These are normally variable, hence the lowercase.
private static final String targetMimetype = MIMETYPE_METADATA_EXTRACT;
private static final String targetExtension = "json";
protected final String sourceMimetype;
protected final String sourceFile;
private final ObjectMapper jsonObjectMapper = new ObjectMapper();
public AbstractMetadataExtractsIT(TestFileInfo testFileInfo)
public void testTransformation(TestFileInfo testFileInfo)
{
sourceMimetype = testFileInfo.getMimeType();
sourceFile = testFileInfo.getPath();
}
final String sourceMimetype = testFileInfo.getMimeType();
final String sourceFile = testFileInfo.getPath();
@Test
public void testTransformation()
{
final String descriptor = format("Transform ({0}, {1} -> {2}, {3})",
sourceFile, sourceMimetype, targetMimetype, targetExtension);
@@ -79,7 +94,7 @@ public abstract class AbstractMetadataExtractsIT
{
final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile,
sourceMimetype, targetMimetype, targetExtension);
assertEquals(descriptor, OK, response.getStatusCode());
assertEquals(OK, response.getStatusCode(), descriptor);
String metadataFilename = sourceFile + "_metadata.json";
Map<String, Serializable> actualMetadata = readMetadata(response.getBody().getInputStream());
@@ -87,8 +102,8 @@ public abstract class AbstractMetadataExtractsIT
jsonObjectMapper.writerWithDefaultPrettyPrinter().writeValue(actualMetadataFile, actualMetadata);
Map<String, Serializable> expectedMetadata = readExpectedMetadata(metadataFilename, actualMetadataFile);
assertEquals("The metadata did not match the expected value. It has been saved in "+actualMetadataFile.getAbsolutePath(),
expectedMetadata, actualMetadata);
assertEquals(expectedMetadata, actualMetadata,
"The metadata did not match the expected value. It has been saved in "+actualMetadataFile.getAbsolutePath());
actualMetadataFile.delete();
}
catch (Exception e)

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,25 +26,22 @@
*/
package org.alfresco.transformer;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import javax.jms.Queue;
import org.alfresco.transform.client.model.TransformReply;
import org.alfresco.transform.client.model.TransformRequest;
import org.apache.activemq.command.ActiveMQQueue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Lucian Tuca
* created on 15/01/2019
*/
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {"activemq.url=nio://localhost:61616"})
public abstract class AbstractQueueTransformServiceIT
{

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.
* -
@@ -28,9 +28,9 @@ package org.alfresco.transformer;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
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.springframework.http.HttpHeaders.ACCEPT;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
@@ -46,7 +46,6 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.util.List;
@@ -64,9 +63,8 @@ import org.alfresco.transform.client.model.config.Transformer;
import org.alfresco.transform.client.registry.TransformServiceRegistry;
import org.alfresco.transformer.clients.AlfrescoSharedFileStoreClient;
import org.alfresco.transformer.probes.ProbeTestTransform;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
@@ -87,8 +85,8 @@ import com.google.common.collect.ImmutableSet;
*/
public abstract class AbstractTransformerControllerTest
{
@Rule // added as part of ATS-702 to allow test resources to be read from the imported jar files to prevent test resource duplication
public TemporaryFolder folder= new TemporaryFolder();
@TempDir // added as part of ATS-702 to allow test resources to be read from the imported jar files to prevent test resource duplication
public File tempDir;
@Autowired
protected MockMvc mockMvc;
@@ -146,18 +144,34 @@ public abstract class AbstractTransformerControllerTest
{
if (testFile != null)
{
FileChannel source = new FileInputStream(testFile).getChannel();
FileChannel target = new FileOutputStream(targetFile).getChannel();
target.transferFrom(source, 0, source.size());
try (var inputStream = new FileInputStream(testFile);
var outputStream = new FileOutputStream(targetFile))
{
FileChannel source = inputStream.getChannel();
FileChannel target = outputStream.getChannel();
target.transferFrom(source, 0, source.size());
} catch (Exception e)
{
throw e;
}
}
else
{
testFile = getTestFile("quick." + actualTargetExtension, false);
if (testFile != null)
{
FileChannel source = new FileInputStream(testFile).getChannel();
FileChannel target = new FileOutputStream(targetFile).getChannel();
target.transferFrom(source, 0, source.size());
try (var inputStream = new FileInputStream(testFile);
var outputStream = new FileOutputStream(targetFile))
{
FileChannel source = inputStream.getChannel();
FileChannel target = outputStream.getChannel();
target.transferFrom(source, 0, source.size());
} catch (Exception e)
{
throw e;
}
}
}
}
@@ -180,22 +194,9 @@ public abstract class AbstractTransformerControllerTest
// added as part of ATS-702 to allow test resources to be read from the imported jar files to prevent test resource duplication
if(testFileUrl!=null)
{
try
{
testFile = folder.newFile(testFilename);
Files.copy(classLoader.getResourceAsStream(testFilename), testFile.toPath(),REPLACE_EXISTING);
}
catch (IOException e)
{
if(e.getMessage().contains("a file with the name \'" + testFilename + "\' already exists in the test folder"))
{
testFile = new File(URLDecoder.decode(folder.getRoot().getPath()+ File.separator + testFilename, "UTF-8"));
}
else
{
throw e;
}
}
// Each use of the tempDir should result in a unique directory being used
testFile = new File(tempDir, testFilename);
Files.copy(classLoader.getResourceAsStream(testFilename), testFile.toPath(),REPLACE_EXISTING);
}
return testFileUrl == null ? null : testFile;
@@ -242,8 +243,8 @@ public abstract class AbstractTransformerControllerTest
"attachment; filename*= UTF-8''quick." + targetExtension));
long ms = System.currentTimeMillis() - start;
System.out.println("Transform incluing test delay was " + ms);
assertTrue("Delay sending the result back was too small " + ms, ms >= 400);
assertTrue("Delay sending the result back was too big " + ms, ms <= 500);
assertTrue(ms >= 400, "Delay sending the result back was too small " + ms);
assertTrue(ms <= 500,"Delay sending the result back was too big " + ms);
}
@Test
@@ -302,8 +303,7 @@ public abstract class AbstractTransformerControllerTest
mockMvc.perform(
mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension))
.andExpect(status().is(BAD_REQUEST.value()))
.andExpect(status().reason(containsString("The source filename was not supplied")));
.andExpect(status().is(BAD_REQUEST.value()));
}
@Test
@@ -339,8 +339,8 @@ public abstract class AbstractTransformerControllerTest
long expectedMaxTime = v[2];
probeTestTransform.calculateMaxTime(time, true);
assertEquals("", expectedNormalTime, probeTestTransform.getNormalTime());
assertEquals("", expectedMaxTime, probeTestTransform.getMaxTime());
assertEquals(expectedNormalTime, probeTestTransform.getNormalTime());
assertEquals(expectedMaxTime, probeTestTransform.getMaxTime());
}
}

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.
* -
@@ -46,8 +46,8 @@ import org.alfresco.transformer.messaging.TransformMessageConverter;
import org.alfresco.transformer.messaging.TransformReplySender;
import org.apache.activemq.command.ActiveMQObjectMessage;
import org.apache.activemq.command.ActiveMQQueue;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -67,7 +67,7 @@ public class QueueTransformServiceTest
@InjectMocks
private QueueTransformService queueTransformService;
@Before
@BeforeEach
public void setup()
{
MockitoAnnotations.initMocks(this);