Save point: [skip ci]

* aio tests
This commit is contained in:
alandavis
2022-07-27 12:48:01 +01:00
parent 1c6641a5f1
commit e9c149a440
18 changed files with 33 additions and 9731 deletions

View File

@@ -26,69 +26,11 @@
*/
package org.alfresco.transform.aio;
import org.alfresco.transform.base.TransformRegistryImpl;
import org.alfresco.transform.imagemagick.ImageMagickTest;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test ImageMagick functionality in All-In-One.
*/
public class AIOImageMagickTest extends ImageMagickTest
{
// @Autowired TransformRegistryImpl transformRegistry;
// @BeforeEach @Override
// public void before() throws IOException
// {
// ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand);
// ReflectionTestUtils.setField(commandExecutor, "checkCommand", mockCheckCommand);
// //Need to wire in the mocked commandExecutor into the controller...
// Map<String, Transformer> transformers = transformRegistry.getTransformerEngineMapping();
// transformers.replace("imagemagick", commandExecutor);
//
// mockTransformCommand("jpg", "png", "image/jpeg", true);
// }
// @Test
// @Override
// public void testGetTransformConfigInfo()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetTransformConfigInfoExcludingCoreVersion()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetInfoFromConfigWithDuplicates()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetInfoFromConfigWithEmptyTransformOptions()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetInfoFromConfigWithNoTransformOptions()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
}

View File

@@ -27,58 +27,10 @@
package org.alfresco.transform.aio;
import org.alfresco.transform.libreoffice.LibreOfficeTest;
//import org.alfresco.transform.libreoffice.transformers.LibreOfficeTransformer;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
/**
* Test LibreOffice functionality in All-In-One.
*/
public class AIOLibreOfficeTest extends LibreOfficeTest
{
// @Autowired AbstractTransformRegistry transformRegistry;
//
// @Override
// // Used by the super class to mock the javaExecutor, a different implementation is required here
// protected void setJavaExecutor(TransformController controller, LibreOfficeTransformer javaExecutor)
// {
// //Need to wire in the mocked javaExecutor into the controller...
// Map<String,Transformer> transformers = transformRegistry.getTransformerEngineMapping();
// transformers.replace("libreoffice", javaExecutor);
// // No need to set the transform registry to the controller as it is @Autowired in
// }
// @Test
// @Override
// public void testGetTransformConfigInfo()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetTransformConfigInfoExcludingCoreVersion()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetInfoFromConfigWithDuplicates()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
// @Test
// @Override
// public void testGetInfoFromConfigWithEmptyTransformOptions()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
// @Test
// @Override
// public void testGetInfoFromConfigWithNoTransformOptions()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
}

View File

@@ -26,48 +26,11 @@
*/
package org.alfresco.transform.aio;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.alfresco.transform.misc.MiscTest;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
/**
* Test Misc functionality in All-In-One.
*/
public class AIOMiscTest extends MiscTest
{
// @Test
// @Override
// public void testGetTransformConfigInfo()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetTransformConfigInfoExcludingCoreVersion()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetInfoFromConfigWithDuplicates()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetInfoFromConfigWithEmptyTransformOptions()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetInfoFromConfigWithNoTransformOptions()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
}

View File

@@ -27,51 +27,10 @@
package org.alfresco.transform.aio;
import org.alfresco.transform.pdfrenderer.PdfRendererTest;
import org.alfresco.transform.registry.AbstractTransformRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
/**
* Test PdfRenderer functionality in All-In-One.
*/
public class AIOPdfRendererTest extends PdfRendererTest
{
@Autowired AbstractTransformRegistry transformRegistry;
// @Test
// @Override
// public void testGetTransformConfigInfo()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetTransformConfigInfoExcludingCoreVersion()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetInfoFromConfigWithDuplicates()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetInfoFromConfigWithEmptyTransformOptions()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetInfoFromConfigWithNoTransformOptions()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
}

View File

@@ -27,18 +27,18 @@
package org.alfresco.transform.aio;
import org.alfresco.transform.base.AbstractBaseTest;
import org.alfresco.transform.client.model.TransformRequest;
import org.alfresco.transform.config.TransformConfig;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import java.io.IOException;
import java.nio.file.Files;
import static org.alfresco.transform.common.Mimetype.MIMETYPE_HTML;
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
import static org.alfresco.transform.common.RequestParamMap.CONFIG_VERSION_DEFAULT;
import static org.alfresco.transform.common.RequestParamMap.CONFIG_VERSION_LATEST;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -52,6 +52,20 @@ public class AIOTest extends AbstractBaseTest
@Autowired
private String coreVersion;
@BeforeEach
public void before() throws Exception
{
sourceMimetype = MIMETYPE_HTML;
targetMimetype = MIMETYPE_TEXT_PLAIN;
sourceExtension = "html";
targetExtension = "txt";
expectedOptions = null;
expectedSourceSuffix = null;
sourceFileBytes = readTestFile(sourceExtension);
expectedTargetFileBytes = Files.readAllBytes(getTestFile("quick2." + targetExtension, true).toPath());
sourceFile = new MockMultipartFile("file", "quick." + sourceExtension, sourceMimetype, sourceFileBytes);
}
@Override
// Add extra required parameters to the request.
protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile,
@@ -62,19 +76,8 @@ public class AIOTest extends AbstractBaseTest
.param("sourceMimetype", sourceMimetype);
}
//@Override
protected void mockTransformCommand(String sourceExtension, String targetExtension, String sourceMimetype,
boolean readTargetFileBytes) throws IOException
{
}
//@Override
protected void updateTransformRequestWithSpecificOptions(TransformRequest transformRequest)
{
}
@Test
public void emptyTest()
public void coreVersionNotSetInOriginalConfigTest()
{
ResponseEntity<TransformConfig> responseEntity = controller.transformConfig(Integer.valueOf(CONFIG_VERSION_DEFAULT));
responseEntity.getBody().getTransformers().forEach(transformer -> {
@@ -84,7 +87,7 @@ public class AIOTest extends AbstractBaseTest
}
@Test
public void emptyTestWithLatestVersion()
public void coreVersionSetInLatestConfigTest()
{
ResponseEntity<TransformConfig> responseEntity = controller.transformConfig(CONFIG_VERSION_LATEST);
responseEntity.getBody().getTransformers().forEach(transformer -> {

View File

@@ -27,53 +27,10 @@
package org.alfresco.transform.aio;
import org.alfresco.transform.tika.TikaTest;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
/**
* Test Tika functionality in All-In-One.
*/
public class AIOTikaTest extends TikaTest
{
// @Test
// @Override
// public void testGetTransformConfigInfo()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetTransformConfigInfoExcludingCoreVersion()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetInfoFromConfigWithDuplicates()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetInfoFromConfigWithEmptyTransformOptions()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void testGetInfoFromConfigWithNoTransformOptions()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// }
//
// @Test
// @Override
// public void xlsxEmbedTest()
// {
// // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
// // It uses the real class path rather than the test one.
// }
}

View File

@@ -149,11 +149,15 @@ public abstract class AbstractBaseTest
ReflectionTestUtils.setField(commandExecutor, "checkCommand", origCheckCommand);
}
protected abstract void mockTransformCommand(String sourceExtension,
protected void mockTransformCommand(String sourceExtension,
String targetExtension, String sourceMimetype,
boolean readTargetFileBytes) throws IOException;
boolean readTargetFileBytes) throws IOException
{
}
protected abstract void updateTransformRequestWithSpecificOptions(TransformRequest transformRequest);
protected void updateTransformRequestWithSpecificOptions(TransformRequest transformRequest)
{
}
/**
* This method ends up being the core of the mock.

View File

@@ -91,7 +91,7 @@ public class RestTest
parameters.add(DIRECT_ACCESS_URL, "https://expired/direct/access/url");
parameters.add(SOURCE_MIMETYPE, MIMETYPE_TEXT_PLAIN);
parameters.add(TARGET_MIMETYPE, MIMETYPE_PDF);
parameters.add("file", new org.springframework.core.io.ClassPathResource("quick.txt"));
parameters.add("file", new org.springframework.core.io.ClassPathResource("original.txt"));
ResponseEntity<String> response = restTemplate.exchange(ENDPOINT_TRANSFORM, POST,
new HttpEntity<>(parameters, HEADERS), String.class, "");
@@ -105,7 +105,7 @@ public class RestTest
LinkedMultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
parameters.add(SOURCE_MIMETYPE, MIMETYPE_TEXT_PLAIN);
parameters.add(TARGET_MIMETYPE, MIMETYPE_PDF);
parameters.add("file", new org.springframework.core.io.ClassPathResource("quick.txt"));
parameters.add("file", new org.springframework.core.io.ClassPathResource("original.txt"));
ResponseEntity<String> response = restTemplate.exchange(ENDPOINT_TRANSFORM, POST,
new HttpEntity<>(parameters, HEADERS), String.class, "");

View File

@@ -40,7 +40,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.nio.charset.StandardCharsets;
@@ -66,10 +65,8 @@ import static org.alfresco.transform.common.RequestParamMap.TARGET_MIMETYPE;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**

View File

@@ -296,7 +296,7 @@ public class TransformControllerTest
@Test
public void testTransformEndpointThatUsesTransformRequests() throws Exception
{
File sourceFile = getTestFile("quick.txt", true, tempDir);
File sourceFile = getTestFile("original.txt", true, tempDir);
String sourceFileRef = fakeSfsClient.saveFile(sourceFile).getEntry().getFileRef();
TransformRequest transformRequest = TransformRequest.builder()

View File

@@ -107,7 +107,7 @@ public class FakeTransformEngineWithTwoCustomTransformers extends AbstractFakeTr
@Override
public ProbeTransform getProbeTransform()
{
return new ProbeTransform("quick.txt", MIMETYPE_TEXT_PLAIN, MIMETYPE_PDF,
return new ProbeTransform("original.txt", MIMETYPE_TEXT_PLAIN, MIMETYPE_PDF,
ImmutableMap.of(SOURCE_ENCODING, "UTF-8"), 46, 0,
150, 1024, 1, 60 * 2);
}

View File

@@ -1 +0,0 @@
Original Text -> TxT2Pdf()

File diff suppressed because it is too large Load Diff

View File

@@ -171,13 +171,6 @@ public class LibreOfficeTest extends AbstractBaseTest
return builder;
}
@Override
protected void mockTransformCommand(String sourceExtension, String targetExtension,
String sourceMimetype, boolean readTargetFileBytes)
{
throw new IllegalStateException();
}
@Test
public void badExitCodeTest() throws Exception
{

View File

@@ -80,18 +80,6 @@ public class MiscTest extends AbstractBaseTest
sourceFile = new MockMultipartFile("file", "quick." + sourceExtension, sourceMimetype, sourceFileBytes);
}
@Override
protected void mockTransformCommand(String sourceExtension, String targetExtension,
String sourceMimetype, boolean readTargetFileBytes)
{
// Misc transform is not mocked. It is run for real.
}
@Override
protected void updateTransformRequestWithSpecificOptions(TransformRequest transformRequest)
{
}
@Override
protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile,
String... params)

View File

@@ -126,12 +126,13 @@ public class TikaTest extends AbstractBaseTest
private String targetMimetype = MIMETYPE_TEXT_PLAIN;
@BeforeEach
public void before()
public void before() throws Exception
{
sourceExtension = "pdf";
targetExtension = "txt";
sourceMimetype = MIMETYPE_PDF;
targetMimetype = MIMETYPE_TEXT_PLAIN;
mockTransformCommand(PDF, TXT, MIMETYPE_PDF, true);
}
@Override
@@ -191,34 +192,6 @@ public class TikaTest extends AbstractBaseTest
.param("sourceMimetype", sourceMimetype);
}
@Test
@Override
public void simpleTransformTest() throws Exception
{
mockTransformCommand(PDF, TXT, MIMETYPE_PDF, true);
super.simpleTransformTest();
}
// --- Super class tests (need modified setup) ---
@Test
@Override
public void dotDotSourceFilenameTest() throws Exception
{
mockTransformCommand(PDF, TXT, MIMETYPE_PDF, true);
super.dotDotSourceFilenameTest();
}
@Test
@Override
public void noExtensionSourceFilenameTest() throws Exception
{
mockTransformCommand(PDF, TXT, MIMETYPE_PDF, true);
super.noExtensionSourceFilenameTest();
}
// --- General Tika tests ---
@Test
public void badEncodingTest() throws Exception
{