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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 647 additions and 836 deletions

View File

@ -97,11 +97,6 @@
<groupId>org.dom4j</groupId> <groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId> <artifactId>dom4j</artifactId>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,12 +26,9 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class AIOControllerHttpRequestTest extends AbstractHttpRequestTest public class AIOControllerHttpRequestTest extends AbstractHttpRequestTest
{ {

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,30 +26,27 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.alfresco.transformer.executors.Transformer; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import;
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.MockHttpServletRequestBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.assertTrue; import org.alfresco.transformer.executors.Transformer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
@RunWith(SpringRunner.class)
@WebMvcTest(AIOController.class)
@Import(AIOCustomConfig.class)
/** /**
* Test the AIOController ImageMagick transforms without a server. * Test the AIOController ImageMagick transforms without a server.
* Super class includes tests for the AbstractTransformerController. * Super class includes tests for the AbstractTransformerController.
*/ */
@WebMvcTest(AIOController.class)
@Import(AIOCustomConfig.class)
public class AIOControllerImageMagickTest extends ImageMagickControllerTest public class AIOControllerImageMagickTest extends ImageMagickControllerTest
{ {
// All tests contained in ImageMagickControllerTest // All tests contained in ImageMagickControllerTest
@ -57,7 +54,7 @@ public class AIOControllerImageMagickTest extends ImageMagickControllerTest
@Autowired @Autowired
AIOTransformRegistry transformRegistry; AIOTransformRegistry transformRegistry;
@Before @Override @BeforeEach @Override
public void before() throws IOException public void before() throws IOException
{ {
ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand); ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand);
@ -90,7 +87,7 @@ public class AIOControllerImageMagickTest extends ImageMagickControllerTest
public void testTestValidity() public void testTestValidity()
{ {
// just test that we are actually testing against the AIOController (instead of MiscController) // just test that we are actually testing against the AIOController (instead of MiscController)
assertTrue("Wrong controller wired for test", controller instanceof AIOController); assertTrue(controller instanceof AIOController, "Wrong controller wired for test");
} }
@Test @Test

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,22 +26,19 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Map;
import org.alfresco.transformer.executors.LibreOfficeJavaExecutor; import org.alfresco.transformer.executors.LibreOfficeJavaExecutor;
import org.alfresco.transformer.executors.Transformer; import org.alfresco.transformer.executors.Transformer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import java.util.Map;
import static org.junit.Assert.assertTrue;
@RunWith(SpringRunner.class)
@WebMvcTest(AIOController.class) @WebMvcTest(AIOController.class)
@Import(AIOCustomConfig.class) @Import(AIOCustomConfig.class)
/** /**
@ -56,7 +53,7 @@ public class AIOControllerLibreOfficeTest extends LibreOfficeControllerTest
public void testTestValidity() public void testTestValidity()
{ {
// just test that we are actually testing against the AIOController (instead of MiscController) // just test that we are actually testing against the AIOController (instead of MiscController)
assertTrue("Wrong controller wired for test", controller instanceof AIOController); assertTrue(controller instanceof AIOController,"Wrong controller wired for test");
} }
@Autowired @Autowired
@ -87,7 +84,7 @@ public class AIOControllerLibreOfficeTest extends LibreOfficeControllerTest
@Override @Override
public void testGetTransformConfigInfo() public void testGetTransformConfigInfo()
{ {
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different. // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
} }
@ -95,21 +92,21 @@ public class AIOControllerLibreOfficeTest extends LibreOfficeControllerTest
@Override @Override
public void testGetInfoFromConfigWithDuplicates() public void testGetInfoFromConfigWithDuplicates()
{ {
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different. // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
} }
@Test @Test
@Override @Override
public void testGetInfoFromConfigWithEmptyTransformOptions() public void testGetInfoFromConfigWithEmptyTransformOptions()
{ {
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different. // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
} }
@Test @Test
@Override @Override
public void testGetInfoFromConfigWithNoTransformOptions() public void testGetInfoFromConfigWithNoTransformOptions()
{ {
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different. // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
} }
} }

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,15 +26,12 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
import static junit.framework.TestCase.assertTrue;
@RunWith(SpringRunner.class)
@WebMvcTest(AIOController.class) @WebMvcTest(AIOController.class)
@Import(AIOCustomConfig.class) @Import(AIOCustomConfig.class)
public class AIOControllerMiscTest extends MiscControllerTest public class AIOControllerMiscTest extends MiscControllerTest
@ -46,14 +43,14 @@ public class AIOControllerMiscTest extends MiscControllerTest
public void testTestValidity() public void testTestValidity()
{ {
// just test that we are actually testing against the AIOController (instead of MiscController) // just test that we are actually testing against the AIOController (instead of MiscController)
assertTrue("Wrong controller wired for test", controller instanceof AIOController); assertTrue(controller instanceof AIOController, "Wrong controller wired for test");
} }
@Test @Test
@Override @Override
public void testGetTransformConfigInfo() public void testGetTransformConfigInfo()
{ {
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different. // Ignore the test in super class as the way the AIO transformer provides config is fundamentality different.
} }
@ -61,21 +58,21 @@ public class AIOControllerMiscTest extends MiscControllerTest
@Override @Override
public void testGetInfoFromConfigWithDuplicates() public void testGetInfoFromConfigWithDuplicates()
{ {
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different. // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
} }
@Test @Test
@Override @Override
public void testGetInfoFromConfigWithEmptyTransformOptions() public void testGetInfoFromConfigWithEmptyTransformOptions()
{ {
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different. // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
} }
@Test @Test
@Override @Override
public void testGetInfoFromConfigWithNoTransformOptions() public void testGetInfoFromConfigWithNoTransformOptions()
{ {
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different. // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
} }
} }

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,22 +26,20 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Map;
import org.alfresco.transformer.executors.Transformer; import org.alfresco.transformer.executors.Transformer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import java.util.Map;
import static org.junit.Assert.assertTrue;
@RunWith(SpringRunner.class)
@WebMvcTest(AIOController.class) @WebMvcTest(AIOController.class)
@Import(AIOCustomConfig.class) @Import(AIOCustomConfig.class)
/** /**
@ -78,14 +76,14 @@ public class AIOControllerPdfRendererTest extends AlfrescoPdfRendererControllerT
public void testTestValidity() public void testTestValidity()
{ {
// just test that we are actually testing against the AIOController (instead of MiscController) // just test that we are actually testing against the AIOController (instead of MiscController)
assertTrue("Wrong controller wired for test", controller instanceof AIOController); assertTrue(controller instanceof AIOController, "Wrong controller wired for test");
} }
@Test @Test
@Override @Override
public void testGetTransformConfigInfo() public void testGetTransformConfigInfo()
{ {
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different. // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
} }
@ -93,7 +91,7 @@ public class AIOControllerPdfRendererTest extends AlfrescoPdfRendererControllerT
@Override @Override
public void testGetInfoFromConfigWithDuplicates() public void testGetInfoFromConfigWithDuplicates()
{ {
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different. // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
} }
@ -101,7 +99,7 @@ public class AIOControllerPdfRendererTest extends AlfrescoPdfRendererControllerT
@Override @Override
public void testGetInfoFromConfigWithEmptyTransformOptions() public void testGetInfoFromConfigWithEmptyTransformOptions()
{ {
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different. // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
} }
@ -109,7 +107,7 @@ public class AIOControllerPdfRendererTest extends AlfrescoPdfRendererControllerT
@Override @Override
public void testGetInfoFromConfigWithNoTransformOptions() public void testGetInfoFromConfigWithNoTransformOptions()
{ {
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different. // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
} }
} }

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,18 +26,14 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import java.io.IOException; import java.io.IOException;
import org.alfresco.transform.client.model.TransformRequest; import org.alfresco.transform.client.model.TransformRequest;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@WebMvcTest(AIOController.class) @WebMvcTest(AIOController.class)
@Import(AIOCustomConfig.class) @Import(AIOCustomConfig.class)
public class AIOControllerTest //extends AbstractTransformerControllerTest public class AIOControllerTest //extends AbstractTransformerControllerTest

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,15 +26,12 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@WebMvcTest(AIOController.class) @WebMvcTest(AIOController.class)
@Import(AIOCustomConfig.class) @Import(AIOCustomConfig.class)
/** /**
@ -49,7 +46,7 @@ public class AIOControllerTikaTest extends TikaControllerTest
public void testTestValidity() public void testTestValidity()
{ {
// just test that we are actually testing against the AIOController (instead of MiscController) // just test that we are actually testing against the AIOController (instead of MiscController)
assertTrue("Wrong controller wired for test", controller instanceof AIOController); assertTrue(controller instanceof AIOController,"Wrong controller wired for test");
} }
@Test @Test

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,16 +26,7 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class AIOImageMagickIT extends ImageMagickTransformationIT public class AIOImageMagickIT extends ImageMagickTransformationIT
{ {
//Tests are in ImageMagickTransformationIT // Tests are in ImageMagickTransformationIT
public AIOImageMagickIT(final Pair<TestFileInfo, Pair<String,String>> entry)
{
super(entry);
}
} }

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,16 +26,7 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class AIOLibreOfficeTransformationIT extends LibreOfficeTransformationIT public class AIOLibreOfficeTransformationIT extends LibreOfficeTransformationIT
{ {
// Tests are in LibreOfficeTransformationIT
public AIOLibreOfficeTransformationIT(final Pair<TestFileInfo, TestFileInfo> entry)
{
super(entry);
}
} }

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,19 +26,13 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
/** /**
* Metadata integration tests in the Misc T-Engine, but run from the AIO T-Engine. * Metadata integration tests in the Misc T-Engine, but run from the AIO T-Engine.
* *
* @author adavis * @author adavis
* @author dedwards
*/ */
@RunWith(Parameterized.class)
public class AIOMiscMetadataExtractsIT extends MiscMetadataExtractsIT public class AIOMiscMetadataExtractsIT extends MiscMetadataExtractsIT
{ {
public AIOMiscMetadataExtractsIT(TestFileInfo testFileInfo) //Tests are in MiscMetadataExtractsIT
{
super(testFileInfo);
}
} }

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,15 +26,7 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class AIOMiscTransformsIT extends MiscTransformsIT public class AIOMiscTransformsIT extends MiscTransformsIT
{ {
//Tests are in ImageMagickTransformationIT // Tests are in ImageMagickTransformationIT
public AIOMiscTransformsIT(final SourceTarget sourceTarget)
{
super(sourceTarget);
}
} }

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,14 +26,6 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class AIOPdfRendererIT extends AlfrescoPdfRendererTransformationIT { public class AIOPdfRendererIT extends AlfrescoPdfRendererTransformationIT {
// Tests are in AlfrescoPdfRendererTransformationIT // Tests are in AlfrescoPdfRendererTransformationIT
public AIOPdfRendererIT(String sourceFile)
{
super(sourceFile);
}
} }

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * 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 java.util.UUID;
import org.alfresco.transform.client.model.TransformRequest; import org.alfresco.transform.client.model.TransformRequest;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* @author David Edwards * @author David Edwards
* created on 21/04/2020 * created on 21/04/2020
*/ */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {"activemq.url=nio://localhost:61616"}) properties = {"activemq.url=nio://localhost:61616"})
public class AIOQueueTransformServiceIT extends AbstractQueueTransformServiceIT public class AIOQueueTransformServiceIT extends AbstractQueueTransformServiceIT

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,19 +26,13 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
/** /**
* Metadata integration tests in the Tika T-Engine, but run from the AIO T-Engine. * Metadata integration tests in the Tika T-Engine, but run from the AIO T-Engine.
* *
* @author adavis * @author adavis
* @author dedwards
*/ */
@RunWith(Parameterized.class)
public class AIOTikaMetadataExtractsIT extends TikaMetadataExtractsIT public class AIOTikaMetadataExtractsIT extends TikaMetadataExtractsIT
{ {
public AIOTikaMetadataExtractsIT(TestFileInfo testFileInfo) // Tests are in TikaMetadataExtractsIT
{
super(testFileInfo);
}
} }

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,17 +26,7 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.apache.commons.lang3.tuple.Triple;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class AIOTikaTransformationIT extends TikaTransformationIT public class AIOTikaTransformationIT extends TikaTransformationIT
{ {
// Tests are in ImageMagickTransformationIT
//Tests are in ImageMagickTransformationIT
public AIOTikaTransformationIT(final Triple<String, String, String> entry)
{
super(entry);
}
} }

View File

@ -44,9 +44,15 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>junit</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -33,8 +33,8 @@ import org.alfresco.transformer.executors.Transformer;
import org.alfresco.transformer.transformers.SelectingTransformer; import org.alfresco.transformer.transformers.SelectingTransformer;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper; import org.apache.pdfbox.text.PDFTextStripper;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import java.io.File; import java.io.File;
@ -52,8 +52,9 @@ import java.util.stream.Stream;
import static org.alfresco.transformer.util.RequestParamMap.PAGE_LIMIT; import static org.alfresco.transformer.util.RequestParamMap.PAGE_LIMIT;
import static org.alfresco.transformer.util.RequestParamMap.TRANSFORM_NAME_PARAMETER; import static org.alfresco.transformer.util.RequestParamMap.TRANSFORM_NAME_PARAMETER;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class AIOTransformRegistryTest public class AIOTransformRegistryTest
{ {
@ -65,7 +66,7 @@ public class AIOTransformRegistryTest
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
@Before @BeforeEach
public void before() throws Exception public void before() throws Exception
{ {
aioTransformerRegistry.registerTransformer(new SelectingTransformer()); aioTransformerRegistry.registerTransformer(new SelectingTransformer());
@ -104,32 +105,34 @@ public class AIOTransformRegistryTest
TransformConfig tikaConfig = loadConfig("tika_engine_config.json"); TransformConfig tikaConfig = loadConfig("tika_engine_config.json");
// check correct number of transformers // check correct number of transformers
assertEquals("Number of expected transformers", assertEquals(
miscConfig.getTransformers().size() + tikaConfig.getTransformers().size(), miscConfig.getTransformers().size() + tikaConfig.getTransformers().size(),
aioTransformerRegistry.getTransformConfig().getTransformers().size()); aioTransformerRegistry.getTransformConfig().getTransformers().size(),
"Number of expected transformers");
List<String> actualTransformerNames = aioTransformerRegistry.getTransformConfig().getTransformers() List<String> actualTransformerNames = aioTransformerRegistry.getTransformConfig().getTransformers()
.stream().map(t -> t.getTransformerName()).collect(Collectors.toList()); .stream().map(t -> t.getTransformerName()).collect(Collectors.toList());
// check all transformers are there // check all transformers are there
for(String transformNames : expectedTransformNames) for(String transformNames : expectedTransformNames)
{ {
assertTrue("Expected transformer missing.", actualTransformerNames.contains(transformNames)); assertTrue(actualTransformerNames.contains(transformNames),"Expected transformer missing.");
} }
// check correct number of options // check correct number of options
long distinctOptionCount = Stream.concat( long distinctOptionCount = Stream.concat(
miscConfig.getTransformOptions().keySet().stream(), miscConfig.getTransformOptions().keySet().stream(),
tikaConfig.getTransformOptions().keySet().stream()).distinct().count(); tikaConfig.getTransformOptions().keySet().stream()).distinct().count();
assertEquals("Number of expected transformers", assertEquals(
distinctOptionCount, distinctOptionCount,
aioTransformerRegistry.getTransformConfig().getTransformOptions().size()); aioTransformerRegistry.getTransformConfig().getTransformOptions().size(),
"Number of expected transformers");
Set<String> actualOptionNames = aioTransformerRegistry.getTransformConfig().getTransformOptions().keySet(); Set<String> actualOptionNames = aioTransformerRegistry.getTransformConfig().getTransformOptions().keySet();
// check all options are there // check all options are there
for (String optionName : expectedTransformOptionNames) for (String optionName : expectedTransformOptionNames)
{ {
assertTrue("Expected transform option missing:"+optionName, actualOptionNames.contains(optionName)); assertTrue(actualOptionNames.contains(optionName), "Expected transform option missing:"+optionName);
} }
} }
@ -142,21 +145,23 @@ public class AIOTransformRegistryTest
for (String transform : tikaTransforms) for (String transform : tikaTransforms)
{ {
String actualId = aioTransformerRegistry.getByTransformName(transform).getTransformerId(); String actualId = aioTransformerRegistry.getByTransformName(transform).getTransformerId();
assertEquals("Wrong mapping for transform "+transform, "tika", actualId); assertEquals("tika", actualId, "Wrong mapping for transform "+transform);
} }
for (String transform : miscTransforms) for (String transform : miscTransforms)
{ {
String actualId = aioTransformerRegistry.getByTransformName(transform).getTransformerId(); String actualId = aioTransformerRegistry.getByTransformName(transform).getTransformerId();
assertEquals("Wrong mapping for transform "+transform, "misc", actualId); assertEquals("misc", actualId, "Wrong mapping for transform "+transform);
} }
} }
@Test(expected = Exception.class) @Test
public void testDuplicateTransformsException() throws Exception public void testDuplicateTransformsException() throws Exception
{ {
// The Misc transformers are already registered assertThrows(Exception.class, () ->{
aioTransformerRegistry.registerTransformer(new SelectingTransformer()); // The Misc transformers are already registered
aioTransformerRegistry.registerTransformer(new SelectingTransformer());
});
} }
// Test copied from Misc (HtmlParserContentTransformerTest) See ATS-712 aioTransformerRegistry - html // Test copied from Misc (HtmlParserContentTransformerTest) See ATS-712 aioTransformerRegistry - html
@ -313,8 +318,8 @@ public class AIOTransformRegistryTest
String roundTrip = clean(textWriter.toString()); String roundTrip = clean(textWriter.toString());
assertEquals( assertEquals(
"Incorrect text in PDF when starting from text in " + encoding, checkText, roundTrip,
checkText, roundTrip "Incorrect text in PDF when starting from text in " + encoding
); );
sourceFile.delete(); sourceFile.delete();

View File

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

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,44 +26,11 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.alfresco.transform.client.model.TransformReply;
import org.alfresco.transform.client.model.TransformRequest;
import org.alfresco.transformer.executors.ImageMagickCommandExecutor;
import org.alfresco.transformer.executors.RuntimeExec;
import org.alfresco.transformer.model.FileRefEntity;
import org.alfresco.transformer.model.FileRefResponse;
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.beans.factory.annotation.Value;
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.request.MockMvcRequestBuilders;
import javax.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static org.alfresco.transformer.executors.RuntimeExec.ExecutionResult;
import static org.alfresco.transformer.util.MimetypeMap.PREFIX_IMAGE; import static org.alfresco.transformer.util.MimetypeMap.PREFIX_IMAGE;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -80,12 +47,47 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.util.StringUtils.getFilenameExtension; import static org.springframework.util.StringUtils.getFilenameExtension;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
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.ImageMagickCommandExecutor;
import org.alfresco.transformer.executors.RuntimeExec;
import org.alfresco.transformer.executors.RuntimeExec.ExecutionResult;
import org.alfresco.transformer.model.FileRefEntity;
import org.alfresco.transformer.model.FileRefResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mock;
import org.mockito.stubbing.Answer;
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.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.request.MockMvcRequestBuilders;
/** /**
* Test the ImageMagickController without a server. * Test the ImageMagickController without a server.
* Super class includes tests for the AbstractTransformerController. * Super class includes tests for the AbstractTransformerController.
*/ */
@RunWith(SpringRunner.class) // Specifying class for @WebMvcTest() will break AIO tests, without specifying it will use all controllers in the application context,
@WebMvcTest(ImageMagickController.class) // currently only ImageMagickController.class
@WebMvcTest()
public class ImageMagickControllerTest extends AbstractTransformerControllerTest public class ImageMagickControllerTest extends AbstractTransformerControllerTest
{ {
private static final String ENGINE_CONFIG_NAME = "imagemagick_engine_config.json"; private static final String ENGINE_CONFIG_NAME = "imagemagick_engine_config.json";
@ -125,7 +127,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
@Autowired @Autowired
protected AbstractTransformerController controller; protected AbstractTransformerController controller;
@Before @BeforeEach
public void before() throws IOException public void before() throws IOException
{ {
ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand); ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand);
@ -161,7 +163,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
when(mockTransformCommand.execute(any(), anyLong())).thenAnswer( when(mockTransformCommand.execute(any(), anyLong())).thenAnswer(
(Answer<RuntimeExec.ExecutionResult>) invocation -> { (Answer<RuntimeExec.ExecutionResult>) invocation -> {
Map<String, String> actualProperties = invocation.getArgument(0); 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 actualOptions = actualProperties.get("options");
String actualSource = actualProperties.get("source"); String actualSource = actualProperties.get("source");
@ -170,26 +172,23 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
assertNotNull(actualSource); assertNotNull(actualSource);
assertNotNull(actualTarget); assertNotNull(actualTarget);
if (expectedSourceSuffix != null) if (expectedSourceSuffix != null) {
{ assertTrue(actualSource.endsWith(expectedSourceSuffix),
assertTrue( "The source file \"" + actualSource + "\" should have ended in \"" + expectedSourceSuffix + "\"");
"The source file \"" + actualSource + "\" should have ended in \"" + expectedSourceSuffix + "\"", actualSource = actualSource.substring(0, actualSource.length() - expectedSourceSuffix.length());
actualSource.endsWith(expectedSourceSuffix));
actualSource = actualSource.substring(0,
actualSource.length() - expectedSourceSuffix.length());
} }
assertNotNull(actualOptions); assertNotNull(actualOptions);
if (expectedOptions != null) if (expectedOptions != null)
{ {
assertEquals("expectedOptions", expectedOptions, actualOptions); assertEquals(expectedOptions, actualOptions,"expectedOptions");
} }
Long actualTimeout = invocation.getArgument(1); Long actualTimeout = invocation.getArgument(1);
assertNotNull(actualTimeout); assertNotNull(actualTimeout);
if (expectedTimeout != null) if (expectedTimeout != null)
{ {
assertEquals("expectedTimeout", expectedTimeout, actualTimeout); assertEquals(expectedTimeout, actualTimeout,"expectedTimeout");
} }
// Copy a test file into the target file location if it exists // Copy a test file into the target file location if it exists
@ -205,8 +204,8 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
// Check the supplied source file has not been changed. // Check the supplied source file has not been changed.
byte[] actualSourceFileBytes = Files.readAllBytes(new File(actualSource).toPath()); byte[] actualSourceFileBytes = Files.readAllBytes(new File(actualSource).toPath());
assertTrue("Source file is not the same", assertTrue(Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes),
Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes)); "Source file is not the same");
return mockExecutionResult; return mockExecutionResult;
}); });
@ -222,25 +221,23 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
return controller; return controller;
} }
@Test @ParameterizedTest
public void cropGravityGoodTest() throws Exception @ValueSource(strings = {"North", "NorthEast", "East", "SouthEast", "South", "SouthWest", "West", "NorthWest", "Center"})
public void cropGravityGoodTest(String value) throws Exception
{ {
for (String value : new String[]{"North", "NorthEast", "East", "SouthEast", "South", "SouthWest", "West", "NorthWest", "Center"}) expectedOptions = "-auto-orient " + "-gravity " + value + " +repage";
{ mockMvc
expectedOptions = "-auto-orient " + "-gravity " + value + " +repage"; .perform(MockMvcRequestBuilders
mockMvc .multipart("/transform")
.perform(MockMvcRequestBuilders .file(sourceFile)
.multipart("/transform") .param("targetExtension", targetExtension)
.file(sourceFile) .param("targetMimetype", targetMimetype)
.param("targetExtension", targetExtension) .param("sourceMimetype", sourceMimetype)
.param("targetMimetype", targetMimetype) .param("cropGravity", value))
.param("sourceMimetype", sourceMimetype) .andExpect(status().is(OK.value()))
.param("cropGravity", value)) .andExpect(content().bytes(expectedTargetFileBytes))
.andExpect(status().is(OK.value())) .andExpect(header().string("Content-Disposition",
.andExpect(content().bytes(expectedTargetFileBytes)) "attachment; filename*= UTF-8''quick." + targetExtension));
.andExpect(header().string("Content-Disposition",
"attachment; filename*= UTF-8''quick." + targetExtension));
}
} }
@Test @Test

View File

@ -26,16 +26,12 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* Tests ImageMagickController with a server test harness. * Tests ImageMagickController with a server test harness.
*/ */
@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class ImageMagickHttpRequestTest extends AbstractHttpRequestTest public class ImageMagickHttpRequestTest extends AbstractHttpRequestTest
{ {
@Override @Override

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -32,15 +32,12 @@ import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_IMAGE_PNG;
import java.util.UUID; import java.util.UUID;
import org.alfresco.transform.client.model.TransformRequest; import org.alfresco.transform.client.model.TransformRequest;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* @author Lucian Tuca * @author Lucian Tuca
* created on 15/01/2019 * created on 15/01/2019
*/ */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {"activemq.url=nio://localhost:61616"}) properties = {"activemq.url=nio://localhost:61616"})
public class ImageMagickQueueTransformServiceIT extends AbstractQueueTransformServiceIT public class ImageMagickQueueTransformServiceIT extends AbstractQueueTransformServiceIT

View File

@ -30,179 +30,158 @@ import static java.text.MessageFormat.format;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static java.util.function.Function.identity; import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap; 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.EngineClient.sendTRequest;
import static org.alfresco.transformer.TestFileInfo.testFile; import static org.alfresco.transformer.TestFileInfo.testFile;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_3FR; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_APPLICATION_EPS;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_ARW;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_BMP; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_BMP;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_CGM; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_CGM;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_CR2;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_DNG;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_APPLICATION_EPS;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_GIF; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_GIF;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_IEF; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_IEF;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_JP2; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_JP2;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_JPEG; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_JPEG;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_K25;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_MRW;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_NEF;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_ORF;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PBM; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PBM;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_PEF;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PGM; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PGM;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PNG; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PNG;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PNM; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PNM;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PPJ; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PPJ;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PPM; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PPM;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PSD; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PSD;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAS;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_3FR;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_ARW;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_CR2;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_DNG;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_K25;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_MRW;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_NEF;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_ORF;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_PEF;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_R3D; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_R3D;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_RAF; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_RAF;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAS;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_RW2; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_RW2;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_RWL; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_RWL;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_TIFF;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_X3F; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_X3F;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_TIFF;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_XBM; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_XBM;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_XPM; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_XPM;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_XWD; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_XWD;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.OK;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runners.Parameterized;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import com.google.common.collect.ImmutableList;
/** /**
* @author Cezar Leahu * @author Cezar Leahu
*/ */
@RunWith(Parameterized.class) public class ImageMagickTransformationIT {
public class ImageMagickTransformationIT
{
private static final Logger logger = LoggerFactory.getLogger(ImageMagickTransformationIT.class); private static final Logger logger = LoggerFactory.getLogger(ImageMagickTransformationIT.class);
private static final String ENGINE_URL = "http://localhost:8090"; private static final String ENGINE_URL = "http://localhost:8090";
private static final List<Pair<String,String>> targetExtensions = new ImmutableList.Builder<Pair<String,String>>() private static final List<Pair<String, String>> targetExtensions = new ImmutableList.Builder<Pair<String, String>>()
.add(Pair.of("3fr",MIMETYPE_IMAGE_RAW_3FR)) .add(Pair.of("3fr", MIMETYPE_IMAGE_RAW_3FR))
.add(Pair.of("arw",MIMETYPE_IMAGE_RAW_ARW)) .add(Pair.of("arw", MIMETYPE_IMAGE_RAW_ARW))
.add(Pair.of("bmp",MIMETYPE_IMAGE_BMP)) .add(Pair.of("bmp", MIMETYPE_IMAGE_BMP))
.add(Pair.of("cgm",MIMETYPE_IMAGE_CGM)) .add(Pair.of("cgm", MIMETYPE_IMAGE_CGM))
.add(Pair.of("cr2",MIMETYPE_IMAGE_RAW_CR2)) .add(Pair.of("cr2", MIMETYPE_IMAGE_RAW_CR2))
.add(Pair.of("dng",MIMETYPE_IMAGE_RAW_DNG)) .add(Pair.of("dng", MIMETYPE_IMAGE_RAW_DNG))
.add(Pair.of("eps",MIMETYPE_APPLICATION_EPS)) .add(Pair.of("eps", MIMETYPE_APPLICATION_EPS))
.add(Pair.of("gif",MIMETYPE_IMAGE_GIF)) .add(Pair.of("gif", MIMETYPE_IMAGE_GIF))
.add(Pair.of("ief",MIMETYPE_IMAGE_IEF)) .add(Pair.of("ief", MIMETYPE_IMAGE_IEF))
.add(Pair.of("jp2",MIMETYPE_IMAGE_JP2)) .add(Pair.of("jp2", MIMETYPE_IMAGE_JP2))
.add(Pair.of("jpg",MIMETYPE_IMAGE_JPEG)) .add(Pair.of("jpg", MIMETYPE_IMAGE_JPEG))
.add(Pair.of("k25",MIMETYPE_IMAGE_RAW_K25)) .add(Pair.of("k25", MIMETYPE_IMAGE_RAW_K25))
.add(Pair.of("mrw",MIMETYPE_IMAGE_RAW_MRW)) .add(Pair.of("mrw", MIMETYPE_IMAGE_RAW_MRW))
.add(Pair.of("nef",MIMETYPE_IMAGE_RAW_NEF)) .add(Pair.of("nef", MIMETYPE_IMAGE_RAW_NEF))
.add(Pair.of("orf",MIMETYPE_IMAGE_RAW_ORF)) .add(Pair.of("orf", MIMETYPE_IMAGE_RAW_ORF))
.add(Pair.of("pbm",MIMETYPE_IMAGE_PBM)) .add(Pair.of("pbm", MIMETYPE_IMAGE_PBM))
.add(Pair.of("pef",MIMETYPE_IMAGE_RAW_PEF)) .add(Pair.of("pef", MIMETYPE_IMAGE_RAW_PEF))
.add(Pair.of("pgm",MIMETYPE_IMAGE_PGM)) .add(Pair.of("pgm", MIMETYPE_IMAGE_PGM))
.add(Pair.of("png",MIMETYPE_IMAGE_PNG)) .add(Pair.of("png", MIMETYPE_IMAGE_PNG))
.add(Pair.of("pnm",MIMETYPE_IMAGE_PNM)) .add(Pair.of("pnm", MIMETYPE_IMAGE_PNM))
.add(Pair.of("ppj",MIMETYPE_IMAGE_PPJ)) .add(Pair.of("ppj", MIMETYPE_IMAGE_PPJ))
.add(Pair.of("ppm",MIMETYPE_IMAGE_PPM)) .add(Pair.of("ppm", MIMETYPE_IMAGE_PPM))
.add(Pair.of("r3d",MIMETYPE_IMAGE_RAW_R3D)) .add(Pair.of("r3d", MIMETYPE_IMAGE_RAW_R3D))
.add(Pair.of("raf",MIMETYPE_IMAGE_RAW_RAF)) .add(Pair.of("raf", MIMETYPE_IMAGE_RAW_RAF))
.add(Pair.of("ras",MIMETYPE_IMAGE_RAS)) .add(Pair.of("ras", MIMETYPE_IMAGE_RAS))
.add(Pair.of("rw2",MIMETYPE_IMAGE_RAW_RW2)) .add(Pair.of("rw2", MIMETYPE_IMAGE_RAW_RW2))
.add(Pair.of("rwl",MIMETYPE_IMAGE_RAW_RWL)) .add(Pair.of("rwl", MIMETYPE_IMAGE_RAW_RWL))
.add(Pair.of("tiff",MIMETYPE_IMAGE_TIFF)) .add(Pair.of("tiff", MIMETYPE_IMAGE_TIFF))
.add(Pair.of("x3f",MIMETYPE_IMAGE_RAW_X3F)) .add(Pair.of("x3f", MIMETYPE_IMAGE_RAW_X3F))
.add(Pair.of("xbm",MIMETYPE_IMAGE_XBM)) .add(Pair.of("xbm", MIMETYPE_IMAGE_XBM))
.add(Pair.of("xpm",MIMETYPE_IMAGE_XPM)) .add(Pair.of("xpm", MIMETYPE_IMAGE_XPM))
.add(Pair.of("xwd",MIMETYPE_IMAGE_XWD)) .add(Pair.of("xwd", MIMETYPE_IMAGE_XWD))
.build();
private static final List<Pair<String,String>> targetExtensionsForPSD = new ImmutableList.Builder<Pair<String,String>>()
.add(Pair.of("x3f",MIMETYPE_IMAGE_RAW_X3F))
.add(Pair.of("tiff",MIMETYPE_IMAGE_TIFF))
.add(Pair.of("rwl",MIMETYPE_IMAGE_RAW_RWL))
.add(Pair.of("rw2",MIMETYPE_IMAGE_RAW_RW2))
.add(Pair.of("ras",MIMETYPE_IMAGE_RAS))
.add(Pair.of("raf",MIMETYPE_IMAGE_RAW_RAF))
.add(Pair.of("r3d",MIMETYPE_IMAGE_RAW_R3D))
.add(Pair.of("psd",MIMETYPE_IMAGE_PSD))
.add(Pair.of("ppm",MIMETYPE_IMAGE_PPM))
.add(Pair.of("ppj",MIMETYPE_IMAGE_PPJ))
.add(Pair.of("pnm",MIMETYPE_IMAGE_PNM))
.add(Pair.of("pgm",MIMETYPE_IMAGE_PGM))
.add(Pair.of("pef",MIMETYPE_IMAGE_RAW_PEF))
.add(Pair.of("pbm",MIMETYPE_IMAGE_PBM))
.add(Pair.of("orf",MIMETYPE_IMAGE_RAW_ORF))
.add(Pair.of("nef",MIMETYPE_IMAGE_RAW_NEF))
.add(Pair.of("mrw",MIMETYPE_IMAGE_RAW_MRW))
.add(Pair.of("k25",MIMETYPE_IMAGE_RAW_K25))
.add(Pair.of("ief",MIMETYPE_IMAGE_IEF))
.add(Pair.of("gif",MIMETYPE_IMAGE_GIF))
.add(Pair.of("dng",MIMETYPE_IMAGE_RAW_DNG))
.add(Pair.of("cr2",MIMETYPE_IMAGE_RAW_CR2))
.add(Pair.of("arw",MIMETYPE_IMAGE_RAW_ARW))
.add(Pair.of("3fr",MIMETYPE_IMAGE_RAW_3FR))
.build(); .build();
private static final List<Pair<String,String>> targetExtensionsForTiffFirstPage = new ImmutableList.Builder<Pair<String,String>>() private static final List<Pair<String, String>> targetExtensionsForPSD = new ImmutableList.Builder<Pair<String, String>>()
.add(Pair.of("bmp",MIMETYPE_IMAGE_BMP)) .add(Pair.of("x3f", MIMETYPE_IMAGE_RAW_X3F))
.add(Pair.of("eps",MIMETYPE_APPLICATION_EPS)) .add(Pair.of("tiff", MIMETYPE_IMAGE_TIFF))
.add(Pair.of("jp2",MIMETYPE_IMAGE_JP2)) .add(Pair.of("rwl", MIMETYPE_IMAGE_RAW_RWL))
.add(Pair.of("jpg",MIMETYPE_IMAGE_JPEG)) .add(Pair.of("rw2", MIMETYPE_IMAGE_RAW_RW2))
.add(Pair.of("png",MIMETYPE_IMAGE_PNG)) .add(Pair.of("ras", MIMETYPE_IMAGE_RAS))
.add(Pair.of("xbm",MIMETYPE_IMAGE_XBM)) .add(Pair.of("raf", MIMETYPE_IMAGE_RAW_RAF))
.add(Pair.of("xpm",MIMETYPE_IMAGE_XPM)) .add(Pair.of("r3d", MIMETYPE_IMAGE_RAW_R3D))
.add(Pair.of("xwd",MIMETYPE_IMAGE_XWD)) .add(Pair.of("psd", MIMETYPE_IMAGE_PSD))
.add(Pair.of("ppm", MIMETYPE_IMAGE_PPM))
.add(Pair.of("ppj", MIMETYPE_IMAGE_PPJ))
.add(Pair.of("pnm", MIMETYPE_IMAGE_PNM))
.add(Pair.of("pgm", MIMETYPE_IMAGE_PGM))
.add(Pair.of("pef", MIMETYPE_IMAGE_RAW_PEF))
.add(Pair.of("pbm", MIMETYPE_IMAGE_PBM))
.add(Pair.of("orf", MIMETYPE_IMAGE_RAW_ORF))
.add(Pair.of("nef", MIMETYPE_IMAGE_RAW_NEF))
.add(Pair.of("mrw", MIMETYPE_IMAGE_RAW_MRW))
.add(Pair.of("k25", MIMETYPE_IMAGE_RAW_K25))
.add(Pair.of("ief", MIMETYPE_IMAGE_IEF))
.add(Pair.of("gif", MIMETYPE_IMAGE_GIF))
.add(Pair.of("dng", MIMETYPE_IMAGE_RAW_DNG))
.add(Pair.of("cr2", MIMETYPE_IMAGE_RAW_CR2))
.add(Pair.of("arw", MIMETYPE_IMAGE_RAW_ARW))
.add(Pair.of("3fr", MIMETYPE_IMAGE_RAW_3FR))
.build();
private static final List<Pair<String, String>> targetExtensionsForTiffFirstPage = new ImmutableList.Builder<Pair<String, String>>()
.add(Pair.of("bmp", MIMETYPE_IMAGE_BMP))
.add(Pair.of("eps", MIMETYPE_APPLICATION_EPS))
.add(Pair.of("jp2", MIMETYPE_IMAGE_JP2))
.add(Pair.of("jpg", MIMETYPE_IMAGE_JPEG))
.add(Pair.of("png", MIMETYPE_IMAGE_PNG))
.add(Pair.of("xbm", MIMETYPE_IMAGE_XBM))
.add(Pair.of("xpm", MIMETYPE_IMAGE_XPM))
.add(Pair.of("xwd", MIMETYPE_IMAGE_XWD))
.build(); .build();
private static final Map<String, TestFileInfo> TEST_FILES = Stream.of( private static final Map<String, TestFileInfo> TEST_FILES = Stream.of(
testFile(MIMETYPE_IMAGE_BMP,"bmp","quick.bmp"), testFile(MIMETYPE_IMAGE_BMP, "bmp", "quick.bmp"),
testFile(MIMETYPE_APPLICATION_EPS,"eps","quick.eps"), testFile(MIMETYPE_APPLICATION_EPS, "eps", "quick.eps"),
testFile(MIMETYPE_IMAGE_GIF,"gif","quick.gif"), testFile(MIMETYPE_IMAGE_GIF, "gif", "quick.gif"),
testFile(MIMETYPE_IMAGE_JPEG,"jpg","quick.jpg"), testFile(MIMETYPE_IMAGE_JPEG, "jpg", "quick.jpg"),
testFile(MIMETYPE_IMAGE_PBM,"pbm","quick.pbm"), testFile(MIMETYPE_IMAGE_PBM, "pbm", "quick.pbm"),
testFile(MIMETYPE_IMAGE_PGM,"pgm","quick.pgm"), testFile(MIMETYPE_IMAGE_PGM, "pgm", "quick.pgm"),
testFile(MIMETYPE_IMAGE_PNG,"png","quick.png"), testFile(MIMETYPE_IMAGE_PNG, "png", "quick.png"),
testFile(MIMETYPE_IMAGE_PNM,"pnm","quick.pnm"), testFile(MIMETYPE_IMAGE_PNM, "pnm", "quick.pnm"),
testFile(MIMETYPE_IMAGE_PPM,"ppm","quick.ppm"), testFile(MIMETYPE_IMAGE_PPM, "ppm", "quick.ppm"),
testFile(MIMETYPE_IMAGE_XBM,"xbm","quick.xbm"), testFile(MIMETYPE_IMAGE_XBM, "xbm", "quick.xbm"),
testFile(MIMETYPE_IMAGE_XPM,"xpm","quick.xpm"), testFile(MIMETYPE_IMAGE_XPM, "xpm", "quick.xpm"),
testFile(MIMETYPE_IMAGE_PSD,"psd","quick.psd"), testFile(MIMETYPE_IMAGE_PSD, "psd", "quick.psd"),
testFile(MIMETYPE_IMAGE_TIFF,"tiff","quick.tiff"), testFile(MIMETYPE_IMAGE_TIFF, "tiff", "quick.tiff"),
testFile(MIMETYPE_IMAGE_XWD,"xwd","quick.xwd") testFile(MIMETYPE_IMAGE_XWD, "xwd", "quick.xwd")
).collect(toMap(TestFileInfo::getPath, identity())); ).collect(toMap(TestFileInfo::getPath, identity()));
private final String sourceFile; public static Stream<Pair<TestFileInfo, Pair<String,String>>> engineTransformations() {
private final String targetExtension; return Stream
private final String sourceMimetype;
private final String targetMimetype;
public ImageMagickTransformationIT(final Pair<TestFileInfo, Pair<String,String>> entry)
{
sourceFile = entry.getLeft().getPath();
targetExtension = entry.getRight().getLeft();
sourceMimetype = entry.getLeft().getMimeType();
targetMimetype = entry.getRight().getRight();
}
@Parameterized.Parameters
public static Set<Pair<TestFileInfo, Pair<String,String>>> engineTransformations()
{
Set<Pair<TestFileInfo, Pair<String,String>>> resolved = null;
resolved = Stream
.of( .of(
allTargets("quick.bmp", targetExtensions), allTargets("quick.bmp", targetExtensions),
allTargets("quick.eps", targetExtensions), allTargets("quick.eps", targetExtensions),
@ -218,22 +197,25 @@ public class ImageMagickTransformationIT
allTargets("quick.xbm", targetExtensions), allTargets("quick.xbm", targetExtensions),
allTargets("quick.xpm", targetExtensions), allTargets("quick.xpm", targetExtensions),
allTargets("quick.xwd", targetExtensions) allTargets("quick.xwd", targetExtensions)
) ).flatMap(identity());
.flatMap(identity())
.collect(toSet());
return resolved;
} }
@Test @ParameterizedTest
public void testTransformation() @MethodSource("engineTransformations")
public void testTransformation(Pair<TestFileInfo, Pair<String, String>> entry)
{ {
String sourceFile = entry.getLeft().getPath();
String targetExtension = entry.getRight().getLeft();
String sourceMimetype = entry.getLeft().getMimeType();
String targetMimetype = entry.getRight().getRight();
final String descriptor = format("Transform ({0}, {1} -> {2}, {3})", final String descriptor = format("Transform ({0}, {1} -> {2}, {3})",
sourceFile, sourceMimetype, targetMimetype, targetExtension); sourceFile, sourceMimetype, targetMimetype, targetExtension);
try try
{ {
// note: some image/tiff->image/* will return multiple page results (hence error) unless options specified for single page // note: some image/tiff->image/* will return multiple page results (hence error) unless options specified for single page
Map<String, String> tOptions = emptyMap(); Map<String, String> tOptions = emptyMap();
Pair targetPair = Pair.of(targetExtension, targetMimetype); Pair<String,String> targetPair = Pair.of(targetExtension, targetMimetype);
if (MIMETYPE_IMAGE_TIFF.equals(sourceMimetype) && targetExtensionsForTiffFirstPage.contains(targetPair)) if (MIMETYPE_IMAGE_TIFF.equals(sourceMimetype) && targetExtensionsForTiffFirstPage.contains(targetPair))
{ {
tOptions = ImmutableMap.of("startPage", "0", "endPage", "0"); tOptions = ImmutableMap.of("startPage", "0", "endPage", "0");
@ -241,7 +223,7 @@ public class ImageMagickTransformationIT
final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile, sourceMimetype, final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile, sourceMimetype,
targetMimetype, targetExtension, tOptions); targetMimetype, targetExtension, tOptions);
assertEquals(descriptor, OK, response.getStatusCode()); assertEquals(OK, response.getStatusCode(), descriptor);
} }
catch (Exception e) catch (Exception e)
{ {
@ -256,4 +238,5 @@ public class ImageMagickTransformationIT
.map(k -> Pair.of(TEST_FILES.get(sourceFile), k)); .map(k -> Pair.of(TEST_FILES.get(sourceFile), k));
} }
} }

View File

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

View File

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

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,14 +26,11 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* Tests LibreOfficeController with a server test harness. * Tests LibreOfficeController with a server test harness.
*/ */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class LibreOfficeHttpRequestTest extends AbstractHttpRequestTest public class LibreOfficeHttpRequestTest extends AbstractHttpRequestTest
{ {

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * 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 java.util.UUID;
import org.alfresco.transform.client.model.TransformRequest; import org.alfresco.transform.client.model.TransformRequest;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* @author Lucian Tuca * @author Lucian Tuca
* created on 15/01/2019 * created on 15/01/2019
*/ */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {"activemq.url=nio://localhost:61616"}) properties = {"activemq.url=nio://localhost:61616"})
public class LibreOfficeQueueTransformServiceIT extends AbstractQueueTransformServiceIT public class LibreOfficeQueueTransformServiceIT extends AbstractQueueTransformServiceIT

View File

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

View File

@ -57,11 +57,6 @@
<groupId>org.dom4j</groupId> <groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId> <artifactId>dom4j</artifactId>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -35,9 +35,9 @@ import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_OPENXML_WORD
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_PDF; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_PDF;
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_RFC822; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_RFC822;
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.OK;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -49,18 +49,17 @@ import java.nio.file.Files;
import org.alfresco.transform.client.model.TransformRequest; import org.alfresco.transform.client.model.TransformRequest;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper; import org.apache.pdfbox.text.PDFTextStripper;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
@RunWith(SpringRunner.class) // Specifying class for @WebMvcTest() will break AIO tests, without specifying it will use all controllers in the application context,
@WebMvcTest(MiscController.class) // currently only MiscController.class
@WebMvcTest()
public class MiscControllerTest extends AbstractTransformerControllerTest public class MiscControllerTest extends AbstractTransformerControllerTest
{ {
@Autowired @Autowired
@ -72,7 +71,7 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
protected static final String ENGINE_CONFIG_NAME = "misc_engine_config.json"; protected static final String ENGINE_CONFIG_NAME = "misc_engine_config.json";
@Before @BeforeEach
public void before() throws Exception public void before() throws Exception
{ {
sourceMimetype = MIMETYPE_HTML; sourceMimetype = MIMETYPE_HTML;
@ -152,8 +151,8 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
null, null,
null, null,
readTestFile("eml")); readTestFile("eml"));
assertTrue("Content from eml transform didn't contain expected value. ", assertTrue(result.getResponse().getContentAsString().contains(expected),
result.getResponse().getContentAsString().contains(expected)); "Content from eml transform didn't contain expected value. ");
} }
/** /**
@ -173,8 +172,8 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
null, readTestFile("spanish.eml")); null, readTestFile("spanish.eml"));
String contentResult = new String(result.getResponse().getContentAsByteArray(), UTF_8); String contentResult = new String(result.getResponse().getContentAsByteArray(), UTF_8);
assertTrue("Content from eml transform didn't contain expected value. ", assertTrue(contentResult.contains(expected),
contentResult.contains(expected)); "Content from eml transform didn't contain expected value. ");
} }
/** /**
@ -194,8 +193,8 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
null, null,
null, null,
readTestFile("attachment.eml")); readTestFile("attachment.eml"));
assertTrue("Content from eml transform didn't contain expected value. ", assertTrue(result.getResponse().getContentAsString().contains(expected),
result.getResponse().getContentAsString().contains(expected)); "Content from eml transform didn't contain expected value. ");
assertFalse(result.getResponse().getContentAsString().contains(notExpected)); assertFalse(result.getResponse().getContentAsString().contains(notExpected));
} }
@ -215,8 +214,8 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
null, null,
null, null,
readTestFile("alternative.eml")); readTestFile("alternative.eml"));
assertTrue("Content from eml transform didn't contain expected value. ", assertTrue(result.getResponse().getContentAsString().contains(expected),
result.getResponse().getContentAsString().contains(expected)); "Content from eml transform didn't contain expected value. ");
} }
/** /**
@ -235,8 +234,8 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
null, null,
null, null,
readTestFile("nested.alternative.eml")); readTestFile("nested.alternative.eml"));
assertTrue("Content from eml transform didn't contain expected value. ", assertTrue(result.getResponse().getContentAsString().contains(expected),
result.getResponse().getContentAsString().contains(expected)); "Content from eml transform didn't contain expected value. ");
} }
/** /**
@ -269,7 +268,7 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
null, null,
readTestFile("eml")); readTestFile("eml"));
String metadata = result.getResponse().getContentAsString(); String metadata = result.getResponse().getContentAsString();
assertEquals("Metadata extract", expected, metadata); assertEquals(expected, metadata, "Metadata extract");
} }
/** /**
@ -301,7 +300,7 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
extractMapping, extractMapping,
readTestFile("eml")); readTestFile("eml"));
String metadata = result.getResponse().getContentAsString(); String metadata = result.getResponse().getContentAsString();
assertEquals("Option metadata extract", expected, metadata); assertEquals(expected, metadata, "Option metadata extract");
} }
/** /**
@ -350,7 +349,7 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
String contentResult = new String(result.getResponse().getContentAsByteArray(), String contentResult = new String(result.getResponse().getContentAsByteArray(),
targetEncoding); targetEncoding);
assertTrue("The content did not include \"" + expected, contentResult.contains(expected)); assertTrue(contentResult.contains(expected), "The content did not include \"" + expected);
} }
@Test @Test
@ -380,7 +379,7 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
String contentResult = new String(result.getResponse().getContentAsByteArray(), String contentResult = new String(result.getResponse().getContentAsByteArray(),
targetEncoding); targetEncoding);
assertTrue("The content did not include \"" + expected, contentResult.contains(expected)); assertTrue(contentResult.contains(expected), "The content did not include \"" + expected);
} }
@Test @Test
@ -399,8 +398,8 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
null, null,
content); content);
assertEquals("Returned content should be empty for an empty source file", 0, assertEquals(0, result.getResponse().getContentLength(),
result.getResponse().getContentLength()); "Returned content should be empty for an empty source file");
} }
@Test @Test
@ -435,7 +434,7 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
expected = clean(expected); expected = clean(expected);
String actual = clean(textWriter.toString()); String actual = clean(textWriter.toString());
assertEquals("The content did not match.", expected, actual); assertEquals(expected, actual, "The content did not match.");
} }
@Test @Test
@ -443,8 +442,8 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
{ {
MvcResult result = sendRequest("numbers", null, MIMETYPE_IWORK_NUMBERS, MvcResult result = sendRequest("numbers", null, MIMETYPE_IWORK_NUMBERS,
"jpeg", MIMETYPE_IMAGE_JPEG, null, null, null, readTestFile("pages")); "jpeg", MIMETYPE_IMAGE_JPEG, null, null, null, readTestFile("pages"));
assertTrue("Expected image content but content is empty.", assertTrue(result.getResponse().getContentLengthLong() > 0L,
result.getResponse().getContentLengthLong() > 0L); "Expected image content but content is empty.");
} }
@Test @Test
@ -452,8 +451,8 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
{ {
MvcResult result = sendRequest("numbers", null, MIMETYPE_IWORK_NUMBERS, MvcResult result = sendRequest("numbers", null, MIMETYPE_IWORK_NUMBERS,
"jpeg", MIMETYPE_IMAGE_JPEG, null, null, null, readTestFile("numbers")); "jpeg", MIMETYPE_IMAGE_JPEG, null, null, null, readTestFile("numbers"));
assertTrue("Expected image content but content is empty.", assertTrue(result.getResponse().getContentLengthLong() > 0L,
result.getResponse().getContentLengthLong() > 0L); "Expected image content but content is empty.");
} }
@Test @Test
@ -461,8 +460,8 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
{ {
MvcResult result = sendRequest("key", null, MIMETYPE_IWORK_KEYNOTE, MvcResult result = sendRequest("key", null, MIMETYPE_IWORK_KEYNOTE,
"jpeg", MIMETYPE_IMAGE_JPEG, null, null, null, readTestFile("key")); "jpeg", MIMETYPE_IMAGE_JPEG, null, null, null, readTestFile("key"));
assertTrue("Expected image content but content is empty.", assertTrue(result.getResponse().getContentLengthLong() > 0L,
result.getResponse().getContentLengthLong() > 0L); "Expected image content but content is empty.");
} }
// @Test // @Test
@ -471,8 +470,8 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
{ {
MvcResult result = sendRequest("docx", null, MIMETYPE_OPENXML_WORDPROCESSING, MvcResult result = sendRequest("docx", null, MIMETYPE_OPENXML_WORDPROCESSING,
"jpeg", MIMETYPE_IMAGE_JPEG, null, null, null, readTestFile("docx")); "jpeg", MIMETYPE_IMAGE_JPEG, null, null, null, readTestFile("docx"));
assertTrue("Expected image content but content is empty.", assertTrue(result.getResponse().getContentLengthLong() > 0L,
result.getResponse().getContentLengthLong() > 0L); "Expected image content but content is empty.");
} }
private MvcResult sendRequest(String sourceExtension, private MvcResult sendRequest(String sourceExtension,

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,38 +26,38 @@
*/ */
package org.alfresco.transformer; 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_HTML; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML;
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_RFC822; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_RFC822;
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_XHTML; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_XHTML;
import static org.alfresco.transformer.TestFileInfo.testFile; import static org.alfresco.transformer.TestFileInfo.testFile;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
/** /**
* Metadata integration tests in the Misc T-Engine. * Metadata integration tests in the Misc T-Engine.
* *
* @author adavis * @author adavis
* @author dedwards
*/ */
@RunWith(Parameterized.class)
public class MiscMetadataExtractsIT extends AbstractMetadataExtractsIT public class MiscMetadataExtractsIT extends AbstractMetadataExtractsIT
{ {
public MiscMetadataExtractsIT(TestFileInfo testFileInfo)
@ParameterizedTest
@MethodSource("engineTransformations")
@Override
public void testTransformation(TestFileInfo testFileInfo)
{ {
super(testFileInfo); super.testTransformation(testFileInfo);
} }
@Parameterized.Parameters private static Stream<TestFileInfo> engineTransformations()
public static List<TestFileInfo> engineTransformations()
{ {
return Stream.of( return Stream.of(
// HtmlMetadataExtractor // HtmlMetadataExtractor
testFile(MIMETYPE_HTML, "html", "quick.html"), testFile(MIMETYPE_HTML, "html", "quick.html"), testFile(MIMETYPE_XHTML, "xhtml", "quick.xhtml.alf"), // avoid the license header check on xhtml
testFile(MIMETYPE_XHTML, "xhtml", "quick.xhtml.alf"), // avoid the license header check on xhtml
// RFC822MetadataExtractor // RFC822MetadataExtractor
testFile(MIMETYPE_RFC822, "eml", "quick.eml"), testFile(MIMETYPE_RFC822, "eml", "quick.eml"),
@ -67,6 +67,6 @@ public class MiscMetadataExtractsIT extends AbstractMetadataExtractsIT
testFile(MIMETYPE_RFC822, "eml", "quick.spanish.eml"), testFile(MIMETYPE_RFC822, "eml", "quick.spanish.eml"),
testFile(MIMETYPE_HTML, "html", "quick.japanese.html") testFile(MIMETYPE_HTML, "html", "quick.japanese.html")
).collect(toList()); );
} }
} }

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -32,11 +32,8 @@ import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
import java.util.UUID; import java.util.UUID;
import org.alfresco.transform.client.model.TransformRequest; import org.alfresco.transform.client.model.TransformRequest;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {"activemq.url=nio://localhost:61616"}) properties = {"activemq.url=nio://localhost:61616"})
public class MiscQueueTransformServiceIT extends AbstractQueueTransformServiceIT public class MiscQueueTransformServiceIT extends AbstractQueueTransformServiceIT

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,11 +26,11 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class) /**
* Tests MiscController with a server test harness.
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class MiscTransformerHttpRequestTest extends AbstractHttpRequestTest public class MiscTransformerHttpRequestTest extends AbstractHttpRequestTest
{ {

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * 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.text.MessageFormat.format;
import static java.util.function.Function.identity; import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap; import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.toSet;
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_DITA; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_DITA;
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_EXCEL; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_EXCEL;
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML;
@ -57,17 +56,15 @@ import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_WORD;
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_XML; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_XML;
import static org.alfresco.transformer.EngineClient.sendTRequest; import static org.alfresco.transformer.EngineClient.sendTRequest;
import static org.alfresco.transformer.TestFileInfo.testFile; import static org.alfresco.transformer.TestFileInfo.testFile;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.OK;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runners.Parameterized;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
@ -76,7 +73,6 @@ import org.springframework.http.ResponseEntity;
/** /**
* @author Cezar Leahu * @author Cezar Leahu
*/ */
@RunWith(Parameterized.class)
public class MiscTransformsIT public class MiscTransformsIT
{ {
private static final Logger logger = LoggerFactory.getLogger(MiscTransformsIT.class); private static final Logger logger = LoggerFactory.getLogger(MiscTransformsIT.class);
@ -120,17 +116,7 @@ public class MiscTransformsIT
testFile(MIMETYPE_RFC822, "eml", "quick.eml") testFile(MIMETYPE_RFC822, "eml", "quick.eml")
).collect(toMap(TestFileInfo::getMimeType, identity())); ).collect(toMap(TestFileInfo::getMimeType, identity()));
private final String sourceMimetype; public static Stream<SourceTarget> engineTransformations()
private final String targetMimetype;
public MiscTransformsIT(final SourceTarget sourceTarget)
{
sourceMimetype = sourceTarget.source;
targetMimetype = sourceTarget.target;
}
@Parameterized.Parameters
public static Set<SourceTarget> engineTransformations()
{ {
return Stream.of( return Stream.of(
SourceTarget.of("text/html", "text/plain"), //duplicate SourceTarget.of("text/html", "text/plain"), //duplicate
@ -162,12 +148,15 @@ public class MiscTransformsIT
SourceTarget.of("text/xml", "application/pdf"), SourceTarget.of("text/xml", "application/pdf"),
SourceTarget.of("message/rfc822", "text/plain") SourceTarget.of("message/rfc822", "text/plain")
).collect(toSet()); );
} }
@Test @ParameterizedTest
public void testTransformation() @MethodSource("engineTransformations")
public void testTransformation(SourceTarget sourceTarget)
{ {
final String sourceMimetype = sourceTarget.source;
final String targetMimetype = sourceTarget.target;
final String sourceFile = TEST_FILES.get(sourceMimetype).getPath(); final String sourceFile = TEST_FILES.get(sourceMimetype).getPath();
final String targetExtension = TEST_FILES.get(targetMimetype).getExtension(); final String targetExtension = TEST_FILES.get(targetMimetype).getExtension();
@ -178,7 +167,7 @@ public class MiscTransformsIT
{ {
final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile, final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile,
sourceMimetype, targetMimetype, targetExtension); sourceMimetype, targetMimetype, targetExtension);
assertEquals(descriptor, OK, response.getStatusCode()); assertEquals(OK, response.getStatusCode(), descriptor);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -71,9 +71,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<version>4.13</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -26,7 +26,7 @@
*/ */
package org.alfresco.transformer.transformers; package org.alfresco.transformer.transformers;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -36,7 +36,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.alfresco.transformer.transformers.StringExtractingContentTransformer.SOURCE_ENCODING; import static org.alfresco.transformer.transformers.StringExtractingContentTransformer.SOURCE_ENCODING;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class HtmlParserContentTransformerTest public class HtmlParserContentTransformerTest
{ {

View File

@ -28,8 +28,8 @@ package org.alfresco.transformer.transformers;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper; import org.apache.pdfbox.text.PDFTextStripper;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -39,13 +39,13 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.alfresco.transformer.util.RequestParamMap.PAGE_LIMIT; import static org.alfresco.transformer.util.RequestParamMap.PAGE_LIMIT;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class TextToPdfContentTransformerTest public class TextToPdfContentTransformerTest
{ {
TextToPdfContentTransformer transformer = new TextToPdfContentTransformer(); TextToPdfContentTransformer transformer = new TextToPdfContentTransformer();
@Before @BeforeEach
public void setUp() public void setUp()
{ {
transformer.setStandardFont("Times-Roman"); transformer.setStandardFont("Times-Roman");
@ -121,8 +121,8 @@ public class TextToPdfContentTransformerTest
String roundTrip = clean(textWriter.toString()); String roundTrip = clean(textWriter.toString());
assertEquals( assertEquals(
"Incorrect text in PDF when starting from text in " + encoding, checkText, roundTrip,
checkText, roundTrip "Incorrect text in PDF when starting from text in " + encoding
); );
sourceFile.delete(); sourceFile.delete();

View File

@ -57,11 +57,6 @@
<groupId>org.dom4j</groupId> <groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId> <artifactId>dom4j</artifactId>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,11 +26,10 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import static org.alfresco.transformer.executors.RuntimeExec.ExecutionResult;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -56,15 +55,17 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import javax.annotation.PostConstruct;
import org.alfresco.transform.client.model.TransformReply; import org.alfresco.transform.client.model.TransformReply;
import org.alfresco.transform.client.model.TransformRequest; import org.alfresco.transform.client.model.TransformRequest;
import org.alfresco.transformer.executors.PdfRendererCommandExecutor; import org.alfresco.transformer.executors.PdfRendererCommandExecutor;
import org.alfresco.transformer.executors.RuntimeExec; import org.alfresco.transformer.executors.RuntimeExec;
import org.alfresco.transformer.executors.RuntimeExec.ExecutionResult;
import org.alfresco.transformer.model.FileRefEntity; import org.alfresco.transformer.model.FileRefEntity;
import org.alfresco.transformer.model.FileRefResponse; import org.alfresco.transformer.model.FileRefResponse;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -75,18 +76,16 @@ import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import javax.annotation.PostConstruct;
/** /**
* Test the AlfrescoPdfRendererController without a server. * Test the AlfrescoPdfRendererController without a server.
* Super class includes tests for the AbstractTransformerController. * Super class includes tests for the AbstractTransformerController.
*/ */
@RunWith(SpringRunner.class) // Specifying class for @WebMvcTest() will break AIO tests, without specifying it will use all controllers in the application context,
@WebMvcTest(AlfrescoPdfRendererController.class) // currently only AlfrescoPdfRendererController.class
@WebMvcTest()
public class AlfrescoPdfRendererControllerTest extends AbstractTransformerControllerTest public class AlfrescoPdfRendererControllerTest extends AbstractTransformerControllerTest
{ {
@ -115,7 +114,7 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
@Autowired @Autowired
protected AbstractTransformerController controller; protected AbstractTransformerController controller;
@Before @BeforeEach
public void before() throws IOException public void before() throws IOException
{ {
setFields(); setFields();
@ -156,7 +155,7 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
when(mockTransformCommand.execute(any(), anyLong())).thenAnswer( when(mockTransformCommand.execute(any(), anyLong())).thenAnswer(
(Answer<RuntimeExec.ExecutionResult>) invocation -> { (Answer<RuntimeExec.ExecutionResult>) invocation -> {
Map<String, String> actualProperties = invocation.getArgument(0); 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 actualOptions = actualProperties.get("options");
String actualSource = actualProperties.get("source"); String actualSource = actualProperties.get("source");
@ -167,9 +166,9 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
assertNotNull(actualTarget); assertNotNull(actualTarget);
if (expectedSourceSuffix != null) if (expectedSourceSuffix != null)
{ {
assertTrue("The source file \"" + actualSource + assertTrue(actualSource.endsWith(expectedSourceSuffix),
"\" should have ended in \"" + expectedSourceSuffix + "\"", "The source file \"" + actualSource +
actualSource.endsWith(expectedSourceSuffix)); "\" should have ended in \"" + expectedSourceSuffix + "\"");
actualSource = actualSource.substring(0, actualSource = actualSource.substring(0,
actualSource.length() - expectedSourceSuffix.length()); actualSource.length() - expectedSourceSuffix.length());
} }
@ -177,14 +176,14 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
assertNotNull(actualOptions); assertNotNull(actualOptions);
if (expectedOptions != null) if (expectedOptions != null)
{ {
assertEquals("expectedOptions", expectedOptions, actualOptions); assertEquals(expectedOptions, actualOptions,"expectedOptions");
} }
Long actualTimeout = invocation.getArgument(1); Long actualTimeout = invocation.getArgument(1);
assertNotNull(actualTimeout); assertNotNull(actualTimeout);
if (expectedTimeout != null) if (expectedTimeout != null)
{ {
assertEquals("expectedTimeout", expectedTimeout, actualTimeout); assertEquals(expectedTimeout, actualTimeout,"expectedTimeout");
} }
// Copy a test file into the target file location if it exists // Copy a test file into the target file location if it exists
@ -200,8 +199,8 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
// Check the supplied source file has not been changed. // Check the supplied source file has not been changed.
byte[] actualSourceFileBytes = Files.readAllBytes(new File(actualSource).toPath()); byte[] actualSourceFileBytes = Files.readAllBytes(new File(actualSource).toPath());
assertTrue("Source file is not the same", assertTrue(Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes),
Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes)); "Source file is not the same");
return mockExecutionResult; return mockExecutionResult;
}); });

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,15 +26,12 @@
*/ */
package org.alfresco.transformer; package org.alfresco.transformer;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* Tests AlfrescoPdfRendererController with a server test harness. * Tests AlfrescoPdfRendererController with a server test harness.
*/ */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class AlfrescoPdfRendererHttpRequestTest extends AbstractHttpRequestTest public class AlfrescoPdfRendererHttpRequestTest extends AbstractHttpRequestTest
{ {

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -32,15 +32,12 @@ import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_PDF;
import java.util.UUID; import java.util.UUID;
import org.alfresco.transform.client.model.TransformRequest; import org.alfresco.transform.client.model.TransformRequest;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* @author Lucian Tuca * @author Lucian Tuca
* created on 15/01/2019 * created on 15/01/2019
*/ */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {"activemq.url=nio://localhost:61616"}) properties = {"activemq.url=nio://localhost:61616"})
public class AlfrescoPdfRendererQueueTransformServiceIT extends AbstractQueueTransformServiceIT public class AlfrescoPdfRendererQueueTransformServiceIT extends AbstractQueueTransformServiceIT

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -31,28 +31,23 @@ import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap; import static java.util.stream.Collectors.toMap;
import static org.alfresco.transformer.EngineClient.sendTRequest; import static org.alfresco.transformer.EngineClient.sendTRequest;
import static org.alfresco.transformer.TestFileInfo.testFile; import static org.alfresco.transformer.TestFileInfo.testFile;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.OK;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runners.Parameterized;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import com.google.common.collect.ImmutableSet;
/** /**
* @author Cezar Leahu * @author Cezar Leahu
*/ */
@RunWith(Parameterized.class)
public class AlfrescoPdfRendererTransformationIT public class AlfrescoPdfRendererTransformationIT
{ {
private static final Logger logger = LoggerFactory.getLogger( private static final Logger logger = LoggerFactory.getLogger(
@ -65,28 +60,21 @@ public class AlfrescoPdfRendererTransformationIT
testFile("application/illustrator","ai","quickCS5.ai") testFile("application/illustrator","ai","quickCS5.ai")
).collect(toMap(TestFileInfo::getPath, identity())); ).collect(toMap(TestFileInfo::getPath, identity()));
private final String sourceFile; public static Stream<String> engineTransformations()
private final String sourceMimetype;
public AlfrescoPdfRendererTransformationIT(String sourceFile)
{ {
this.sourceFile = sourceFile; return Stream.of(
this.sourceMimetype = TEST_FILES.get(sourceFile).getMimeType();
}
@Parameterized.Parameters
public static Set<String> engineTransformations()
{
return ImmutableSet.of(
"quick.pdf", "quick.pdf",
"quickCS3.ai", "quickCS3.ai",
"quickCS5.ai" "quickCS5.ai"
); );
} }
@Test @ParameterizedTest
public void testTransformation() @MethodSource("engineTransformations")
public void testTransformation(String sourceFile)
{ {
final String sourceMimetype = TEST_FILES.get(sourceFile).getMimeType();
final String descriptor = format("Transform ({0}, {1} -> {2}, {3})", final String descriptor = format("Transform ({0}, {1} -> {2}, {3})",
sourceFile, sourceMimetype, "image/png", "png"); sourceFile, sourceMimetype, "image/png", "png");
@ -94,7 +82,7 @@ public class AlfrescoPdfRendererTransformationIT
{ {
final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile, sourceMimetype, final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile, sourceMimetype,
"image/png", "png"); "image/png", "png");
assertEquals(descriptor, OK, response.getStatusCode()); assertEquals(OK, response.getStatusCode(),descriptor);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -137,13 +137,6 @@
<groupId>org.apache.pdfbox</groupId> <groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox-tools</artifactId> <artifactId>pdfbox-tools</artifactId>
</dependency> </dependency>
<!-- Test dependenciues -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -26,40 +26,6 @@
*/ */
package org.alfresco.transformer; 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 java.nio.file.Files.readAllBytes;
import static org.alfresco.transformer.executors.Tika.ARCHIVE; import static org.alfresco.transformer.executors.Tika.ARCHIVE;
import static org.alfresco.transformer.executors.Tika.CSV; 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.MimetypeMap.MIMETYPE_ZIP;
import static org.alfresco.transformer.util.RequestParamMap.INCLUDE_CONTENTS; import static org.alfresco.transformer.util.RequestParamMap.INCLUDE_CONTENTS;
import static org.alfresco.transformer.util.RequestParamMap.NOT_EXTRACT_BOOKMARK_TEXT; import static org.alfresco.transformer.util.RequestParamMap.NOT_EXTRACT_BOOKMARK_TEXT;
import static org.junit.Assert.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when; 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.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.util.StringUtils.getFilenameExtension; 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. * Test the TikaController without a server.
* Super class includes tests for the AbstractTransformerController. * Super class includes tests for the AbstractTransformerController.
*/ */
@RunWith(SpringRunner.class) // Specifying class for @WebMvcTest() will break AIO tests, without specifying it will use all controllers in the application context,
@WebMvcTest(TikaController.class) // currently only TikaController.class
@WebMvcTest()
public class TikaControllerTest extends AbstractTransformerControllerTest public class TikaControllerTest extends AbstractTransformerControllerTest
{ {
private static final String ENGINE_CONFIG_NAME = "tika_engine_config.json"; 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 targetEncoding = "UTF-8";
private String targetMimetype = MIMETYPE_TEXT_PLAIN; private String targetMimetype = MIMETYPE_TEXT_PLAIN;
@Before @BeforeEach
public void before() public void before()
{ {
sourceExtension = "pdf"; sourceExtension = "pdf";
@ -180,7 +180,7 @@ public class TikaControllerTest extends AbstractTransformerControllerTest
when(mockTransformCommand.execute(any(), anyLong())).thenAnswer( when(mockTransformCommand.execute(any(), anyLong())).thenAnswer(
(Answer<RuntimeExec.ExecutionResult>) invocation -> { (Answer<RuntimeExec.ExecutionResult>) invocation -> {
Map<String, String> actualProperties = invocation.getArgument(0); 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 actualOptions = actualProperties.get("options");
String actualSource = actualProperties.get("source"); String actualSource = actualProperties.get("source");
@ -191,9 +191,8 @@ public class TikaControllerTest extends AbstractTransformerControllerTest
assertNotNull(actualTarget); assertNotNull(actualTarget);
if (expectedSourceSuffix != null) if (expectedSourceSuffix != null)
{ {
assertTrue( assertTrue(actualSource.endsWith(expectedSourceSuffix),
"The source file \"" + actualSource + "\" should have ended in \"" + expectedSourceSuffix + "\"", "The source file \"" + actualSource + "\" should have ended in \"" + expectedSourceSuffix + "\"");
actualSource.endsWith(expectedSourceSuffix));
actualSource = actualSource.substring(0, actualSource = actualSource.substring(0,
actualSource.length() - expectedSourceSuffix.length()); actualSource.length() - expectedSourceSuffix.length());
} }
@ -201,14 +200,14 @@ public class TikaControllerTest extends AbstractTransformerControllerTest
assertNotNull(actualOptions); assertNotNull(actualOptions);
if (expectedOptions != null) if (expectedOptions != null)
{ {
assertEquals("expectedOptions", expectedOptions, actualOptions); assertEquals(expectedOptions, actualOptions, "expectedOptions");
} }
Long actualTimeout = invocation.getArgument(1); Long actualTimeout = invocation.getArgument(1);
assertNotNull(actualTimeout); assertNotNull(actualTimeout);
if (expectedTimeout != null) if (expectedTimeout != null)
{ {
assertEquals("expectedTimeout", expectedTimeout, actualTimeout); assertEquals(expectedTimeout, actualTimeout, "expectedTimeout");
} }
// Copy a test file into the target file location if it exists // 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. // Check the supplied source file has not been changed.
byte[] actualSourceFileBytes = readAllBytes(new File(actualSource).toPath()); byte[] actualSourceFileBytes = readAllBytes(new File(actualSource).toPath());
assertArrayEquals("Source file is not the same", expectedSourceFileBytes, assertArrayEquals(expectedSourceFileBytes, actualSourceFileBytes,
actualSourceFileBytes); "Source file is not the same");
return mockExecutionResult; return mockExecutionResult;
}); });
@ -261,8 +260,8 @@ public class TikaControllerTest extends AbstractTransformerControllerTest
"attachment; filename*= UTF-8''quick." + this.targetExtension)). "attachment; filename*= UTF-8''quick." + this.targetExtension)).
andReturn(); andReturn();
String content = result.getResponse().getContentAsString(); String content = result.getResponse().getContentAsString();
assertTrue("The content did not include \"" + expectedContentContains, assertTrue(content.contains(expectedContentContains),
content.contains(expectedContentContains)); "The content did not include \"" + expectedContentContains);
} }
@Override @Override

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * 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 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;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
/** /**
* Tests TikaController with a server test harness. * Tests TikaController with a server test harness.
*/ */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class TikaHttpRequestTest extends AbstractHttpRequestTest public class TikaHttpRequestTest extends AbstractHttpRequestTest
{ {

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,13 +26,6 @@
*/ */
package org.alfresco.transformer; 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_APP_DWG;
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_OUTLOOK_MSG; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_OUTLOOK_MSG;
import static org.alfresco.transformer.TestFileInfo.testFile; 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_XML;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_ZIP; 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. * Metadata integration tests in the Tika T-Engine.
* *
* @author adavis * @author adavis
* @author dedwards
*/ */
@RunWith(Parameterized.class)
public class TikaMetadataExtractsIT extends AbstractMetadataExtractsIT 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 private static Stream<TestFileInfo> engineTransformations()
public static List<TestFileInfo> engineTransformations()
{ {
// The following files are the ones tested in the content repository. // The following files are the ones tested in the content repository.
// There are many more mimetypes supported by these extractors. // 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 // cause OutOfMemory in Tika Note - doesn't use extractFromMimetype
testFile(MIMETYPE_OPENXML_SPREADSHEET, "xlsx", "dmsu1332-reproduced.xlsx") testFile(MIMETYPE_OPENXML_SPREADSHEET, "xlsx", "dmsu1332-reproduced.xlsx")
).collect(toList()); );
} }
} }

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * 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 java.util.UUID;
import org.alfresco.transform.client.model.TransformRequest; import org.alfresco.transform.client.model.TransformRequest;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* @author Lucian Tuca * @author Lucian Tuca
* created on 15/01/2019 * created on 15/01/2019
*/ */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {"activemq.url=nio://localhost:61616"}) properties = {"activemq.url=nio://localhost:61616"})
public class TikaQueueTransformServiceIT extends AbstractQueueTransformServiceIT public class TikaQueueTransformServiceIT extends AbstractQueueTransformServiceIT

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * 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.text.MessageFormat.format;
import static java.util.function.Function.identity; import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toSet;
import static org.alfresco.transformer.EngineClient.sendTRequest; import static org.alfresco.transformer.EngineClient.sendTRequest;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.OK;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.tuple.Triple; import org.apache.commons.lang3.tuple.Triple;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runners.Parameterized;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import com.google.common.collect.ImmutableMap;
/** /**
* @author Cezar Leahu * @author Cezar Leahu
*/ */
@RunWith(Parameterized.class)
public class TikaTransformationIT public class TikaTransformationIT
{ {
private static final Logger logger = LoggerFactory.getLogger(TikaTransformationIT.class); private static final Logger logger = LoggerFactory.getLogger(TikaTransformationIT.class);
@ -63,15 +59,16 @@ public class TikaTransformationIT
"xhtml", "application/xhtml+xml", "xhtml", "application/xhtml+xml",
"xml", "text/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(); final String sourceFile = entry.getLeft();
targetExtension = entry.getMiddle(); final String sourceMimetype = entry.getRight();
final String targetExtension = entry.getMiddle();
String targetMimetype;
//Single test to cover pdf-->csv //Single test to cover pdf-->csv
if (sourceFile.contains("pdf") && targetExtension.contains("csv")) if (sourceFile.contains("pdf") && targetExtension.contains("csv"))
{ {
@ -81,7 +78,31 @@ public class TikaTransformationIT
{ {
targetMimetype = extensionMimetype.get(entry.getMiddle()); 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): // 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) // *.cpio (application/x-cpio)
// *.cdf (application/x-netcdf) // *.cdf (application/x-netcdf)
// *.hdf (application/x-hdf) // *.hdf (application/x-hdf)
public static Stream<Triple<String, String, String>> engineTransformations()
@Parameterized.Parameters
public static Set<Triple<String, String, String>> engineTransformations()
{ {
return Stream return Stream
.of( .of(
@ -152,35 +171,6 @@ public class TikaTransformationIT
allTargets("quick.z", "application/x-compress"), allTargets("quick.z", "application/x-compress"),
allTargets("quick.csv", "text/csv"), allTargets("quick.csv", "text/csv"),
allTargets("quick.tar.gz", "application/x-gzip")) allTargets("quick.tar.gz", "application/x-gzip"))
.flatMap(identity()) .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));
} }
} }

View File

@ -47,6 +47,10 @@
<groupId>org.quartz-scheduler</groupId> <groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId> <artifactId>quartz</artifactId>
</exclusion> </exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions> </exclusions>
</dependency> </dependency>

View File

@ -74,11 +74,6 @@
<artifactId>google-collections</artifactId> <artifactId>google-collections</artifactId>
<version>1.0</version> <version>1.0</version>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * 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. * This file is part of the Alfresco software.
* - * -
@ -26,12 +26,12 @@
*/ */
package org.alfresco.transformer; 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.HttpMethod.POST;
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA; import static org.springframework.http.MediaType.MULTIPART_FORM_DATA;
import static org.springframework.test.util.AssertionErrors.assertTrue; 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.beans.factory.annotation.Autowired;
import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.web.server.LocalServerPort;

View File

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

View File

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

View File

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

View File

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