diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/pom.xml b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/pom.xml index 7a7729245..64a5a3f63 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/pom.xml +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/pom.xml @@ -97,11 +97,6 @@ org.dom4j dom4j - - junit - junit - test - diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerHttpRequestTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerHttpRequestTest.java index 0618960b9..037fa750d 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerHttpRequestTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerHttpRequestTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,12 +26,9 @@ */ package org.alfresco.transformer; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class AIOControllerHttpRequestTest extends AbstractHttpRequestTest { diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerImageMagickTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerImageMagickTest.java index c75d8e77c..0be23b4be 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerImageMagickTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerImageMagickTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,30 +26,27 @@ */ package org.alfresco.transformer; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.util.Map; + import org.alfresco.transformer.executors.Transformer; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.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.util.Map; - -import static org.junit.Assert.assertTrue; - -@RunWith(SpringRunner.class) -@WebMvcTest(AIOController.class) -@Import(AIOCustomConfig.class) /** * Test the AIOController ImageMagick transforms without a server. * Super class includes tests for the AbstractTransformerController. */ +@WebMvcTest(AIOController.class) +@Import(AIOCustomConfig.class) public class AIOControllerImageMagickTest extends ImageMagickControllerTest { // All tests contained in ImageMagickControllerTest @@ -57,7 +54,7 @@ public class AIOControllerImageMagickTest extends ImageMagickControllerTest @Autowired AIOTransformRegistry transformRegistry; - @Before @Override + @BeforeEach @Override public void before() throws IOException { ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand); @@ -90,7 +87,7 @@ protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipart public void testTestValidity() { // 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 diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerLibreOfficeTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerLibreOfficeTest.java index 8bf206730..b0613dc4b 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerLibreOfficeTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerLibreOfficeTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,22 +26,19 @@ */ 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.Transformer; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.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.web.servlet.request.MockHttpServletRequestBuilder; -import java.util.Map; - -import static org.junit.Assert.assertTrue; - -@RunWith(SpringRunner.class) @WebMvcTest(AIOController.class) @Import(AIOCustomConfig.class) /** @@ -56,7 +53,7 @@ public class AIOControllerLibreOfficeTest extends LibreOfficeControllerTest public void testTestValidity() { // 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 @@ -87,7 +84,7 @@ protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipart @Override 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 void testGetTransformConfigInfo() @Override 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 @Override 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 @Override 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. } } \ No newline at end of file diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerMiscTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerMiscTest.java index 714f1c601..5b94df755 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerMiscTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerMiscTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,15 +26,12 @@ */ package org.alfresco.transformer; -import org.junit.Test; -import org.junit.runner.RunWith; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; 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) @Import(AIOCustomConfig.class) public class AIOControllerMiscTest extends MiscControllerTest @@ -46,14 +43,14 @@ public class AIOControllerMiscTest extends MiscControllerTest public void testTestValidity() { // 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 @Override 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 void testGetTransformConfigInfo() @Override 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 @Override 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 @Override 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. } } \ No newline at end of file diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerPdfRendererTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerPdfRendererTest.java index cc1760a4e..a944aaf41 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerPdfRendererTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerPdfRendererTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,22 +26,20 @@ */ package org.alfresco.transformer; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Map; + import org.alfresco.transformer.executors.Transformer; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.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.util.Map; - -import static org.junit.Assert.assertTrue; - -@RunWith(SpringRunner.class) @WebMvcTest(AIOController.class) @Import(AIOCustomConfig.class) /** @@ -78,14 +76,14 @@ protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipart public void testTestValidity() { // 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 @Override 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 void testGetTransformConfigInfo() @Override 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 void testGetInfoFromConfigWithDuplicates() @Override 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 void testGetInfoFromConfigWithEmptyTransformOptions() @Override 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. } } \ No newline at end of file diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTest.java index 30b877c69..2b62642f6 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,18 +26,14 @@ */ package org.alfresco.transformer; - import java.io.IOException; import org.alfresco.transform.client.model.TransformRequest; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.context.annotation.Import; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @WebMvcTest(AIOController.class) @Import(AIOCustomConfig.class) public class AIOControllerTest //extends AbstractTransformerControllerTest diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTikaTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTikaTest.java index 739e458d4..9c720faa8 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTikaTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTikaTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,15 +26,12 @@ */ 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.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.context.annotation.Import; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @WebMvcTest(AIOController.class) @Import(AIOCustomConfig.class) /** @@ -49,7 +46,7 @@ public class AIOControllerTikaTest extends TikaControllerTest public void testTestValidity() { // 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 diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOImageMagickIT.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOImageMagickIT.java index 5e26c5c9a..d6160b6a7 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOImageMagickIT.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOImageMagickIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,16 +26,7 @@ */ 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 { - //Tests are in ImageMagickTransformationIT - public AIOImageMagickIT(final Pair> entry) - { - super(entry); - } + // Tests are in ImageMagickTransformationIT } diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOLibreOfficeTransformationIT.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOLibreOfficeTransformationIT.java index 589fe43e3..ffa86390b 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOLibreOfficeTransformationIT.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOLibreOfficeTransformationIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,16 +26,7 @@ */ 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 AIOLibreOfficeTransformationIT(final Pair entry) - { - super(entry); - } + // Tests are in LibreOfficeTransformationIT } \ No newline at end of file diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOMiscMetadataExtractsIT.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOMiscMetadataExtractsIT.java index 17508b282..df7033b65 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOMiscMetadataExtractsIT.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOMiscMetadataExtractsIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,19 +26,13 @@ */ 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. * * @author adavis + * @author dedwards */ -@RunWith(Parameterized.class) public class AIOMiscMetadataExtractsIT extends MiscMetadataExtractsIT { - public AIOMiscMetadataExtractsIT(TestFileInfo testFileInfo) - { - super(testFileInfo); - } + //Tests are in MiscMetadataExtractsIT } diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOMiscTransformsIT.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOMiscTransformsIT.java index 4f415a6d8..614cb78f5 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOMiscTransformsIT.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOMiscTransformsIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,15 +26,7 @@ */ package org.alfresco.transformer; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -@RunWith(Parameterized.class) public class AIOMiscTransformsIT extends MiscTransformsIT { - //Tests are in ImageMagickTransformationIT - public AIOMiscTransformsIT(final SourceTarget sourceTarget) - { - super(sourceTarget); - } + // Tests are in ImageMagickTransformationIT } diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOPdfRendererIT.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOPdfRendererIT.java index 91d715e09..2ade1494f 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOPdfRendererIT.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOPdfRendererIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,14 +26,6 @@ */ package org.alfresco.transformer; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -@RunWith(Parameterized.class) public class AIOPdfRendererIT extends AlfrescoPdfRendererTransformationIT { // Tests are in AlfrescoPdfRendererTransformationIT - public AIOPdfRendererIT(String sourceFile) - { - super(sourceFile); - } } diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOQueueTransformServiceIT.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOQueueTransformServiceIT.java index 0736dbb9b..59e630c11 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOQueueTransformServiceIT.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOQueueTransformServiceIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -32,15 +32,12 @@ import java.util.UUID; import org.alfresco.transform.client.model.TransformRequest; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; /** * @author David Edwards * created on 21/04/2020 */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"activemq.url=nio://localhost:61616"}) public class AIOQueueTransformServiceIT extends AbstractQueueTransformServiceIT diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOTikaMetadataExtractsIT.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOTikaMetadataExtractsIT.java index 8ed60eacc..b0b2b83c7 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOTikaMetadataExtractsIT.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOTikaMetadataExtractsIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,19 +26,13 @@ */ 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. * * @author adavis + * @author dedwards */ -@RunWith(Parameterized.class) public class AIOTikaMetadataExtractsIT extends TikaMetadataExtractsIT { - public AIOTikaMetadataExtractsIT(TestFileInfo testFileInfo) - { - super(testFileInfo); - } + // Tests are in TikaMetadataExtractsIT } diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOTikaTransformationIT.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOTikaTransformationIT.java index efddfa723..01f355b43 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOTikaTransformationIT.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOTikaTransformationIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,17 +26,7 @@ */ 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 { - - //Tests are in ImageMagickTransformationIT - public AIOTikaTransformationIT(final Triple entry) - { - super(entry); - } + // Tests are in ImageMagickTransformationIT } \ No newline at end of file diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio/pom.xml b/alfresco-transform-core-aio/alfresco-transform-core-aio/pom.xml index 10239f5dc..8e84502ee 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio/pom.xml +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio/pom.xml @@ -44,9 +44,15 @@ ${project.version} - junit - junit + org.springframework.boot + spring-boot-starter-test test + + + com.vaadin.external.google + android-json + + diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio/src/test/java/org/alfresco/transformer/AIOTransformRegistryTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio/src/test/java/org/alfresco/transformer/AIOTransformRegistryTest.java index 230e2454d..820d822b5 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio/src/test/java/org/alfresco/transformer/AIOTransformRegistryTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio/src/test/java/org/alfresco/transformer/AIOTransformRegistryTest.java @@ -33,8 +33,8 @@ import org.alfresco.transformer.transformers.SelectingTransformer; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.text.PDFTextStripper; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.core.io.ClassPathResource; import java.io.File; @@ -52,8 +52,9 @@ import static org.alfresco.transformer.util.RequestParamMap.PAGE_LIMIT; import static org.alfresco.transformer.util.RequestParamMap.TRANSFORM_NAME_PARAMETER; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class AIOTransformRegistryTest { @@ -65,7 +66,7 @@ public class AIOTransformRegistryTest ObjectMapper objectMapper = new ObjectMapper(); - @Before + @BeforeEach public void before() throws Exception { aioTransformerRegistry.registerTransformer(new SelectingTransformer()); @@ -104,32 +105,34 @@ public void testConfigAggregation() throws Exception TransformConfig tikaConfig = loadConfig("tika_engine_config.json"); // check correct number of transformers - assertEquals("Number of expected transformers", + assertEquals( miscConfig.getTransformers().size() + tikaConfig.getTransformers().size(), - aioTransformerRegistry.getTransformConfig().getTransformers().size()); + aioTransformerRegistry.getTransformConfig().getTransformers().size(), + "Number of expected transformers"); List actualTransformerNames = aioTransformerRegistry.getTransformConfig().getTransformers() .stream().map(t -> t.getTransformerName()).collect(Collectors.toList()); // check all transformers are there for(String transformNames : expectedTransformNames) { - assertTrue("Expected transformer missing.", actualTransformerNames.contains(transformNames)); + assertTrue(actualTransformerNames.contains(transformNames),"Expected transformer missing."); } // check correct number of options long distinctOptionCount = Stream.concat( miscConfig.getTransformOptions().keySet().stream(), tikaConfig.getTransformOptions().keySet().stream()).distinct().count(); - assertEquals("Number of expected transformers", + assertEquals( distinctOptionCount, - aioTransformerRegistry.getTransformConfig().getTransformOptions().size()); + aioTransformerRegistry.getTransformConfig().getTransformOptions().size(), + "Number of expected transformers"); Set actualOptionNames = aioTransformerRegistry.getTransformConfig().getTransformOptions().keySet(); // check all options are there 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 void testTransformerMapping() for (String transform : tikaTransforms) { 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) { 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 { - // The Misc transformers are already registered - aioTransformerRegistry.registerTransformer(new SelectingTransformer()); + assertThrows(Exception.class, () ->{ + // The Misc transformers are already registered + aioTransformerRegistry.registerTransformer(new SelectingTransformer()); + }); } // Test copied from Misc (HtmlParserContentTransformerTest) See ATS-712 aioTransformerRegistry - html @@ -313,8 +318,8 @@ private void transformTextAndCheck(String text, String encoding, String checkTex String roundTrip = clean(textWriter.toString()); 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(); diff --git a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/pom.xml b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/pom.xml index 568138f3d..29c313a89 100644 --- a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/pom.xml +++ b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/pom.xml @@ -59,11 +59,6 @@ org.apache.commons commons-lang3 - - junit - junit - test - diff --git a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTest.java b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTest.java index e325c0a2d..65d58c17a 100644 --- a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTest.java +++ b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,15 +26,48 @@ */ package org.alfresco.transformer; +import static org.alfresco.transformer.util.MimetypeMap.PREFIX_IMAGE; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.when; +import static org.springframework.http.HttpHeaders.ACCEPT; +import static org.springframework.http.HttpHeaders.CONTENT_DISPOSITION; +import static org.springframework.http.HttpHeaders.CONTENT_TYPE; +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.http.MediaType.IMAGE_PNG_VALUE; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +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.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +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; @@ -45,47 +78,16 @@ 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.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.when; -import static org.springframework.http.HttpHeaders.ACCEPT; -import static org.springframework.http.HttpHeaders.CONTENT_DISPOSITION; -import static org.springframework.http.HttpHeaders.CONTENT_TYPE; -import static org.springframework.http.HttpStatus.BAD_REQUEST; -import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.OK; -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -import static org.springframework.http.MediaType.IMAGE_PNG_VALUE; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.util.StringUtils.getFilenameExtension; - /** * Test the ImageMagickController without a server. * Super class includes tests for the AbstractTransformerController. */ -@RunWith(SpringRunner.class) -@WebMvcTest(ImageMagickController.class) +// Specifying class for @WebMvcTest() will break AIO tests, without specifying it will use all controllers in the application context, +// currently only ImageMagickController.class +@WebMvcTest() public class ImageMagickControllerTest extends AbstractTransformerControllerTest { private static final String ENGINE_CONFIG_NAME = "imagemagick_engine_config.json"; @@ -125,7 +127,7 @@ private void init() @Autowired protected AbstractTransformerController controller; - @Before + @BeforeEach public void before() throws IOException { ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand); @@ -161,7 +163,7 @@ protected void mockTransformCommand(String sourceExtension, when(mockTransformCommand.execute(any(), anyLong())).thenAnswer( (Answer) invocation -> { Map 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 actualSource = actualProperties.get("source"); @@ -170,26 +172,23 @@ protected void mockTransformCommand(String sourceExtension, assertNotNull(actualSource); assertNotNull(actualTarget); - if (expectedSourceSuffix != null) - { - assertTrue( - "The source file \"" + actualSource + "\" should have ended in \"" + expectedSourceSuffix + "\"", - actualSource.endsWith(expectedSourceSuffix)); - actualSource = actualSource.substring(0, - actualSource.length() - expectedSourceSuffix.length()); + if (expectedSourceSuffix != null) { + assertTrue(actualSource.endsWith(expectedSourceSuffix), + "The source file \"" + actualSource + "\" should have ended in \"" + expectedSourceSuffix + "\""); + actualSource = actualSource.substring(0, actualSource.length() - expectedSourceSuffix.length()); } assertNotNull(actualOptions); if (expectedOptions != null) { - assertEquals("expectedOptions", expectedOptions, actualOptions); + assertEquals(expectedOptions, actualOptions,"expectedOptions"); } Long actualTimeout = invocation.getArgument(1); assertNotNull(actualTimeout); if (expectedTimeout != null) { - assertEquals("expectedTimeout", expectedTimeout, actualTimeout); + assertEquals(expectedTimeout, actualTimeout,"expectedTimeout"); } // Copy a test file into the target file location if it exists @@ -205,8 +204,8 @@ protected void mockTransformCommand(String sourceExtension, // Check the supplied source file has not been changed. byte[] actualSourceFileBytes = Files.readAllBytes(new File(actualSource).toPath()); - assertTrue("Source file is not the same", - Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes)); + assertTrue(Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes), + "Source file is not the same"); return mockExecutionResult; }); @@ -222,25 +221,23 @@ protected AbstractTransformerController getController() return controller; } - @Test - public void cropGravityGoodTest() throws Exception + @ParameterizedTest + @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 - .perform(MockMvcRequestBuilders - .multipart("/transform") - .file(sourceFile) - .param("targetExtension", targetExtension) - .param("targetMimetype", targetMimetype) - .param("sourceMimetype", sourceMimetype) - .param("cropGravity", value)) - .andExpect(status().is(OK.value())) - .andExpect(content().bytes(expectedTargetFileBytes)) - .andExpect(header().string("Content-Disposition", - "attachment; filename*= UTF-8''quick." + targetExtension)); - } + expectedOptions = "-auto-orient " + "-gravity " + value + " +repage"; + mockMvc + .perform(MockMvcRequestBuilders + .multipart("/transform") + .file(sourceFile) + .param("targetExtension", targetExtension) + .param("targetMimetype", targetMimetype) + .param("sourceMimetype", sourceMimetype) + .param("cropGravity", value)) + .andExpect(status().is(OK.value())) + .andExpect(content().bytes(expectedTargetFileBytes)) + .andExpect(header().string("Content-Disposition", + "attachment; filename*= UTF-8''quick." + targetExtension)); } @Test diff --git a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickHttpRequestTest.java b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickHttpRequestTest.java index 6e4ccbd80..3c5082fbf 100644 --- a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickHttpRequestTest.java +++ b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickHttpRequestTest.java @@ -26,16 +26,12 @@ */ package org.alfresco.transformer; -import org.junit.runner.RunWith; 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. */ -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class ImageMagickHttpRequestTest extends AbstractHttpRequestTest { @Override diff --git a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickQueueTransformServiceIT.java b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickQueueTransformServiceIT.java index a6a749613..0b0b53984 100644 --- a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickQueueTransformServiceIT.java +++ b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickQueueTransformServiceIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -32,15 +32,12 @@ import java.util.UUID; import org.alfresco.transform.client.model.TransformRequest; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; /** * @author Lucian Tuca * created on 15/01/2019 */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"activemq.url=nio://localhost:61616"}) public class ImageMagickQueueTransformServiceIT extends AbstractQueueTransformServiceIT diff --git a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickTransformationIT.java b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickTransformationIT.java index 571a018e0..2845f2631 100644 --- a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickTransformationIT.java +++ b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickTransformationIT.java @@ -30,210 +30,192 @@ import static java.util.Collections.emptyMap; import static java.util.function.Function.identity; import static java.util.stream.Collectors.toMap; -import static java.util.stream.Collectors.toSet; import static org.alfresco.transformer.EngineClient.sendTRequest; import static org.alfresco.transformer.TestFileInfo.testFile; -import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_3FR; -import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_ARW; +import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_APPLICATION_EPS; 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_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_IEF; 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_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_RAW_PEF; 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_PNM; 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_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_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_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_TIFF; 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_XWD; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.springframework.http.HttpStatus.OK; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Stream; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; + import org.apache.commons.lang3.tuple.Pair; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; import org.springframework.http.ResponseEntity; -import com.google.common.collect.ImmutableList; - /** * @author Cezar Leahu */ -@RunWith(Parameterized.class) -public class ImageMagickTransformationIT -{ +public class ImageMagickTransformationIT { private static final Logger logger = LoggerFactory.getLogger(ImageMagickTransformationIT.class); private static final String ENGINE_URL = "http://localhost:8090"; - private static final List> targetExtensions = new ImmutableList.Builder>() - .add(Pair.of("3fr",MIMETYPE_IMAGE_RAW_3FR)) - .add(Pair.of("arw",MIMETYPE_IMAGE_RAW_ARW)) - .add(Pair.of("bmp",MIMETYPE_IMAGE_BMP)) - .add(Pair.of("cgm",MIMETYPE_IMAGE_CGM)) - .add(Pair.of("cr2",MIMETYPE_IMAGE_RAW_CR2)) - .add(Pair.of("dng",MIMETYPE_IMAGE_RAW_DNG)) - .add(Pair.of("eps",MIMETYPE_APPLICATION_EPS)) - .add(Pair.of("gif",MIMETYPE_IMAGE_GIF)) - .add(Pair.of("ief",MIMETYPE_IMAGE_IEF)) - .add(Pair.of("jp2",MIMETYPE_IMAGE_JP2)) - .add(Pair.of("jpg",MIMETYPE_IMAGE_JPEG)) - .add(Pair.of("k25",MIMETYPE_IMAGE_RAW_K25)) - .add(Pair.of("mrw",MIMETYPE_IMAGE_RAW_MRW)) - .add(Pair.of("nef",MIMETYPE_IMAGE_RAW_NEF)) - .add(Pair.of("orf",MIMETYPE_IMAGE_RAW_ORF)) - .add(Pair.of("pbm",MIMETYPE_IMAGE_PBM)) - .add(Pair.of("pef",MIMETYPE_IMAGE_RAW_PEF)) - .add(Pair.of("pgm",MIMETYPE_IMAGE_PGM)) - .add(Pair.of("png",MIMETYPE_IMAGE_PNG)) - .add(Pair.of("pnm",MIMETYPE_IMAGE_PNM)) - .add(Pair.of("ppj",MIMETYPE_IMAGE_PPJ)) - .add(Pair.of("ppm",MIMETYPE_IMAGE_PPM)) - .add(Pair.of("r3d",MIMETYPE_IMAGE_RAW_R3D)) - .add(Pair.of("raf",MIMETYPE_IMAGE_RAW_RAF)) - .add(Pair.of("ras",MIMETYPE_IMAGE_RAS)) - .add(Pair.of("rw2",MIMETYPE_IMAGE_RAW_RW2)) - .add(Pair.of("rwl",MIMETYPE_IMAGE_RAW_RWL)) - .add(Pair.of("tiff",MIMETYPE_IMAGE_TIFF)) - .add(Pair.of("x3f",MIMETYPE_IMAGE_RAW_X3F)) - .add(Pair.of("xbm",MIMETYPE_IMAGE_XBM)) - .add(Pair.of("xpm",MIMETYPE_IMAGE_XPM)) - .add(Pair.of("xwd",MIMETYPE_IMAGE_XWD)) - .build(); + private static final List> targetExtensions = new ImmutableList.Builder>() + .add(Pair.of("3fr", MIMETYPE_IMAGE_RAW_3FR)) + .add(Pair.of("arw", MIMETYPE_IMAGE_RAW_ARW)) + .add(Pair.of("bmp", MIMETYPE_IMAGE_BMP)) + .add(Pair.of("cgm", MIMETYPE_IMAGE_CGM)) + .add(Pair.of("cr2", MIMETYPE_IMAGE_RAW_CR2)) + .add(Pair.of("dng", MIMETYPE_IMAGE_RAW_DNG)) + .add(Pair.of("eps", MIMETYPE_APPLICATION_EPS)) + .add(Pair.of("gif", MIMETYPE_IMAGE_GIF)) + .add(Pair.of("ief", MIMETYPE_IMAGE_IEF)) + .add(Pair.of("jp2", MIMETYPE_IMAGE_JP2)) + .add(Pair.of("jpg", MIMETYPE_IMAGE_JPEG)) + .add(Pair.of("k25", MIMETYPE_IMAGE_RAW_K25)) + .add(Pair.of("mrw", MIMETYPE_IMAGE_RAW_MRW)) + .add(Pair.of("nef", MIMETYPE_IMAGE_RAW_NEF)) + .add(Pair.of("orf", MIMETYPE_IMAGE_RAW_ORF)) + .add(Pair.of("pbm", MIMETYPE_IMAGE_PBM)) + .add(Pair.of("pef", MIMETYPE_IMAGE_RAW_PEF)) + .add(Pair.of("pgm", MIMETYPE_IMAGE_PGM)) + .add(Pair.of("png", MIMETYPE_IMAGE_PNG)) + .add(Pair.of("pnm", MIMETYPE_IMAGE_PNM)) + .add(Pair.of("ppj", MIMETYPE_IMAGE_PPJ)) + .add(Pair.of("ppm", MIMETYPE_IMAGE_PPM)) + .add(Pair.of("r3d", MIMETYPE_IMAGE_RAW_R3D)) + .add(Pair.of("raf", MIMETYPE_IMAGE_RAW_RAF)) + .add(Pair.of("ras", MIMETYPE_IMAGE_RAS)) + .add(Pair.of("rw2", MIMETYPE_IMAGE_RAW_RW2)) + .add(Pair.of("rwl", MIMETYPE_IMAGE_RAW_RWL)) + .add(Pair.of("tiff", MIMETYPE_IMAGE_TIFF)) + .add(Pair.of("x3f", MIMETYPE_IMAGE_RAW_X3F)) + .add(Pair.of("xbm", MIMETYPE_IMAGE_XBM)) + .add(Pair.of("xpm", MIMETYPE_IMAGE_XPM)) + .add(Pair.of("xwd", MIMETYPE_IMAGE_XWD)) + .build(); - private static final List> targetExtensionsForPSD = new ImmutableList.Builder>() - .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)) + private static final List> targetExtensionsForPSD = new ImmutableList.Builder>() + .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(); - private static final List> targetExtensionsForTiffFirstPage = new ImmutableList.Builder>() - .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)) + private static final List> targetExtensionsForTiffFirstPage = new ImmutableList.Builder>() + .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(); private static final Map TEST_FILES = Stream.of( - testFile(MIMETYPE_IMAGE_BMP,"bmp","quick.bmp"), - testFile(MIMETYPE_APPLICATION_EPS,"eps","quick.eps"), - testFile(MIMETYPE_IMAGE_GIF,"gif","quick.gif"), - testFile(MIMETYPE_IMAGE_JPEG,"jpg","quick.jpg"), - testFile(MIMETYPE_IMAGE_PBM,"pbm","quick.pbm"), - testFile(MIMETYPE_IMAGE_PGM,"pgm","quick.pgm"), - testFile(MIMETYPE_IMAGE_PNG,"png","quick.png"), - testFile(MIMETYPE_IMAGE_PNM,"pnm","quick.pnm"), - testFile(MIMETYPE_IMAGE_PPM,"ppm","quick.ppm"), - testFile(MIMETYPE_IMAGE_XBM,"xbm","quick.xbm"), - testFile(MIMETYPE_IMAGE_XPM,"xpm","quick.xpm"), - testFile(MIMETYPE_IMAGE_PSD,"psd","quick.psd"), - testFile(MIMETYPE_IMAGE_TIFF,"tiff","quick.tiff"), - testFile(MIMETYPE_IMAGE_XWD,"xwd","quick.xwd") - ).collect(toMap(TestFileInfo::getPath, identity())); - - private final String sourceFile; - private final String targetExtension; - private final String sourceMimetype; - private final String targetMimetype; + testFile(MIMETYPE_IMAGE_BMP, "bmp", "quick.bmp"), + testFile(MIMETYPE_APPLICATION_EPS, "eps", "quick.eps"), + testFile(MIMETYPE_IMAGE_GIF, "gif", "quick.gif"), + testFile(MIMETYPE_IMAGE_JPEG, "jpg", "quick.jpg"), + testFile(MIMETYPE_IMAGE_PBM, "pbm", "quick.pbm"), + testFile(MIMETYPE_IMAGE_PGM, "pgm", "quick.pgm"), + testFile(MIMETYPE_IMAGE_PNG, "png", "quick.png"), + testFile(MIMETYPE_IMAGE_PNM, "pnm", "quick.pnm"), + testFile(MIMETYPE_IMAGE_PPM, "ppm", "quick.ppm"), + testFile(MIMETYPE_IMAGE_XBM, "xbm", "quick.xbm"), + testFile(MIMETYPE_IMAGE_XPM, "xpm", "quick.xpm"), + testFile(MIMETYPE_IMAGE_PSD, "psd", "quick.psd"), + testFile(MIMETYPE_IMAGE_TIFF, "tiff", "quick.tiff"), + testFile(MIMETYPE_IMAGE_XWD, "xwd", "quick.xwd") + ).collect(toMap(TestFileInfo::getPath, identity())); - public ImageMagickTransformationIT(final Pair> entry) - { - sourceFile = entry.getLeft().getPath(); - targetExtension = entry.getRight().getLeft(); - sourceMimetype = entry.getLeft().getMimeType(); - targetMimetype = entry.getRight().getRight(); - } - - @Parameterized.Parameters - public static Set>> engineTransformations() - { - Set>> resolved = null; - resolved = Stream + public static Stream>> engineTransformations() { + return Stream .of( - allTargets("quick.bmp", targetExtensions), + allTargets("quick.bmp", targetExtensions), allTargets("quick.eps", targetExtensions), - allTargets("quick.gif", targetExtensions), + allTargets("quick.gif", targetExtensions), allTargets("quick.jpg", targetExtensions), - allTargets("quick.pbm", targetExtensions), + allTargets("quick.pbm", targetExtensions), allTargets("quick.pgm", targetExtensions), - allTargets("quick.png", targetExtensions), + allTargets("quick.png", targetExtensions), allTargets("quick.pnm", targetExtensions), - allTargets("quick.ppm", targetExtensions), + allTargets("quick.ppm", targetExtensions), allTargets("quick.psd", targetExtensionsForPSD), - allTargets("quick.tiff", targetExtensions), + allTargets("quick.tiff", targetExtensions), allTargets("quick.xbm", targetExtensions), - allTargets("quick.xpm", targetExtensions), + allTargets("quick.xpm", targetExtensions), allTargets("quick.xwd", targetExtensions) - ) - .flatMap(identity()) - .collect(toSet()); - return resolved; + ).flatMap(identity()); } - @Test - public void testTransformation() + @ParameterizedTest + @MethodSource("engineTransformations") + public void testTransformation(Pair> 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})", sourceFile, sourceMimetype, targetMimetype, targetExtension); try { // note: some image/tiff->image/* will return multiple page results (hence error) unless options specified for single page Map tOptions = emptyMap(); - Pair targetPair = Pair.of(targetExtension, targetMimetype); + Pair targetPair = Pair.of(targetExtension, targetMimetype); if (MIMETYPE_IMAGE_TIFF.equals(sourceMimetype) && targetExtensionsForTiffFirstPage.contains(targetPair)) { tOptions = ImmutableMap.of("startPage", "0", "endPage", "0"); @@ -241,7 +223,7 @@ public void testTransformation() final ResponseEntity response = sendTRequest(ENGINE_URL, sourceFile, sourceMimetype, targetMimetype, targetExtension, tOptions); - assertEquals(descriptor, OK, response.getStatusCode()); + assertEquals(OK, response.getStatusCode(), descriptor); } catch (Exception e) { @@ -256,4 +238,5 @@ private static Stream>> allTargets(final .map(k -> Pair.of(TEST_FILES.get(sourceFile), k)); } + } diff --git a/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/pom.xml b/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/pom.xml index e87a37bbf..174bd2a04 100644 --- a/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/pom.xml +++ b/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/pom.xml @@ -67,11 +67,6 @@ org.apache.commons commons-lang3 - - junit - junit - test - diff --git a/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeControllerTest.java b/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeControllerTest.java index 486c13f3c..82b7b914f 100644 --- a/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeControllerTest.java +++ b/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeControllerTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,15 +26,14 @@ */ package org.alfresco.transformer; +import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_PDF; import static org.alfresco.transformer.util.RequestParamMap.SOURCE_MIMETYPE; import static org.alfresco.transformer.util.RequestParamMap.TARGET_EXTENSION; import static org.alfresco.transformer.util.RequestParamMap.TARGET_MIMETYPE; -import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_PDF; -import static org.alfresco.transformer.executors.RuntimeExec.ExecutionResult; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; @@ -55,15 +54,17 @@ import java.util.HashMap; import java.util.UUID; +import javax.annotation.PostConstruct; + import org.alfresco.transform.client.model.TransformReply; import org.alfresco.transform.client.model.TransformRequest; import org.alfresco.transformer.executors.LibreOfficeJavaExecutor; +import org.alfresco.transformer.executors.RuntimeExec.ExecutionResult; import org.alfresco.transformer.model.FileRefEntity; import org.alfresco.transformer.model.FileRefResponse; import org.artofsolving.jodconverter.office.OfficeException; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -74,18 +75,16 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import javax.annotation.PostConstruct; - /** * Test the LibreOfficeController without a server. * Super class includes tests for the AbstractTransformerController. */ -@RunWith(SpringRunner.class) -@WebMvcTest(LibreOfficeController.class) +// Specifying class for @WebMvcTest() will break AIO tests, without specifying it will use all controllers in the application context, +// currently only LibreOfficeController.class +@WebMvcTest() public class LibreOfficeControllerTest extends AbstractTransformerControllerTest { @@ -124,7 +123,7 @@ private void init() @Autowired protected AbstractTransformerController controller; - @Before + @BeforeEach public void before() throws IOException { sourceExtension = "doc"; @@ -164,8 +163,7 @@ public void before() throws IOException // Check the supplied source file has not been changed. byte[] actualSourceFileBytes = Files.readAllBytes(sourceFile.toPath()); - assertTrue("Source file is not the same", - Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes)); + assertTrue(Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes), "Source file is not the same"); return null; }).when(javaExecutor).convert(any(), any()); diff --git a/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeHttpRequestTest.java b/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeHttpRequestTest.java index aeebb9b10..3bb6b0bc4 100644 --- a/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeHttpRequestTest.java +++ b/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeHttpRequestTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,14 +26,11 @@ */ package org.alfresco.transformer; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; /** * Tests LibreOfficeController with a server test harness. */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class LibreOfficeHttpRequestTest extends AbstractHttpRequestTest { diff --git a/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeQueueTransformServiceIT.java b/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeQueueTransformServiceIT.java index 2e1f4d7ed..990fcd484 100644 --- a/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeQueueTransformServiceIT.java +++ b/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeQueueTransformServiceIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -31,15 +31,12 @@ import java.util.UUID; import org.alfresco.transform.client.model.TransformRequest; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; /** * @author Lucian Tuca * created on 15/01/2019 */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"activemq.url=nio://localhost:61616"}) public class LibreOfficeQueueTransformServiceIT extends AbstractQueueTransformServiceIT diff --git a/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeTransformationIT.java b/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeTransformationIT.java index c63139c11..886a00c54 100644 --- a/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeTransformationIT.java +++ b/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeTransformationIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -29,7 +29,6 @@ import static java.text.MessageFormat.format; import static java.util.function.Function.identity; import static java.util.stream.Collectors.toMap; -import static java.util.stream.Collectors.toSet; import static org.alfresco.transformer.EngineClient.sendTRequest; import static org.alfresco.transformer.TestFileInfo.testFile; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_EXCEL; @@ -63,8 +62,8 @@ import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_STW; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_STI; import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_STC; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.springframework.http.HttpStatus.OK; import java.util.Map; @@ -74,9 +73,8 @@ import com.google.common.collect.ImmutableSet; import org.apache.commons.lang3.tuple.Pair; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; @@ -85,7 +83,6 @@ /** * @author Cezar Leahu */ -@RunWith(Parameterized.class) public class LibreOfficeTransformationIT { private static final Logger logger = LoggerFactory.getLogger(LibreOfficeTransformationIT.class); @@ -127,11 +124,6 @@ public class LibreOfficeTransformationIT testFile(MIMETYPE_TEXT_PLAIN,"txt",null) ); - private final String sourceFile; - private final String targetExtension; - private final String sourceMimetype; - private final String targetMimetype; - private static final Map TEST_FILES = Stream.of( testFile(MIMETYPE_WORD ,"doc" ,"quick.doc"), testFile(MIMETYPE_OPENXML_WORDPROCESSING ,"docx" ,"quick.docx"), @@ -164,16 +156,7 @@ public class LibreOfficeTransformationIT testFile(MIMETYPE_TSV ,"tsv" ,"sample.tsv") ).collect(toMap(TestFileInfo::getPath, identity())); - public LibreOfficeTransformationIT(final Pair entry) - { - sourceFile = entry.getLeft().getPath(); - targetExtension = entry.getRight().getExtension(); - sourceMimetype = entry.getLeft().getMimeType(); - targetMimetype = entry.getRight().getMimeType(); - } - - @Parameterized.Parameters - public static Set> engineTransformations() + public static Stream> engineTransformations() { return Stream .of( @@ -213,20 +196,24 @@ public static Set> engineTransformations() allTargets("quick.msg", txtTarget) ) - .flatMap(identity()) - .collect(toSet()); + .flatMap(identity()); } - @Test - public void testTransformation() + @ParameterizedTest + @MethodSource("engineTransformations") + public void testTransformation(final Pair entry) { + final String sourceFile = entry.getLeft().getPath(); + final String targetExtension = entry.getRight().getExtension(); + final String sourceMimetype = entry.getLeft().getMimeType(); + final String targetMimetype = entry.getRight().getMimeType(); final String descriptor = format("Transform ({0}, {1} -> {2}, {3})", sourceFile, sourceMimetype, targetMimetype, targetExtension); try { final ResponseEntity response = sendTRequest(ENGINE_URL, sourceFile, sourceMimetype, targetMimetype, targetExtension); - assertEquals(descriptor, OK, response.getStatusCode()); + assertEquals(OK, response.getStatusCode(), descriptor); } catch (Exception e) { diff --git a/alfresco-transform-misc/alfresco-transform-misc-boot/pom.xml b/alfresco-transform-misc/alfresco-transform-misc-boot/pom.xml index 3ecbcdb76..cc02d0253 100644 --- a/alfresco-transform-misc/alfresco-transform-misc-boot/pom.xml +++ b/alfresco-transform-misc/alfresco-transform-misc-boot/pom.xml @@ -57,11 +57,6 @@ org.dom4j dom4j - - junit - junit - test - diff --git a/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscControllerTest.java b/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscControllerTest.java index cdfc27217..92cce075e 100644 --- a/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscControllerTest.java +++ b/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscControllerTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -35,9 +35,9 @@ 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_TEXT_PLAIN; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; 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.status; @@ -49,18 +49,17 @@ import org.alfresco.transform.client.model.TransformRequest; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.text.PDFTextStripper; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; 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.request.MockHttpServletRequestBuilder; -@RunWith(SpringRunner.class) -@WebMvcTest(MiscController.class) +// Specifying class for @WebMvcTest() will break AIO tests, without specifying it will use all controllers in the application context, +// currently only MiscController.class +@WebMvcTest() public class MiscControllerTest extends AbstractTransformerControllerTest { @Autowired @@ -72,7 +71,7 @@ public class MiscControllerTest extends AbstractTransformerControllerTest protected static final String ENGINE_CONFIG_NAME = "misc_engine_config.json"; - @Before + @BeforeEach public void before() throws Exception { sourceMimetype = MIMETYPE_HTML; @@ -152,8 +151,8 @@ public void testRFC822ToText() throws Exception null, null, readTestFile("eml")); - assertTrue("Content from eml transform didn't contain expected value. ", - result.getResponse().getContentAsString().contains(expected)); + assertTrue(result.getResponse().getContentAsString().contains(expected), + "Content from eml transform didn't contain expected value. "); } /** @@ -173,8 +172,8 @@ public void testNonAsciiRFC822ToText() throws Exception null, readTestFile("spanish.eml")); String contentResult = new String(result.getResponse().getContentAsByteArray(), UTF_8); - assertTrue("Content from eml transform didn't contain expected value. ", - contentResult.contains(expected)); + assertTrue(contentResult.contains(expected), + "Content from eml transform didn't contain expected value. "); } /** @@ -194,8 +193,8 @@ public void testRFC822WithAttachmentToText() throws Exception null, null, readTestFile("attachment.eml")); - assertTrue("Content from eml transform didn't contain expected value. ", - result.getResponse().getContentAsString().contains(expected)); + assertTrue(result.getResponse().getContentAsString().contains(expected), + "Content from eml transform didn't contain expected value. "); assertFalse(result.getResponse().getContentAsString().contains(notExpected)); } @@ -215,8 +214,8 @@ public void testRFC822AlternativeToText() throws Exception null, null, readTestFile("alternative.eml")); - assertTrue("Content from eml transform didn't contain expected value. ", - result.getResponse().getContentAsString().contains(expected)); + assertTrue(result.getResponse().getContentAsString().contains(expected), + "Content from eml transform didn't contain expected value. "); } /** @@ -235,8 +234,8 @@ public void testRFC822NestedAlternativeToText() throws Exception null, null, readTestFile("nested.alternative.eml")); - assertTrue("Content from eml transform didn't contain expected value. ", - result.getResponse().getContentAsString().contains(expected)); + assertTrue(result.getResponse().getContentAsString().contains(expected), + "Content from eml transform didn't contain expected value. "); } /** @@ -269,7 +268,7 @@ public void testExtractMetadataRFC822() throws Exception null, readTestFile("eml")); String metadata = result.getResponse().getContentAsString(); - assertEquals("Metadata extract", expected, metadata); + assertEquals(expected, metadata, "Metadata extract"); } /** @@ -301,7 +300,7 @@ public void testExtractMetadataOptionRFC822() throws Exception extractMapping, readTestFile("eml")); String metadata = result.getResponse().getContentAsString(); - assertEquals("Option metadata extract", expected, metadata); + assertEquals(expected, metadata, "Option metadata extract"); } /** @@ -350,7 +349,7 @@ public void testHTMLtoString() throws Exception String contentResult = new String(result.getResponse().getContentAsByteArray(), targetEncoding); - assertTrue("The content did not include \"" + expected, contentResult.contains(expected)); + assertTrue(contentResult.contains(expected), "The content did not include \"" + expected); } @Test @@ -380,7 +379,7 @@ public void testStringToString() throws Exception String contentResult = new String(result.getResponse().getContentAsByteArray(), targetEncoding); - assertTrue("The content did not include \"" + expected, contentResult.contains(expected)); + assertTrue(contentResult.contains(expected), "The content did not include \"" + expected); } @Test @@ -399,8 +398,8 @@ public void testEmptyTextFileReturnsEmptyFile() throws Exception null, content); - assertEquals("Returned content should be empty for an empty source file", 0, - result.getResponse().getContentLength()); + assertEquals(0, result.getResponse().getContentLength(), + "Returned content should be empty for an empty source file"); } @Test @@ -435,7 +434,7 @@ public void textToPdf() throws Exception expected = clean(expected); String actual = clean(textWriter.toString()); - assertEquals("The content did not match.", expected, actual); + assertEquals(expected, actual, "The content did not match."); } @Test @@ -443,8 +442,8 @@ public void testAppleIWorksPages() throws Exception { MvcResult result = sendRequest("numbers", null, MIMETYPE_IWORK_NUMBERS, "jpeg", MIMETYPE_IMAGE_JPEG, null, null, null, readTestFile("pages")); - assertTrue("Expected image content but content is empty.", - result.getResponse().getContentLengthLong() > 0L); + assertTrue(result.getResponse().getContentLengthLong() > 0L, + "Expected image content but content is empty."); } @Test @@ -452,8 +451,8 @@ public void testAppleIWorksNumbers() throws Exception { MvcResult result = sendRequest("numbers", null, MIMETYPE_IWORK_NUMBERS, "jpeg", MIMETYPE_IMAGE_JPEG, null, null, null, readTestFile("numbers")); - assertTrue("Expected image content but content is empty.", - result.getResponse().getContentLengthLong() > 0L); + assertTrue(result.getResponse().getContentLengthLong() > 0L, + "Expected image content but content is empty."); } @Test @@ -461,8 +460,8 @@ public void testAppleIWorksKey() throws Exception { MvcResult result = sendRequest("key", null, MIMETYPE_IWORK_KEYNOTE, "jpeg", MIMETYPE_IMAGE_JPEG, null, null, null, readTestFile("key")); - assertTrue("Expected image content but content is empty.", - result.getResponse().getContentLengthLong() > 0L); + assertTrue(result.getResponse().getContentLengthLong() > 0L, + "Expected image content but content is empty."); } // @Test @@ -471,8 +470,8 @@ public void testOOXML() throws Exception { MvcResult result = sendRequest("docx", null, MIMETYPE_OPENXML_WORDPROCESSING, "jpeg", MIMETYPE_IMAGE_JPEG, null, null, null, readTestFile("docx")); - assertTrue("Expected image content but content is empty.", - result.getResponse().getContentLengthLong() > 0L); + assertTrue(result.getResponse().getContentLengthLong() > 0L, + "Expected image content but content is empty."); } private MvcResult sendRequest(String sourceExtension, diff --git a/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscMetadataExtractsIT.java b/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscMetadataExtractsIT.java index d6720a257..cfb8775ed 100644 --- a/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscMetadataExtractsIT.java +++ b/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscMetadataExtractsIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,38 +26,38 @@ */ 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_RFC822; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_XHTML; 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. * * @author adavis + * @author dedwards */ -@RunWith(Parameterized.class) 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 - public static List engineTransformations() + + private static Stream engineTransformations() { return Stream.of( // HtmlMetadataExtractor - testFile(MIMETYPE_HTML, "html", "quick.html"), - testFile(MIMETYPE_XHTML, "xhtml", "quick.xhtml.alf"), // avoid the license header check on xhtml + testFile(MIMETYPE_HTML, "html", "quick.html"), testFile(MIMETYPE_XHTML, "xhtml", "quick.xhtml.alf"), // avoid the license header check on xhtml // RFC822MetadataExtractor testFile(MIMETYPE_RFC822, "eml", "quick.eml"), @@ -67,6 +67,6 @@ public static List engineTransformations() testFile(MIMETYPE_RFC822, "eml", "quick.spanish.eml"), testFile(MIMETYPE_HTML, "html", "quick.japanese.html") - ).collect(toList()); + ); } } diff --git a/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscQueueTransformServiceIT.java b/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscQueueTransformServiceIT.java index ed883dd8a..6e4479a6b 100644 --- a/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscQueueTransformServiceIT.java +++ b/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscQueueTransformServiceIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -32,11 +32,8 @@ import java.util.UUID; import org.alfresco.transform.client.model.TransformRequest; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"activemq.url=nio://localhost:61616"}) public class MiscQueueTransformServiceIT extends AbstractQueueTransformServiceIT diff --git a/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscTransformerHttpRequestTest.java b/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscTransformerHttpRequestTest.java index 3d18f2cad..d1380d14f 100644 --- a/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscTransformerHttpRequestTest.java +++ b/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscTransformerHttpRequestTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,11 +26,11 @@ */ package org.alfresco.transformer; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) +/** + * Tests MiscController with a server test harness. + */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class MiscTransformerHttpRequestTest extends AbstractHttpRequestTest { diff --git a/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscTransformsIT.java b/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscTransformsIT.java index e183392ce..a0ebf2068 100644 --- a/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscTransformsIT.java +++ b/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscTransformsIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -29,7 +29,6 @@ import static java.text.MessageFormat.format; import static java.util.function.Function.identity; import static java.util.stream.Collectors.toMap; -import static java.util.stream.Collectors.toSet; import static org.alfresco.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_HTML; @@ -57,17 +56,15 @@ import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_XML; import static org.alfresco.transformer.EngineClient.sendTRequest; import static org.alfresco.transformer.TestFileInfo.testFile; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.springframework.http.HttpStatus.OK; import java.util.Map; -import java.util.Set; import java.util.stream.Stream; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; @@ -76,7 +73,6 @@ /** * @author Cezar Leahu */ -@RunWith(Parameterized.class) public class MiscTransformsIT { private static final Logger logger = LoggerFactory.getLogger(MiscTransformsIT.class); @@ -119,18 +115,8 @@ public class MiscTransformsIT testFile(MIMETYPE_IWORK_PAGES, "pages", "quick.pages"), testFile(MIMETYPE_RFC822, "eml", "quick.eml") ).collect(toMap(TestFileInfo::getMimeType, identity())); - - private final String sourceMimetype; - private final String targetMimetype; - - public MiscTransformsIT(final SourceTarget sourceTarget) - { - sourceMimetype = sourceTarget.source; - targetMimetype = sourceTarget.target; - } - - @Parameterized.Parameters - public static Set engineTransformations() + + public static Stream engineTransformations() { return Stream.of( SourceTarget.of("text/html", "text/plain"), //duplicate @@ -162,12 +148,15 @@ public static Set engineTransformations() SourceTarget.of("text/xml", "application/pdf"), SourceTarget.of("message/rfc822", "text/plain") - ).collect(toSet()); + ); } - @Test - public void testTransformation() + @ParameterizedTest + @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 targetExtension = TEST_FILES.get(targetMimetype).getExtension(); @@ -178,7 +167,7 @@ public void testTransformation() { final ResponseEntity response = sendTRequest(ENGINE_URL, sourceFile, sourceMimetype, targetMimetype, targetExtension); - assertEquals(descriptor, OK, response.getStatusCode()); + assertEquals(OK, response.getStatusCode(), descriptor); } catch (Exception e) { diff --git a/alfresco-transform-misc/alfresco-transform-misc/pom.xml b/alfresco-transform-misc/alfresco-transform-misc/pom.xml index f166a617a..5d74d0631 100644 --- a/alfresco-transform-misc/alfresco-transform-misc/pom.xml +++ b/alfresco-transform-misc/alfresco-transform-misc/pom.xml @@ -71,9 +71,8 @@ - junit - junit - 4.13 + org.junit.jupiter + junit-jupiter-engine test diff --git a/alfresco-transform-misc/alfresco-transform-misc/src/test/java/org/alfresco/transformer/transformers/HtmlParserContentTransformerTest.java b/alfresco-transform-misc/alfresco-transform-misc/src/test/java/org/alfresco/transformer/transformers/HtmlParserContentTransformerTest.java index ee54fcef6..c41b72204 100644 --- a/alfresco-transform-misc/alfresco-transform-misc/src/test/java/org/alfresco/transformer/transformers/HtmlParserContentTransformerTest.java +++ b/alfresco-transform-misc/alfresco-transform-misc/src/test/java/org/alfresco/transformer/transformers/HtmlParserContentTransformerTest.java @@ -26,7 +26,7 @@ */ package org.alfresco.transformer.transformers; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.FileOutputStream; @@ -36,7 +36,7 @@ import java.util.Map; 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 { diff --git a/alfresco-transform-misc/alfresco-transform-misc/src/test/java/org/alfresco/transformer/transformers/TextToPdfContentTransformerTest.java b/alfresco-transform-misc/alfresco-transform-misc/src/test/java/org/alfresco/transformer/transformers/TextToPdfContentTransformerTest.java index f26aa5a76..7de1e75a4 100644 --- a/alfresco-transform-misc/alfresco-transform-misc/src/test/java/org/alfresco/transformer/transformers/TextToPdfContentTransformerTest.java +++ b/alfresco-transform-misc/alfresco-transform-misc/src/test/java/org/alfresco/transformer/transformers/TextToPdfContentTransformerTest.java @@ -28,8 +28,8 @@ import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.text.PDFTextStripper; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.FileOutputStream; @@ -39,13 +39,13 @@ import java.util.Map; 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 { TextToPdfContentTransformer transformer = new TextToPdfContentTransformer(); - @Before + @BeforeEach public void setUp() { transformer.setStandardFont("Times-Roman"); @@ -121,8 +121,8 @@ private void transformTextAndCheck(String text, String encoding, String checkTex String roundTrip = clean(textWriter.toString()); 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(); diff --git a/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/pom.xml b/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/pom.xml index 65d7c0755..d4fca2e94 100644 --- a/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/pom.xml +++ b/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/pom.xml @@ -57,11 +57,6 @@ org.dom4j dom4j - - junit - junit - test - diff --git a/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererControllerTest.java b/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererControllerTest.java index 6e01fc936..d9d218218 100644 --- a/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererControllerTest.java +++ b/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererControllerTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,11 +26,10 @@ */ package org.alfresco.transformer; -import static org.alfresco.transformer.executors.RuntimeExec.ExecutionResult; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.when; @@ -56,15 +55,17 @@ 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.PdfRendererCommandExecutor; 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.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.stubbing.Answer; import org.springframework.beans.factory.annotation.Autowired; @@ -75,18 +76,16 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import javax.annotation.PostConstruct; - /** * Test the AlfrescoPdfRendererController without a server. * Super class includes tests for the AbstractTransformerController. */ -@RunWith(SpringRunner.class) -@WebMvcTest(AlfrescoPdfRendererController.class) +// Specifying class for @WebMvcTest() will break AIO tests, without specifying it will use all controllers in the application context, +// currently only AlfrescoPdfRendererController.class +@WebMvcTest() public class AlfrescoPdfRendererControllerTest extends AbstractTransformerControllerTest { @@ -115,7 +114,7 @@ private void init() @Autowired protected AbstractTransformerController controller; - @Before + @BeforeEach public void before() throws IOException { setFields(); @@ -156,7 +155,7 @@ public void mockTransformCommand(String sourceExtension, when(mockTransformCommand.execute(any(), anyLong())).thenAnswer( (Answer) invocation -> { Map 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 actualSource = actualProperties.get("source"); @@ -167,9 +166,9 @@ public void mockTransformCommand(String sourceExtension, assertNotNull(actualTarget); if (expectedSourceSuffix != null) { - assertTrue("The source file \"" + actualSource + - "\" should have ended in \"" + expectedSourceSuffix + "\"", - actualSource.endsWith(expectedSourceSuffix)); + assertTrue(actualSource.endsWith(expectedSourceSuffix), + "The source file \"" + actualSource + + "\" should have ended in \"" + expectedSourceSuffix + "\""); actualSource = actualSource.substring(0, actualSource.length() - expectedSourceSuffix.length()); } @@ -177,14 +176,14 @@ public void mockTransformCommand(String sourceExtension, assertNotNull(actualOptions); if (expectedOptions != null) { - assertEquals("expectedOptions", expectedOptions, actualOptions); + assertEquals(expectedOptions, actualOptions,"expectedOptions"); } Long actualTimeout = invocation.getArgument(1); assertNotNull(actualTimeout); if (expectedTimeout != null) { - assertEquals("expectedTimeout", expectedTimeout, actualTimeout); + assertEquals(expectedTimeout, actualTimeout,"expectedTimeout"); } // Copy a test file into the target file location if it exists @@ -200,8 +199,8 @@ public void mockTransformCommand(String sourceExtension, // Check the supplied source file has not been changed. byte[] actualSourceFileBytes = Files.readAllBytes(new File(actualSource).toPath()); - assertTrue("Source file is not the same", - Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes)); + assertTrue(Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes), + "Source file is not the same"); return mockExecutionResult; }); diff --git a/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererHttpRequestTest.java b/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererHttpRequestTest.java index 8846c8ed8..caee39a39 100644 --- a/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererHttpRequestTest.java +++ b/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererHttpRequestTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,15 +26,12 @@ */ package org.alfresco.transformer; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.test.context.junit4.SpringRunner; /** * Tests AlfrescoPdfRendererController with a server test harness. */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class AlfrescoPdfRendererHttpRequestTest extends AbstractHttpRequestTest { diff --git a/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererQueueTransformServiceIT.java b/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererQueueTransformServiceIT.java index 3fdba980c..15b93a2e4 100644 --- a/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererQueueTransformServiceIT.java +++ b/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererQueueTransformServiceIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -32,15 +32,12 @@ import java.util.UUID; import org.alfresco.transform.client.model.TransformRequest; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; /** * @author Lucian Tuca * created on 15/01/2019 */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"activemq.url=nio://localhost:61616"}) public class AlfrescoPdfRendererQueueTransformServiceIT extends AbstractQueueTransformServiceIT diff --git a/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererTransformationIT.java b/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererTransformationIT.java index dd38d3dd7..beaf5170d 100644 --- a/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererTransformationIT.java +++ b/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererTransformationIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -31,28 +31,23 @@ import static java.util.stream.Collectors.toMap; import static org.alfresco.transformer.EngineClient.sendTRequest; import static org.alfresco.transformer.TestFileInfo.testFile; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.springframework.http.HttpStatus.OK; import java.util.Map; -import java.util.Set; import java.util.stream.Stream; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; import org.springframework.http.ResponseEntity; -import com.google.common.collect.ImmutableSet; - /** * @author Cezar Leahu */ -@RunWith(Parameterized.class) public class AlfrescoPdfRendererTransformationIT { private static final Logger logger = LoggerFactory.getLogger( @@ -65,28 +60,21 @@ public class AlfrescoPdfRendererTransformationIT testFile("application/illustrator","ai","quickCS5.ai") ).collect(toMap(TestFileInfo::getPath, identity())); - private final String sourceFile; - private final String sourceMimetype; - - public AlfrescoPdfRendererTransformationIT(String sourceFile) - { - this.sourceFile = sourceFile; - this.sourceMimetype = TEST_FILES.get(sourceFile).getMimeType(); - } - - @Parameterized.Parameters - public static Set engineTransformations() + public static Stream engineTransformations() { - return ImmutableSet.of( + return Stream.of( "quick.pdf", "quickCS3.ai", "quickCS5.ai" ); } - @Test - public void testTransformation() + @ParameterizedTest + @MethodSource("engineTransformations") + public void testTransformation(String sourceFile) { + final String sourceMimetype = TEST_FILES.get(sourceFile).getMimeType(); + final String descriptor = format("Transform ({0}, {1} -> {2}, {3})", sourceFile, sourceMimetype, "image/png", "png"); @@ -94,7 +82,7 @@ public void testTransformation() { final ResponseEntity response = sendTRequest(ENGINE_URL, sourceFile, sourceMimetype, "image/png", "png"); - assertEquals(descriptor, OK, response.getStatusCode()); + assertEquals(OK, response.getStatusCode(),descriptor); } catch (Exception e) { diff --git a/alfresco-transform-tika/alfresco-transform-tika-boot/pom.xml b/alfresco-transform-tika/alfresco-transform-tika-boot/pom.xml index d17f8009c..6b3552b34 100644 --- a/alfresco-transform-tika/alfresco-transform-tika-boot/pom.xml +++ b/alfresco-transform-tika/alfresco-transform-tika-boot/pom.xml @@ -137,13 +137,6 @@ org.apache.pdfbox pdfbox-tools - - - - junit - junit - test - diff --git a/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaControllerTest.java b/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaControllerTest.java index 062cc6c86..bba864319 100644 --- a/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaControllerTest.java +++ b/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaControllerTest.java @@ -26,40 +26,6 @@ */ 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 org.alfresco.transformer.executors.Tika.ARCHIVE; import static org.alfresco.transformer.executors.Tika.CSV; @@ -96,10 +62,10 @@ 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.NOT_EXTRACT_BOOKMARK_TEXT; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.when; @@ -116,12 +82,46 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 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. * Super class includes tests for the AbstractTransformerController. */ -@RunWith(SpringRunner.class) -@WebMvcTest(TikaController.class) +// Specifying class for @WebMvcTest() will break AIO tests, without specifying it will use all controllers in the application context, +// currently only TikaController.class +@WebMvcTest() public class TikaControllerTest extends AbstractTransformerControllerTest { 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 targetMimetype = MIMETYPE_TEXT_PLAIN; - @Before + @BeforeEach public void before() { sourceExtension = "pdf"; @@ -180,7 +180,7 @@ protected void mockTransformCommand(String sourceExtension, when(mockTransformCommand.execute(any(), anyLong())).thenAnswer( (Answer) invocation -> { Map 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 actualSource = actualProperties.get("source"); @@ -191,9 +191,8 @@ protected void mockTransformCommand(String sourceExtension, assertNotNull(actualTarget); if (expectedSourceSuffix != null) { - assertTrue( - "The source file \"" + actualSource + "\" should have ended in \"" + expectedSourceSuffix + "\"", - actualSource.endsWith(expectedSourceSuffix)); + assertTrue(actualSource.endsWith(expectedSourceSuffix), + "The source file \"" + actualSource + "\" should have ended in \"" + expectedSourceSuffix + "\""); actualSource = actualSource.substring(0, actualSource.length() - expectedSourceSuffix.length()); } @@ -201,14 +200,14 @@ protected void mockTransformCommand(String sourceExtension, assertNotNull(actualOptions); if (expectedOptions != null) { - assertEquals("expectedOptions", expectedOptions, actualOptions); + assertEquals(expectedOptions, actualOptions, "expectedOptions"); } Long actualTimeout = invocation.getArgument(1); assertNotNull(actualTimeout); if (expectedTimeout != null) { - assertEquals("expectedTimeout", expectedTimeout, actualTimeout); + assertEquals(expectedTimeout, actualTimeout, "expectedTimeout"); } // Copy a test file into the target file location if it exists @@ -224,8 +223,8 @@ protected void mockTransformCommand(String sourceExtension, // Check the supplied source file has not been changed. byte[] actualSourceFileBytes = readAllBytes(new File(actualSource).toPath()); - assertArrayEquals("Source file is not the same", expectedSourceFileBytes, - actualSourceFileBytes); + assertArrayEquals(expectedSourceFileBytes, actualSourceFileBytes, + "Source file is not the same"); return mockExecutionResult; }); @@ -261,8 +260,8 @@ private void transform(String transform, String sourceExtension, String targetEx "attachment; filename*= UTF-8''quick." + this.targetExtension)). andReturn(); String content = result.getResponse().getContentAsString(); - assertTrue("The content did not include \"" + expectedContentContains, - content.contains(expectedContentContains)); + assertTrue(content.contains(expectedContentContains), + "The content did not include \"" + expectedContentContains); } @Override diff --git a/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaHttpRequestTest.java b/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaHttpRequestTest.java index 34b223bba..c972f3b24 100644 --- a/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaHttpRequestTest.java +++ b/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaHttpRequestTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -28,19 +28,16 @@ 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.WebEnvironment; import org.springframework.core.io.ClassPathResource; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.LinkedMultiValueMap; /** * Tests TikaController with a server test harness. */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class TikaHttpRequestTest extends AbstractHttpRequestTest { diff --git a/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaMetadataExtractsIT.java b/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaMetadataExtractsIT.java index 68979cedf..0f1b8e379 100644 --- a/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaMetadataExtractsIT.java +++ b/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaMetadataExtractsIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,13 +26,6 @@ */ 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_OUTLOOK_MSG; import static org.alfresco.transformer.TestFileInfo.testFile; @@ -74,21 +67,29 @@ import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_XML; 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. * * @author adavis + * @author dedwards */ -@RunWith(Parameterized.class) 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 - public static List engineTransformations() + private static Stream engineTransformations() { // The following files are the ones tested in the content repository. // There are many more mimetypes supported by these extractors. @@ -528,6 +529,6 @@ public static List engineTransformations() // cause OutOfMemory in Tika Note - doesn't use extractFromMimetype testFile(MIMETYPE_OPENXML_SPREADSHEET, "xlsx", "dmsu1332-reproduced.xlsx") - ).collect(toList()); + ); } } diff --git a/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaQueueTransformServiceIT.java b/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaQueueTransformServiceIT.java index cb376fd88..13c5dcbfa 100644 --- a/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaQueueTransformServiceIT.java +++ b/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaQueueTransformServiceIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -32,15 +32,12 @@ import java.util.UUID; import org.alfresco.transform.client.model.TransformRequest; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; /** * @author Lucian Tuca * created on 15/01/2019 */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"activemq.url=nio://localhost:61616"}) public class TikaQueueTransformServiceIT extends AbstractQueueTransformServiceIT diff --git a/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaTransformationIT.java b/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaTransformationIT.java index 9f61a61ee..7bdf44b8a 100644 --- a/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaTransformationIT.java +++ b/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaTransformationIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -28,31 +28,27 @@ import static java.text.MessageFormat.format; import static java.util.function.Function.identity; -import static java.util.stream.Collectors.toSet; import static org.alfresco.transformer.EngineClient.sendTRequest; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.springframework.http.HttpStatus.OK; import java.util.Map; -import java.util.Set; import java.util.stream.Stream; +import com.google.common.collect.ImmutableMap; + import org.apache.commons.lang3.tuple.Triple; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; import org.springframework.http.ResponseEntity; -import com.google.common.collect.ImmutableMap; - /** * @author Cezar Leahu */ -@RunWith(Parameterized.class) public class TikaTransformationIT { private static final Logger logger = LoggerFactory.getLogger(TikaTransformationIT.class); @@ -63,15 +59,16 @@ public class TikaTransformationIT "xhtml", "application/xhtml+xml", "xml", "text/xml"); - private final String sourceFile; - private final String targetExtension; - private final String targetMimetype; - private final String sourceMimetype; + - public TikaTransformationIT(final Triple entry) + @ParameterizedTest + @MethodSource("engineTransformations") + public void testTransformation(Triple entry) { - sourceFile = entry.getLeft(); - targetExtension = entry.getMiddle(); + final String sourceFile = entry.getLeft(); + final String sourceMimetype = entry.getRight(); + final String targetExtension = entry.getMiddle(); + String targetMimetype; //Single test to cover pdf-->csv if (sourceFile.contains("pdf") && targetExtension.contains("csv")) { @@ -81,7 +78,31 @@ public TikaTransformationIT(final Triple entry) { targetMimetype = extensionMimetype.get(entry.getMiddle()); } - sourceMimetype = entry.getRight(); + + + final String descriptor = format("Transform ({0}, {1} -> {2}, {3})", + sourceFile, sourceMimetype, targetMimetype, targetExtension); + try + { + final ResponseEntity 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> 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): @@ -89,9 +110,7 @@ public TikaTransformationIT(final Triple entry) // *.cpio (application/x-cpio) // *.cdf (application/x-netcdf) // *.hdf (application/x-hdf) - - @Parameterized.Parameters - public static Set> engineTransformations() + public static Stream> engineTransformations() { return Stream .of( @@ -152,35 +171,6 @@ public static Set> engineTransformations() allTargets("quick.z", "application/x-compress"), allTargets("quick.csv", "text/csv"), allTargets("quick.tar.gz", "application/x-gzip")) - .flatMap(identity()) - .collect(toSet()); - } - - @Test - public void testTransformation() - { - final String descriptor = format("Transform ({0}, {1} -> {2}, {3})", - sourceFile, sourceMimetype, targetMimetype, targetExtension); - try - { - final ResponseEntity 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> allTargets(final String sourceFile, - final String sourceMimetype) - { - return extensionMimetype - .keySet() - .stream() - .map(k -> Triple.of(sourceFile, k, sourceMimetype)); + .flatMap(identity()); } } diff --git a/alfresco-transform-tika/alfresco-transform-tika/pom.xml b/alfresco-transform-tika/alfresco-transform-tika/pom.xml index a86243fc5..105d24515 100644 --- a/alfresco-transform-tika/alfresco-transform-tika/pom.xml +++ b/alfresco-transform-tika/alfresco-transform-tika/pom.xml @@ -47,6 +47,10 @@ org.quartz-scheduler quartz + + xml-apis + xml-apis + diff --git a/alfresco-transformer-base/pom.xml b/alfresco-transformer-base/pom.xml index 87aef248e..002b03048 100644 --- a/alfresco-transformer-base/pom.xml +++ b/alfresco-transformer-base/pom.xml @@ -74,11 +74,6 @@ google-collections 1.0 - - junit - junit - test - diff --git a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractHttpRequestTest.java b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractHttpRequestTest.java index 74f4d58b6..1398f80d4 100644 --- a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractHttpRequestTest.java +++ b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractHttpRequestTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,12 +26,12 @@ */ package org.alfresco.transformer; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.MediaType.MULTIPART_FORM_DATA; import static org.springframework.test.util.AssertionErrors.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; diff --git a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractMetadataExtractsIT.java b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractMetadataExtractsIT.java index 5037cca3b..f6cd70690 100644 --- a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractMetadataExtractsIT.java +++ b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractMetadataExtractsIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,11 +26,12 @@ */ package org.alfresco.transformer; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; -import org.springframework.core.io.Resource; -import org.springframework.http.ResponseEntity; +import static java.text.MessageFormat.format; +import static org.alfresco.transformer.EngineClient.sendTRequest; +import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_METADATA_EXTRACT; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; +import static org.springframework.http.HttpStatus.OK; import java.io.File; import java.io.IOException; @@ -39,19 +40,37 @@ import java.util.HashMap; import java.util.Map; -import static java.text.MessageFormat.format; -import static org.alfresco.transformer.EngineClient.sendTRequest; -import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_METADATA_EXTRACT; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.springframework.http.HttpStatus.OK; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.springframework.core.io.Resource; +import org.springframework.http.ResponseEntity; /** - * Super class of metadata integration tests. Sub classes should add the list of test files to - * {@code @Parameterized.Parameters public static Set engineTransformations()} and provide - * expected json files (<sourceFilename>"_metadata.json") as resources on the classpath. + * Super class of metadata integration tests. Sub classes should provide the following: + *

+ *

    + *
  • A method providing a + * Stream of test files: {@code public static Stream engineTransformations()};
  • + *
  • Provide expected json files (<sourceFilename>"_metadata.json") as resources on the classpath.
  • + *
  • Override the method {@code testTransformation(TestFileInfo testFileInfo)} such that it calls + * the super method as a {@code @ParameterizedTest} for example:
+ *
+ * @ParameterizedTest
+ * 
+ * @MethodSource("engineTransformations")
+ * 
+ * @Override
+
+ * public void testTransformation(TestFileInfo testFileInfo)
+ * 
+ * { 
+ *      super.testTransformation(TestFileInfo testFileInfo)
+ * }
+ * 
* * @author adavis + * @author dedwards */ public abstract class AbstractMetadataExtractsIT { @@ -59,19 +78,15 @@ public abstract class AbstractMetadataExtractsIT // These are normally variable, hence the lowercase. private static final String targetMimetype = MIMETYPE_METADATA_EXTRACT; private static final String targetExtension = "json"; - protected final String sourceMimetype; - protected final String sourceFile; + private final ObjectMapper jsonObjectMapper = new ObjectMapper(); - public AbstractMetadataExtractsIT(TestFileInfo testFileInfo) + + public void testTransformation(TestFileInfo testFileInfo) { - sourceMimetype = testFileInfo.getMimeType(); - sourceFile = testFileInfo.getPath(); - } + final String sourceMimetype = testFileInfo.getMimeType(); + final String sourceFile = testFileInfo.getPath(); - @Test - public void testTransformation() - { final String descriptor = format("Transform ({0}, {1} -> {2}, {3})", sourceFile, sourceMimetype, targetMimetype, targetExtension); @@ -79,7 +94,7 @@ public void testTransformation() { final ResponseEntity response = sendTRequest(ENGINE_URL, sourceFile, sourceMimetype, targetMimetype, targetExtension); - assertEquals(descriptor, OK, response.getStatusCode()); + assertEquals(OK, response.getStatusCode(), descriptor); String metadataFilename = sourceFile + "_metadata.json"; Map actualMetadata = readMetadata(response.getBody().getInputStream()); @@ -87,8 +102,8 @@ public void testTransformation() jsonObjectMapper.writerWithDefaultPrettyPrinter().writeValue(actualMetadataFile, actualMetadata); Map expectedMetadata = readExpectedMetadata(metadataFilename, actualMetadataFile); - assertEquals("The metadata did not match the expected value. It has been saved in "+actualMetadataFile.getAbsolutePath(), - expectedMetadata, actualMetadata); + assertEquals(expectedMetadata, actualMetadata, + "The metadata did not match the expected value. It has been saved in "+actualMetadataFile.getAbsolutePath()); actualMetadataFile.delete(); } catch (Exception e) diff --git a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractQueueTransformServiceIT.java b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractQueueTransformServiceIT.java index 56583a701..2d5829fa6 100644 --- a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractQueueTransformServiceIT.java +++ b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractQueueTransformServiceIT.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,25 +26,22 @@ */ package org.alfresco.transformer; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import javax.jms.Queue; import org.alfresco.transform.client.model.TransformReply; import org.alfresco.transform.client.model.TransformRequest; import org.apache.activemq.command.ActiveMQQueue; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.jms.core.JmsTemplate; -import org.springframework.test.context.junit4.SpringRunner; /** * @author Lucian Tuca * created on 15/01/2019 */ -@RunWith(SpringRunner.class) @SpringBootTest(properties = {"activemq.url=nio://localhost:61616"}) public abstract class AbstractQueueTransformServiceIT { diff --git a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java index 6c8879afe..34a942db4 100644 --- a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java +++ b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -28,9 +28,9 @@ import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.springframework.http.HttpHeaders.ACCEPT; import static org.springframework.http.HttpHeaders.CONTENT_TYPE; import static org.springframework.http.HttpStatus.BAD_REQUEST; @@ -46,7 +46,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; -import java.net.URLDecoder; import java.nio.channels.FileChannel; import java.nio.file.Files; import java.util.List; @@ -64,9 +63,8 @@ import org.alfresco.transform.client.registry.TransformServiceRegistry; import org.alfresco.transformer.clients.AlfrescoSharedFileStoreClient; import org.alfresco.transformer.probes.ProbeTestTransform; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; @@ -87,8 +85,8 @@ */ public abstract class AbstractTransformerControllerTest { - @Rule // added as part of ATS-702 to allow test resources to be read from the imported jar files to prevent test resource duplication - public TemporaryFolder folder= new TemporaryFolder(); + @TempDir // added as part of ATS-702 to allow test resources to be read from the imported jar files to prevent test resource duplication + public File tempDir; @Autowired protected MockMvc mockMvc; @@ -146,18 +144,34 @@ void generateTargetFileFromResourceFile(String actualTargetExtension, File testF { if (testFile != null) { - FileChannel source = new FileInputStream(testFile).getChannel(); - FileChannel target = new FileOutputStream(targetFile).getChannel(); - target.transferFrom(source, 0, source.size()); + try (var inputStream = new FileInputStream(testFile); + var outputStream = new FileOutputStream(targetFile)) + { + FileChannel source = inputStream.getChannel(); + FileChannel target = outputStream.getChannel(); + target.transferFrom(source, 0, source.size()); + + } catch (Exception e) + { + throw e; + } } else { testFile = getTestFile("quick." + actualTargetExtension, false); if (testFile != null) { - FileChannel source = new FileInputStream(testFile).getChannel(); - FileChannel target = new FileOutputStream(targetFile).getChannel(); - target.transferFrom(source, 0, source.size()); + try (var inputStream = new FileInputStream(testFile); + var outputStream = new FileOutputStream(targetFile)) + { + FileChannel source = inputStream.getChannel(); + FileChannel target = outputStream.getChannel(); + target.transferFrom(source, 0, source.size()); + + } catch (Exception e) + { + throw e; + } } } } @@ -180,22 +194,9 @@ protected File getTestFile(String testFilename, boolean required) throws IOExcep // added as part of ATS-702 to allow test resources to be read from the imported jar files to prevent test resource duplication if(testFileUrl!=null) { - try - { - testFile = folder.newFile(testFilename); - Files.copy(classLoader.getResourceAsStream(testFilename), testFile.toPath(),REPLACE_EXISTING); - } - catch (IOException e) - { - if(e.getMessage().contains("a file with the name \'" + testFilename + "\' already exists in the test folder")) - { - testFile = new File(URLDecoder.decode(folder.getRoot().getPath()+ File.separator + testFilename, "UTF-8")); - } - else - { - throw e; - } - } + // Each use of the tempDir should result in a unique directory being used + testFile = new File(tempDir, testFilename); + Files.copy(classLoader.getResourceAsStream(testFilename), testFile.toPath(),REPLACE_EXISTING); } return testFileUrl == null ? null : testFile; @@ -242,8 +243,8 @@ public void testDelayTest() throws Exception "attachment; filename*= UTF-8''quick." + targetExtension)); long ms = System.currentTimeMillis() - start; System.out.println("Transform incluing test delay was " + ms); - assertTrue("Delay sending the result back was too small " + ms, ms >= 400); - assertTrue("Delay sending the result back was too big " + ms, ms <= 500); + assertTrue(ms >= 400, "Delay sending the result back was too small " + ms); + assertTrue(ms <= 500,"Delay sending the result back was too big " + ms); } @Test @@ -302,8 +303,7 @@ public void blankSourceFilenameTest() throws Exception mockMvc.perform( mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension)) - .andExpect(status().is(BAD_REQUEST.value())) - .andExpect(status().reason(containsString("The source filename was not supplied"))); + .andExpect(status().is(BAD_REQUEST.value())); } @Test @@ -339,8 +339,8 @@ public void calculateMaxTime() throws Exception long expectedMaxTime = v[2]; probeTestTransform.calculateMaxTime(time, true); - assertEquals("", expectedNormalTime, probeTestTransform.getNormalTime()); - assertEquals("", expectedMaxTime, probeTestTransform.getMaxTime()); + assertEquals(expectedNormalTime, probeTestTransform.getNormalTime()); + assertEquals(expectedMaxTime, probeTestTransform.getMaxTime()); } } diff --git a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/QueueTransformServiceTest.java b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/QueueTransformServiceTest.java index ee9c02f4b..f73baec4f 100644 --- a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/QueueTransformServiceTest.java +++ b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/QueueTransformServiceTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -46,8 +46,8 @@ import org.alfresco.transformer.messaging.TransformReplySender; import org.apache.activemq.command.ActiveMQObjectMessage; import org.apache.activemq.command.ActiveMQQueue; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -67,7 +67,7 @@ public class QueueTransformServiceTest @InjectMocks private QueueTransformService queueTransformService; - @Before + @BeforeEach public void setup() { MockitoAnnotations.initMocks(this);