engineTransformations()} and provide
- * expected json files (<sourceFilename>"_metadata.json") as resources on the classpath.
+ * Super class of metadata integration tests. Sub classes should provide the following:
+ *
+ *
+ * - A method providing a
+ * Stream of test files: {@code public static Stream engineTransformations()};
+ * - Provide expected json files (<sourceFilename>"_metadata.json") as resources on the classpath.
+ * - Override the method {@code testTransformation(TestFileInfo testFileInfo)} such that it calls
+ * the super method as a {@code @ParameterizedTest} for example:
+ *
+ * @ParameterizedTest
+ *
+ * @MethodSource("engineTransformations")
+ *
+ * @Override
+
+ * public void testTransformation(TestFileInfo testFileInfo)
+ *
+ * {
+ * super.testTransformation(TestFileInfo testFileInfo)
+ * }
+ *
*
* @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 response = sendTRequest(ENGINE_URL, sourceFile,
sourceMimetype, targetMimetype, targetExtension);
- assertEquals(descriptor, OK, response.getStatusCode());
+ assertEquals(OK, response.getStatusCode(), descriptor);
String metadataFilename = sourceFile + "_metadata.json";
Map actualMetadata = readMetadata(response.getBody().getInputStream());
@@ -87,8 +102,8 @@ public abstract class AbstractMetadataExtractsIT
jsonObjectMapper.writerWithDefaultPrettyPrinter().writeValue(actualMetadataFile, actualMetadata);
Map 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)
diff --git a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractQueueTransformServiceIT.java b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractQueueTransformServiceIT.java
index 56583a70..2d5829fa 100644
--- a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractQueueTransformServiceIT.java
+++ b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractQueueTransformServiceIT.java
@@ -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
{
diff --git a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java
index 6c8879af..34a942db 100644
--- a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java
+++ b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java
@@ -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());
}
}
diff --git a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/QueueTransformServiceTest.java b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/QueueTransformServiceTest.java
index ee9c02f4..f73baec4 100644
--- a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/QueueTransformServiceTest.java
+++ b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/QueueTransformServiceTest.java
@@ -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);