diff --git a/Kitodo/pom.xml b/Kitodo/pom.xml index f3faa6fb2ed..3933d83c3ad 100644 --- a/Kitodo/pom.xml +++ b/Kitodo/pom.xml @@ -226,10 +226,6 @@ org.junit.jupiter junit-jupiter-engine - - org.junit.vintage - junit-vintage-engine - org.xmlunit xmlunit-core @@ -250,6 +246,14 @@ org.mockito mockito-core + + org.mockito + mockito-junit-jupiter + + + org.hamcrest + hamcrest + org.primefaces.extensions primefaces-extensions diff --git a/Kitodo/src/test/java/de/sub/goobi/helper/encryption/MD4Test.java b/Kitodo/src/test/java/de/sub/goobi/helper/encryption/MD4Test.java index bec15a6e188..41a99c1e4b7 100644 --- a/Kitodo/src/test/java/de/sub/goobi/helper/encryption/MD4Test.java +++ b/Kitodo/src/test/java/de/sub/goobi/helper/encryption/MD4Test.java @@ -11,13 +11,13 @@ package de.sub.goobi.helper.encryption; -import static org.junit.Assert.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import java.nio.charset.StandardCharsets; import java.util.HashMap; import org.bouncycastle.crypto.digests.MD4Digest; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MD4Test { private static HashMap testData; @@ -43,8 +43,7 @@ public void encryptTest() { byte[] encrypted = new byte[digester.getDigestSize()]; digester.update(unicodePassword, 0, unicodePassword.length); digester.doFinal(encrypted, 0); - assertArrayEquals("Encrypted password doesn't match the precomputed one! ", - encrypted, testData.get(clearText)); + assertArrayEquals(encrypted, testData.get(clearText), "Encrypted password doesn't match the precomputed one! "); } } } diff --git a/Kitodo/src/test/java/org/kitodo/BasePrimefaceTest.java b/Kitodo/src/test/java/org/kitodo/BasePrimefaceTest.java index 3b1015a40a8..913282b305b 100644 --- a/Kitodo/src/test/java/org/kitodo/BasePrimefaceTest.java +++ b/Kitodo/src/test/java/org/kitodo/BasePrimefaceTest.java @@ -16,12 +16,12 @@ import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; -import org.junit.Before; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public abstract class BasePrimefaceTest { @Mock @@ -31,7 +31,7 @@ public abstract class BasePrimefaceTest { protected ExternalContext externalContext; - @Before + @BeforeEach public void initPrimeface() { when(facesContext.getExternalContext()).thenReturn(externalContext); } diff --git a/Kitodo/src/test/java/org/kitodo/config/ConfigCoreTest.java b/Kitodo/src/test/java/org/kitodo/config/ConfigCoreTest.java index a745d752556..8e2a77c83ef 100644 --- a/Kitodo/src/test/java/org/kitodo/config/ConfigCoreTest.java +++ b/Kitodo/src/test/java/org/kitodo/config/ConfigCoreTest.java @@ -11,9 +11,9 @@ package org.kitodo.config; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ConfigCoreTest { @@ -21,13 +21,13 @@ public class ConfigCoreTest { public void shouldGetKitodoConfigDirectory() { String expected = "src/test/resources/"; - assertEquals("Directory was queried incorrectly!", expected, ConfigCore.getKitodoConfigDirectory()); + assertEquals(expected, ConfigCore.getKitodoConfigDirectory(), "Directory was queried incorrectly!"); } @Test public void shouldGetKitodoDataDirectory() { String expected = "src/test/resources/metadata/"; - assertEquals("Directory was queried incorrectly!", expected, ConfigCore.getKitodoDataDirectory()); + assertEquals(expected, ConfigCore.getKitodoDataDirectory(), "Directory was queried incorrectly!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/config/ConfigProjectTest.java b/Kitodo/src/test/java/org/kitodo/config/ConfigProjectTest.java index 33462bfd467..ffd6b753706 100644 --- a/Kitodo/src/test/java/org/kitodo/config/ConfigProjectTest.java +++ b/Kitodo/src/test/java/org/kitodo/config/ConfigProjectTest.java @@ -11,28 +11,28 @@ package org.kitodo.config; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.IOException; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.FileLoader; import org.kitodo.exceptions.DoctypeMissingException; -import static org.junit.Assert.assertEquals; - public class ConfigProjectTest { private static ConfigProject configProject; - @BeforeClass + @BeforeAll public static void setUp() throws Exception { FileLoader.createConfigProjectsFile(); configProject = new ConfigProject("default"); } - @AfterClass + @AfterAll public static void tearDown() throws IOException { FileLoader.deleteConfigProjectsFile(); } @@ -40,35 +40,35 @@ public static void tearDown() throws IOException { @Test public void shouldGetConfigProjectsForItems() { List items = configProject.getParamList("createNewProcess.itemlist.item"); - assertEquals("Incorrect amount of items!", 10, items.size()); + assertEquals(10, items.size(), "Incorrect amount of items!"); } @Test public void shouldGetConfigProjectsForSelectItems() { List items = configProject.getParamList("createNewProcess.itemlist.item(1).select"); - assertEquals("Incorrect amount of select items for second element!", 3, items.size()); + assertEquals(3, items.size(), "Incorrect amount of select items for second element!"); } @Test public void shouldGetConfigProjectsForProcessTitles() { List processTitles = configProject.getParamList("createNewProcess.itemlist.processtitle"); - assertEquals("Incorrect amount of process titles!", 5, processTitles.size()); + assertEquals(5, processTitles.size(), "Incorrect amount of process titles!"); } @Test public void shouldGetDocType() throws DoctypeMissingException { - assertEquals("Document type is incorrect!", "monograph", configProject.getDocType()); + assertEquals("monograph", configProject.getDocType(), "Document type is incorrect!"); } @Test public void shouldGetTifDefinition() throws DoctypeMissingException { - assertEquals("Tif definition is incorrect!", "kitodo", configProject.getTifDefinition()); + assertEquals("kitodo", configProject.getTifDefinition(), "Tif definition is incorrect!"); } @Test public void shouldGetTitleDefinition() throws DoctypeMissingException { String titleDefinition = configProject.getTitleDefinition(); String expected = "TSL_ATS+'_'+CatalogIDDigital"; - assertEquals("Title definition is incorrect!", expected, titleDefinition); + assertEquals(expected, titleDefinition, "Title definition is incorrect!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/config/enums/KitodoConfigFileTest.java b/Kitodo/src/test/java/org/kitodo/config/enums/KitodoConfigFileTest.java index babbc916e7b..0b8811b455b 100644 --- a/Kitodo/src/test/java/org/kitodo/config/enums/KitodoConfigFileTest.java +++ b/Kitodo/src/test/java/org/kitodo/config/enums/KitodoConfigFileTest.java @@ -11,77 +11,68 @@ package org.kitodo.config.enums; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.File; import java.io.FileNotFoundException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.FileLoader; import org.kitodo.config.ConfigCore; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class KitodoConfigFileTest { - @Rule - public final ExpectedException exception = ExpectedException.none(); - - @BeforeClass + @BeforeAll public static void setUp() throws Exception { FileLoader.createConfigProjectsFile(); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { FileLoader.deleteConfigProjectsFile(); } @Test public void shouldGetFileNameTest() { - assertEquals("Config projects file name is incorrect!", "kitodo_projects.xml", - String.valueOf(KitodoConfigFile.PROJECT_CONFIGURATION)); - assertEquals("Config projects file name is incorrect!", "kitodo_projects.xml", - KitodoConfigFile.PROJECT_CONFIGURATION.getName()); + assertEquals("kitodo_projects.xml", String.valueOf(KitodoConfigFile.PROJECT_CONFIGURATION), "Config projects file name is incorrect!"); + assertEquals("kitodo_projects.xml", KitodoConfigFile.PROJECT_CONFIGURATION.getName(), "Config projects file name is incorrect!"); } @Test public void shouldGetAbsolutePathTest() { - assertTrue("Config projects file absolute path is incorrect!", - KitodoConfigFile.PROJECT_CONFIGURATION.getAbsolutePath().contains("Kitodo" + File.separator + "src" - + File.separator + "test" + File.separator + "resources" + File.separator + "kitodo_projects.xml")); + assertTrue(KitodoConfigFile.PROJECT_CONFIGURATION.getAbsolutePath().contains("Kitodo" + File.separator + "src" + + File.separator + "test" + File.separator + "resources" + File.separator + "kitodo_projects.xml"), "Config projects file absolute path is incorrect!"); } @Test public void shouldGetFileTest() { - assertEquals("Config projects file absolute path is incorrect!", - new File(ConfigCore.getKitodoConfigDirectory() + "kitodo_projects.xml"), - KitodoConfigFile.PROJECT_CONFIGURATION.getFile()); + assertEquals(new File(ConfigCore.getKitodoConfigDirectory() + "kitodo_projects.xml"), KitodoConfigFile.PROJECT_CONFIGURATION.getFile(), "Config projects file absolute path is incorrect!"); } @Test public void shouldGetByFileNameTest() throws FileNotFoundException { - assertEquals("Config projects file doesn't exists for given!", KitodoConfigFile.PROJECT_CONFIGURATION, - KitodoConfigFile.getByName("kitodo_projects.xml")); + assertEquals(KitodoConfigFile.PROJECT_CONFIGURATION, KitodoConfigFile.getByName("kitodo_projects.xml"), "Config projects file doesn't exists for given!"); } @Test - public void shouldNotGetByFileNameTest() throws FileNotFoundException { - exception.expect(FileNotFoundException.class); - exception.expectMessage("Configuration file 'kitodo_nonexistent.xml' doesn't exists!"); - KitodoConfigFile.getByName("kitodo_nonexistent.xml"); + public void shouldNotGetByFileNameTest() { + Exception exception = assertThrows(FileNotFoundException.class, + () -> KitodoConfigFile.getByName("kitodo_nonexistent.xml")); + + assertEquals("Configuration file 'kitodo_nonexistent.xml' doesn't exists!", exception.getMessage()); } @Test public void configFileShouldExistTest() { - assertTrue("Config projects file doesn't exist!", KitodoConfigFile.PROJECT_CONFIGURATION.exists()); + assertTrue(KitodoConfigFile.PROJECT_CONFIGURATION.exists(), "Config projects file doesn't exist!"); } @Test public void configFileShouldNotExistTest() { - assertTrue("Config OPAC file exists!", KitodoConfigFile.OPAC_CONFIGURATION.exists()); + assertTrue(KitodoConfigFile.OPAC_CONFIGURATION.exists(), "Config OPAC file exists!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/config/enums/ParameterCoreTest.java b/Kitodo/src/test/java/org/kitodo/config/enums/ParameterCoreTest.java index c8eaff5e77c..b318ccbaa04 100644 --- a/Kitodo/src/test/java/org/kitodo/config/enums/ParameterCoreTest.java +++ b/Kitodo/src/test/java/org/kitodo/config/enums/ParameterCoreTest.java @@ -11,23 +11,21 @@ package org.kitodo.config.enums; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ParameterCoreTest { @Test public void shouldGetParameterWithoutDefaultValueTest() { - assertNull("Default value for param exists!", - ParameterCore.DIR_USERS.getParameter().getDefaultValue()); + assertNull(ParameterCore.DIR_USERS.getParameter().getDefaultValue(), "Default value for param exists!"); } @Test public void shouldOverrideToStringWithParameterKeyTests() { ParameterCore parameterCore = ParameterCore.DIR_USERS; - assertEquals("Methods toString() was not overridden!", parameterCore.getParameter().getKey(), - String.valueOf(parameterCore)); + assertEquals(parameterCore.getParameter().getKey(), String.valueOf(parameterCore), "Methods toString() was not overridden!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/config/xml/fileformats/FileFormatsConfigIT.java b/Kitodo/src/test/java/org/kitodo/config/xml/fileformats/FileFormatsConfigIT.java index c2b4d7bff82..1ccfa733acf 100644 --- a/Kitodo/src/test/java/org/kitodo/config/xml/fileformats/FileFormatsConfigIT.java +++ b/Kitodo/src/test/java/org/kitodo/config/xml/fileformats/FileFormatsConfigIT.java @@ -11,44 +11,34 @@ package org.kitodo.config.xml.fileformats; -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.assertTrue; -import java.util.Locale; import java.util.Locale.LanguageRange; import javax.xml.bind.JAXBException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kitodo.api.imagemanagement.ImageFileFormat; + public class FileFormatsConfigIT { @Test public void testFileFormatsConfig() throws JAXBException { - assertEquals("kitodo_fileFormats.xml does not contain exactly 8 entries", 8, - FileFormatsConfig.getFileFormats().size()); + assertEquals(8, FileFormatsConfig.getFileFormats().size(), "kitodo_fileFormats.xml does not contain exactly 8 entries"); FileFormat tiff = FileFormatsConfig.getFileFormat("image/tiff").get(); - assertEquals("Wrong label of TIFF file format", "Tagged Image File Format (image/tiff, *.tif)", - tiff.getLabel()); - assertEquals("Wrong label with declared language range of TIFF file format", - "Tagged Image File Format (image/tiff, *.tif)", - tiff.getLabel(Locale.LanguageRange.parse("fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5"))); - assertTrue("Long time preservation validation file type is missing for TIFF file format", - tiff.getFileType().isPresent()); - assertEquals("Image management file format of TIFF file format is not TIFF", ImageFileFormat.TIFF, - tiff.getImageFileFormat().get()); + assertEquals("Tagged Image File Format (image/tiff, *.tif)", tiff.getLabel(), "Wrong label of TIFF file format"); + assertEquals("Tagged Image File Format (image/tiff, *.tif)", tiff.getLabel(LanguageRange.parse("fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5")), "Wrong label with declared language range of TIFF file format"); + assertTrue(tiff.getFileType().isPresent(), "Long time preservation validation file type is missing for TIFF file format"); + assertEquals(ImageFileFormat.TIFF, tiff.getImageFileFormat().get(), "Image management file format of TIFF file format is not TIFF"); } @Test public void testFileFormatsConfigTransliteration() throws JAXBException { FileFormat gif = FileFormatsConfig.getFileFormat("image/gif").get(); - assertEquals("Wrong label without declared language of GIF file format", - "Graphics Interchange Format (image/gif, *.gif)", gif.getLabel()); - assertEquals("Wrong label for language requesting arab of GIF file format", - "تنسيق تبادل الرسومات (image/gif, *.gif)", gif.getLabel(LanguageRange.parse("fr;q=0.9,ar;q=0.4,*;q=0.2"))); - assertEquals("Wrong label for language requesting no specialized label of GIF file format", - "Graphics Interchange Format (image/gif, *.gif)", - gif.getLabel(LanguageRange.parse("en;q=0.9,fr;q=0.4,*;q=0.2"))); + assertEquals("Graphics Interchange Format (image/gif, *.gif)", gif.getLabel(), "Wrong label without declared language of GIF file format"); + assertEquals("تنسيق تبادل الرسومات (image/gif, *.gif)", gif.getLabel(LanguageRange.parse("fr;q=0.9,ar;q=0.4,*;q=0.2")), "Wrong label for language requesting arab of GIF file format"); + assertEquals("Graphics Interchange Format (image/gif, *.gif)", gif.getLabel(LanguageRange.parse("en;q=0.9,fr;q=0.4,*;q=0.2")), "Wrong label for language requesting no specialized label of GIF file format"); } } diff --git a/Kitodo/src/test/java/org/kitodo/export/ExportDmsIT.java b/Kitodo/src/test/java/org/kitodo/export/ExportDmsIT.java index f15d9a9d2a9..74854953442 100644 --- a/Kitodo/src/test/java/org/kitodo/export/ExportDmsIT.java +++ b/Kitodo/src/test/java/org/kitodo/export/ExportDmsIT.java @@ -11,8 +11,8 @@ package org.kitodo.export; -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.assertTrue; import java.io.File; import java.io.FileNotFoundException; @@ -21,9 +21,9 @@ import java.lang.reflect.Method; import java.net.URI; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.TreeDeleter; import org.kitodo.data.database.beans.Process; @@ -39,7 +39,7 @@ public class ExportDmsIT { /** * Initializes the test. */ - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesForWorkflowFull(); @@ -75,7 +75,7 @@ static void makeDirectoryWithSomeFiles(File parent, int count, String pattern, i /** * Cleans up after the test. */ - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -99,35 +99,30 @@ public void testDirectoryDownload() throws Exception { directoryDownload.invoke(new ExportDms(), process, destination); final long tookNanos = System.nanoTime() - start; - assertTrue("Destination location should exist", downloadDir.isDirectory()); + assertTrue(downloadDir.isDirectory(), "Destination location should exist"); File jpgsMax = new File(downloadDir, "jpgs/max"); - assertTrue("Folder jpgs/max should exist in destination location", jpgsMax.isDirectory()); - assertEquals("jpgs/max should contain 184 JPEGs", 184, - jpgsMax.list((directory, filename) -> filename.endsWith(".jpg")).length); + assertTrue(jpgsMax.isDirectory(), "Folder jpgs/max should exist in destination location"); + assertEquals(184, jpgsMax.list((directory, filename) -> filename.endsWith(".jpg")).length, "jpgs/max should contain 184 JPEGs"); File jpgsDefault = new File(downloadDir, "jpgs/default"); - assertTrue("Folder jpgs/default should exist in destination location", jpgsDefault.isDirectory()); - assertEquals("jpgs/default should contain 184 JPEGs", 184, - jpgsDefault.list((directory, filename) -> filename.endsWith(".jpg")).length); + assertTrue(jpgsDefault.isDirectory(), "Folder jpgs/default should exist in destination location"); + assertEquals(184, jpgsDefault.list((directory, filename) -> filename.endsWith(".jpg")).length, "jpgs/default should contain 184 JPEGs"); File jpgsThumbs = new File(downloadDir, "jpgs/thumbs"); - assertTrue("Folder jpgs/thumbs should exist in destination location", jpgsThumbs.isDirectory()); - assertEquals("jpgs/thumbs should contain 184 JPEGs", 184, - jpgsThumbs.list((directory, filename) -> filename.endsWith(".jpg")).length); + assertTrue(jpgsThumbs.isDirectory(), "Folder jpgs/thumbs should exist in destination location"); + assertEquals(184, jpgsThumbs.list((directory, filename) -> filename.endsWith(".jpg")).length, "jpgs/thumbs should contain 184 JPEGs"); File ocrAlto = new File(downloadDir, "ocr/alto"); - assertTrue("Folder ocr/alto should exist in destination location", ocrAlto.isDirectory()); - assertEquals("ocr/alto should contain 184 XMLs", 184, - ocrAlto.list((directory, filename) -> filename.endsWith(".xml")).length); + assertTrue(ocrAlto.isDirectory(), "Folder ocr/alto should exist in destination location"); + assertEquals(184, ocrAlto.list((directory, filename) -> filename.endsWith(".xml")).length, "ocr/alto should contain 184 XMLs"); File pdf = new File(downloadDir, "pdf"); - assertTrue("Folder pdf should exist in destination location", pdf.isDirectory()); - assertEquals("pdf should contain 184 PDFs", 184, - pdf.list((directory, filename) -> filename.endsWith(".pdf")).length); + assertTrue(pdf.isDirectory(), "Folder pdf should exist in destination location"); + assertEquals(184, pdf.list((directory, filename) -> filename.endsWith(".pdf")).length, "pdf should contain 184 PDFs"); float totalBytes = 184f * (358000 + 181554 + 1890 + 25157 + 3548885); float mbps = totalBytes / tookNanos * 1953125 / 2048; - assertTrue("It should have been copied >50 MB/s (was: " + mbps + " MB/s)", mbps > 50); + assertTrue(mbps > 50, "It should have been copied >50 MB/s (was: " + mbps + " MB/s)"); } } diff --git a/Kitodo/src/test/java/org/kitodo/export/XsltHelperTest.java b/Kitodo/src/test/java/org/kitodo/export/XsltHelperTest.java index d7a05ce90fa..ea52d525c86 100644 --- a/Kitodo/src/test/java/org/kitodo/export/XsltHelperTest.java +++ b/Kitodo/src/test/java/org/kitodo/export/XsltHelperTest.java @@ -11,7 +11,7 @@ package org.kitodo.export; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.ByteArrayOutputStream; import java.io.File; @@ -21,7 +21,7 @@ import javax.xml.transform.stream.StreamSource; import org.apache.commons.io.FileUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xmlunit.matchers.CompareMatcher; public class XsltHelperTest { diff --git a/Kitodo/src/test/java/org/kitodo/production/converter/AuthorityConverterIT.java b/Kitodo/src/test/java/org/kitodo/production/converter/AuthorityConverterIT.java index eb1b5c7337a..002fda9b83e 100644 --- a/Kitodo/src/test/java/org/kitodo/production/converter/AuthorityConverterIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/converter/AuthorityConverterIT.java @@ -11,12 +11,12 @@ package org.kitodo.production.converter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Authority; @@ -24,13 +24,13 @@ public class AuthorityConverterIT { private static final String MESSAGE = "Authority was not converted correctly!"; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertAuthorities(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -40,28 +40,28 @@ public static void cleanDatabase() throws Exception { public void shouldGetAsObject() { AuthorityConverter authorityConverter = new AuthorityConverter(); Authority authority = (Authority) authorityConverter.getAsObject(null, null, "20"); - assertEquals(MESSAGE, 20, authority.getId().intValue()); + assertEquals(20, authority.getId().intValue(), MESSAGE); } @Test public void shouldGetAsObjectIncorrectString() { AuthorityConverter authorityConverter = new AuthorityConverter(); String authority = (String) authorityConverter.getAsObject(null, null, "in"); - assertEquals(MESSAGE, "0", authority); + assertEquals("0", authority, MESSAGE); } @Test public void shouldGetAsObjectIncorrectId() { AuthorityConverter authorityConverter = new AuthorityConverter(); String authority = (String) authorityConverter.getAsObject(null, null, "1000"); - assertEquals(MESSAGE, "0", authority); + assertEquals("0", authority, MESSAGE); } @Test public void shouldGetAsObjectNullObject() { AuthorityConverter authorityConverter = new AuthorityConverter(); Object authority = authorityConverter.getAsObject(null, null, null); - assertNull(MESSAGE, authority); + assertNull(authority, MESSAGE); } @Test @@ -70,7 +70,7 @@ public void shouldGetAsString() { Authority newAuthority = new Authority(); newAuthority.setId(20); String authority = authorityConverter.getAsString(null, null, newAuthority); - assertEquals(MESSAGE, "20", authority); + assertEquals("20", authority, MESSAGE); } @Test @@ -78,20 +78,20 @@ public void shouldGetAsStringWithoutId() { AuthorityConverter authorityConverter = new AuthorityConverter(); Authority newAuthority = new Authority(); String authority = authorityConverter.getAsString(null, null, newAuthority); - assertEquals(MESSAGE, "0", authority); + assertEquals("0", authority, MESSAGE); } @Test public void shouldGetAsStringWithString() { AuthorityConverter authorityConverter = new AuthorityConverter(); String authority = authorityConverter.getAsString(null, null, "20"); - assertEquals(MESSAGE, "20", authority); + assertEquals("20", authority, MESSAGE); } @Test public void shouldNotGetAsStringNullObject() { AuthorityConverter authorityConverter = new AuthorityConverter(); String authority = authorityConverter.getAsString(null, null, null); - assertNull(MESSAGE, authority); + assertNull(authority, MESSAGE); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/converter/ClientConverterIT.java b/Kitodo/src/test/java/org/kitodo/production/converter/ClientConverterIT.java index 4d51d044051..08a38e82eb8 100644 --- a/Kitodo/src/test/java/org/kitodo/production/converter/ClientConverterIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/converter/ClientConverterIT.java @@ -11,12 +11,12 @@ package org.kitodo.production.converter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Client; @@ -24,13 +24,13 @@ public class ClientConverterIT { private static final String MESSAGE = "Client was not converted correctly!"; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertClients(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -40,28 +40,28 @@ public static void cleanDatabase() throws Exception { public void shouldGetAsObject() { ClientConverter clientConverter = new ClientConverter(); Client client = (Client) clientConverter.getAsObject(null, null, "2"); - assertEquals(MESSAGE, 2, client.getId().intValue()); + assertEquals(2, client.getId().intValue(), MESSAGE); } @Test public void shouldGetAsObjectIncorrectString() { ClientConverter clientConverter = new ClientConverter(); String client = (String) clientConverter.getAsObject(null, null, "in"); - assertEquals(MESSAGE, "0", client); + assertEquals("0", client, MESSAGE); } @Test public void shouldGetAsObjectIncorrectId() { ClientConverter clientConverter = new ClientConverter(); String client = (String) clientConverter.getAsObject(null, null, "10"); - assertEquals(MESSAGE, "0", client); + assertEquals("0", client, MESSAGE); } @Test public void shouldGetAsObjectNullObject() { ClientConverter clientConverter = new ClientConverter(); Object client = clientConverter.getAsObject(null, null, null); - assertNull(MESSAGE, client); + assertNull(client, MESSAGE); } @Test @@ -70,7 +70,7 @@ public void shouldGetAsString() { Client newClient = new Client(); newClient.setId(20); String client = clientConverter.getAsString(null, null, newClient); - assertEquals(MESSAGE, "20", client); + assertEquals("20", client, MESSAGE); } @Test @@ -78,20 +78,20 @@ public void shouldGetAsStringWithoutId() { ClientConverter clientConverter = new ClientConverter(); Client newClient = new Client(); String client = clientConverter.getAsString(null, null, newClient); - assertEquals(MESSAGE, "0", client); + assertEquals("0", client, MESSAGE); } @Test public void shouldGetAsStringWithString() { ClientConverter clientConverter = new ClientConverter(); String client = clientConverter.getAsString(null, null, "20"); - assertEquals(MESSAGE, "20", client); + assertEquals("20", client, MESSAGE); } @Test public void shouldNotGetAsStringNullObject() { ClientConverter clientConverter = new ClientConverter(); String client = clientConverter.getAsString(null, null, null); - assertNull(MESSAGE, client); + assertNull(client, MESSAGE); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/converter/DocketConverterIT.java b/Kitodo/src/test/java/org/kitodo/production/converter/DocketConverterIT.java index b4563912883..e69ae3279ff 100644 --- a/Kitodo/src/test/java/org/kitodo/production/converter/DocketConverterIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/converter/DocketConverterIT.java @@ -11,12 +11,12 @@ package org.kitodo.production.converter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Docket; @@ -24,14 +24,14 @@ public class DocketConverterIT { private static final String MESSAGE = "Docket was not converted correctly!"; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertClients(); MockDatabase.insertDockets(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -41,28 +41,28 @@ public static void cleanDatabase() throws Exception { public void shouldGetAsObject() { DocketConverter docketConverter = new DocketConverter(); Docket docket = (Docket) docketConverter.getAsObject(null, null, "2"); - assertEquals(MESSAGE, 2, docket.getId().intValue()); + assertEquals(2, docket.getId().intValue(), MESSAGE); } @Test public void shouldGetAsObjectIncorrectString() { DocketConverter docketConverter = new DocketConverter(); String docket = (String) docketConverter.getAsObject(null, null, "in"); - assertEquals(MESSAGE, "0", docket); + assertEquals("0", docket, MESSAGE); } @Test public void shouldGetAsObjectIncorrectId() { DocketConverter docketConverter = new DocketConverter(); String docket = (String) docketConverter.getAsObject(null, null, "10"); - assertEquals(MESSAGE, "0", docket); + assertEquals("0", docket, MESSAGE); } @Test public void shouldGetAsObjectNullObject() { DocketConverter docketConverter = new DocketConverter(); Object docket = docketConverter.getAsObject(null, null, null); - assertNull(MESSAGE, docket); + assertNull(docket, MESSAGE); } @Test @@ -71,7 +71,7 @@ public void shouldGetAsString() { Docket newDocket = new Docket(); newDocket.setId(20); String docket = docketConverter.getAsString(null, null, newDocket); - assertEquals(MESSAGE, "20", docket); + assertEquals("20", docket, MESSAGE); } @Test @@ -79,20 +79,20 @@ public void shouldGetAsStringWithoutId() { DocketConverter docketConverter = new DocketConverter(); Docket newDocket = new Docket(); String docket = docketConverter.getAsString(null, null, newDocket); - assertEquals(MESSAGE, "0", docket); + assertEquals("0", docket, MESSAGE); } @Test public void shouldGetAsStringWithString() { DocketConverter docketConverter = new DocketConverter(); String docket = docketConverter.getAsString(null, null, "20"); - assertEquals(MESSAGE, "20", docket); + assertEquals("20", docket, MESSAGE); } @Test public void shouldNotGetAsStringNullObject() { DocketConverter docketConverter = new DocketConverter(); String docket = docketConverter.getAsString(null, null, null); - assertNull(MESSAGE, docket); + assertNull(docket, MESSAGE); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/converter/RulesetConverterIT.java b/Kitodo/src/test/java/org/kitodo/production/converter/RulesetConverterIT.java index 1de3cdfb279..ac7fc1d75b8 100644 --- a/Kitodo/src/test/java/org/kitodo/production/converter/RulesetConverterIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/converter/RulesetConverterIT.java @@ -11,12 +11,12 @@ package org.kitodo.production.converter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Ruleset; @@ -24,14 +24,14 @@ public class RulesetConverterIT { private static final String MESSAGE = "Ruleset was not converted correctly!"; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertClients(); MockDatabase.insertRulesets(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -41,28 +41,28 @@ public static void cleanDatabase() throws Exception { public void shouldGetAsObject() { RulesetConverter rulesetConverter = new RulesetConverter(); Ruleset ruleset = (Ruleset) rulesetConverter.getAsObject(null, null, "2"); - assertEquals(MESSAGE, 2, ruleset.getId().intValue()); + assertEquals(2, ruleset.getId().intValue(), MESSAGE); } @Test public void shouldGetAsObjectIncorrectString() { RulesetConverter rulesetConverter = new RulesetConverter(); String ruleset = (String) rulesetConverter.getAsObject(null, null, "in"); - assertEquals(MESSAGE, "0", ruleset); + assertEquals("0", ruleset, MESSAGE); } @Test public void shouldGetAsObjectIncorrectId() { RulesetConverter rulesetConverter = new RulesetConverter(); String ruleset = (String) rulesetConverter.getAsObject(null, null, "10"); - assertEquals(MESSAGE, "0", ruleset); + assertEquals("0", ruleset, MESSAGE); } @Test public void shouldGetAsObjectNullObject() { RulesetConverter rulesetConverter = new RulesetConverter(); Object ruleset = rulesetConverter.getAsObject(null, null, null); - assertNull(MESSAGE, ruleset); + assertNull(ruleset, MESSAGE); } @Test @@ -71,7 +71,7 @@ public void shouldGetAsString() { Ruleset newRuleset = new Ruleset(); newRuleset.setId(20); String ruleset = rulesetConverter.getAsString(null, null, newRuleset); - assertEquals(MESSAGE, "20", ruleset); + assertEquals("20", ruleset, MESSAGE); } @Test @@ -79,20 +79,20 @@ public void shouldGetAsStringWithoutId() { RulesetConverter rulesetConverter = new RulesetConverter(); Ruleset newRuleset = new Ruleset(); String ruleset = rulesetConverter.getAsString(null, null, newRuleset); - assertEquals(MESSAGE, "0", ruleset); + assertEquals("0", ruleset, MESSAGE); } @Test public void shouldGetAsStringWithString() { RulesetConverter rulesetConverter = new RulesetConverter(); String ruleset = rulesetConverter.getAsString(null, null, "20"); - assertEquals(MESSAGE, "20", ruleset); + assertEquals("20", ruleset, MESSAGE); } @Test public void shouldNotGetAsStringNullObject() { RulesetConverter rulesetConverter = new RulesetConverter(); String ruleset = rulesetConverter.getAsString(null, null, null); - assertNull(MESSAGE, ruleset); + assertNull(ruleset, MESSAGE); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/converter/WorkflowConverterIT.java b/Kitodo/src/test/java/org/kitodo/production/converter/WorkflowConverterIT.java index 7d839ba741c..d1a0ac5b812 100644 --- a/Kitodo/src/test/java/org/kitodo/production/converter/WorkflowConverterIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/converter/WorkflowConverterIT.java @@ -11,12 +11,12 @@ package org.kitodo.production.converter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Workflow; @@ -24,13 +24,13 @@ public class WorkflowConverterIT { private static final String MESSAGE = "Workflow was not converted correctly!"; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -40,28 +40,28 @@ public static void cleanDatabase() throws Exception { public void shouldGetAsObject() { WorkflowConverter workflowConverter = new WorkflowConverter(); Workflow workflow = (Workflow) workflowConverter.getAsObject(null, null, "2"); - assertEquals(MESSAGE, 2, workflow.getId().intValue()); + assertEquals(2, workflow.getId().intValue(), MESSAGE); } @Test public void shouldGetAsObjectIncorrectString() { WorkflowConverter workflowConverter = new WorkflowConverter(); String workflow = (String) workflowConverter.getAsObject(null, null, "in"); - assertEquals(MESSAGE, "0", workflow); + assertEquals("0", workflow, MESSAGE); } @Test public void shouldGetAsObjectIncorrectId() { WorkflowConverter workflowConverter = new WorkflowConverter(); String workflow = (String) workflowConverter.getAsObject(null, null, "10"); - assertEquals(MESSAGE, "0", workflow); + assertEquals("0", workflow, MESSAGE); } @Test public void shouldGetAsObjectNullObject() { WorkflowConverter workflowConverter = new WorkflowConverter(); Object workflow = workflowConverter.getAsObject(null, null, null); - assertNull(MESSAGE, workflow); + assertNull(workflow, MESSAGE); } @Test @@ -70,7 +70,7 @@ public void shouldGetAsString() { Workflow newWorkflow = new Workflow(); newWorkflow.setId(20); String workflow = workflowConverter.getAsString(null, null, newWorkflow); - assertEquals(MESSAGE, "20", workflow); + assertEquals("20", workflow, MESSAGE); } @Test @@ -78,20 +78,20 @@ public void shouldGetAsStringWithoutId() { WorkflowConverter workflowConverter = new WorkflowConverter(); Workflow newWorkflow = new Workflow(); String workflow = workflowConverter.getAsString(null, null, newWorkflow); - assertEquals(MESSAGE, "0", workflow); + assertEquals("0", workflow, MESSAGE); } @Test public void shouldGetAsStringWithString() { WorkflowConverter workflowConverter = new WorkflowConverter(); String workflow = workflowConverter.getAsString(null, null, "20"); - assertEquals(MESSAGE, "20", workflow); + assertEquals("20", workflow, MESSAGE); } @Test public void shouldNotGetAsStringNullObject() { WorkflowConverter workflowConverter = new WorkflowConverter(); String workflow = workflowConverter.getAsString(null, null, null); - assertNull(MESSAGE, workflow); + assertNull(workflow, MESSAGE); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/editor/XMLEditorTest.java b/Kitodo/src/test/java/org/kitodo/production/editor/XMLEditorTest.java index 3572af4444e..145e9e87ff0 100644 --- a/Kitodo/src/test/java/org/kitodo/production/editor/XMLEditorTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/editor/XMLEditorTest.java @@ -11,6 +11,7 @@ package org.kitodo.production.editor; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.nio.file.Files; @@ -19,10 +20,9 @@ import java.util.List; import org.apache.commons.io.FileUtils; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.config.ConfigCore; import org.kitodo.config.enums.KitodoConfigFile; @@ -37,7 +37,7 @@ public class XMLEditorTest { private static String absolutePath = ConfigCore.getKitodoConfigDirectory() + KitodoConfigFile.PROJECT_CONFIGURATION; private static XMLEditor xmlEditor = null; - @BeforeClass + @BeforeAll public static void setUp() throws IOException { List lines = new ArrayList<>(); lines.add(LOAD_XML); @@ -46,7 +46,7 @@ public static void setUp() throws IOException { xmlEditor.loadInitialConfiguration(); } - @AfterClass + @AfterAll public static void tearDown() throws IOException { Files.deleteIfExists(Paths.get(absolutePath)); } @@ -54,7 +54,7 @@ public static void tearDown() throws IOException { @Test public void shouldLoadXMLConfiguration() { xmlEditor.loadXMLConfiguration(KitodoConfigFile.PROJECT_CONFIGURATION.getName()); - Assert.assertEquals(LOAD_XML, xmlEditor.getXMLConfiguration().replace("\n", "").replace("\r", "")); + assertEquals(LOAD_XML, xmlEditor.getXMLConfiguration().replace("\n", "").replace("\r", "")); } @Test @@ -63,6 +63,6 @@ public void shouldSaveXMLConfiguration() throws IOException { xmlEditor.setXMLConfiguration(SAVE_XML); xmlEditor.saveXMLConfiguration(); String savedString = FileUtils.readFileToString(KitodoConfigFile.PROJECT_CONFIGURATION.getFile(), "utf-8"); - Assert.assertEquals(SAVE_XML, savedString); + assertEquals(SAVE_XML, savedString); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/exporter/download/ExportMetsIT.java b/Kitodo/src/test/java/org/kitodo/production/exporter/download/ExportMetsIT.java index 98f5c391352..b047b359baa 100644 --- a/Kitodo/src/test/java/org/kitodo/production/exporter/download/ExportMetsIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/exporter/download/ExportMetsIT.java @@ -11,6 +11,7 @@ package org.kitodo.production.exporter.download; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.kitodo.test.utils.ProcessTestUtils.METADATA_DIR; import static org.kitodo.test.utils.ProcessTestUtils.META_XML; @@ -22,10 +23,9 @@ import java.util.List; import org.apache.commons.lang3.SystemUtils; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.ExecutionPermission; import org.kitodo.FileLoader; import org.kitodo.MockDatabase; @@ -50,7 +50,7 @@ public class ExportMetsIT { private final ExportMets exportMets = new ExportMets(); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -75,7 +75,7 @@ public static void setUp() throws Exception { } } - @AfterClass + @AfterAll public static void tearDown() throws Exception { SecurityTestUtils.cleanSecurityContext(); MockDatabase.stopNode(); @@ -104,11 +104,8 @@ public void exportMetsTest() throws Exception { exportMets.startExport(process); List strings = Files.readAllLines(Paths.get(ConfigCore.getParameter(ParameterCore.DIR_USERS) + userDirectory + "/" + Helper.getNormalizedTitle(process.getTitle()) + "_mets.xml")); - Assert.assertTrue("Export of metadata 'singleDigCollection' was wrong", - strings.toString().contains("test collection")); - Assert.assertTrue("Export of metadata 'TitleDocMain' was wrong", - strings.toString().contains("test title")); - Assert.assertTrue("Export of metadata 'PublisherName' was wrong", - strings.toString().contains("Publisher test name")); + assertTrue(strings.toString().contains("test collection"), "Export of metadata 'singleDigCollection' was wrong"); + assertTrue(strings.toString().contains("test title"), "Export of metadata 'TitleDocMain' was wrong"); + assertTrue(strings.toString().contains("Publisher test name"), "Export of metadata 'PublisherName' was wrong"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/file/BackupFileRotationTest.java b/Kitodo/src/test/java/org/kitodo/production/file/BackupFileRotationTest.java index 1e94af15174..e14f7012586 100644 --- a/Kitodo/src/test/java/org/kitodo/production/file/BackupFileRotationTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/file/BackupFileRotationTest.java @@ -11,9 +11,9 @@ package org.kitodo.production.file; -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 java.io.BufferedReader; import java.io.File; @@ -23,9 +23,9 @@ import java.io.PrintStream; import java.net.URI; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.kitodo.data.database.beans.Process; import org.kitodo.production.services.ServiceManager; import org.kitodo.production.services.data.ProcessService; @@ -37,13 +37,13 @@ public class BackupFileRotationTest { private static ProcessService processService = ServiceManager.getProcessService(); private static FileService fileService = new FileService(); - @Before + @BeforeEach public void setUp() throws Exception { URI directory = fileService.createDirectory(URI.create(""), "12"); fileService.createResource(directory, BACKUP_FILE_NAME); } - @After + @AfterEach public void tearDown() throws Exception { fileService.delete(URI.create("12")); } @@ -198,8 +198,7 @@ public void nothingHappensIfFilePatternDontMatch() throws Exception { private void assertLastModifiedDate(String fileName, long expectedLastModifiedDate) { long currentLastModifiedDate = getLastModifiedFileDate(fileName); - assertEquals("Last modified date of file " + fileName + " differ:", expectedLastModifiedDate, - currentLastModifiedDate); + assertEquals(expectedLastModifiedDate, currentLastModifiedDate, "Last modified date of file " + fileName + " differ:"); } private long getLastModifiedFileDate(String fileName) { @@ -229,15 +228,15 @@ private void assertFileHasContent(String fileName, String expectedContent) throw content.append(line); } br.close(); - assertEquals("File " + fileName + " does not contain expected content:", expectedContent, content.toString()); + assertEquals(expectedContent, content.toString(), "File " + fileName + " does not contain expected content:"); } private void assertFileExists(String fileName) { - assertTrue("File " + fileName + " does not exist.", fileService.fileExist(URI.create(fileName))); + assertTrue(fileService.fileExist(URI.create(fileName)), "File " + fileName + " does not exist."); } private void assertFileNotExists(String fileName) { - assertFalse("File " + fileName + " should not exist.", fileService.fileExist(URI.create(fileName))); + assertFalse(fileService.fileExist(URI.create(fileName)), "File " + fileName + " should not exist."); } private void writeFile(URI uri, String content) throws IOException { diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/ClientFormIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/ClientFormIT.java index 84d81ae0321..79268e7398c 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/ClientFormIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/ClientFormIT.java @@ -11,10 +11,11 @@ package org.kitodo.production.forms; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.exceptions.DAOException; import org.kitodo.production.services.ServiceManager; @@ -27,7 +28,7 @@ public class ClientFormIT { * Setup Database and start elasticsearch. * @throws Exception If databaseConnection failed. */ - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -39,7 +40,7 @@ public static void prepareDatabase() throws Exception { * @throws Exception * if elasticsearch could not been stopped. */ - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -52,7 +53,7 @@ public void testRoleAdding() throws DAOException { final int numberOfAuthoritiesToCopy = ServiceManager.getRoleService().getAllRolesByClientId(2).get(0).getAuthorities() .size(); - Assert.assertEquals("Number of roles is incorrect", 8, numberOfRolesForFirstClient); + assertEquals(8, numberOfRolesForFirstClient, "Number of roles is incorrect"); clientForm.getRolesForClient(); clientForm.setClientToCopyRoles(ServiceManager.getClientService().getById(2)); @@ -64,9 +65,8 @@ public void testRoleAdding() throws DAOException { .size(); int numberOfNewAuthorities = ServiceManager.getRoleService().getAllRolesByClientId(1).get(8).getAuthorities() .size(); - Assert.assertEquals("Role was not added", 10, numberOfRolesForFirstClient); - Assert.assertEquals("Authorities were not added", numberOfOldAuthorities, numberOfNewAuthorities); - Assert.assertEquals("Authorities were removed from second client", numberOfAuthoritiesToCopy, - numberOfOldAuthorities); + assertEquals(10, numberOfRolesForFirstClient, "Role was not added"); + assertEquals(numberOfOldAuthorities, numberOfNewAuthorities, "Authorities were not added"); + assertEquals(numberOfAuthoritiesToCopy, numberOfOldAuthorities, "Authorities were removed from second client"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/CurrenTaskFormIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/CurrenTaskFormIT.java index 892231e6e27..3ea922c77b1 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/CurrenTaskFormIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/CurrenTaskFormIT.java @@ -11,13 +11,13 @@ package org.kitodo.production.forms; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.net.URI; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.data.database.beans.Process; @@ -41,7 +41,7 @@ public class CurrenTaskFormIT { * @throws Exception * If databaseConnection failed. */ - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesForWorkflowFull(); @@ -54,7 +54,7 @@ public static void prepareDatabase() throws Exception { * @throws Exception * if elasticsearch could not been stopped. */ - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -77,9 +77,8 @@ public void testCloseTaskOnAccept() throws DataException, DAOException { Task taskTypeAcceptCloseUpdated = taskService.getById(taskTypeAcceptClose.getId()); Task followingTaskUpdated = taskService.getById(followingTask.getId()); - assertEquals("Task of type typeAcceptClose was closed!", TaskStatus.DONE, - taskTypeAcceptCloseUpdated.getProcessingStatus()); - assertEquals("Following task is open!", TaskStatus.OPEN, followingTaskUpdated.getProcessingStatus()); + assertEquals(TaskStatus.DONE, taskTypeAcceptCloseUpdated.getProcessingStatus(), "Task of type typeAcceptClose was closed!"); + assertEquals(TaskStatus.OPEN, followingTaskUpdated.getProcessingStatus(), "Following task is open!"); } diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/IndexingFormIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/IndexingFormIT.java index 14fbec25d0c..393159978d5 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/IndexingFormIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/IndexingFormIT.java @@ -13,14 +13,17 @@ import static org.awaitility.Awaitility.await; import static org.awaitility.Awaitility.given; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Objects; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.data.database.beans.Client; @@ -35,7 +38,7 @@ public class IndexingFormIT { private IndexingForm indexingForm = new IndexingForm(); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { MockDatabase.startNodeWithoutMapping(); Client client = new Client(); @@ -49,20 +52,20 @@ public static void setUp() throws Exception { }); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { MockDatabase.stopNode(); } @Test public void shouldCreateMapping() { - Assert.assertFalse(indexingForm.indexExists()); + assertFalse(indexingForm.indexExists()); indexingForm.createMapping(false); - Assert.assertTrue(indexingForm.indexExists()); + assertTrue(indexingForm.indexExists()); } @Test - @Ignore("Not working due to CDI injection problems") + @Disabled("Not working due to CDI injection problems") public void indexingAll() throws Exception { indexingForm.createMapping(false); Project project = new Project(); @@ -78,15 +81,15 @@ public void indexingAll() throws Exception { indexingForm.countDatabaseObjects(); ProcessDTO processOne = ServiceManager.getProcessService().findById(1); - Assert.assertNull("process should not be found in index", processOne.getTitle()); + assertNull(processOne.getTitle(), "process should not be found in index"); IndexAction indexAction = ServiceManager.getProcessService().getById(1).getIndexAction(); - Assert.assertEquals("Index Action should be Index", IndexAction.INDEX, indexAction); + assertEquals(IndexAction.INDEX, indexAction, "Index Action should be Index"); indexingForm.startAllIndexing(); given().ignoreExceptions().await() .until(() -> Objects.nonNull(ServiceManager.getProcessService().findById(1).getTitle())); processOne = ServiceManager.getProcessService().findById(1); - Assert.assertEquals("process should be found", "testIndex",processOne.getTitle()); + assertEquals("testIndex", processOne.getTitle(), "process should be found"); indexAction = ServiceManager.getProcessService().getById(1).getIndexAction(); - Assert.assertEquals("Index Action should be Index", IndexAction.INDEX, indexAction); + assertEquals(IndexAction.INDEX, indexAction, "Index Action should be Index"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/MassImportFormIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/MassImportFormIT.java index b8842dfea14..83353e2e0af 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/MassImportFormIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/MassImportFormIT.java @@ -11,12 +11,15 @@ package org.kitodo.production.forms; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import java.util.List; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.data.database.beans.User; @@ -35,7 +38,7 @@ public class MassImportFormIT { private static final String FIRST_TEMPLATE_TITLE = "First template"; private static final String TSL_ATS = "TSL/ATS"; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -43,7 +46,7 @@ public static void prepareDatabase() throws Exception { SecurityTestUtils.addUserDataToSecurityContext(userOne, 1); } - @AfterClass + @AfterAll public static void cleanup() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -53,12 +56,12 @@ public static void cleanup() throws Exception { public void shouldPrepareMassImport() { MassImportForm massImportForm = new MassImportForm(); massImportForm.prepareMassImport(TEMPLATE_ID, PROJECT_ID); - Assert.assertEquals("Wrong template title", FIRST_TEMPLATE_TITLE, massImportForm.getTemplateTitle()); + assertEquals(FIRST_TEMPLATE_TITLE, massImportForm.getTemplateTitle(), "Wrong template title"); AddMetadataDialog addMetadataDialog = massImportForm.getAddMetadataDialog(); - Assert.assertNotNull("'Add metadata' dialog should not be null", addMetadataDialog); + assertNotNull(addMetadataDialog, "'Add metadata' dialog should not be null"); List metadataTypes = addMetadataDialog.getAllMetadataTypes(); - Assert.assertFalse("List of metadata types should not be empty", metadataTypes.isEmpty()); + assertFalse(metadataTypes.isEmpty(), "List of metadata types should not be empty"); ProcessDetail firstDetail = metadataTypes.get(0); - Assert.assertEquals(String.format("First metadata type should be '%s'", TSL_ATS), TSL_ATS, firstDetail.getLabel()); + assertEquals(TSL_ATS, firstDetail.getLabel(), String.format("First metadata type should be '%s'", TSL_ATS)); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/MigrationFormIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/MigrationFormIT.java index 1a87bc8c4fe..64b8b4c58ad 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/MigrationFormIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/MigrationFormIT.java @@ -11,13 +11,16 @@ package org.kitodo.production.forms; +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 java.util.ArrayList; import java.util.Collections; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Project; import org.kitodo.data.database.exceptions.DAOException; @@ -32,7 +35,7 @@ public class MigrationFormIT { * @throws Exception * If databaseConnection failed. */ - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -44,7 +47,7 @@ public static void prepareDatabase() throws Exception { * @throws Exception * if elasticsearch could not been stopped. */ - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -52,16 +55,16 @@ public static void cleanDatabase() throws Exception { @Test public void testShowPossibleProjects() { - Assert.assertEquals("Projectslist should be empty", Collections.emptyList(), migrationForm.getAllProjects()); - Assert.assertFalse("Projectslist should not be shown", migrationForm.isProjectListRendered()); + assertEquals(Collections.emptyList(), migrationForm.getAllProjects(), "Projectslist should be empty"); + assertFalse(migrationForm.isProjectListRendered(), "Projectslist should not be shown"); migrationForm.showPossibleProjects(); - Assert.assertEquals("Should get all Projects", 3, migrationForm.getAllProjects().size()); - Assert.assertTrue("Projectslist should be shown", migrationForm.isProjectListRendered()); + assertEquals(3, migrationForm.getAllProjects().size(), "Should get all Projects"); + assertTrue(migrationForm.isProjectListRendered(), "Projectslist should be shown"); } @Test public void testShowProcessesForProjects() throws DAOException { - Assert.assertEquals(Collections.emptyList(), migrationForm.getAggregatedTasks()); + assertEquals(Collections.emptyList(), migrationForm.getAggregatedTasks()); ArrayList selectedProjects = new ArrayList<>(); selectedProjects.add(ServiceManager.getProjectService().getById(1)); @@ -69,26 +72,26 @@ public void testShowProcessesForProjects() throws DAOException { migrationForm.showAggregatedProcesses(); String processesShouldBeFound = "Processes should be found"; - Assert.assertEquals(processesShouldBeFound, 0, migrationForm.getAggregatedTasks().size()); + assertEquals(0, migrationForm.getAggregatedTasks().size(), processesShouldBeFound); selectedProjects.add(ServiceManager.getProjectService().getById(2)); migrationForm.setSelectedProjects(selectedProjects); migrationForm.showAggregatedProcesses(); - Assert.assertEquals(processesShouldBeFound, 1, migrationForm.getAggregatedTasks().size()); + assertEquals(1, migrationForm.getAggregatedTasks().size(), processesShouldBeFound); selectedProjects.add(ServiceManager.getProjectService().getById(2)); migrationForm.setSelectedProjects(selectedProjects); migrationForm.showAggregatedProcesses(); - Assert.assertEquals(processesShouldBeFound, 1, migrationForm.getAggregatedTasks().size()); + assertEquals(1, migrationForm.getAggregatedTasks().size(), processesShouldBeFound); selectedProjects.remove(2); selectedProjects.remove(1); migrationForm.setSelectedProjects(selectedProjects); migrationForm.showAggregatedProcesses(); - Assert.assertEquals(processesShouldBeFound, 0, migrationForm.getAggregatedTasks().size()); + assertEquals(0, migrationForm.getAggregatedTasks().size(), processesShouldBeFound); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/ProcessFormIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/ProcessFormIT.java index 4bbedb7dfb2..20237812da8 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/ProcessFormIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/ProcessFormIT.java @@ -11,6 +11,8 @@ package org.kitodo.production.forms; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.sql.Date; import java.time.LocalDate; import java.time.ZoneId; @@ -19,10 +21,9 @@ import java.util.List; import java.util.stream.Collectors; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.data.database.beans.Process; @@ -39,7 +40,7 @@ public class ProcessFormIT { * * @throws Exception If databaseConnection failed. */ - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -79,7 +80,7 @@ private static void addProcesses() throws Exception { * * @throws Exception if elasticsearch could not been stopped. */ - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -95,18 +96,18 @@ public void testProcessesSelection() throws Exception { selectedIds = processForm.getSelectedProcesses() .stream().map(Process::getId).sorted().collect(Collectors.toList()); - Assert.assertEquals(new ArrayList<>(Arrays.asList(1, 2, 4, 5)), selectedIds); + assertEquals(new ArrayList<>(Arrays.asList(1, 2, 4, 5)), selectedIds); processForm.getExcludedProcessIds().add(4); selectedIds = processForm.getSelectedProcesses() .stream().map(Process::getId).sorted().collect(Collectors.toList()); - Assert.assertEquals(new ArrayList<>(Arrays.asList(1, 2, 5)), selectedIds); + assertEquals(new ArrayList<>(Arrays.asList(1, 2, 5)), selectedIds); processForm.setAllSelected(false); processForm.selectedProcessesOrProcessDTOs = ServiceManager.getProcessService().findByAnything("SelectionTest"); selectedIds = processForm.getSelectedProcesses() .stream().map(Process::getId).sorted().collect(Collectors.toList()); - Assert.assertEquals(new ArrayList<>(Arrays.asList(4, 5)), selectedIds); + assertEquals(new ArrayList<>(Arrays.asList(4, 5)), selectedIds); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/SearchResultFormIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/SearchResultFormIT.java index c41edf0abe6..b4bf32fd9a0 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/SearchResultFormIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/SearchResultFormIT.java @@ -11,12 +11,14 @@ package org.kitodo.production.forms; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.util.List; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.production.dto.ProcessDTO; @@ -26,7 +28,7 @@ public class SearchResultFormIT { private final SearchResultForm searchResultForm = new SearchResultForm(); - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -39,7 +41,7 @@ public static void prepareDatabase() throws Exception { * @throws Exception * if elasticsearch could not been stopped. */ - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -52,49 +54,49 @@ public void testSearch() { searchResultForm.searchForProcessesBySearchQuery(); List resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(3, resultList.size()); + assertEquals(3, resultList.size()); searchResultForm.setSearchQuery("process"); searchResultForm.searchForProcessesBySearchQuery(); resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(2, resultList.size()); + assertEquals(2, resultList.size()); searchResultForm.setSearchQuery("First process"); searchResultForm.searchForProcessesBySearchQuery(); resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(1, resultList.size()); + assertEquals(1, resultList.size()); searchResultForm.setSearchQuery("Not Existing"); searchResultForm.searchForProcessesBySearchQuery(); resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(0, resultList.size()); + assertEquals(0, resultList.size()); searchResultForm.setSearchQuery("First project"); searchResultForm.searchForProcessesBySearchQuery(); resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(2, resultList.size()); + assertEquals(2, resultList.size()); searchResultForm.setSearchQuery("proc"); searchResultForm.searchForProcessesBySearchQuery(); resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(2, resultList.size()); + assertEquals(2, resultList.size()); searchResultForm.setSearchQuery("problem"); searchResultForm.searchForProcessesBySearchQuery(); resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(1, resultList.size()); + assertEquals(1, resultList.size()); searchResultForm.setSearchQuery("2"); searchResultForm.searchForProcessesBySearchQuery(); resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(1, resultList.size()); + assertEquals(1, resultList.size()); } @Test @@ -105,17 +107,17 @@ public void testFilterByProject() { searchResultForm.setCurrentProjectFilter(1000); searchResultForm.filterList(); List resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(0, resultList.size()); + assertEquals(0, resultList.size()); searchResultForm.setCurrentProjectFilter(1); searchResultForm.filterList(); resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(2, resultList.size()); + assertEquals(2, resultList.size()); searchResultForm.searchForProcessesBySearchQuery(); searchResultForm.filterList(); resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(3, resultList.size()); + assertEquals(3, resultList.size()); } @@ -125,9 +127,9 @@ public void testResetOfFilter() { searchResultForm.searchForProcessesBySearchQuery(); searchResultForm.setCurrentProjectFilter(1); searchResultForm.filterListByProject(); - Assert.assertEquals(1, searchResultForm.getCurrentProjectFilter().intValue()); + assertEquals(1, searchResultForm.getCurrentProjectFilter().intValue()); searchResultForm.searchForProcessesBySearchQuery(); - Assert.assertNull(searchResultForm.getCurrentProjectFilter()); + assertNull(searchResultForm.getCurrentProjectFilter()); } @Test @@ -139,17 +141,17 @@ public void testFilterByTaskAndStatus() { searchResultForm.setCurrentTaskStatusFilter(0); searchResultForm.filterList(); List resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(0, resultList.size()); + assertEquals(0, resultList.size()); searchResultForm.setCurrentTaskFilter("Progress"); searchResultForm.filterList(); resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(0, resultList.size()); + assertEquals(0, resultList.size()); searchResultForm.setCurrentTaskStatusFilter(2); searchResultForm.filterList(); resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(1, resultList.size()); + assertEquals(1, resultList.size()); } @Test @@ -160,24 +162,22 @@ public void testFilterList() { searchResultForm.setCurrentProjectFilter(1); searchResultForm.filterList(); List resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(2, resultList.size()); + assertEquals(2, resultList.size()); searchResultForm.setCurrentTaskFilter(""); searchResultForm.filterList(); resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(2, resultList.size()); + assertEquals(2, resultList.size()); searchResultForm.setCurrentTaskFilter("TaskNotExistent"); searchResultForm.filterList(); resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(2, resultList.size()); + assertEquals(2, resultList.size()); searchResultForm.setCurrentTaskFilter("TaskNotExistent"); searchResultForm.setCurrentTaskStatusFilter(0); searchResultForm.filterList(); resultList = searchResultForm.getFilteredList(); - Assert.assertEquals(0, resultList.size()); - + assertEquals(0, resultList.size()); } - } diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/WorkflowFormIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/WorkflowFormIT.java index 82ec64146aa..17181e1d7ee 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/WorkflowFormIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/WorkflowFormIT.java @@ -11,15 +11,17 @@ package org.kitodo.production.forms; -import static org.junit.Assert.assertEquals; +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 java.io.IOException; import java.util.Arrays; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.DataEditorSetting; import org.kitodo.data.database.beans.Task; @@ -46,7 +48,7 @@ public class WorkflowFormIT { * @throws Exception * If databaseConnection failed. */ - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesForWorkflowFull(); @@ -59,7 +61,7 @@ public static void prepareDatabase() throws Exception { * @throws Exception * if elasticsearch could not been stopped. */ - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -80,7 +82,7 @@ public void shouldUpdateTemplateTasksAndDeleteOnlyAffectedDataEditorSettings() t firstTemplate.setWorkflow(workflow); ServiceManager.getTemplateService().save(firstTemplate); currentWorkflowForm.load(workflow.getId()); - assertEquals(true, dataEditorSettingService.areDataEditorSettingsDefinedForWorkflow(workflow)); + assertTrue(dataEditorSettingService.areDataEditorSettingsDefinedForWorkflow(workflow)); //Get second template (without predefined tasks) and assign a task. //Assign data editor settings to this task @@ -104,7 +106,7 @@ public void shouldUpdateTemplateTasksAndDeleteOnlyAffectedDataEditorSettings() t currentWorkflowForm.updateTemplateTasks(); firstTemplate = ServiceManager.getTemplateService().getById(1); - assertEquals(false, dataEditorSettingService.areDataEditorSettingsDefinedForWorkflow(workflow)); + assertFalse(dataEditorSettingService.areDataEditorSettingsDefinedForWorkflow(workflow)); int numberOfTasksAfterUpdate = firstTemplate.getTasks().size(); assertEquals(numberOfTasksAfterUpdate, 1); dataEditorSettingForTaskOfFirstTemplate = dataEditorSettingService.getByTaskId( @@ -115,9 +117,9 @@ public void shouldUpdateTemplateTasksAndDeleteOnlyAffectedDataEditorSettings() t assertEquals(1, dataEditorSettingForTaskOfSecondTemplate.size()); List completeEditorSettingsAfterUpdate = dataEditorSettingService.getAll(); assertEquals(1, completeEditorSettingsAfterUpdate.size()); - assertEquals(0.5f, dataEditorSettingForTaskOfSecondTemplate.get(0).getStructureWidth(),0); - assertEquals(0.6f, dataEditorSettingForTaskOfSecondTemplate.get(0).getMetadataWidth(),0); - assertEquals(0.6f, dataEditorSettingForTaskOfSecondTemplate.get(0).getGalleryWidth(),0); + assertEquals(0.5f, dataEditorSettingForTaskOfSecondTemplate.get(0).getStructureWidth(), 0); + assertEquals(0.6f, dataEditorSettingForTaskOfSecondTemplate.get(0).getMetadataWidth(), 0); + assertEquals(0.6f, dataEditorSettingForTaskOfSecondTemplate.get(0).getGalleryWidth(), 0); } private Task createAndSaveTemplateTask(TaskStatus taskStatus, int ordering, Template template) throws DataException { diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/WorkflowFormTest.java b/Kitodo/src/test/java/org/kitodo/production/forms/WorkflowFormTest.java index 0de3d0f2604..f267153b6b3 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/WorkflowFormTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/WorkflowFormTest.java @@ -11,16 +11,16 @@ package org.kitodo.production.forms; -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 java.io.File; import java.net.URI; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.FileLoader; import org.kitodo.config.ConfigCore; import org.kitodo.data.database.beans.Workflow; @@ -31,13 +31,13 @@ public class WorkflowFormTest { private static FileService fileService = ServiceManager.getFileService(); - @BeforeClass + @BeforeAll public static void createDiagrams() throws Exception { FileLoader.createDiagramBaseFile(); FileLoader.createDiagramTestFile(); } - @AfterClass + @AfterAll public static void removeDiagram() throws Exception { fileService.delete(new File(ConfigCore.getKitodoDiagramDirectory() + "new.bpmn20.xml").toURI()); fileService.delete(new File(ConfigCore.getKitodoDiagramDirectory() + "test2.bpmn20.xml").toURI()); @@ -53,7 +53,7 @@ public void shouldReadXMLDiagram() { modelerForm.setWorkflow(new Workflow("test")); modelerForm.readXMLDiagram(); - assertNotNull("Diagram XML was not read!", modelerForm.getXmlDiagram()); + assertNotNull(modelerForm.getXmlDiagram(), "Diagram XML was not read!"); } @Test @@ -96,8 +96,8 @@ public void shouldSaveXMLDiagram() { modelerForm.setWorkflow(new Workflow(fileName)); modelerForm.saveFile(xmlDiagramURI, xmlDiagram); - assertEquals("Diagram XML was not saved!", xmlDiagram, modelerForm.getXmlDiagram()); - assertTrue("Diagram XML was not saved!", file.exists()); + assertEquals(xmlDiagram, modelerForm.getXmlDiagram(), "Diagram XML was not saved!"); + assertTrue(file.exists(), "Diagram XML was not saved!"); file.deleteOnExit(); } @@ -179,8 +179,8 @@ public void shouldSaveSVGDiagram() { modelerForm.setWorkflow(new Workflow(fileName)); modelerForm.saveFile(svgDiagramURI, svgDiagram); - assertEquals("Diagram SVG was not saved!", svgDiagram, modelerForm.getSvgDiagram()); - assertTrue("Diagram SVG was not saved!", file.exists()); + assertEquals(svgDiagram, modelerForm.getSvgDiagram(), "Diagram SVG was not saved!"); + assertTrue(file.exists(), "Diagram SVG was not saved!"); file.deleteOnExit(); } diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/copyprocess/CreateProcessFormIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/copyprocess/CreateProcessFormIT.java index d6aa1d16106..d823f8e3886 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/copyprocess/CreateProcessFormIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/copyprocess/CreateProcessFormIT.java @@ -12,9 +12,9 @@ package org.kitodo.production.forms.copyprocess; import static org.awaitility.Awaitility.await; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.net.URI; @@ -22,11 +22,9 @@ import java.util.LinkedList; import org.apache.commons.lang3.SystemUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.ExecutionPermission; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; @@ -54,7 +52,7 @@ public class CreateProcessFormIT { /** * Is running before the class runs. */ - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -71,15 +69,12 @@ public static void prepareDatabase() throws Exception { /** * Is running after the class has run. */ - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); } - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void shouldCreateNewProcess() throws Exception { CreateProcessForm underTest = new CreateProcessForm(); @@ -102,7 +97,7 @@ public void shouldCreateNewProcess() throws Exception { ExecutionPermission.setNoExecutePermission(script); } long after = processService.count(); - assertEquals("No process was created!", before + 1, after); + assertEquals(before + 1, after, "No process was created!"); // clean up database, index and file system Integer processId = newProcess.getId(); @@ -131,10 +126,10 @@ public void shouldCreateNewProcessWithoutWorkflow() throws Exception { underTest.createNewProcess(); ExecutionPermission.setNoExecutePermission(script); long after = processService.count(); - assertEquals("No process was created!", before + 1, after); + assertEquals(before + 1, after, "No process was created!"); - assertTrue("Process should not have tasks", newProcess.getTasks().isEmpty()); - assertNull("process should not have sortHelperStatus", newProcess.getSortHelperStatus()); + assertTrue(newProcess.getTasks().isEmpty(), "Process should not have tasks"); + assertNull(newProcess.getSortHelperStatus(), "process should not have sortHelperStatus"); // clean up database, index and file system Integer processId = newProcess.getId(); diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/copyprocess/TitleRecordLinkTabIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/copyprocess/TitleRecordLinkTabIT.java index 8eb1b1dbf1b..033b7e7d489 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/copyprocess/TitleRecordLinkTabIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/copyprocess/TitleRecordLinkTabIT.java @@ -12,16 +12,16 @@ package org.kitodo.production.forms.copyprocess; import static org.awaitility.Awaitility.await; +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 java.util.Map; import java.util.Objects; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.data.database.beans.Project; @@ -43,7 +43,7 @@ public class TitleRecordLinkTabIT { /** * Is running before the class runs. */ - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -62,24 +62,22 @@ public static void prepareDatabase() throws Exception { /** * Is running after the class has run. */ - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { ProcessTestUtils.removeTestProcess(parentProcessId); MockDatabase.stopNode(); MockDatabase.cleanDatabase(); } - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void shouldChooseParentProcess() { TitleRecordLinkTab testedTitleRecordLinkTab = new TitleRecordLinkTab(null); testedTitleRecordLinkTab.setChosenParentProcess("1"); testedTitleRecordLinkTab.chooseParentProcess(); - Assert.assertFalse("titleRecordProcess is null!", Objects.isNull(testedTitleRecordLinkTab.getTitleRecordProcess())); - Assert.assertEquals("titleRecordProcess has wrong ID!", (Integer) 1, - testedTitleRecordLinkTab.getTitleRecordProcess().getId()); + assertFalse(Objects.isNull(testedTitleRecordLinkTab.getTitleRecordProcess()), + "titleRecordProcess is null!"); + assertEquals((Integer) 1, testedTitleRecordLinkTab.getTitleRecordProcess().getId(), + "titleRecordProcess has wrong ID!"); } @Test @@ -91,10 +89,10 @@ public void shouldSearchForParentProcesses() throws Exception { testedTitleRecordLinkTab.setSearchQuery("HierarchyParent"); testedTitleRecordLinkTab.searchForParentProcesses(); - Assert.assertEquals("Wrong number of possibleParentProcesses found!", 1, - testedTitleRecordLinkTab.getPossibleParentProcesses().size()); - Assert.assertEquals("Wrong possibleParentProcesses found!", "4", - testedTitleRecordLinkTab.getPossibleParentProcesses().get(0).getValue()); + assertEquals(1, testedTitleRecordLinkTab.getPossibleParentProcesses().size(), + "Wrong number of possibleParentProcesses found!"); + assertEquals("4", testedTitleRecordLinkTab.getPossibleParentProcesses().get(0).getValue(), + "Wrong possibleParentProcesses found!"); } /** @@ -110,10 +108,10 @@ public void shouldPreventLinkingToParentProcessOfUnassignedProject() throws DAOE TitleRecordLinkTab testedTitleRecordLinkTab = searchForHierarchyParent(); - Assert.assertEquals("Wrong number of potential parent processes found!", 1, - testedTitleRecordLinkTab.getPossibleParentProcesses().size()); - Assert.assertTrue("Process of unassigned project should be deactivated in TitleRecordLinkTab!", - testedTitleRecordLinkTab.getPossibleParentProcesses().get(0).isDisabled()); + assertEquals(1, testedTitleRecordLinkTab.getPossibleParentProcesses().size(), + "Wrong number of potential parent processes found!"); + assertTrue(testedTitleRecordLinkTab.getPossibleParentProcesses().get(0).isDisabled(), + "Process of unassigned project should be deactivated in TitleRecordLinkTab!"); // re-add first project to user user.getProjects().add(firstProject); diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/CreateProcessFormTest.java b/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/CreateProcessFormTest.java index 7ada3f5d269..22e8617d013 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/CreateProcessFormTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/CreateProcessFormTest.java @@ -11,13 +11,13 @@ package org.kitodo.production.forms.createprocess; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; import java.util.Locale; import java.util.stream.Collectors; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kitodo.api.Metadata; import org.kitodo.api.MetadataEntry; import org.kitodo.api.dataformat.Workpiece; @@ -42,9 +42,8 @@ public void shouldSetChildCount() throws Exception { Workpiece result = new Workpiece(); CreateProcessForm.setChildCount(parentProcess, ServiceManager.getRulesetService().openRuleset(ruleset), result); - assertEquals("The child count was not set correctly", "4", - result.getLogicalStructure().getMetadata().parallelStream().filter(MetadataEntry.class::isInstance) - .map(MetadataEntry.class::cast) - .collect(Collectors.toMap(Metadata::getKey, MetadataEntry::getValue)).get("ChildCount")); + assertEquals("4", result.getLogicalStructure().getMetadata().parallelStream().filter(MetadataEntry.class::isInstance) + .map(MetadataEntry.class::cast) + .collect(Collectors.toMap(Metadata::getKey, MetadataEntry::getValue)).get("ChildCount"), "The child count was not set correctly"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/ProcessDataTabTest.java b/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/ProcessDataTabTest.java index 72ee6ed19b9..01fa56d1f1e 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/ProcessDataTabTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/ProcessDataTabTest.java @@ -11,11 +11,11 @@ package org.kitodo.production.forms.createprocess; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Locale; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kitodo.data.database.beans.Process; import org.kitodo.data.database.beans.Ruleset; import org.kitodo.production.helper.TempProcess; @@ -57,8 +57,7 @@ public void testGenerationOfAtstslField() throws Exception { createProcessForm.getProcessMetadata().setProcessDetails(processDetails); underTest.generateAtstslFields(); - assertEquals("TSL/ATS does not match expected value", "Titl", - createProcessForm.getCurrentProcess().getAtstsl()); + assertEquals("Titl", createProcessForm.getCurrentProcess().getAtstsl(), "TSL/ATS does not match expected value"); } @@ -94,7 +93,6 @@ public void shouldCreateChildProcessTitlePrefixedByParentItile() throws Exceptio underTest.generateAtstslFields(); - assertEquals("Process title could not be build", "TitlOfPa_1234567X_8888", - createProcessForm.getCurrentProcess().getTiffHeaderDocumentName()); + assertEquals("TitlOfPa_1234567X_8888", createProcessForm.getCurrentProcess().getTiffHeaderDocumentName(), "Process title could not be build"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/ProcessDetailIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/ProcessDetailIT.java index e71194664ae..8e5d4a57af5 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/ProcessDetailIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/ProcessDetailIT.java @@ -11,11 +11,12 @@ package org.kitodo.production.forms.createprocess; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.File; import java.util.Locale; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kitodo.api.MdSec; import org.kitodo.api.MetadataEntry; import org.kitodo.api.dataeditor.rulesetmanagement.RulesetManagementInterface; @@ -45,6 +46,6 @@ public void shouldCopyProcessDetail() throws Exception { ProcessDetail processDetail = (ProcessDetail) treeNode.getChildren().get(0).getData(); int beforeCopying = treeNode.getChildCount(); processDetail.copy(); - Assert.assertEquals("Should have copied metadata", beforeCopying + 1, treeNode.getChildCount()); + assertEquals(beforeCopying + 1, treeNode.getChildCount(), "Should have copied metadata"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/dataeditor/StructurePanelIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/dataeditor/StructurePanelIT.java index 64b9d020b44..31e2ff96315 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/dataeditor/StructurePanelIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/dataeditor/StructurePanelIT.java @@ -11,11 +11,12 @@ package org.kitodo.production.forms.dataeditor; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.lang.reflect.Method; import java.net.URI; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kitodo.data.database.beans.Process; import org.primefaces.model.DefaultTreeNode; @@ -38,6 +39,6 @@ public void testAddParentLinksRecursive() throws Exception { addParentLinksRecursive.setAccessible(true); addParentLinksRecursive.invoke(underTest, child, result); - Assert.assertTrue(((StructureTreeNode) result.getChildren().get(0).getData()).isLinked()); + assertTrue(((StructureTreeNode) result.getChildren().get(0).getData()).isLinked()); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/dataeditor/StructurePanelTest.java b/Kitodo/src/test/java/org/kitodo/production/forms/dataeditor/StructurePanelTest.java index 56a37efd088..5f896815f2a 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/dataeditor/StructurePanelTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/dataeditor/StructurePanelTest.java @@ -11,12 +11,14 @@ package org.kitodo.production.forms.dataeditor; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URI; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kitodo.DummyRulesetManagement; import org.kitodo.api.dataformat.LogicalDivision; import org.kitodo.api.dataformat.mets.LinkedMetsResource; @@ -52,13 +54,13 @@ public void testBuildStructureTreeRecursively() throws Exception { buildStructureTreeRecursively.setAccessible(true); buildStructureTreeRecursively.invoke(underTest, structure, result); - Assert.assertTrue(((StructureTreeNode) result.getChildren().get(0).getData()).isLinked()); + assertTrue(((StructureTreeNode) result.getChildren().get(0).getData()).isLinked()); } @Test public void preventNullPointerExceptionInIsSeparateMediaOnNotFullInitializedDataEditorForm() { DataEditorForm dummyDataEditorForm = new DataEditorForm(); final StructurePanel underTest = new StructurePanel(dummyDataEditorForm); - Assert.assertFalse(underTest.isSeparateMedia()); + assertFalse(underTest.isSeparateMedia()); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/handler/RangeStreamContentHandlerIT.java b/Kitodo/src/test/java/org/kitodo/production/handler/RangeStreamContentHandlerIT.java index d41cb041e0e..9972b376c4b 100644 --- a/Kitodo/src/test/java/org/kitodo/production/handler/RangeStreamContentHandlerIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/handler/RangeStreamContentHandlerIT.java @@ -12,7 +12,7 @@ package org.kitodo.production.handler; import static org.apache.commons.io.IOUtils.toInputStream; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.kitodo.production.helper.RangeStreamHelper.DEFAULT_BUFFER_SIZE; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -29,8 +29,8 @@ import javax.servlet.http.HttpServletResponse; import org.jboss.weld.el.WeldExpressionFactory; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.kitodo.BasePrimefaceTest; import org.mockito.Mock; import org.mockito.Spy; @@ -70,7 +70,7 @@ public class RangeStreamContentHandlerIT extends BasePrimefaceTest { * * @throws Exception the exceptions thrown by method */ - @Before + @BeforeEach public void init() throws Exception { when(externalContext.getRequest()).thenReturn(httpServletRequest); when(externalContext.getResponse()).thenReturn(httpServletResponse); diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/FilesystemHelperTest.java b/Kitodo/src/test/java/org/kitodo/production/helper/FilesystemHelperTest.java index c4b8802f020..f8dd89e3812 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/FilesystemHelperTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/FilesystemHelperTest.java @@ -11,7 +11,8 @@ package org.kitodo.production.helper; -import static junit.framework.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; import java.io.File; import java.io.IOException; @@ -19,26 +20,26 @@ import java.net.URI; import java.nio.file.Paths; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.kitodo.config.ConfigCore; import org.kitodo.production.services.file.FileService; public class FilesystemHelperTest { - @After + @AfterEach public void tearDown() throws Exception { FileService fileService = new FileService(); fileService.delete(URI.create("old.xml")); fileService.delete(URI.create("new.xml")); } - @Test(expected = java.io.FileNotFoundException.class) + @Test public void renamingOfNonExistingFileShouldThrowFileNotFoundException() throws IOException { FileService fileService = new FileService(); URI oldFileName = Paths.get(ConfigCore.getKitodoDataDirectory() + "none.xml").toUri(); String newFileName = "new.xml"; - fileService.renameFile(oldFileName, newFileName); + assertThrows(java.io.FileNotFoundException.class, () -> fileService.renameFile(oldFileName, newFileName)); } @Test diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/ProcessHelperIT.java b/Kitodo/src/test/java/org/kitodo/production/helper/ProcessHelperIT.java index c434958e4f0..e3677375b25 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/ProcessHelperIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/ProcessHelperIT.java @@ -11,19 +11,19 @@ package org.kitodo.production.helper; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Locale; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.api.dataeditor.rulesetmanagement.RulesetManagementInterface; @@ -53,7 +53,7 @@ public class ProcessHelperIT { * @throws Exception * the exception when set up test */ - @BeforeClass + @BeforeAll public static void setUp() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -63,19 +63,19 @@ public static void setUp() throws Exception { priorityList = ServiceManager.getUserService().getCurrentMetadataLanguage(); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); } - @Before + @BeforeEach public void prepareTestProcess() throws DAOException, DataException, IOException { processHelperTestProcessId = MockDatabase.insertTestProcess(TEST_PROCESS_TITLE, 1, 1, 1); ProcessTestUtils.copyTestMetadataFile(processHelperTestProcessId, metadataTestfile); } - @After + @AfterEach public void removeTestProcess() throws DAOException { ProcessTestUtils.removeTestProcess(processHelperTestProcessId); processHelperTestProcessId = -1; diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java b/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java index 8a44734da5f..7012ee9667c 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java @@ -11,14 +11,14 @@ package org.kitodo.production.helper; -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 java.io.IOException; import java.net.URI; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kitodo.api.dataformat.Workpiece; import org.kitodo.config.KitodoConfig; import org.kitodo.data.database.beans.Folder; @@ -39,7 +39,7 @@ public void shouldReplaceTitle() { String replaced = variableReplacer.replace("-title (processtitle) -hardcoded test"); String expected = "-title Replacement -hardcoded test"; - assertEquals("String was replaced incorrectly!", expected, replaced); + assertEquals(expected, replaced, "String was replaced incorrectly!"); } @Test @@ -49,7 +49,7 @@ public void shouldReplacePrefs() { String replaced = variableReplacer.replace("-prefs (prefs) -hardcoded test"); String expected = "-prefs src/test/resources/rulesets/ruleset_test.xml -hardcoded test"; - assertEquals("String was replaced incorrectly!", expected, replaced); + assertEquals(expected, replaced, "String was replaced incorrectly!"); } @Test @@ -59,7 +59,7 @@ public void shouldReplaceProcessPath() { String replaced = variableReplacer.replace("-processpath (processpath) -hardcoded test"); String expected = "-processpath 2 -hardcoded test"; - assertEquals("String was replaced incorrectly!", expected, replaced); + assertEquals(expected, replaced, "String was replaced incorrectly!"); } @Test @@ -69,7 +69,7 @@ public void shouldReplaceProjectId() { String replaced = variableReplacer.replace("-processpath (projectid) -hardcoded test"); String expected = "-processpath " + projectId + " -hardcoded test"; - assertEquals("String was replaced incorrectly!", expected, replaced); + assertEquals(expected, replaced, "String was replaced incorrectly!"); } @Test @@ -82,7 +82,7 @@ public void shouldReplaceTitleAndFilename() { "-title (processtitle) -filename (filename) -hardcoded test", testFilenameWithPath); String expected = "-title Replacement -filename " + testFilename + " -hardcoded test"; - assertEquals("String was replaced incorrectly!", expected, replaced); + assertEquals(expected, replaced, "String was replaced incorrectly!"); } @Test @@ -96,7 +96,7 @@ public void shouldReplaceFilename() { testFilenameWithPath); String expected = "-filename " + testFilename + " -hardcoded test"; - assertEquals("String was replaced incorrectly!", expected, replaced); + assertEquals(expected, replaced, "String was replaced incorrectly!"); } @Test @@ -108,7 +108,7 @@ public void shouldReplaceBasename() { String replaced = variableReplacer.replaceWithFilename("-basename (basename) -hardcoded test", testFilename); String expected = "-basename testFilename -hardcoded test"; - assertEquals("String was replaced incorrectly!", expected, replaced); + assertEquals(expected, replaced, "String was replaced incorrectly!"); } @Test @@ -121,7 +121,7 @@ public void shouldReplaceRelativePath() { testFilenameWithPath); String expected = "-filename " + testFilenameWithPath + " -hardcoded test"; - assertEquals("String was replaced incorrectly!", expected, replaced); + assertEquals(expected, replaced, "String was replaced incorrectly!"); } @Test @@ -130,7 +130,7 @@ public void shouldContainFile() { String toBeMatched = "src/(basename)/test.txt"; - assertTrue("String does not match as containing file variables!", variableReplacer.containsFiles(toBeMatched)); + assertTrue(variableReplacer.containsFiles(toBeMatched), "String does not match as containing file variables!"); } @Test @@ -139,8 +139,7 @@ public void shouldNotContainFile() { String toBeMatched = "src/(projectid)/test.txt"; - assertFalse("String should not match as containing file variables!", - variableReplacer.containsFiles(toBeMatched)); + assertFalse(variableReplacer.containsFiles(toBeMatched), "String should not match as containing file variables!"); } @Test @@ -149,8 +148,7 @@ public void shouldReplaceGeneratorSource() { String replaced = variableReplacer.replace("-filename (generatorsource) -hardcoded test"); String expected = "-filename " + "images/Replacementscans" + " -hardcoded test"; - assertEquals("String should not match as containing file variables!", expected, - replaced); + assertEquals(expected, replaced, "String should not match as containing file variables!"); } @Test @@ -159,8 +157,7 @@ public void shouldReplaceGeneratorSourcePath() { String replaced = variableReplacer.replace("-filename (generatorsourcepath) -hardcoded test"); String expected = "-filename " + KitodoConfig.getKitodoDataDirectory() + "2/" + "images/Replacementscans" + " -hardcoded test"; - assertEquals("String should not match as containing file variables!", expected, - replaced); + assertEquals(expected, replaced, "String should not match as containing file variables!"); } @Test @@ -173,13 +170,13 @@ public void shouldReplaceOcrdWorkflowId() { VariableReplacer variableReplacerTemplate = new VariableReplacer(null, process, null); String replaced = variableReplacerTemplate.replace("-title (ocrdworkflowid) -hardcoded test"); String expected = "-title " + template.getOcrdWorkflowId() + " -hardcoded test"; - assertEquals("String was replaced incorrectly!", expected, replaced); + assertEquals(expected, replaced, "String was replaced incorrectly!"); process.setOcrdWorkflowId("/process-ocrd-workflow.sh"); VariableReplacer variableReplacerProcess = new VariableReplacer(null, process, null); replaced = variableReplacerProcess.replace("-title (ocrdworkflowid) -hardcoded test"); expected = "-title " + process.getOcrdWorkflowId() + " -hardcoded test"; - assertEquals("String was replaced incorrectly!", expected, replaced); + assertEquals(expected, replaced, "String was replaced incorrectly!"); } @Test @@ -190,7 +187,7 @@ public void shouldReturnMetadataOfNewspaperIssue() throws IOException { String replaced = variableReplacer.replace("-language $(meta.DocLanguage) -scriptType $(meta.slub_script)"); String expected = "-language ger -scriptType Antiqua"; - assertEquals("String should contain expected metadata!", expected, replaced); + assertEquals(expected, replaced, "String should contain expected metadata!"); } @Test @@ -201,7 +198,7 @@ public void shouldReturnMetadataOfPeriodialVolume() throws IOException { String replaced = variableReplacer.replace("-language $(meta.DocLanguage) -scriptType $(meta.slub_script)"); String expected = "-language ger -scriptType Fraktur"; - assertEquals("String should contain expected metadata!", expected, replaced); + assertEquals(expected, replaced, "String should contain expected metadata!"); } @Test @@ -213,7 +210,7 @@ public void shouldReturnMetadataOfMonograph() throws IOException { String replaced = variableReplacer.replace("-language $(meta.DocLanguage) -scriptType $(meta.slub_script)"); // missing meta data element will be replaced by emtpy string and a warning message appear in the log String expected = "-language -scriptType keine_OCR"; - assertEquals("String should contain expected metadata!", expected, replaced); + assertEquals(expected, replaced, "String should contain expected metadata!"); } private Process prepareProcess(int processId, String processFolder) { diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/WikiFieldHelperIT.java b/Kitodo/src/test/java/org/kitodo/production/helper/WikiFieldHelperIT.java index cd0b9f2cd6a..fcd90285bc6 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/WikiFieldHelperIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/WikiFieldHelperIT.java @@ -11,16 +11,16 @@ package org.kitodo.production.helper; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.List; import java.util.Locale; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Comment; import org.kitodo.data.database.beans.Process; @@ -28,13 +28,13 @@ public class WikiFieldHelperIT { - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -49,9 +49,9 @@ public void shouldTransformWikiFieldToComment() throws Exception { List comments = ServiceManager.getCommentService().getAllCommentsByProcess(process); int found = comments.size(); - assertEquals("Not all comments in wiki field are converted", 2, found); + assertEquals(2, found, "Not all comments in wiki field are converted"); - assertEquals("Wiki field is not correctly converted", "", process.getWikiField()); + assertEquals("", process.getWikiField(), "Wiki field is not correctly converted"); DateFormat dateFormat = new SimpleDateFormat("MMM dd, yyyy h:mm:ss a", Locale.ENGLISH); assertEquals("Oct 10, 2016 8:42:55 AM", dateFormat.format(comments.get(0).getCreationDate())); @@ -67,9 +67,9 @@ public void shouldTransformWikiFieldToCommentWithGermanDateTime() throws Excepti List comments = ServiceManager.getCommentService().getAllCommentsByProcess(process); int found = comments.size(); - assertEquals("Not all comments in wiki field are converted", 2, found); + assertEquals(2, found, "Not all comments in wiki field are converted"); - assertEquals("Wiki field is not correctly converted", "", process.getWikiField()); + assertEquals("", process.getWikiField(), "Wiki field is not correctly converted"); DateFormat dateFormat = new SimpleDateFormat("MMM dd, yyyy h:mm:ss a", Locale.ENGLISH); assertEquals("Oct 10, 2016 8:42:55 AM", dateFormat.format(comments.get(0).getCreationDate())); diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/messages/ErrorTest.java b/Kitodo/src/test/java/org/kitodo/production/helper/messages/ErrorTest.java index ce99a6b300c..00abdb8c68d 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/messages/ErrorTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/messages/ErrorTest.java @@ -11,16 +11,15 @@ package org.kitodo.production.helper.messages; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Enumeration; import java.util.Locale; import java.util.MissingResourceException; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.jupiter.api.Assertions.assertThrows; - +import org.junit.jupiter.api.Test; public class ErrorTest { @@ -41,32 +40,26 @@ public void shouldGetKeys() { } } - assertTrue("Keys set doesn't contain searched key!", containsKey); + assertTrue(containsKey, "Keys set doesn't contain searched key!"); } @Test public void shouldGetStringFromDefaultBundle() { // in case custom bundle does not exist - assertEquals( - "Error...", - Error.getResourceBundle(defaultBundle, "non-existent-bundle", locale).getString("error") - ); + assertEquals("Error...", Error.getResourceBundle(defaultBundle, "non-existent-bundle", locale).getString("error")); } @Test public void shouldGetStringFromCustomBundle() { // in case custom bundle exists, and also contains definition for the requested key - assertEquals( - "Test custom error", - Error.getResourceBundle(defaultBundle, customBundle, locale).getString("error") - ); + assertEquals("Test custom error", Error.getResourceBundle(defaultBundle, customBundle, locale).getString("error")); } @Test public void shouldThrowMissingRessourceExceptionForNonExistentKey() { // in case custom bundle is loaded, but key does not exist in either resource bundles assertThrows( - MissingResourceException.class, + MissingResourceException.class, () -> Error.getResourceBundle(defaultBundle, customBundle, locale).getString("non-existent-key") ); diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/messages/MessageTest.java b/Kitodo/src/test/java/org/kitodo/production/helper/messages/MessageTest.java index e07fed3368c..e5ddd953b60 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/messages/MessageTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/messages/MessageTest.java @@ -11,16 +11,15 @@ package org.kitodo.production.helper.messages; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Enumeration; import java.util.Locale; import java.util.MissingResourceException; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.jupiter.api.Assertions.assertThrows; - +import org.junit.jupiter.api.Test; public class MessageTest { @@ -41,25 +40,19 @@ public void shouldGetKeys() { } } - assertTrue("Keys set doesn't contain searched key!", containsKey); + assertTrue(containsKey, "Keys set doesn't contain searched key!"); } @Test public void shouldGetStringFromDefaultBundle() { // in case custom bundle does not exist - assertEquals( - "Ready", - Message.getResourceBundle(defaultBundle, "non-existent-bundle", locale).getString("ready") - ); + assertEquals("Ready", Message.getResourceBundle(defaultBundle, "non-existent-bundle", locale).getString("ready")); } @Test public void shouldGetStringFromCustomBundle() throws Exception { // in case custom bundle exists, and also contains definition for the requested key - assertEquals( - "Test custom message", - Message.getResourceBundle(defaultBundle, customBundle, locale).getString("ready") - ); + assertEquals("Test custom message", Message.getResourceBundle(defaultBundle, customBundle, locale).getString("ready")); } @Test diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/metadata/pagination/PaginatorTest.java b/Kitodo/src/test/java/org/kitodo/production/helper/metadata/pagination/PaginatorTest.java index 7707253719e..e4f241fd224 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/metadata/pagination/PaginatorTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/metadata/pagination/PaginatorTest.java @@ -11,188 +11,189 @@ package org.kitodo.production.helper.metadata.pagination; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; public class PaginatorTest { @Test public void firstPagination() { Paginator paginator = new Paginator("[`0`-(1)]"); - Assert.assertEquals("[0-(1)]", paginator.next()); - Assert.assertEquals("[0-(2)]", paginator.next()); - Assert.assertEquals("[0-(3)]", paginator.next()); - Assert.assertEquals("[0-(4)]", paginator.next()); + assertEquals("[0-(1)]", paginator.next()); + assertEquals("[0-(2)]", paginator.next()); + assertEquals("[0-(3)]", paginator.next()); + assertEquals("[0-(4)]", paginator.next()); } @Test public void secondPagination() { Paginator paginator = new Paginator("[`1`-1²]"); - Assert.assertEquals("[1-1]", paginator.next()); - Assert.assertEquals("[1-3]", paginator.next()); - Assert.assertEquals("[1-5]", paginator.next()); - Assert.assertEquals("[1-7]", paginator.next()); + assertEquals("[1-1]", paginator.next()); + assertEquals("[1-3]", paginator.next()); + assertEquals("[1-5]", paginator.next()); + assertEquals("[1-7]", paginator.next()); } @Test public void thirdPagination() { Paginator paginator = new Paginator("[`1`]-5²"); - Assert.assertEquals("[1]-5", paginator.next()); - Assert.assertEquals("[1]-7", paginator.next()); - Assert.assertEquals("[1]-9", paginator.next()); - Assert.assertEquals("[1]-11", paginator.next()); + assertEquals("[1]-5", paginator.next()); + assertEquals("[1]-7", paginator.next()); + assertEquals("[1]-9", paginator.next()); + assertEquals("[1]-11", paginator.next()); } @Test public void fourthPagination() { Paginator paginator = new Paginator("([`1`]-11²)"); - Assert.assertEquals("([1]-11)", paginator.next()); - Assert.assertEquals("([1]-13)", paginator.next()); - Assert.assertEquals("([1]-15)", paginator.next()); + assertEquals("([1]-11)", paginator.next()); + assertEquals("([1]-13)", paginator.next()); + assertEquals("([1]-15)", paginator.next()); } @Test public void interleavePagination() { Paginator paginator = new Paginator("1²"); - Assert.assertEquals("1", paginator.next()); - Assert.assertEquals("3", paginator.next()); - Assert.assertEquals("5", paginator.next()); - Assert.assertEquals("7", paginator.next()); - Assert.assertEquals("9", paginator.next()); + assertEquals("1", paginator.next()); + assertEquals("3", paginator.next()); + assertEquals("5", paginator.next()); + assertEquals("7", paginator.next()); + assertEquals("9", paginator.next()); } @Test public void rectoVersoOnOnePagePagination() { Paginator paginator = new Paginator("1`v` 2°r"); - Assert.assertEquals("1v 2r", paginator.next()); - Assert.assertEquals("2v 3r", paginator.next()); - Assert.assertEquals("3v 4r", paginator.next()); + assertEquals("1v 2r", paginator.next()); + assertEquals("2v 3r", paginator.next()); + assertEquals("3v 4r", paginator.next()); } @Test public void interleavePaginationHalf() { Paginator paginator = new Paginator("1½"); - Assert.assertEquals("1", paginator.next()); - Assert.assertEquals("1", paginator.next()); - Assert.assertEquals("2", paginator.next()); - Assert.assertEquals("2", paginator.next()); - Assert.assertEquals("3", paginator.next()); + assertEquals("1", paginator.next()); + assertEquals("1", paginator.next()); + assertEquals("2", paginator.next()); + assertEquals("2", paginator.next()); + assertEquals("3", paginator.next()); } @Test public void inteleavePaginationThree() { Paginator paginator = new Paginator("1³"); - Assert.assertEquals("1", paginator.next()); - Assert.assertEquals("4", paginator.next()); - Assert.assertEquals("7", paginator.next()); - Assert.assertEquals("10", paginator.next()); - Assert.assertEquals("13", paginator.next()); + assertEquals("1", paginator.next()); + assertEquals("4", paginator.next()); + assertEquals("7", paginator.next()); + assertEquals("10", paginator.next()); + assertEquals("13", paginator.next()); } @Test public void rectoVersoPagination() { Paginator paginator = new Paginator("1° ¡r¿v½"); - Assert.assertEquals("1 r", paginator.next()); - Assert.assertEquals("1 v", paginator.next()); - Assert.assertEquals("2 r", paginator.next()); - Assert.assertEquals("2 v", paginator.next()); + assertEquals("1 r", paginator.next()); + assertEquals("1 v", paginator.next()); + assertEquals("2 r", paginator.next()); + assertEquals("2 v", paginator.next()); } @Test public void rectoVersoPaginationStartRight() { Paginator paginator = new Paginator("½1° ¡r¿v½"); - Assert.assertEquals("1 v", paginator.next()); - Assert.assertEquals("2 r", paginator.next()); - Assert.assertEquals("2 v", paginator.next()); - Assert.assertEquals("3 r", paginator.next()); - Assert.assertEquals("3 v", paginator.next()); + assertEquals("1 v", paginator.next()); + assertEquals("2 r", paginator.next()); + assertEquals("2 v", paginator.next()); + assertEquals("3 r", paginator.next()); + assertEquals("3 v", paginator.next()); } @Test public void romanPaginationLowercase() { Paginator p = new Paginator("i"); - Assert.assertEquals("i", p.next()); - Assert.assertEquals("ii", p.next()); - Assert.assertEquals("iii", p.next()); - Assert.assertEquals("iv", p.next()); - Assert.assertEquals("v", p.next()); + assertEquals("i", p.next()); + assertEquals("ii", p.next()); + assertEquals("iii", p.next()); + assertEquals("iv", p.next()); + assertEquals("v", p.next()); } @Test public void romanPaginationUppercase() { Paginator paginator = new Paginator("I"); - Assert.assertEquals("I", paginator.next()); - Assert.assertEquals("II", paginator.next()); - Assert.assertEquals("III", paginator.next()); - Assert.assertEquals("IV", paginator.next()); - Assert.assertEquals("V", paginator.next()); + assertEquals("I", paginator.next()); + assertEquals("II", paginator.next()); + assertEquals("III", paginator.next()); + assertEquals("IV", paginator.next()); + assertEquals("V", paginator.next()); } @Test public void simplePagination() { Paginator paginator = new Paginator("1"); - Assert.assertEquals("1", paginator.next()); - Assert.assertEquals("2", paginator.next()); - Assert.assertEquals("3", paginator.next()); - Assert.assertEquals("4", paginator.next()); - Assert.assertEquals("5", paginator.next()); - Assert.assertEquals("6", paginator.next()); - Assert.assertEquals("7", paginator.next()); + assertEquals("1", paginator.next()); + assertEquals("2", paginator.next()); + assertEquals("3", paginator.next()); + assertEquals("4", paginator.next()); + assertEquals("5", paginator.next()); + assertEquals("6", paginator.next()); + assertEquals("7", paginator.next()); } @Test public void twoColumnPagination() { Paginator paginator = new Paginator("1 2"); - Assert.assertEquals("1 2", paginator.next()); - Assert.assertEquals("3 4", paginator.next()); - Assert.assertEquals("5 6", paginator.next()); - Assert.assertEquals("7 8", paginator.next()); - Assert.assertEquals("9 10", paginator.next()); + assertEquals("1 2", paginator.next()); + assertEquals("3 4", paginator.next()); + assertEquals("5 6", paginator.next()); + assertEquals("7 8", paginator.next()); + assertEquals("9 10", paginator.next()); } @Test public void twoColumnPaginationRightToLeft() { Paginator paginator = new Paginator("2 1"); - Assert.assertEquals("2 1", paginator.next()); - Assert.assertEquals("4 3", paginator.next()); - Assert.assertEquals("6 5", paginator.next()); - Assert.assertEquals("8 7", paginator.next()); - Assert.assertEquals("10 9", paginator.next()); + assertEquals("2 1", paginator.next()); + assertEquals("4 3", paginator.next()); + assertEquals("6 5", paginator.next()); + assertEquals("8 7", paginator.next()); + assertEquals("10 9", paginator.next()); } @Test public void ignoreRomanNumeralsThatArePartsOfWordsWithLatin() { Paginator paginator = new Paginator("Kapitel 1"); - Assert.assertEquals("Kapitel 1", paginator.next()); - Assert.assertEquals("Kapitel 2", paginator.next()); - Assert.assertEquals("Kapitel 3", paginator.next()); - Assert.assertEquals("Kapitel 4", paginator.next()); + assertEquals("Kapitel 1", paginator.next()); + assertEquals("Kapitel 2", paginator.next()); + assertEquals("Kapitel 3", paginator.next()); + assertEquals("Kapitel 4", paginator.next()); } @Test public void ignoreRomanNumeralsThatArePartsOfWordsWithLowercaseRoman() { Paginator paginator = new Paginator("Kapitel i"); - Assert.assertEquals("Kapitel i", paginator.next()); - Assert.assertEquals("Kapitel ii", paginator.next()); - Assert.assertEquals("Kapitel iii", paginator.next()); - Assert.assertEquals("Kapitel iv", paginator.next()); + assertEquals("Kapitel i", paginator.next()); + assertEquals("Kapitel ii", paginator.next()); + assertEquals("Kapitel iii", paginator.next()); + assertEquals("Kapitel iv", paginator.next()); } @Test public void handleRectoVersoForWhiteSpaceCharacterAsWell() { Paginator paginator = new Paginator("1°¿ ¿(¿R¿ü¿c¿k¿s¿e¿i¿t¿e¿)½"); - Assert.assertEquals("1", paginator.next()); - Assert.assertEquals("1 (Rückseite)", paginator.next()); - Assert.assertEquals("2", paginator.next()); - Assert.assertEquals("2 (Rückseite)", paginator.next()); + assertEquals("1", paginator.next()); + assertEquals("1 (Rückseite)", paginator.next()); + assertEquals("2", paginator.next()); + assertEquals("2 (Rückseite)", paginator.next()); } @Test public void allowGroupingOfRectoVersoText() { Paginator paginator = new Paginator("1°¿` (Rückseite)`½"); - Assert.assertEquals("1", paginator.next()); - Assert.assertEquals("1 (Rückseite)", paginator.next()); - Assert.assertEquals("2", paginator.next()); - Assert.assertEquals("2 (Rückseite)", paginator.next()); + assertEquals("1", paginator.next()); + assertEquals("1 (Rückseite)", paginator.next()); + assertEquals("2", paginator.next()); + assertEquals("2 (Rückseite)", paginator.next()); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/metadata/pagination/PaginatorTypeTest.java b/Kitodo/src/test/java/org/kitodo/production/helper/metadata/pagination/PaginatorTypeTest.java index 1eca28a7717..53c92dc1dd0 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/metadata/pagination/PaginatorTypeTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/metadata/pagination/PaginatorTypeTest.java @@ -11,9 +11,10 @@ package org.kitodo.production.helper.metadata.pagination; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PaginatorTypeTest { @@ -122,9 +123,9 @@ public void testArabicFormatFoliationFromUppercaseRoman() { assertEquals("68½", PaginatorType.ARABIC.format(PaginatorMode.FOLIATION, "LXVIII", false, UNUSED_STRING)); } - @Test(expected = NumberFormatException.class) + @Test public void testArabicFormatFromJunk() { - PaginatorType.ARABIC.format(UNUSED_PAGINATOR_MODE, "junk", UNUSED_BOOLEAN, UNUSED_STRING); + assertThrows(NumberFormatException.class, () -> PaginatorType.ARABIC.format(UNUSED_PAGINATOR_MODE, "junk", UNUSED_BOOLEAN, UNUSED_STRING)); } @Test @@ -382,9 +383,9 @@ public void testRomanFormatFoliationFromUppercaseRoman() { assertEquals("I½", PaginatorType.ROMAN.format(PaginatorMode.FOLIATION, "I", false, UNUSED_STRING)); } - @Test(expected = NumberFormatException.class) + @Test public void testRomanFormatFromJunk() { - PaginatorType.ROMAN.format(UNUSED_PAGINATOR_MODE, "junk", UNUSED_BOOLEAN, UNUSED_STRING); + assertThrows(NumberFormatException.class, () -> PaginatorType.ROMAN.format(UNUSED_PAGINATOR_MODE, "junk", UNUSED_BOOLEAN, UNUSED_STRING)); } @Test @@ -569,9 +570,9 @@ public void testValueOfThree() { assertEquals(PaginatorType.UNCOUNTED, PaginatorType.valueOf(3)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testValueOfFourtytwo() { - PaginatorType.valueOf(42); + assertThrows(IllegalArgumentException.class, () -> PaginatorType.valueOf(42)); } @Test diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/metadata/pagination/RomanNumeralTest.java b/Kitodo/src/test/java/org/kitodo/production/helper/metadata/pagination/RomanNumeralTest.java index 425db8802d4..2a22a11c79b 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/metadata/pagination/RomanNumeralTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/metadata/pagination/RomanNumeralTest.java @@ -11,9 +11,9 @@ package org.kitodo.production.helper.metadata.pagination; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RomanNumeralTest { diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/tasks/HierarchyMigrationTaskIT.java b/Kitodo/src/test/java/org/kitodo/production/helper/tasks/HierarchyMigrationTaskIT.java index 1003adf48f8..488baf3b60e 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/tasks/HierarchyMigrationTaskIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/tasks/HierarchyMigrationTaskIT.java @@ -11,6 +11,9 @@ package org.kitodo.production.helper.tasks; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.File; import java.io.IOException; import java.util.Collections; @@ -21,10 +24,9 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.SystemUtils; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.ExecutionPermission; import org.kitodo.MockDatabase; import org.kitodo.config.ConfigCore; @@ -45,7 +47,7 @@ public class HierarchyMigrationTaskIT { /** * prepares database. */ - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { if (!SystemUtils.IS_OS_WINDOWS) { ExecutionPermission.setExecutePermission(script); @@ -64,7 +66,7 @@ public static void prepareDatabase() throws Exception { /** * cleans database. */ - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { if (!SystemUtils.IS_OS_WINDOWS) { ExecutionPermission.setNoExecutePermission(script); @@ -83,13 +85,12 @@ public void testHierarchyMigration() throws DAOException, ProcessGenerationExcep IOException, SAXException, ParserConfigurationException { HierarchyMigrationTask hierarchyMigrationTask = new HierarchyMigrationTask(Collections.singletonList(project)); hierarchyMigrationTask.migrate(ServiceManager.getProcessService().getById(2)); - Assert.assertTrue("Tasks should have been removed", - ServiceManager.getProcessService().getById(4).getTasks().isEmpty()); - Assert.assertEquals("JahrdeDeG_404810993", ServiceManager.getProcessService().getById(4).getTitle()); + assertTrue(ServiceManager.getProcessService().getById(4).getTasks().isEmpty(), "Tasks should have been removed"); + assertEquals("JahrdeDeG_404810993", ServiceManager.getProcessService().getById(4).getTitle()); Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new File("src/test/resources/metadata/4/meta.xml")); String documentId = document.getElementsByTagName("mets:metsDocumentID").item(0).getTextContent(); - Assert.assertEquals("DocumentId not set", "4", documentId); + assertEquals("4", documentId, "DocumentId not set"); } private static void createTestMetaAnchorfile() throws Exception { diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/tasks/MigrationTaskIT.java b/Kitodo/src/test/java/org/kitodo/production/helper/tasks/MigrationTaskIT.java index 4a90668e34d..bb57a528560 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/tasks/MigrationTaskIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/tasks/MigrationTaskIT.java @@ -11,10 +11,14 @@ package org.kitodo.production.helper.tasks; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Project; import org.kitodo.production.services.ServiceManager; @@ -34,7 +38,7 @@ public class MigrationTaskIT { private static final int TEMPLATE_ID = 1; private static final int RULESET_ID = 1; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -44,7 +48,7 @@ public static void prepareDatabase() throws Exception { ProcessTestUtils.copyTestMetadataFile(migrationTestProcessId, METADATA_MIGRATION_SOURCE_FILE); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { ProcessTestUtils.removeTestProcess(migrationTestProcessId); MockDatabase.stopNode(); @@ -55,11 +59,10 @@ public static void cleanDatabase() throws Exception { public void testMigrationTask() throws Exception { MigrationTask migrationTask = new MigrationTask(project); migrationTask.start(); - Assert.assertTrue(migrationTask.isAlive()); + assertTrue(migrationTask.isAlive()); migrationTask.join(); - Assert.assertFalse(migrationTask.isAlive()); - Assert.assertEquals(100, migrationTask.getProgress()); - Assert.assertNotNull("Process migration failed", - metsService.loadWorkpiece(processService.getMetadataFileUri(processService.getById(migrationTestProcessId)))); + assertFalse(migrationTask.isAlive()); + assertEquals(100, migrationTask.getProgress()); + assertNotNull(metsService.loadWorkpiece(processService.getMetadataFileUri(processService.getById(migrationTestProcessId))), "Process migration failed"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/tasks/NewspaperMigrationTaskIT.java b/Kitodo/src/test/java/org/kitodo/production/helper/tasks/NewspaperMigrationTaskIT.java index 62ab47108bd..d77b6490d08 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/tasks/NewspaperMigrationTaskIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/tasks/NewspaperMigrationTaskIT.java @@ -11,15 +11,19 @@ package org.kitodo.production.helper.tasks; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.File; import java.util.List; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.SystemUtils; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.ExecutionPermission; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; @@ -47,7 +51,7 @@ public class NewspaperMigrationTaskIT { private static final File script = new File(ConfigCore.getParameter(ParameterCore.SCRIPT_CREATE_DIR_META)); - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { if (!SystemUtils.IS_OS_WINDOWS) { @@ -94,43 +98,38 @@ private static void moveOriginMetadataDirectoryAside() throws Exception { public void testNewspaperMigrationTask() throws Exception { Process issueOne = processService.getById(1); - Assert.assertNull("should not yet have parent", issueOne.getParent()); + assertNull(issueOne.getParent(), "should not yet have parent"); Process issueTwo = processService.getById(2); - Assert.assertNull("should not yet have parent", issueTwo.getParent()); - Assert.assertEquals("should not yet have created year process", 0, - processService.findByTitle("NewsMiTe_1850").size()); - Assert.assertEquals("should not yet have created overall process", 0, - processService.findByTitle("NewsMiTe").size()); + assertNull(issueTwo.getParent(), "should not yet have parent"); + assertEquals(0, processService.findByTitle("NewsMiTe_1850").size(), "should not yet have created year process"); + assertEquals(0, processService.findByTitle("NewsMiTe").size(), "should not yet have created overall process"); NewspaperMigrationTask underTest = new NewspaperMigrationTask(batchService.getById(5)); underTest.start(); - Assert.assertTrue("should be running", underTest.isAlive()); + assertTrue(underTest.isAlive(), "should be running"); underTest.join(); - Assert.assertFalse("should have finished", underTest.isAlive()); - Assert.assertEquals("should have completed", 100, underTest.getProgress()); + assertFalse(underTest.isAlive(), "should have finished"); + assertEquals(100, underTest.getProgress(), "should have completed"); Workpiece workpiece = ServiceManager.getMetsService() .loadWorkpiece(processService.getMetadataFileUri(issueOne)); LogicalDivision logicalStructure = workpiece.getLogicalStructure(); - Assert.assertEquals("should have modified METS file", "NewspaperMonth", logicalStructure.getType()); - Assert.assertEquals("should have added date for month", "1850-03", logicalStructure.getOrderlabel()); - Assert.assertEquals("should have added date for day", "1850-03-12", - logicalStructure.getChildren().get(0).getOrderlabel()); + assertEquals("NewspaperMonth", logicalStructure.getType(), "should have modified METS file"); + assertEquals("1850-03", logicalStructure.getOrderlabel(), "should have added date for month"); + assertEquals("1850-03-12", logicalStructure.getChildren().get(0).getOrderlabel(), "should have added date for day"); Process newspaperProcess = processService.getById(4); processService.save(newspaperProcess); Process yearProcess = processService.getById(5); processService.save(yearProcess); - Assert.assertEquals("should have created year process", 1, processService.findByTitle("NewsMiTe-1850").size()); - Assert.assertEquals("should have created overall process", 1, processService.findByTitle("NewsMiTe", true, true).size()); - Assert.assertTrue("should have added link from newspaper process to year process", - newspaperProcess.getChildren().contains(yearProcess)); + assertEquals(1, processService.findByTitle("NewsMiTe-1850").size(), "should have created year process"); + assertEquals(1, processService.findByTitle("NewsMiTe", true, true).size(), "should have created overall process"); + assertTrue(newspaperProcess.getChildren().contains(yearProcess), "should have added link from newspaper process to year process"); List linksInYear = yearProcess.getChildren(); - Assert.assertTrue("should have added links from year process to issues", - linksInYear.contains(issueOne) && linksInYear.contains(issueTwo)); + assertTrue(linksInYear.contains(issueOne) && linksInYear.contains(issueTwo), "should have added links from year process to issues"); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); diff --git a/Kitodo/src/test/java/org/kitodo/production/interfaces/activemq/TaskActionProcessorIT.java b/Kitodo/src/test/java/org/kitodo/production/interfaces/activemq/TaskActionProcessorIT.java index a520ce193eb..fbee35311ba 100644 --- a/Kitodo/src/test/java/org/kitodo/production/interfaces/activemq/TaskActionProcessorIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/interfaces/activemq/TaskActionProcessorIT.java @@ -11,7 +11,8 @@ package org.kitodo.production.interfaces.activemq; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -23,9 +24,9 @@ import javax.jms.JMSException; import org.apache.commons.lang3.StringUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.kitodo.ExecutionPermission; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; @@ -53,7 +54,7 @@ public class TaskActionProcessorIT { * @throws Exception * if something goes wrong */ - @Before + @BeforeEach public void prepare() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesForWorkflowFull(); @@ -68,7 +69,7 @@ public void prepare() throws Exception { * @throws Exception * if something goes wrong */ - @After + @AfterEach public void clean() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -77,14 +78,14 @@ public void clean() throws Exception { ExecutionPermission.setNoExecutePermission(scriptDeleteSymLink); } - @Test(expected = ProcessorException.class) - public void testTaskNotFound() throws Exception { - processAction(Integer.MIN_VALUE, TaskAction.COMMENT.name(), StringUtils.EMPTY, null); + @Test + public void testTaskNotFound() { + assertThrows(ProcessorException.class, () -> processAction(Integer.MIN_VALUE, TaskAction.COMMENT.name(), StringUtils.EMPTY, null)); } - @Test(expected = ProcessorException.class) - public void testUnsupportedAction() throws Exception { - processAction(9, "UNSUPPORTED", StringUtils.EMPTY, null); + @Test + public void testUnsupportedAction() { + assertThrows(ProcessorException.class, () -> processAction(9, "UNSUPPORTED", StringUtils.EMPTY, null)); } /** @@ -96,11 +97,9 @@ public void testUnsupportedAction() throws Exception { @Test public void testActionProcess() throws Exception { Task task = taskService.getById(9); - assertEquals("Task '" + task.getTitle() + "' status should be OPEN!", TaskStatus.OPEN, - task.getProcessingStatus()); + assertEquals(TaskStatus.OPEN, task.getProcessingStatus(), "Task '" + task.getTitle() + "' status should be OPEN!"); processAction(task, TaskAction.PROCESS); - assertEquals("Task '" + task.getTitle() + "' status should be INWORK!", TaskStatus.INWORK, - taskService.getById(task.getId()).getProcessingStatus()); + assertEquals(TaskStatus.INWORK, taskService.getById(task.getId()).getProcessingStatus(), "Task '" + task.getTitle() + "' status should be INWORK!"); } /** @@ -109,12 +108,11 @@ public void testActionProcess() throws Exception { * @throws Exception * if something goes wrong */ - @Test(expected = ProcessorException.class) + @Test public void testActionProcessWithoutTaskStatusOpen() throws Exception { Task task = taskService.getById(8); - assertEquals("Task '" + task.getTitle() + "' status should be INWORK!", TaskStatus.INWORK, - task.getProcessingStatus()); - processAction(task, TaskAction.PROCESS); + assertEquals(TaskStatus.INWORK, task.getProcessingStatus(), "Task '" + task.getTitle() + "' status should be INWORK!"); + assertThrows(ProcessorException.class, () -> processAction(task, TaskAction.PROCESS)); } /** @@ -126,11 +124,9 @@ public void testActionProcessWithoutTaskStatusOpen() throws Exception { @Test public void testActionClose() throws Exception { Task task = taskService.getById(9); - assertEquals("Task '" + task.getTitle() + "' status should be OPEN!", TaskStatus.OPEN, - task.getProcessingStatus()); + assertEquals(TaskStatus.OPEN, task.getProcessingStatus(), "Task '" + task.getTitle() + "' status should be OPEN!"); processAction(task, TaskAction.CLOSE); - assertEquals("Task '" + task.getTitle() + "' status should be DONE!", TaskStatus.DONE, - taskService.getById(task.getId()).getProcessingStatus()); + assertEquals(TaskStatus.DONE, taskService.getById(task.getId()).getProcessingStatus(), "Task '" + task.getTitle() + "' status should be DONE!"); } /** @@ -142,11 +138,9 @@ public void testActionClose() throws Exception { @Test public void testActionErrorOpen() throws Exception { Task inWorkTask = taskService.getById(8); - assertEquals("Task '" + inWorkTask.getTitle() + "' status should be INWORK!", TaskStatus.INWORK, - inWorkTask.getProcessingStatus()); + assertEquals(TaskStatus.INWORK, inWorkTask.getProcessingStatus(), "Task '" + inWorkTask.getTitle() + "' status should be INWORK!"); processAction(inWorkTask, TaskAction.ERROR_OPEN); - assertEquals("Task '" + inWorkTask.getTitle() + "' status should be INWORK!", TaskStatus.INWORK, - taskService.getById(inWorkTask.getId()).getProcessingStatus()); + assertEquals(TaskStatus.INWORK, taskService.getById(inWorkTask.getId()).getProcessingStatus(), "Task '" + inWorkTask.getTitle() + "' status should be INWORK!"); } /** @@ -159,13 +153,10 @@ public void testActionErrorOpen() throws Exception { public void testActionErrorOpenWithCorrectionTask() throws Exception { Task task = taskService.getById(8); Task correctionTask = taskService.getById(6); - assertEquals("Task '" + task.getTitle() + "' status should be INWORK!", TaskStatus.INWORK, - task.getProcessingStatus()); + assertEquals(TaskStatus.INWORK, task.getProcessingStatus(), "Task '" + task.getTitle() + "' status should be INWORK!"); processAction(task, TaskAction.ERROR_OPEN, correctionTask.getId(), 1); - assertEquals("Task '" + task.getTitle() + "' status should be LOCKED!", TaskStatus.LOCKED, - taskService.getById(task.getId()).getProcessingStatus()); - assertEquals("Correction task '" + correctionTask.getTitle() + "' status should be OPEN!", TaskStatus.OPEN, - taskService.getById(correctionTask.getId()).getProcessingStatus()); + assertEquals(TaskStatus.LOCKED, taskService.getById(task.getId()).getProcessingStatus(), "Task '" + task.getTitle() + "' status should be LOCKED!"); + assertEquals(TaskStatus.OPEN, taskService.getById(correctionTask.getId()).getProcessingStatus(), "Correction task '" + correctionTask.getTitle() + "' status should be OPEN!"); } /** @@ -174,12 +165,11 @@ public void testActionErrorOpenWithCorrectionTask() throws Exception { * @throws Exception * if something goes wrong */ - @Test(expected = ProcessorException.class) + @Test public void testActionErrorOpenWithoutTaskStatusInWork() throws Exception { Task task = taskService.getById(9); - assertEquals("Task '" + task.getTitle() + "' status should be OPEN!", TaskStatus.OPEN, - task.getProcessingStatus()); - processAction(task, TaskAction.ERROR_OPEN); + assertEquals(TaskStatus.OPEN, task.getProcessingStatus(), "Task '" + task.getTitle() + "' status should be OPEN!"); + assertThrows(ProcessorException.class, () -> processAction(task, TaskAction.ERROR_OPEN)); } /** @@ -188,10 +178,10 @@ public void testActionErrorOpenWithoutTaskStatusInWork() throws Exception { * @throws Exception * if something goes wrong */ - @Test(expected = ProcessorException.class) + @Test public void testActionErrorOpenWithoutMessage() throws Exception { Task task = taskService.getById(10); - processAction(task.getId(), TaskAction.ERROR_OPEN.name(), StringUtils.EMPTY, null); + assertThrows(ProcessorException.class, () -> processAction(task.getId(), TaskAction.ERROR_OPEN.name(), StringUtils.EMPTY, null)); } /** @@ -203,11 +193,9 @@ public void testActionErrorOpenWithoutMessage() throws Exception { @Test public void testActionErrorClose() throws Exception { Task task = taskService.getById(8); - assertEquals("Task '" + task.getTitle() + "' status should be INWORK!", TaskStatus.INWORK, - task.getProcessingStatus()); + assertEquals(TaskStatus.INWORK, task.getProcessingStatus(), "Task '" + task.getTitle() + "' status should be INWORK!"); processAction(task, TaskAction.ERROR_CLOSE); - assertEquals("Task '" + task.getTitle() + "' status should be OPEN!", TaskStatus.OPEN, - taskService.getById(task.getId()).getProcessingStatus()); + assertEquals(TaskStatus.OPEN, taskService.getById(task.getId()).getProcessingStatus(), "Task '" + task.getTitle() + "' status should be OPEN!"); } /** @@ -220,20 +208,15 @@ public void testActionErrorClose() throws Exception { public void testActionErrorCloseWithCorrectionTask() throws Exception { Task task = taskService.getById(8); Task correctionTask = taskService.getById(6); - assertEquals("Task '" + task.getTitle() + "' status should be INWORK!", TaskStatus.INWORK, - task.getProcessingStatus()); + assertEquals(TaskStatus.INWORK, task.getProcessingStatus(), "Task '" + task.getTitle() + "' status should be INWORK!"); processAction(task, TaskAction.ERROR_OPEN, correctionTask.getId(), 1); - assertEquals("Task '" + task.getTitle() + "' status should be LOCKED!", TaskStatus.LOCKED, - taskService.getById(task.getId()).getProcessingStatus()); - assertEquals("Correction task '" + correctionTask.getTitle() + "' status should be OPEN!", TaskStatus.OPEN, - taskService.getById(correctionTask.getId()).getProcessingStatus()); + assertEquals(TaskStatus.LOCKED, taskService.getById(task.getId()).getProcessingStatus(), "Task '" + task.getTitle() + "' status should be LOCKED!"); + assertEquals(TaskStatus.OPEN, taskService.getById(correctionTask.getId()).getProcessingStatus(), "Correction task '" + correctionTask.getTitle() + "' status should be OPEN!"); processAction(task, TaskAction.ERROR_CLOSE, correctionTask.getId(), 2); - assertEquals("Task '" + task.getTitle() + "' status should be OPEN!", TaskStatus.OPEN, - taskService.getById(task.getId()).getProcessingStatus()); - assertEquals("Correction task '" + correctionTask.getTitle() + "' status should be DONE!", TaskStatus.DONE, - taskService.getById(correctionTask.getId()).getProcessingStatus()); + assertEquals(TaskStatus.OPEN, taskService.getById(task.getId()).getProcessingStatus(), "Task '" + task.getTitle() + "' status should be OPEN!"); + assertEquals(TaskStatus.DONE, taskService.getById(correctionTask.getId()).getProcessingStatus(), "Correction task '" + correctionTask.getTitle() + "' status should be DONE!"); } /** @@ -242,12 +225,11 @@ public void testActionErrorCloseWithCorrectionTask() throws Exception { * @throws Exception * if something goes wrong */ - @Test(expected = ProcessorException.class) + @Test public void testActionErrorCloseWithoutTaskStatusInWork() throws Exception { Task task = taskService.getById(9); - assertEquals("Task '" + task.getTitle() + "' status should be OPEN!", TaskStatus.OPEN, - task.getProcessingStatus()); - processAction(task, TaskAction.ERROR_CLOSE); + assertEquals(TaskStatus.OPEN, task.getProcessingStatus(), "Task '" + task.getTitle() + "' status should be OPEN!"); + assertThrows(ProcessorException.class, () -> processAction(task, TaskAction.ERROR_CLOSE)); } /** @@ -259,12 +241,10 @@ public void testActionErrorCloseWithoutTaskStatusInWork() throws Exception { @Test public void testActionComment() throws Exception { Task task = taskService.getById(9); - assertEquals("Task '" + task.getTitle() + "' status should be OPEN!", TaskStatus.OPEN, - task.getProcessingStatus()); + assertEquals(TaskStatus.OPEN, task.getProcessingStatus(), "Task '" + task.getTitle() + "' status should be OPEN!"); processAction(task, TaskAction.COMMENT, null, 1); processAction(task, TaskAction.COMMENT, null, 2); - assertEquals("Task '" + task.getTitle() + "' status should be OPEN!", TaskStatus.OPEN, - taskService.getById(task.getId()).getProcessingStatus()); + assertEquals(TaskStatus.OPEN, taskService.getById(task.getId()).getProcessingStatus(), "Task '" + task.getTitle() + "' status should be OPEN!"); } private static void processAction(Task task, TaskAction taskAction) throws JMSException, ProcessorException { @@ -276,9 +256,8 @@ private static void processAction(Task task, TaskAction taskAction, Integer corr String message = "Process action " + taskAction.name(); processAction(task.getId(), taskAction.name(), message, correctionTaskId); List comments = ServiceManager.getCommentService().getAllCommentsByTask(task); - assertEquals("Comment should be created!", commentCount, comments.size()); - assertEquals("Comment message should be '" + message + "'!", message, - comments.get(commentCount - 1).getMessage()); + assertEquals(commentCount, comments.size(), "Comment should be created!"); + assertEquals(message, comments.get(commentCount - 1).getMessage(), "Comment message should be '" + message + "'!"); } private static void processAction(Integer taskId, String action, String message, Integer correctionTaskId) diff --git a/Kitodo/src/test/java/org/kitodo/production/metadata/MetadataEditorIT.java b/Kitodo/src/test/java/org/kitodo/production/metadata/MetadataEditorIT.java index 11f3a6961be..b5033cccaec 100644 --- a/Kitodo/src/test/java/org/kitodo/production/metadata/MetadataEditorIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/metadata/MetadataEditorIT.java @@ -12,7 +12,8 @@ package org.kitodo.production.metadata; import static org.awaitility.Awaitility.await; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.kitodo.test.utils.ProcessTestUtils.METADATA_BASE_DIR; import static org.kitodo.test.utils.ProcessTestUtils.META_XML; @@ -24,11 +25,9 @@ import java.util.Map; import org.apache.commons.io.FileUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.api.Metadata; @@ -57,7 +56,7 @@ public class MetadataEditorIT { /** * Is running before the class runs. */ - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -76,7 +75,7 @@ public static void prepareDatabase() throws Exception { /** * Is running after the class has run. */ - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { ProcessTestUtils.removeTestProcess(testProcessIds.get(MockDatabase.HIERARCHY_PARENT)); ProcessTestUtils.removeTestProcess(testProcessIds.get(MockDatabase.HIERARCHY_CHILD_TO_ADD)); @@ -84,9 +83,6 @@ public static void cleanDatabase() throws Exception { MockDatabase.cleanDatabase(); } - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void shouldAddLink() throws Exception { int parentId = testProcessIds.get(MockDatabase.HIERARCHY_PARENT); @@ -96,8 +92,7 @@ public void shouldAddLink() throws Exception { MetadataEditor.addLink(ServiceManager.getProcessService().getById(parentId), "0", childId); - assertTrue("The link was not added correctly!", - isInternalMetsLink(FileUtils.readLines(metaXmlFile, StandardCharsets.UTF_8).get(36), childId)); + assertTrue(isInternalMetsLink(FileUtils.readLines(metaXmlFile, StandardCharsets.UTF_8).get(36), childId), "The link was not added correctly!"); FileUtils.writeLines(metaXmlFile, StandardCharsets.UTF_8.toString(), metaXmlContentBefore); FileUtils.deleteQuietly(new File(METADATA_BASE_DIR + parentId + "/meta.xml.1")); @@ -118,7 +113,7 @@ public void shouldAddMultipleStructuresWithoutMetadata() throws Exception { InsertionPosition.FIRST_CHILD_OF_CURRENT_ELEMENT); List logicalDivisions = workpiece.getAllLogicalDivisions(); - assertTrue("Metadata should be empty", logicalDivisions.get(newNrDivisions - 1).getMetadata().isEmpty()); + assertTrue(logicalDivisions.get(newNrDivisions - 1).getMetadata().isEmpty(), "Metadata should be empty"); ProcessTestUtils.removeTestProcess(testProcessId); } @@ -152,9 +147,9 @@ public void shouldAddMultipleStructuresWithMetadataGroup() throws Exception { Metadata metadatumOne = metadataListOne.get(0); Metadata metadatumTwo = metadataListTwo.get(0); - assertTrue("Metadata should be of type MetadataEntry", metadatumOne instanceof MetadataEntry); - assertTrue("Metadata value was incorrectly added", ((MetadataEntry) metadatumOne).getValue().equals("value 1") - && ((MetadataEntry) metadatumTwo).getValue().equals("value 2")); + assertInstanceOf(MetadataEntry.class, metadatumOne, "Metadata should be of type MetadataEntry"); + assertTrue(((MetadataEntry) metadatumOne).getValue().equals("value 1") + && ((MetadataEntry) metadatumTwo).getValue().equals("value 2"), "Metadata value was incorrectly added"); ProcessTestUtils.removeTestProcess(testProcessId); } @@ -187,10 +182,8 @@ public void shouldAddMultipleStructuresWithMetadataEntry() throws Exception { Metadata metadatumOne = metadataListOne.get(0); Metadata metadatumTwo = metadataListTwo.get(0); - assertTrue("Metadata should be of type MetadataGroup", - metadatumOne instanceof MetadataGroup && metadatumTwo instanceof MetadataGroup); - assertTrue("Metadata value was incorrectly added", - metadatumOne.getKey().equals("Person") && metadatumTwo.getKey().equals("Person")); + assertTrue(metadatumOne instanceof MetadataGroup && metadatumTwo instanceof MetadataGroup, "Metadata should be of type MetadataGroup"); + assertTrue(metadatumOne.getKey().equals("Person") && metadatumTwo.getKey().equals("Person"), "Metadata value was incorrectly added"); ProcessTestUtils.removeTestProcess(testProcessId); } diff --git a/Kitodo/src/test/java/org/kitodo/production/metadata/MetadataEditorTest.java b/Kitodo/src/test/java/org/kitodo/production/metadata/MetadataEditorTest.java index f4e591b0438..38b12d8729e 100644 --- a/Kitodo/src/test/java/org/kitodo/production/metadata/MetadataEditorTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/metadata/MetadataEditorTest.java @@ -11,14 +11,15 @@ package org.kitodo.production.metadata; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.lang.reflect.Method; import java.net.URI; import java.util.Arrays; import java.util.LinkedList; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kitodo.api.dataformat.LogicalDivision; import org.kitodo.api.dataformat.mets.LinkedMetsResource; @@ -58,7 +59,7 @@ public void testDetermineLogicalDivisionPathToChildRecursive() throws Exception List result = (List) determineLogicalDivisionPathToChild .invoke(null, logicalDivision, number); - Assert.assertEquals(new LinkedList<>(Arrays.asList(logicalDivision, monthLogicalDivision, + assertEquals(new LinkedList<>(Arrays.asList(logicalDivision, monthLogicalDivision, correctDayLogicalDivision)), result); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/migration/NewspaperProcessesMigratorTest.java b/Kitodo/src/test/java/org/kitodo/production/migration/NewspaperProcessesMigratorTest.java index 0306fa70352..326e3156b63 100644 --- a/Kitodo/src/test/java/org/kitodo/production/migration/NewspaperProcessesMigratorTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/migration/NewspaperProcessesMigratorTest.java @@ -11,14 +11,14 @@ package org.kitodo.production.migration; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.Arrays; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kitodo.data.database.beans.Batch; - public class NewspaperProcessesMigratorTest { @Test @@ -39,8 +39,8 @@ public void checkNewspaperShortedTitleGeneration() { for (String newspaperTitle : listOfNewspaperTitles) { String dailyTitle = newspaperTitle + "-20210804"; String multipleDailyTitle = dailyTitle + "01p_01-p"; - Assert.assertEquals(newspaperTitle, migrator.generateNewspaperShortTitle(dailyTitle)); - Assert.assertEquals(newspaperTitle, migrator.generateNewspaperShortTitle(multipleDailyTitle)); + assertEquals(newspaperTitle, migrator.generateNewspaperShortTitle(dailyTitle)); + assertEquals(newspaperTitle, migrator.generateNewspaperShortTitle(multipleDailyTitle)); } } } diff --git a/Kitodo/src/test/java/org/kitodo/production/migration/TasksToWorkflowConverterIT.java b/Kitodo/src/test/java/org/kitodo/production/migration/TasksToWorkflowConverterIT.java index 9fe19cdce37..fcc0402dff4 100644 --- a/Kitodo/src/test/java/org/kitodo/production/migration/TasksToWorkflowConverterIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/migration/TasksToWorkflowConverterIT.java @@ -11,15 +11,15 @@ package org.kitodo.production.migration; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.nio.charset.StandardCharsets; import org.apache.commons.io.FileUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.config.ConfigCore; import org.kitodo.data.database.beans.Template; @@ -27,13 +27,13 @@ public class TasksToWorkflowConverterIT { - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -47,7 +47,7 @@ public void shouldConvertTemplateToWorkflowFile() throws Exception { templateConverter.convertTasksToWorkflowFile(template.getTitle(), template.getTasks()); File xmlDiagram = new File(ConfigCore.getKitodoDiagramDirectory() + template.getTitle() + ".bpmn20.xml"); - assertTrue("Template was not converted to xml file!", xmlDiagram.exists()); + assertTrue(xmlDiagram.exists(), "Template was not converted to xml file!"); assertTrue(FileUtils.readFileToString(xmlDiagram, StandardCharsets.UTF_8) .contains("\n" + " \n"; - assertEquals("Generate task is incorrect!", expected, taskString); + assertEquals(expected, taskString, "Generate task is incorrect!"); } @Test @@ -75,7 +75,7 @@ public void shouldGenerateTaskWithSourceTarget() { + " \n" + " \n"; - assertEquals("Generate task is incorrect!", expected, taskString); + assertEquals(expected, taskString, "Generate task is incorrect!"); } @Test @@ -93,6 +93,6 @@ public void shouldGenerateTaskShape() { + " \n" + " \n"; - assertEquals("Generate task shaped is incorrect!", expected, taskString); + assertEquals(expected, taskString, "Generate task shaped is incorrect!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/model/LazyDTOModelIT.java b/Kitodo/src/test/java/org/kitodo/production/model/LazyDTOModelIT.java index a65d6fb2a84..b70cdd068b9 100644 --- a/Kitodo/src/test/java/org/kitodo/production/model/LazyDTOModelIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/model/LazyDTOModelIT.java @@ -11,13 +11,13 @@ package org.kitodo.production.model; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.data.database.beans.Client; @@ -31,14 +31,14 @@ public class LazyDTOModelIT { private static final ClientService clientService = ServiceManager.getClientService(); private static LazyDTOModel lazyDTOModel = null; - @BeforeClass + @BeforeAll public static void setUp() throws Exception { MockDatabase.startNode(); MockDatabase.insertClients(); lazyDTOModel = new LazyDTOModel(clientService); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); diff --git a/Kitodo/src/test/java/org/kitodo/production/process/NewspaperProcessesGeneratorIT.java b/Kitodo/src/test/java/org/kitodo/production/process/NewspaperProcessesGeneratorIT.java index 719de1cd0b5..18763ab75c3 100644 --- a/Kitodo/src/test/java/org/kitodo/production/process/NewspaperProcessesGeneratorIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/process/NewspaperProcessesGeneratorIT.java @@ -11,6 +11,11 @@ package org.kitodo.production.process; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.File; import java.io.IOException; import java.net.URI; @@ -22,14 +27,11 @@ import org.apache.commons.lang3.SystemUtils; import org.awaitility.Awaitility; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.ExecutionPermission; import org.kitodo.FileLoader; import org.kitodo.MockDatabase; @@ -65,16 +67,13 @@ public class NewspaperProcessesGeneratorIT { private static final String NEWSPAPER_TEST_METADATA_FILE = "testmetaNewspaper.xml"; private static final String NEWSPAPER_TEST_PROCESS_TITLE = "NewspaperOverallProcess"; - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - /** * The test environment is being set up. * * @throws Exception * if that does not work */ - @BeforeClass + @BeforeAll public static void setUp() throws Exception { if (!SystemUtils.IS_OS_WINDOWS) { ExecutionPermission.setExecutePermission(script); @@ -96,7 +95,7 @@ public static void setUp() throws Exception { /** * The test environment is cleaned up and the database is closed. */ - @AfterClass + @AfterAll public static void tearDown() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -113,7 +112,7 @@ public static void tearDown() throws Exception { * @throws DataException when inserting test or dummy processes fails * @throws IOException when copying test metadata file fails */ - @Before + @BeforeEach public void prepareNewspaperProcess() throws DAOException, DataException, IOException { newspaperTestProcessId = MockDatabase.insertTestProcess(NEWSPAPER_TEST_PROCESS_TITLE, 1, 1, rulesetId); ProcessTestUtils.copyTestFiles(newspaperTestProcessId, NEWSPAPER_TEST_METADATA_FILE); @@ -125,7 +124,7 @@ public void prepareNewspaperProcess() throws DAOException, DataException, IOExce * @throws DataException when deleting newspaper test processes fails * @throws IOException when deleting metadata test files fails */ - @After + @AfterEach public void cleanupNewspaperProcess() throws DAOException, DataException, IOException { if (newspaperTestProcessId > 0) { deleteProcessHierarchy(ServiceManager.getProcessService().getById(newspaperTestProcessId)); @@ -153,14 +152,10 @@ public void shouldGenerateNewspaperProcesses() throws Exception { underTest.nextStep(); } int maxId = getChildProcessWithLargestId(completeEdition, 0); - Assert.assertEquals("The newspaper processes generator has not been completed!", underTest.getNumberOfSteps(), - underTest.getProgress()); - Assert.assertEquals("Process title missing in newspaper's meta.xml", "NewspaperOverallProcess", - readProcessTitleFromMetadata(newspaperTestProcessId, false)); - Assert.assertEquals("Process title missing in year's meta.xml", "NewspaperOverallProcess_1703", - readProcessTitleFromMetadata(newspaperTestProcessId + 1, false)); - Assert.assertEquals("Process title missing in issue's meta.xml", "NewspaperOverallProcess_17050127", - readProcessTitleFromMetadata(maxId, true)); + assertEquals(underTest.getNumberOfSteps(), underTest.getProgress(), "The newspaper processes generator has not been completed!"); + assertEquals("NewspaperOverallProcess", readProcessTitleFromMetadata(newspaperTestProcessId, false), "Process title missing in newspaper's meta.xml"); + assertEquals("NewspaperOverallProcess_1703", readProcessTitleFromMetadata(newspaperTestProcessId + 1, false), "Process title missing in year's meta.xml"); + assertEquals("NewspaperOverallProcess_17050127", readProcessTitleFromMetadata(maxId, true), "Process title missing in issue's meta.xml"); } private int getChildProcessWithLargestId(Process process, int maxId) { @@ -209,8 +204,7 @@ public void shouldGenerateSeasonProcesses() throws Exception { while (underTest.getProgress() < underTest.getNumberOfSteps()) { underTest.nextStep(); } - Assert.assertEquals("The newspaper processes generator has not been completed!", underTest.getNumberOfSteps(), - underTest.getProgress()); + assertEquals(underTest.getNumberOfSteps(), underTest.getProgress(), "The newspaper processes generator has not been completed!"); // check season-year processes for (Process process : processService.getAll()) { @@ -224,8 +218,7 @@ public void shouldGenerateSeasonProcesses() throws Exception { */ String twoYears = workpiece.getLogicalStructure().getOrderlabel(); List years = Arrays.asList(twoYears.split("/", 2)); - Assert.assertEquals("Bad season-year in " + seasonProcess + ": " + twoYears, - Integer.parseInt(years.get(0)) + 1, Integer.parseInt(years.get(1))); + assertEquals(Integer.parseInt(years.get(0)) + 1, Integer.parseInt(years.get(1)), "Bad season-year in " + seasonProcess + ": " + twoYears); // more tests monthChecksOfShouldGenerateSeasonProcesses(seasonProcess, workpiece, twoYears, years); @@ -243,7 +236,7 @@ public void shouldNotGenerateDuplicateProcessTitle() throws DAOException, DataEx generatesNewspaperProcessesThread.start(); ProcessDTO byId = ServiceManager.getProcessService().findById(11); - Assert.assertNull("Process should not have been created", byId.getTitle()); + assertNull(byId.getTitle(), "Process should not have been created"); } private void dayChecksOfShouldGenerateSeasonProcesses(Process seasonProcess, Workpiece seasonYearWorkpiece) { @@ -254,9 +247,7 @@ private void dayChecksOfShouldGenerateSeasonProcesses(Process seasonProcess, Wor for (LogicalDivision dayLogicalDivision : monthLogicalDivision .getChildren()) { String dayValue = dayLogicalDivision.getOrderlabel(); - Assert.assertTrue( - "Error in " + seasonProcess + ": " + dayValue + " misplaced in month " + monthValue + '!', - dayValue.startsWith(monthValue)); + assertTrue(dayValue.startsWith(monthValue), "Error in " + seasonProcess + ": " + dayValue + " misplaced in month " + monthValue + '!'); } } @@ -268,9 +259,8 @@ private void dayChecksOfShouldGenerateSeasonProcesses(Process seasonProcess, Wor .getChildren()) { String dayValue = dayLogicalDivision.getOrderlabel(); if (Objects.nonNull(previousDayValue)) { - Assert.assertTrue("Bad order of days in " + seasonProcess + ": " + dayValue + " should be before " - + previousDayValue + ", but isn’t!", - dayValue.compareTo(previousDayValue) > 0); + assertTrue(dayValue.compareTo(previousDayValue) > 0, "Bad order of days in " + seasonProcess + ": " + dayValue + " should be before " + + previousDayValue + ", but isn’t!"); } previousDayValue = dayValue; } @@ -286,16 +276,13 @@ private void monthChecksOfShouldGenerateSeasonProcesses(Process seasonProcess, W List monthValueFields = Arrays.asList(monthValue.split("-", 2)); int monthNumberOfMonth = Integer.parseInt(monthValueFields.get(1)); if (monthValueFields.get(0).equals(years.get(0))) { - Assert.assertTrue("Error in " + seasonProcess + ": Found misplaced month " + monthValue - + ", should not be in year " + twoYears + ", starting by the 1st of July!", - monthNumberOfMonth >= 7); + assertTrue(monthNumberOfMonth >= 7, "Error in " + seasonProcess + ": Found misplaced month " + monthValue + + ", should not be in year " + twoYears + ", starting by the 1st of July!"); } else if (monthValueFields.get(0).equals(years.get(1))) { - Assert.assertTrue("Error in " + seasonProcess + ": Found misplaced month " + monthValue - + ", should not be in year " + twoYears + ", starting by the 1st of July!", - monthNumberOfMonth < 7); + assertTrue(monthNumberOfMonth < 7, "Error in " + seasonProcess + ": Found misplaced month " + monthValue + + ", should not be in year " + twoYears + ", starting by the 1st of July!"); } else { - Assert.fail( - "Error in " + seasonProcess + ": Month " + monthValue + " is not in years " + twoYears + '!'); + fail("Error in " + seasonProcess + ": Month " + monthValue + " is not in years " + twoYears + '!'); } } @@ -305,9 +292,8 @@ private void monthChecksOfShouldGenerateSeasonProcesses(Process seasonProcess, W .getChildren()) { String monthValue = monthLogicalDivision.getOrderlabel(); if (Objects.nonNull(previousMonthValue)) { - Assert.assertTrue("Bad order of months in " + seasonProcess + ": " + monthValue + " should be before " - + previousMonthValue + ", but isn’t!", - monthValue.compareTo(previousMonthValue) > 0); + assertTrue(monthValue.compareTo(previousMonthValue) > 0, "Bad order of months in " + seasonProcess + ": " + monthValue + " should be before " + + previousMonthValue + ", but isn’t!"); } previousMonthValue = monthValue; } diff --git a/Kitodo/src/test/java/org/kitodo/production/process/ProcessGeneratorIT.java b/Kitodo/src/test/java/org/kitodo/production/process/ProcessGeneratorIT.java index e84d7f41528..eb15ae2de40 100644 --- a/Kitodo/src/test/java/org/kitodo/production/process/ProcessGeneratorIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/process/ProcessGeneratorIT.java @@ -11,14 +11,13 @@ package org.kitodo.production.process; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Process; import org.kitodo.data.database.beans.Property; @@ -32,16 +31,13 @@ public class ProcessGeneratorIT { private static final String NEW = "new"; - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - - @BeforeClass + @BeforeAll public static void setUp() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesForWorkflowFull(); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -51,27 +47,26 @@ public static void tearDown() throws Exception { public void shouldGenerateProcess() throws Exception { ProcessGenerator processGenerator = new ProcessGenerator(); boolean generated = processGenerator.generateProcess(5, 1); - assertTrue("Process was not generated!", generated); + assertTrue(generated, "Process was not generated!"); Process process = processGenerator.getGeneratedProcess(); Template template = processGenerator.getTemplate(); Ruleset expectedRuleset = template.getRuleset(); Ruleset actualRuleset = process.getRuleset(); - assertEquals("Ruleset was copied incorrectly!", expectedRuleset, actualRuleset); + assertEquals(expectedRuleset, actualRuleset, "Ruleset was copied incorrectly!"); int expected = template.getTasks().size(); int actual = process.getTasks().size(); - assertEquals("Tasks were copied incorrectly!", expected, actual); + assertEquals(expected, actual, "Tasks were copied incorrectly!"); } @Test public void shouldNotGenerateProcess() throws Exception { ProcessGenerator processGenerator = new ProcessGenerator(); - expectedEx.expect(ProcessGenerationException.class); - expectedEx.expectMessage("No steps of the workflow defined."); - processGenerator.generateProcess(2, 1); + Exception exception = assertThrows(ProcessGenerationException.class, () -> processGenerator.generateProcess(2, 1)); + assertEquals("No steps of the workflow defined.", exception.getMessage()); } @Test @@ -79,8 +74,7 @@ public void shouldAddPropertyForProcess() throws Exception { Process process = ServiceManager.getProcessService().getById(1); ProcessGenerator.addPropertyForProcess(process, NEW, "process"); - assertTrue("Property was added incorrectly!", - process.getProperties().stream().anyMatch(property -> property.getTitle().equals("new"))); + assertTrue(process.getProperties().stream().anyMatch(property -> property.getTitle().equals("new")), "Property was added incorrectly!"); } @Test @@ -88,8 +82,7 @@ public void shouldAddPropertyForTemplate() throws Exception { Process process = ServiceManager.getProcessService().getById(1); ProcessGenerator.addPropertyForTemplate(process, NEW, "template"); - assertTrue("Property was added incorrectly!", - process.getTemplates().stream().anyMatch(property -> property.getTitle().equals(NEW))); + assertTrue(process.getTemplates().stream().anyMatch(property -> property.getTitle().equals(NEW)), "Property was added incorrectly!"); } @Test @@ -97,8 +90,7 @@ public void shouldAddPropertyForWorkpiece() throws Exception { Process process = ServiceManager.getProcessService().getById(1); ProcessGenerator.addPropertyForWorkpiece(process, NEW, "workpiece"); - assertTrue("Property was added incorrectly!", - process.getWorkpieces().stream().anyMatch(property -> property.getTitle().equals(NEW))); + assertTrue(process.getWorkpieces().stream().anyMatch(property -> property.getTitle().equals(NEW)), "Property was added incorrectly!"); } @Test @@ -109,7 +101,7 @@ public void shouldCopyPropertyForProcess() throws Exception { property.setValue("process"); ProcessGenerator.copyPropertyForProcess(process, new Property()); - assertTrue("Property was copied incorrectly!", process.getProperties().contains(property)); + assertTrue(process.getProperties().contains(property), "Property was copied incorrectly!"); } @Test @@ -120,7 +112,7 @@ public void shouldCopyPropertyForTemplate() throws Exception { property.setValue("template"); ProcessGenerator.copyPropertyForTemplate(process, new Property()); - assertTrue("Property was copied incorrectly!", process.getTemplates().contains(property)); + assertTrue(process.getTemplates().contains(property), "Property was copied incorrectly!"); } @Test @@ -131,7 +123,7 @@ public void shouldCopyPropertyForWorkpiece() throws Exception { property.setValue("workpiece"); ProcessGenerator.copyPropertyForWorkpiece(process, property); - assertTrue("Property was copied incorrectly!", process.getWorkpieces().contains(property)); + assertTrue(process.getWorkpieces().contains(property), "Property was copied incorrectly!"); } @Test @@ -144,15 +136,14 @@ public void shouldNotCopyPropertyForProcess() throws Exception { boolean propertyForUpdateAlreadyExists = process.getProperties().stream() .anyMatch(property -> property.getTitle().equals(newProperty.getTitle()) && !property.getValue().equals(newProperty.getValue())); - assertTrue("Property which is going be updated doesn't exists or have exactly the same value!", - propertyForUpdateAlreadyExists); + assertTrue(propertyForUpdateAlreadyExists, "Property which is going be updated doesn't exists or have exactly the same value!"); ProcessGenerator.copyPropertyForProcess(process, newProperty); boolean propertyValueUpdated = process.getProperties().stream() .anyMatch(property -> property.getTitle().equals(newProperty.getTitle()) && property.getValue().equals(newProperty.getValue())); - assertTrue("Property value was not updated!", propertyValueUpdated); + assertTrue(propertyValueUpdated, "Property value was not updated!"); } @@ -166,15 +157,14 @@ public void shouldNotCopyPropertyForTemplate() throws Exception { boolean propertyForUpdateAlreadyExists = process.getTemplates().stream() .anyMatch(property -> property.getTitle().equals(newProperty.getTitle()) && !property.getValue().equals(newProperty.getValue())); - assertTrue("Property which is going be updated doesn't exists or have exactly the same value!", - propertyForUpdateAlreadyExists); + assertTrue(propertyForUpdateAlreadyExists, "Property which is going be updated doesn't exists or have exactly the same value!"); ProcessGenerator.copyPropertyForTemplate(process, newProperty); boolean propertyValueUpdated = process.getTemplates().stream() .anyMatch(property -> property.getTitle().equals(newProperty.getTitle()) && property.getValue().equals(newProperty.getValue())); - assertTrue("Property value was not updated!", propertyValueUpdated); + assertTrue(propertyValueUpdated, "Property value was not updated!"); } @Test @@ -187,15 +177,14 @@ public void shouldNotCopyPropertyForWorkpiece() throws Exception { boolean propertyForUpdateAlreadyExists = process.getWorkpieces().stream() .anyMatch(property -> property.getTitle().equals(newProperty.getTitle()) && !property.getValue().equals(newProperty.getValue())); - assertTrue("Property which is going be updated doesn't exists or have exactly the same value!", - propertyForUpdateAlreadyExists); + assertTrue(propertyForUpdateAlreadyExists, "Property which is going be updated doesn't exists or have exactly the same value!"); ProcessGenerator.copyPropertyForWorkpiece(process, newProperty); boolean propertyValueUpdated = process.getWorkpieces().stream() .anyMatch(property -> property.getTitle().equals(newProperty.getTitle()) && property.getValue().equals(newProperty.getValue())); - assertTrue("Property value was not updated!", propertyValueUpdated); + assertTrue(propertyValueUpdated, "Property value was not updated!"); } @Test @@ -209,6 +198,6 @@ public void shouldCopyTasks() throws Exception { ProcessGenerator.copyTasks(template, process); int actual = process.getTasks().size(); - assertEquals("Tasks were copied incorrectly!", 5, actual); + assertEquals(5, actual, "Tasks were copied incorrectly!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/process/ProcessValidatorIT.java b/Kitodo/src/test/java/org/kitodo/production/process/ProcessValidatorIT.java index b2ee868dae5..6178bc87059 100644 --- a/Kitodo/src/test/java/org/kitodo/production/process/ProcessValidatorIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/process/ProcessValidatorIT.java @@ -11,18 +11,18 @@ package org.kitodo.production.process; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; import java.util.List; import java.util.Locale; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.api.dataeditor.rulesetmanagement.RulesetManagementInterface; @@ -39,14 +39,14 @@ public class ProcessValidatorIT { private static final String NON_EXISTENT = "NonExistentTitle"; - @BeforeClass + @BeforeAll public static void setUp() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); SecurityTestUtils.addUserDataToSecurityContext(ServiceManager.getUserService().getById(1), 1); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -55,38 +55,38 @@ public static void tearDown() throws Exception { @Test public void contentShouldBeValid() throws Exception { boolean valid = ProcessValidator.isContentValid(NON_EXISTENT, createProcessDetailsList(), true); - assertTrue("Process content is invalid!", valid); + assertTrue(valid, "Process content is invalid!"); } @Test public void contentShouldBeInvalidTitle() throws Exception { boolean valid = ProcessValidator.isContentValid("First process", createProcessDetailsList(), true); - assertFalse("Process content is valid - title should be invalid!", valid); + assertFalse(valid, "Process content is valid - title should be invalid!"); } - @Ignore("find ou values for which it fails") + @Disabled("find ou values for which it fails") @Test public void contentShouldBeInvalidAdditionalFields() throws Exception { boolean valid = ProcessValidator.isContentValid(NON_EXISTENT, createProcessDetailsList(), true); - assertTrue("Process content is valid - additional fields should be invalid!", valid); + assertTrue(valid, "Process content is valid - additional fields should be invalid!"); } @Test public void processTitleShouldBeCorrect() { boolean valid = ProcessValidator.isProcessTitleCorrect(NON_EXISTENT); - assertTrue("Process title is invalid!", valid); + assertTrue(valid, "Process title is invalid!"); } @Test public void processTitleShouldBeIncorrectWhiteSpaces() { boolean valid = ProcessValidator.isProcessTitleCorrect("First process"); - assertFalse("Process content is valid - title should be invalid!", valid); + assertFalse(valid, "Process content is valid - title should be invalid!"); } @Test public void processTitleShouldBeIncorrectNotUnique() { boolean valid = ProcessValidator.isProcessTitleCorrect("DBConnectionTest"); - assertFalse("Process content is valid - title should be invalid!", valid); + assertFalse(valid, "Process content is valid - title should be invalid!"); } @Test @@ -95,7 +95,7 @@ public void propertyShouldExist() throws Exception { Property property = new Property(); property.setTitle("Korrektur notwendig"); boolean exists = ProcessValidator.existsProperty(process.getProperties(), property); - assertTrue("Property doesn't exist!", exists); + assertTrue(exists, "Property doesn't exist!"); } @Test @@ -104,7 +104,7 @@ public void propertyShouldNotExist() throws Exception { Property property = new Property(); property.setTitle("Korrektur"); boolean exists = ProcessValidator.existsProperty(process.getProperties(), property); - assertFalse("Property exists!", exists); + assertFalse(exists, "Property exists!"); } private List createProcessDetailsList() throws IOException { diff --git a/Kitodo/src/test/java/org/kitodo/production/process/TiffHeaderGeneratorTest.java b/Kitodo/src/test/java/org/kitodo/production/process/TiffHeaderGeneratorTest.java index 54e150c9811..aa178d32575 100644 --- a/Kitodo/src/test/java/org/kitodo/production/process/TiffHeaderGeneratorTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/process/TiffHeaderGeneratorTest.java @@ -11,9 +11,9 @@ package org.kitodo.production.process; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TiffHeaderGeneratorTest { @@ -26,9 +26,7 @@ public void shouldGenerateTiffHeader() throws Exception { + "'|[[JAHR]]'+PublicationYear+'|[[ERSCHEINUNGSORT]]'+PlaceOfPublication+'|[[VERZ_STRCT]]'+" + "TSL_ATS+'_'+CatalogIDDigital+'|'", "monograph"); - assertEquals("Created hash doesn't match the precomputed one!", - "|Monographie|Test|TestAuthor|||" - + "TestTest_123|", - created); + assertEquals("|Monographie|Test|TestAuthor|||" + + "TestTest_123|", created, "Created hash doesn't match the precomputed one!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/process/TitleGeneratorTest.java b/Kitodo/src/test/java/org/kitodo/production/process/TitleGeneratorTest.java index 2d37f42195c..31bda1b742f 100644 --- a/Kitodo/src/test/java/org/kitodo/production/process/TitleGeneratorTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/process/TitleGeneratorTest.java @@ -11,7 +11,7 @@ package org.kitodo.production.process; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.File; import java.io.IOException; @@ -20,7 +20,7 @@ import java.util.Locale; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kitodo.api.dataeditor.rulesetmanagement.RulesetManagementInterface; import org.kitodo.api.dataeditor.rulesetmanagement.StructuralElementViewInterface; import org.kitodo.api.dataformat.Workpiece; @@ -86,7 +86,7 @@ public void shouldCreateAtstsl() { for (String givenHash : testData.keySet()) { for (Map.Entry entry : testData.get(givenHash).entrySet()) { String created = TitleGenerator.createAtstsl(entry.getValue(), entry.getKey()); - assertEquals("Created hash doesn't match the precomputed one!", givenHash, created); + assertEquals(givenHash, created, "Created hash doesn't match the precomputed one!"); } } } @@ -96,7 +96,7 @@ public void shouldCreateAtstsl() { public void shouldGenerateTitle() throws Exception { TitleGenerator titleGenerator = new TitleGenerator("", createProcessDetailsList()); String created = titleGenerator.generateTitle("TSL_ATS+'_'+CatalogIDDigital", null); - assertEquals("Created hash doesn't match the precomputed one!", "TestTest_123", created); + assertEquals("TestTest_123", created, "Created hash doesn't match the precomputed one!"); } static List createProcessDetailsList() throws IOException { diff --git a/Kitodo/src/test/java/org/kitodo/production/process/field/AdditionalFieldTest.java b/Kitodo/src/test/java/org/kitodo/production/process/field/AdditionalFieldTest.java index 201f65d0fe3..c6ef63a6f47 100644 --- a/Kitodo/src/test/java/org/kitodo/production/process/field/AdditionalFieldTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/process/field/AdditionalFieldTest.java @@ -11,10 +11,10 @@ package org.kitodo.production.process.field; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AdditionalFieldTest { diff --git a/Kitodo/src/test/java/org/kitodo/production/renderer/KitodoMediaRendererIT.java b/Kitodo/src/test/java/org/kitodo/production/renderer/KitodoMediaRendererIT.java index 68004c78c93..3ec526a9c5b 100644 --- a/Kitodo/src/test/java/org/kitodo/production/renderer/KitodoMediaRendererIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/renderer/KitodoMediaRendererIT.java @@ -11,7 +11,7 @@ package org.kitodo.production.renderer; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -29,8 +29,8 @@ import javax.faces.context.ResponseWriter; import javax.faces.context.ResponseWriterWrapper; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.platform.commons.support.ReflectionSupport; import org.kitodo.BasePrimefaceTest; import org.mockito.Mock; @@ -60,7 +60,7 @@ public class KitodoMediaRendererIT extends BasePrimefaceTest { * * @throws Exception the exceptions thrown by method */ - @Before + @BeforeEach public void init() throws Exception { when(primeApplicationContext.getEnvironment()).thenReturn(primeEnvironment); diff --git a/Kitodo/src/test/java/org/kitodo/production/security/AESUtilTest.java b/Kitodo/src/test/java/org/kitodo/production/security/AESUtilTest.java index 08870800980..7eae1e808eb 100644 --- a/Kitodo/src/test/java/org/kitodo/production/security/AESUtilTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/security/AESUtilTest.java @@ -11,12 +11,14 @@ package org.kitodo.production.security; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.itextpdf.xmp.impl.Base64; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AESUtilTest { @@ -30,7 +32,7 @@ public void encryptAndDecryptTest() throws Exception { String potentialInput = AESUtil.decrypt(base64CipherCombined, secretInConfig); - assertEquals("Decrypted text does not match the original text", input, potentialInput); + assertEquals(input, potentialInput, "Decrypted text does not match the original text"); } @Test @@ -39,15 +41,15 @@ public void differsEncrypt() throws Exception { String secondEncrypt = AESUtil.encrypt(input, secretInConfig); - Assert.assertNotEquals("The encrypted value results are the same. IV does not work.", firstEncrypt, secondEncrypt); + assertNotEquals(firstEncrypt, secondEncrypt, "The encrypted value results are the same. IV does not work."); String firstDecrypt = AESUtil.decrypt(firstEncrypt, secretInConfig); - assertEquals("First decrypted text does not match the original text", input, firstDecrypt); + assertEquals(input, firstDecrypt, "First decrypted text does not match the original text"); String secondDecrypt = AESUtil.decrypt(secondEncrypt, secretInConfig); - assertEquals("Secound decrypted text does not match the original text", input, secondDecrypt); + assertEquals(input, secondDecrypt, "Secound decrypted text does not match the original text"); } diff --git a/Kitodo/src/test/java/org/kitodo/production/security/password/PasswordConstraintValidatorTest.java b/Kitodo/src/test/java/org/kitodo/production/security/password/PasswordConstraintValidatorTest.java index 987787a672a..4f8004d0ff8 100644 --- a/Kitodo/src/test/java/org/kitodo/production/security/password/PasswordConstraintValidatorTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/security/password/PasswordConstraintValidatorTest.java @@ -11,22 +11,22 @@ package org.kitodo.production.security.password; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import javax.validation.ConstraintValidatorContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - public class PasswordConstraintValidatorTest { private ConstraintValidatorContext context; private ConstraintValidatorContext.ConstraintViolationBuilder builder; private PasswordConstraintValidator passwordConstraintValidator = new PasswordConstraintValidator(); - @Before + @BeforeEach public void setup() { // mock the context context = Mockito.mock(ConstraintValidatorContext.class); @@ -43,16 +43,14 @@ public void setup() { @Test public void passwordsShouldBeValid() { - assertTrue("Password 'Random_2425!' was incorrect!", - passwordConstraintValidator.isValid("Random_2425!", context)); - assertTrue("Password 'teRand3435!' was incorrect!", - passwordConstraintValidator.isValid("teRand3435!", context)); + assertTrue(passwordConstraintValidator.isValid("Random_2425!", context), "Password 'Random_2425!' was incorrect!"); + assertTrue(passwordConstraintValidator.isValid("teRand3435!", context), "Password 'teRand3435!' was incorrect!"); } @Test public void passwordsShouldBeInvalid() { - assertFalse("Password 'password' was correct!", passwordConstraintValidator.isValid("password", context)); - assertFalse("Password 'white space' was correct!", passwordConstraintValidator.isValid("white space", context)); - assertFalse("Password 'short' was correct!", passwordConstraintValidator.isValid("short", context)); + assertFalse(passwordConstraintValidator.isValid("password", context), "Password 'password' was correct!"); + assertFalse(passwordConstraintValidator.isValid("white space", context), "Password 'white space' was correct!"); + assertFalse(passwordConstraintValidator.isValid("short", context), "Password 'short' was correct!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/security/password/SecurityPasswordEncoderTest.java b/Kitodo/src/test/java/org/kitodo/production/security/password/SecurityPasswordEncoderTest.java index 41e0a0351f3..92d6312074a 100644 --- a/Kitodo/src/test/java/org/kitodo/production/security/password/SecurityPasswordEncoderTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/security/password/SecurityPasswordEncoderTest.java @@ -11,12 +11,12 @@ package org.kitodo.production.security.password; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SecurityPasswordEncoderTest { private static Map testData; @@ -34,8 +34,7 @@ public class SecurityPasswordEncoderTest { public void encryptTest() { for (String clearText : testData.keySet()) { String encrypted = new SecurityPasswordEncoder().encrypt(clearText); - assertEquals("Encrypted Password doesn't match the precomputed one!", testData.get(clearText), - encrypted); + assertEquals(testData.get(clearText), encrypted, "Encrypted Password doesn't match the precomputed one!"); } } @@ -43,7 +42,7 @@ public void encryptTest() { public void decryptTest() { for (String clearText : testData.keySet()) { String decrypted = new SecurityPasswordEncoder().decrypt(testData.get(clearText)); - assertEquals("Decrypted Password doesn't match the given plain text", clearText, decrypted); + assertEquals(clearText, decrypted, "Decrypted Password doesn't match the given plain text"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java index 8f34cc09e24..4b003bb79a3 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java @@ -11,16 +11,17 @@ package org.kitodo.production.services.catalogimport; +import static org.junit.jupiter.api.Assertions.assertEquals; + import com.xebialabs.restito.server.StubServer; import java.io.IOException; import java.util.Collections; import java.util.LinkedList; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.production.helper.TempProcess; @@ -37,7 +38,7 @@ public class CatalogImportIT { private static final int TEMPLATE_ID = 1; private static final int IMPORT_DEPTH = 2; - @BeforeClass + @BeforeAll public static void setup() throws Exception { setupServer(); MockDatabase.startNode(); @@ -48,7 +49,7 @@ public static void setup() throws Exception { SecurityTestUtils.addUserDataToSecurityContext(ServiceManager.getUserService().getById(1), 1); } - @AfterClass + @AfterAll public static void shutdown() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -60,7 +61,7 @@ public void shouldImportProcessHierarchy() throws Exception { LinkedList processes = ServiceManager.getImportService().importProcessHierarchy(CHILD_RECORD_ID, MockDatabase.getKalliopeImportConfiguration(), PROJECT_ID, TEMPLATE_ID, IMPORT_DEPTH, Collections.singleton("CatalogIDPredecessorPeriodical")); - Assert.assertEquals(IMPORT_DEPTH, processes.size()); + assertEquals(IMPORT_DEPTH, processes.size()); } private static void setupServer() throws IOException { diff --git a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/ImportServiceTest.java b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/ImportServiceTest.java index f78bfc8c83b..98b94da6add 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/ImportServiceTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/ImportServiceTest.java @@ -11,13 +11,17 @@ package org.kitodo.production.services.catalogimport; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.ArrayList; import java.util.Date; import java.util.LinkedList; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kitodo.api.externaldatamanagement.ImportConfigurationType; import org.kitodo.api.externaldatamanagement.SearchInterfaceType; import org.kitodo.data.database.beans.ImportConfiguration; @@ -46,8 +50,7 @@ public class ImportServiceTest { @Test public void shouldSkipHitListForOaiImportConfiguration() { ImportConfiguration oaiConfiguration = createImportConfiguration(SearchInterfaceType.OAI); - Assert.assertTrue("'Skip hit list' should return 'true' for OAI configurations", - ImportService.skipHitlist(oaiConfiguration, null)); + assertTrue(ImportService.skipHitlist(oaiConfiguration, null), "'Skip hit list' should return 'true' for OAI configurations"); } /** @@ -56,8 +59,7 @@ public void shouldSkipHitListForOaiImportConfiguration() { @Test public void shouldNotSkipHitListForFtpImportConfiguration() { ImportConfiguration ftpConfiguration = createImportConfiguration(SearchInterfaceType.FTP); - Assert.assertFalse("'Skip hit list' should return 'false' for FTP configurations", - ImportService.skipHitlist(ftpConfiguration, null)); + assertFalse(ImportService.skipHitlist(ftpConfiguration, null), "'Skip hit list' should return 'false' for FTP configurations"); } /** @@ -68,9 +70,9 @@ public void shouldRetrieveSearchFieldsFromSruImportConfigurations() { ImportConfiguration sruConfiguration = createImportConfiguration(SearchInterfaceType.SRU); sruConfiguration.setSearchFields(createSearchFields(sruConfiguration)); List visibleSearchFields = ServiceManager.getImportService().getAvailableSearchFields(sruConfiguration); - Assert.assertEquals("Wrong number of visible search fields in SRU configuration", 2, visibleSearchFields.size()); - Assert.assertTrue("Title search field should be visible", visibleSearchFields.contains(TITLE)); - Assert.assertFalse("Parent ID search field should be invisible", visibleSearchFields.contains(PARENT_ID)); + assertEquals(2, visibleSearchFields.size(), "Wrong number of visible search fields in SRU configuration"); + assertTrue(visibleSearchFields.contains(TITLE), "Title search field should be visible"); + assertFalse(visibleSearchFields.contains(PARENT_ID), "Parent ID search field should be invisible"); } /** @@ -81,9 +83,9 @@ public void shouldRetrieveSearchFieldsFromOaiImportConfiguration() { ImportConfiguration oaiConfiguration = createImportConfiguration(SearchInterfaceType.OAI); oaiConfiguration.setSearchFields(createSearchFields(oaiConfiguration)); List visibleSearchFields = ServiceManager.getImportService().getAvailableSearchFields(oaiConfiguration); - Assert.assertEquals("Wrong number of visible search fields in OAI configuration", 1, visibleSearchFields.size()); - Assert.assertFalse("Title search field is not allowed in OAI configuration", visibleSearchFields.contains(TITLE)); - Assert.assertTrue("OAI configuration should only contain 'recordId' search field", visibleSearchFields.contains(RECORD_ID_LABEL)); + assertEquals(1, visibleSearchFields.size(), "Wrong number of visible search fields in OAI configuration"); + assertFalse(visibleSearchFields.contains(TITLE), "Title search field is not allowed in OAI configuration"); + assertTrue(visibleSearchFields.contains(RECORD_ID_LABEL), "OAI configuration should only contain 'recordId' search field"); } /** @@ -94,9 +96,9 @@ public void shouldRetrieveSearchFieldsFromFtpImportConfiguration() { ImportConfiguration ftpConfiguration = createImportConfiguration(SearchInterfaceType.FTP); ftpConfiguration.setSearchFields(createSearchFields(ftpConfiguration)); List visibleSearchFields = ServiceManager.getImportService().getAvailableSearchFields(ftpConfiguration); - Assert.assertEquals("Wrong number of visible search fields in FTP configuration", 1, visibleSearchFields.size()); - Assert.assertFalse("Title search field is not allowed in FTP configuration", visibleSearchFields.contains(TITLE)); - Assert.assertTrue("OAI configuration should only contain 'filename' search field", visibleSearchFields.contains(FILENAME_LABEL)); + assertEquals(1, visibleSearchFields.size(), "Wrong number of visible search fields in FTP configuration"); + assertFalse(visibleSearchFields.contains(TITLE), "Title search field is not allowed in FTP configuration"); + assertTrue(visibleSearchFields.contains(FILENAME_LABEL), "OAI configuration should only contain 'filename' search field"); } /** @@ -106,7 +108,7 @@ public void shouldRetrieveSearchFieldsFromFtpImportConfiguration() { public void shouldRetrieveOaiDefaultSearchField() { ImportConfiguration oaiConfiguration = createImportConfiguration(SearchInterfaceType.OAI); String defaultSearchField = ImportService.getDefaultSearchField(oaiConfiguration); - Assert.assertEquals("OAI configuration should have 'recordId' as default search field", RECORD_ID_LABEL, defaultSearchField); + assertEquals(RECORD_ID_LABEL, defaultSearchField, "OAI configuration should have 'recordId' as default search field"); } /** @@ -116,7 +118,7 @@ public void shouldRetrieveOaiDefaultSearchField() { public void shouldRetrieveFtpDefaultSearchField() { ImportConfiguration ftpConfiguration = createImportConfiguration(SearchInterfaceType.FTP); String defaultSearchField = ImportService.getDefaultSearchField(ftpConfiguration); - Assert.assertEquals("FTP configuration should have 'filename' as default search field", FILENAME_LABEL, defaultSearchField); + assertEquals(FILENAME_LABEL, defaultSearchField, "FTP configuration should have 'filename' as default search field"); } /** @@ -128,10 +130,10 @@ public void shouldReturnSearchTermWithDelimiter() { configurationWithDelimiter.setQueryDelimiter(DELIMITER); String delimited = DELIMITER + SEARCH_TERM + DELIMITER; String searchTermOfConfigurationWithDelimiter = ServiceManager.getImportService().getSearchTermWithDelimiter(SEARCH_TERM, configurationWithDelimiter); - Assert.assertEquals(String.format("Delimited search term should be %s", SEARCH_TERM), delimited, searchTermOfConfigurationWithDelimiter); + assertEquals(delimited, searchTermOfConfigurationWithDelimiter, String.format("Delimited search term should be %s", SEARCH_TERM)); ImportConfiguration configurationWithoutDelimiter = createImportConfiguration(SearchInterfaceType.SRU); String searchTermOfConfigurationWithoutDelimiter = ServiceManager.getImportService().getSearchTermWithDelimiter(SEARCH_TERM, configurationWithoutDelimiter); - Assert.assertEquals("Search term should not be delimited", searchTermOfConfigurationWithoutDelimiter, SEARCH_TERM); + assertEquals(searchTermOfConfigurationWithoutDelimiter, SEARCH_TERM, "Search term should not be delimited"); } /** @@ -153,15 +155,11 @@ public void shouldUpdateTasks() { tasks.add(secondTask); tasks.add(thirdTask); process.setTasks(tasks); - Assert.assertEquals("Wrong processing end for closed task before update", date, - process.getTasks().get(0).getProcessingEnd()); + assertEquals(date, process.getTasks().get(0).getProcessingEnd(), "Wrong processing end for closed task before update"); ImportService.updateTasks(process); - Assert.assertTrue("Processing end of CLOSED task should have been updated", - process.getTasks().get(0).getProcessingEnd().after(date)); - Assert.assertNull("Processing end of OPEN task should remain null after update", - process.getTasks().get(1).getProcessingEnd()); - Assert.assertNull("Processing end of LOCKED task should remain null after update", - process.getTasks().get(2).getProcessingEnd()); + assertTrue(process.getTasks().get(0).getProcessingEnd().after(date), "Processing end of CLOSED task should have been updated"); + assertNull(process.getTasks().get(1).getProcessingEnd(), "Processing end of OPEN task should remain null after update"); + assertNull(process.getTasks().get(2).getProcessingEnd(), "Processing end of LOCKED task should remain null after update"); } /** diff --git a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/MassImportTest.java b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/MassImportTest.java index 4edf806123d..ef86e37b980 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/MassImportTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/MassImportTest.java @@ -12,9 +12,18 @@ package org.kitodo.production.services.catalogimport; +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 com.opencsv.exceptions.CsvException; -import org.junit.Assert; -import org.junit.Test; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Test; import org.kitodo.constants.StringConstants; import org.kitodo.exceptions.ImportException; import org.kitodo.production.forms.CsvCell; @@ -22,11 +31,6 @@ import org.kitodo.production.services.ServiceManager; import org.kitodo.production.services.data.MassImportService; -import java.io.IOException; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - public class MassImportTest { private static final String ID = "ID"; @@ -56,30 +60,30 @@ public void shouldParseLines() throws IOException, CsvException { MassImportService service = ServiceManager.getMassImportService(); // test parsing CSV lines with correct delimiter List csvRecords = service.parseLines(CSV_LINES, StringConstants.COMMA_DELIMITER); - Assert.assertEquals("Wrong number of CSV records", 3, csvRecords.size()); + assertEquals(3, csvRecords.size(), "Wrong number of CSV records"); List cells = csvRecords.get(0).getCsvCells(); - Assert.assertEquals("Wrong number of cells in first CSV record", 3, cells.size()); - Assert.assertEquals("Wrong value in first cell of first CSV record", "123", cells.get(0).getValue()); - Assert.assertEquals("Wrong value in second cell of first CSV record", "Band 1", cells.get(1).getValue()); - Assert.assertEquals("Wrong value in third cell of first CSV record", "Hamburg", cells.get(2).getValue()); + assertEquals(3, cells.size(), "Wrong number of cells in first CSV record"); + assertEquals("123", cells.get(0).getValue(), "Wrong value in first cell of first CSV record"); + assertEquals("Band 1", cells.get(1).getValue(), "Wrong value in second cell of first CSV record"); + assertEquals("Hamburg", cells.get(2).getValue(), "Wrong value in third cell of first CSV record"); cells = csvRecords.get(1).getCsvCells(); - Assert.assertEquals("Wrong number of cells in second CSV record", 3, cells.size()); - Assert.assertEquals("Wrong value in first cell of second CSV record", "456", cells.get(0).getValue()); - Assert.assertEquals("Wrong value in second cell of second CSV record", "Band 2", cells.get(1).getValue()); - Assert.assertEquals("Wrong value in third cell of second CSV record", "Dresden", cells.get(2).getValue()); + assertEquals(3, cells.size(), "Wrong number of cells in second CSV record"); + assertEquals("456", cells.get(0).getValue(), "Wrong value in first cell of second CSV record"); + assertEquals("Band 2", cells.get(1).getValue(), "Wrong value in second cell of second CSV record"); + assertEquals("Dresden", cells.get(2).getValue(), "Wrong value in third cell of second CSV record"); cells = csvRecords.get(2).getCsvCells(); - Assert.assertEquals("Wrong number of cells in second CSV record", 3, cells.size()); - Assert.assertEquals("Wrong value in first cell of third CSV record", "789", cells.get(0).getValue()); - Assert.assertEquals("Wrong value in second cell of third CSV record", "Band 3", cells.get(1).getValue()); - Assert.assertEquals("Wrong value in third cell of third CSV record", "Berlin", cells.get(2).getValue()); + assertEquals(3, cells.size(), "Wrong number of cells in second CSV record"); + assertEquals("789", cells.get(0).getValue(), "Wrong value in first cell of third CSV record"); + assertEquals("Band 3", cells.get(1).getValue(), "Wrong value in second cell of third CSV record"); + assertEquals("Berlin", cells.get(2).getValue(), "Wrong value in third cell of third CSV record"); // test parsing CSV lines with incorrect delimiter csvRecords = service.parseLines(CSV_LINES, ";"); cells = csvRecords.get(0).getCsvCells(); - Assert.assertEquals("Wrong number of cells in first CSV record", 1, cells.size()); + assertEquals(1, cells.size(), "Wrong number of cells in first CSV record"); cells = csvRecords.get(1).getCsvCells(); - Assert.assertEquals("Wrong number of cells in second CSV record", 1, cells.size()); + assertEquals(1, cells.size(), "Wrong number of cells in second CSV record"); cells = csvRecords.get(2).getCsvCells(); - Assert.assertEquals("Wrong number of cells in third CSV record", 1, cells.size()); + assertEquals(1, cells.size(), "Wrong number of cells in third CSV record"); } /** @@ -91,14 +95,14 @@ public void shouldParseLinesWithCommaInValues() throws IOException, CsvException // test parsing CSV lines with correct delimiter List csvRecords = service.parseLines(CSV_LINES_WITH_COMMA, StringConstants.COMMA_DELIMITER); List cells = csvRecords.get(0).getCsvCells(); - Assert.assertEquals("Wrong number of CSV records", 3, csvRecords.size()); - Assert.assertEquals("Wrong number of cells in first CSV record", 3, cells.size()); - Assert.assertEquals("Wrong value in first cell of first CSV record", "123", cells.get(0).getValue()); - Assert.assertEquals("Wrong value in second cell of first CSV record", "Band 1,2", cells.get(1).getValue()); - Assert.assertEquals("Wrong value in third cell of first CSV record", "Hamburg", cells.get(2).getValue()); + assertEquals(3, csvRecords.size(), "Wrong number of CSV records"); + assertEquals(3, cells.size(), "Wrong number of cells in first CSV record"); + assertEquals("123", cells.get(0).getValue(), "Wrong value in first cell of first CSV record"); + assertEquals("Band 1,2", cells.get(1).getValue(), "Wrong value in second cell of first CSV record"); + assertEquals("Hamburg", cells.get(2).getValue(), "Wrong value in third cell of first CSV record"); csvRecords = service.parseLines(CSV_LINES, ";"); cells = csvRecords.get(0).getCsvCells(); - Assert.assertEquals("Wrong number of cells in first CSV record", 1, cells.size()); + assertEquals(1, cells.size(), "Wrong number of cells in first CSV record"); } @@ -110,18 +114,18 @@ public void shouldParseLinesWithCommaInValues() throws IOException, CsvException public void shouldParseCorrectlyAfterSeparatorUpdate() throws IOException, CsvException { MassImportService service = ServiceManager.getMassImportService(); List oldCsvRecords = service.parseLines(CSV_LINES, StringConstants.SEMICOLON_DELIMITER); - Assert.assertTrue("CSV lines should not be separated into multiple records when using incorrect separator character", - oldCsvRecords.stream().noneMatch(csvRecord -> csvRecord.getCsvCells().size() > 1)); + assertTrue(oldCsvRecords.stream().noneMatch(csvRecord -> csvRecord.getCsvCells().size() > 1), + "CSV lines should not be separated into multiple records when using incorrect separator character"); List newCsvRecords = service.parseLines(CSV_LINES, StringConstants.COMMA_DELIMITER); - Assert.assertEquals("Updating separator character should not alter number of CSV records", oldCsvRecords.size(), - newCsvRecords.size()); - Assert.assertTrue("CSV lines be separated into multiple records when using correct separator character", - newCsvRecords.stream().allMatch(csvRecord -> csvRecord.getCsvCells().size() > 1)); + assertEquals(oldCsvRecords.size(), newCsvRecords.size(), + "Updating separator character should not alter number of CSV records"); + assertTrue(newCsvRecords.stream().allMatch(csvRecord -> csvRecord.getCsvCells().size() > 1), + "CSV lines be separated into multiple records when using correct separator character"); List newCsvRecordsWithComma = service.parseLines(CSV_LINES_WITH_COMMA, StringConstants.COMMA_DELIMITER); - Assert.assertEquals("Updating separator character should not alter number of CSV records", oldCsvRecords.size(), - newCsvRecordsWithComma.size()); - Assert.assertTrue("CSV lines be separated into multiple records when using correct separator character", - newCsvRecordsWithComma.stream().allMatch(csvRecord -> csvRecord.getCsvCells().size() > 1)); + assertEquals(oldCsvRecords.size(), newCsvRecordsWithComma.size(), + "Updating separator character should not alter number of CSV records"); + assertTrue(newCsvRecordsWithComma.stream().allMatch(csvRecord -> csvRecord.getCsvCells().size() > 1), + "CSV lines be separated into multiple records when using correct separator character"); } /** @@ -132,52 +136,40 @@ public void shouldPrepareMetadata() throws ImportException, IOException, CsvExce MassImportService service = ServiceManager.getMassImportService(); List csvRecords = service.parseLines(CSV_LINES, StringConstants.COMMA_DELIMITER); Map>> metadata = service.prepareMetadata(METADATA_KEYS, csvRecords); - Assert.assertEquals("Wrong number of metadata sets prepared", 3, metadata.size()); + assertEquals(3, metadata.size(), "Wrong number of metadata sets prepared"); Map> metadataSet = metadata.get("123"); - Assert.assertNotNull("Metadata for record with ID 123 is null", metadataSet); - Assert.assertEquals("Wrong number of metadata sets prepared", 2, - metadataSet.size()); - Assert.assertEquals("Metadata for record with ID 123 contains wrong title", "Band 1", - metadataSet.get(TITLE).get(0)); - Assert.assertEquals("Metadata for record with ID 123 has wrong size of place list", - 1, metadataSet.get(PLACE).size()); - Assert.assertEquals("Metadata for record with ID 123 contains wrong place", "Hamburg", - metadataSet.get(PLACE).get(0)); + assertNotNull(metadataSet, "Metadata for record with ID 123 is null"); + assertEquals(2, metadataSet.size(), "Wrong number of metadata sets prepared"); + assertEquals("Band 1", metadataSet.get(TITLE).get(0), "Metadata for record with ID 123 contains wrong title"); + assertEquals(1, metadataSet.get(PLACE).size(), "Metadata for record with ID 123 has wrong size of place list"); + assertEquals("Hamburg", metadataSet.get(PLACE).get(0), "Metadata for record with ID 123 contains wrong place"); List csvRecordsMultipleValues = service.parseLines(CSV_LINES_MULTIPLE_VALUES, StringConstants.COMMA_DELIMITER); - Map>> metadataMultipleValues = service. - prepareMetadata(METADATA_KEYS_MUTLIPLE_VALUES, csvRecordsMultipleValues); + Map>> metadataMultipleValues = service.prepareMetadata(METADATA_KEYS_MUTLIPLE_VALUES, csvRecordsMultipleValues); Map> metadataSetMultipleValues = metadataMultipleValues.get("321"); - Assert.assertNotNull("Metadata for record with ID 321 is null", metadataSetMultipleValues); - Assert.assertEquals("Wrong number of metadata sets prepared", 2, - metadataSetMultipleValues.size()); - Assert.assertTrue("Metadata for record with ID 321 does not contain place metadata", - metadataSetMultipleValues.containsKey(PLACE)); - Assert.assertEquals("Metadata for record with ID 123 has wrong size of place list", 2, - metadataSetMultipleValues.get(PLACE).size()); - Assert.assertEquals("Metadata for record with ID 321 contains wrong place", "Hamburg", - metadataSetMultipleValues.get(PLACE).get(0)); - Assert.assertEquals("Metadata for record with ID 321 contains wrong place", "Berlin", - metadataSetMultipleValues.get(PLACE).get(1)); + assertNotNull(metadataSetMultipleValues, "Metadata for record with ID 321 is null"); + assertEquals(2, metadataSetMultipleValues.size(), "Wrong number of metadata sets prepared"); + assertTrue(metadataSetMultipleValues.containsKey(PLACE), "Metadata for record with ID 321 does not contain place metadata"); + assertEquals(2, metadataSetMultipleValues.get(PLACE).size(), "Metadata for record with ID 123 has wrong size of place list"); + assertEquals("Hamburg", metadataSetMultipleValues.get(PLACE).get(0), "Metadata for record with ID 321 contains wrong place"); + assertEquals("Berlin", metadataSetMultipleValues.get(PLACE).get(1), "Metadata for record with ID 321 contains wrong place"); List csvRecordsMultipleValuesWithComma = service.parseLines(CSV_LINES_MULTIPLE_VALUES_WITH_COMMA, StringConstants.COMMA_DELIMITER); - Map>> metadataMultipleValuesWithComma = service. - prepareMetadata(METADATA_KEYS_MUTLIPLE_VALUES, csvRecordsMultipleValuesWithComma); + Map>> metadataMultipleValuesWithComma = + service.prepareMetadata(METADATA_KEYS_MUTLIPLE_VALUES, csvRecordsMultipleValuesWithComma); Map> metadataSetMultipleValuesWithComma = metadataMultipleValuesWithComma.get("978"); - Assert.assertNotNull("Metadata for record with ID 978 is null", metadataSetMultipleValuesWithComma); - Assert.assertEquals("Wrong number of metadata sets prepared", 2, - metadataSetMultipleValuesWithComma.size()); - Assert.assertTrue("Metadata for record with ID 978 does not contain place metadata", - metadataSetMultipleValuesWithComma.containsKey(PLACE)); - Assert.assertEquals("Metadata for record with ID 978 has wrong size of place list", 2, - metadataSetMultipleValuesWithComma.get(PLACE).size()); - Assert.assertEquals("Metadata for record with ID 978 contains wrong place", "Hamburg", - metadataSetMultipleValuesWithComma.get(PLACE).get(0)); - Assert.assertEquals("Metadata for record with ID 978 contains wrong place", "Berlin, Kopenhagen", - metadataSetMultipleValuesWithComma.get(PLACE).get(1)); - + assertNotNull(metadataSetMultipleValuesWithComma, "Metadata for record with ID 978 is null"); + assertEquals(2, metadataSetMultipleValuesWithComma.size(), "Wrong number of metadata sets prepared"); + assertTrue(metadataSetMultipleValuesWithComma.containsKey(PLACE), + "Metadata for record with ID 978 does not contain place metadata"); + assertEquals(2, metadataSetMultipleValuesWithComma.get(PLACE).size(), + "Metadata for record with ID 978 has wrong size of place list"); + assertEquals("Hamburg", metadataSetMultipleValuesWithComma.get(PLACE).get(0), + "Metadata for record with ID 978 contains wrong place"); + assertEquals("Berlin, Kopenhagen", metadataSetMultipleValuesWithComma.get(PLACE).get(1), + "Metadata for record with ID 978 contains wrong place"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/command/CommandServiceTest.java b/Kitodo/src/test/java/org/kitodo/production/services/command/CommandServiceTest.java index 98c42861b7c..9c16c263d74 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/command/CommandServiceTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/command/CommandServiceTest.java @@ -11,9 +11,10 @@ package org.kitodo.production.services.command; -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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -22,9 +23,9 @@ import java.util.List; import org.apache.commons.lang3.SystemUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.ExecutionPermission; import org.kitodo.api.command.CommandResult; @@ -41,7 +42,7 @@ public class CommandServiceTest { private static File longWorkingScript1s = new File( System.getProperty("user.dir") + "/" + scriptPath + "long_working_script_1s.sh"); - @BeforeClass + @BeforeAll public static void setUp() throws IOException { if (SystemUtils.IS_OS_WINDOWS) { @@ -58,7 +59,7 @@ public static void setUp() throws IOException { } - @AfterClass + @AfterAll public static void tearDown() throws IOException { if (!windows) { ExecutionPermission.setNoExecutePermission(workingScript); @@ -81,7 +82,7 @@ public void runScriptWithString() throws IOException { } expectedMessages.add("Hello World"); - assertEquals("result messages are not identical", expectedMessages, result.getMessages()); + assertEquals(expectedMessages, result.getMessages(), "result messages are not identical"); } @Test @@ -98,8 +99,8 @@ public void runScriptWithFile() throws IOException { } expectedMessages.add("Hello World"); - assertEquals("result messages are not identical", expectedMessages, result.getMessages()); - assertTrue("successful booleans are not matching", result.isSuccessful()); + assertEquals(expectedMessages, result.getMessages(), "result messages are not identical"); + assertTrue(result.isSuccessful(), "successful booleans are not matching"); } @Test @@ -118,15 +119,15 @@ public void runScriptParameters() throws IOException { } expectedMessages.add("HelloWorld"); - assertEquals("result messages are not identical", expectedMessages, result.getMessages()); - assertTrue("successful booleans are not matching", result.isSuccessful()); + assertEquals(expectedMessages, result.getMessages(), "result messages are not identical"); + assertTrue(result.isSuccessful(), "successful booleans are not matching"); } - @Test(expected = IOException.class) + @Test public void runNotExistingScript() throws IOException { String commandString = scriptPath + "not_existing_script" + scriptExtension; CommandService service = new CommandService(); - service.runCommand(commandString); + assertThrows(IOException.class, () -> service.runCommand(commandString)); } @Test @@ -136,8 +137,8 @@ public void runScriptAsync() throws InterruptedException { service.runCommandAsync(commandString); Thread.sleep(1000); // wait for async thread to finish; CommandResult result = getLastFinishedCommandResult(service.getFinishedCommandResults()); - assertNotNull("There were not results!", result); - assertEquals("path to scripts are not identical", result.getCommand(), commandString); + assertNotNull(result, "There were not results!"); + assertEquals(result.getCommand(), commandString, "path to scripts are not identical"); } @Test @@ -149,8 +150,8 @@ public void runLongScriptAsync() throws InterruptedException { service.runCommandAsync(commandString1s); Thread.sleep(3000); // wait for async thread to finish; CommandResult result = getLastFinishedCommandResult(service.getFinishedCommandResults()); - assertNotNull("There were no results!", result); - assertEquals("latest finished command should be the 2 s one", result.getCommand(), commandString2s); + assertNotNull(result, "There were no results!"); + assertEquals(result.getCommand(), commandString2s, "latest finished command should be the 2 s one"); } @Test @@ -160,9 +161,8 @@ public void runNotExistingScriptAsync() throws InterruptedException { service.runCommandAsync(commandString); Thread.sleep(1000); // wait for async thread to finish; CommandResult result = getLastFinishedCommandResult(service.getFinishedCommandResults()); - assertNotNull("There were no results!", result); - assertTrue("result message should contain IOException", - result.getMessages().get(0).contains("IOException")); + assertNotNull(result, "There were no results!"); + assertTrue(result.getMessages().get(0).contains("IOException"), "result message should contain IOException"); } @Test @@ -183,9 +183,9 @@ public void runScriptParametersAsync() throws InterruptedException { } expectedMessages.add("HelloWorld"); - assertNotNull("There were no results!", result); - assertEquals("result messages are not identical", expectedMessages, result.getMessages()); - assertTrue("successful booleans are not identical", result.isSuccessful()); + assertNotNull(result, "There were no results!"); + assertEquals(expectedMessages, result.getMessages(), "result messages are not identical"); + assertTrue(result.isSuccessful(), "successful booleans are not identical"); } /** diff --git a/Kitodo/src/test/java/org/kitodo/production/services/command/ImportProcessesIT.java b/Kitodo/src/test/java/org/kitodo/production/services/command/ImportProcessesIT.java index 30630c31157..3919572f139 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/command/ImportProcessesIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/command/ImportProcessesIT.java @@ -15,9 +15,9 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -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; // base Java import java.io.File; @@ -30,11 +30,11 @@ // open source code import org.apache.commons.lang3.SystemUtils; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.kitodo.ExecutionPermission; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; @@ -57,7 +57,7 @@ public class ImportProcessesIT { private int firstProcessId, secondProcessId, thirdProcessId; private static Template template; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -98,7 +98,7 @@ public static void prepareDatabase() throws Exception { SecurityTestUtils.addUserDataToSecurityContext(userOne, 1); } - @BeforeClass + @BeforeAll public static void setScriptPermission() throws Exception { if (!SystemUtils.IS_OS_WINDOWS) { ExecutionPermission @@ -106,7 +106,7 @@ public static void setScriptPermission() throws Exception { } } - @Before + @BeforeEach public void createOutputDirectories() throws Exception { Files.createDirectories(ERRORS_DIR_PATH); } @@ -127,77 +127,69 @@ public void shouldImport() throws Exception { // initialize underTest.run(0); - assertEquals("should require 43 actions", 43, underTest.totalActions); + assertEquals(43, underTest.totalActions, "should require 43 actions"); // validate: correct processes underTest.run(1); - assertEquals("should have validated p1_valid", "p1_valid", underTest.validatingImportingProcess.directoryName); + assertEquals("p1_valid", underTest.validatingImportingProcess.directoryName, "should have validated p1_valid"); ImportingProcess p1_valid = underTest.validatingImportingProcess; - assertTrue("should have validated without errors", p1_valid.errors.isEmpty()); + assertTrue(p1_valid.errors.isEmpty(), "should have validated without errors"); underTest.run(2); - assertEquals("should have validated p1c1_valid", "p1c1_valid", - underTest.validatingImportingProcess.directoryName); + assertEquals("p1c1_valid", underTest.validatingImportingProcess.directoryName, "should have validated p1c1_valid"); ImportingProcess p1c1_valid = underTest.validatingImportingProcess; - assertTrue("should have validated without errors", p1c1_valid.errors.isEmpty()); + assertTrue(p1c1_valid.errors.isEmpty(), "should have validated without errors"); underTest.run(3); - assertEquals("should have validated p1c2_valid", "p1c2_valid", - underTest.validatingImportingProcess.directoryName); + assertEquals("p1c2_valid", underTest.validatingImportingProcess.directoryName, "should have validated p1c2_valid"); ImportingProcess p1c2_valid = underTest.validatingImportingProcess; - assertTrue("should have validated without errors", p1c2_valid.errors.isEmpty()); + assertTrue(p1c2_valid.errors.isEmpty(), "should have validated without errors"); - assertTrue("p1_valid should be correct", p1_valid.isCorrect()); - assertTrue("p1c1_valid should be correct", p1c1_valid.isCorrect()); - assertTrue("p1c2_valid should be correct", p1c2_valid.isCorrect()); + assertTrue(p1_valid.isCorrect(), "p1_valid should be correct"); + assertTrue(p1c1_valid.isCorrect(), "p1c1_valid should be correct"); + assertTrue(p1c2_valid.isCorrect(), "p1c2_valid should be correct"); // validate: error case 'parent is missing a child' underTest.run(4); - assertEquals("should have validated p2_parentMissingAChild", "p2_parentMissingAChild", - underTest.validatingImportingProcess.directoryName); + assertEquals("p2_parentMissingAChild", underTest.validatingImportingProcess.directoryName, "should have validated p2_parentMissingAChild"); ImportingProcess p2_parentMissingAChild = underTest.validatingImportingProcess; - assertFalse("should have validated with error", p2_parentMissingAChild.errors.isEmpty()); + assertFalse(p2_parentMissingAChild.errors.isEmpty(), "should have validated with error"); underTest.run(5); - assertEquals("should have validated p2c1_valid", "p2c1_valid", - underTest.validatingImportingProcess.directoryName); + assertEquals("p2c1_valid", underTest.validatingImportingProcess.directoryName, "should have validated p2c1_valid"); ImportingProcess p2c1_valid = underTest.validatingImportingProcess; - assertTrue("should have validated without errors", p2c1_valid.errors.isEmpty()); + assertTrue(p2c1_valid.errors.isEmpty(), "should have validated without errors"); - assertFalse("p1_valid should not be correct", p2_parentMissingAChild.isCorrect()); - assertFalse("p1c1_valid should not be correct, due to problem in parent case", p2c1_valid.isCorrect()); + assertFalse(p2_parentMissingAChild.isCorrect(), "p1_valid should not be correct"); + assertFalse(p2c1_valid.isCorrect(), "p1c1_valid should not be correct, due to problem in parent case"); // validate: error case 'parent not valid' underTest.run(6); - assertEquals("should have validated p3_not-valid", "p3_not-valid", - underTest.validatingImportingProcess.directoryName); + assertEquals("p3_not-valid", underTest.validatingImportingProcess.directoryName, "should have validated p3_not-valid"); ImportingProcess p3_notValid = underTest.validatingImportingProcess; - assertFalse("should have validated with error", p3_notValid.errors.isEmpty()); + assertFalse(p3_notValid.errors.isEmpty(), "should have validated with error"); underTest.run(7); - assertEquals("should have validated p3c1_valid", "p3c1_valid", - underTest.validatingImportingProcess.directoryName); + assertEquals("p3c1_valid", underTest.validatingImportingProcess.directoryName, "should have validated p3c1_valid"); ImportingProcess p3c1_valid = underTest.validatingImportingProcess; - assertTrue("should have validated without errors", p3c1_valid.errors.isEmpty()); + assertTrue(p3c1_valid.errors.isEmpty(), "should have validated without errors"); - assertFalse("p1_valid should not be correct", p3_notValid.isCorrect()); - assertFalse("p1c1_valid should not be correct, due to problem in parent case", p3c1_valid.isCorrect()); + assertFalse(p3_notValid.isCorrect(), "p1_valid should not be correct"); + assertFalse(p3c1_valid.isCorrect(), "p1c1_valid should not be correct, due to problem in parent case"); // validate: error case 'child not valid' underTest.run(8); - assertEquals("should have validated p4_valid_butChildIsNot", "p4_valid_butChildIsNot", - underTest.validatingImportingProcess.directoryName); + assertEquals("p4_valid_butChildIsNot", underTest.validatingImportingProcess.directoryName, "should have validated p4_valid_butChildIsNot"); ImportingProcess p4_valid_butChildIsNot = underTest.validatingImportingProcess; - assertTrue("should have validated without errors", p4_valid_butChildIsNot.errors.isEmpty()); + assertTrue(p4_valid_butChildIsNot.errors.isEmpty(), "should have validated without errors"); underTest.run(9); - assertEquals("should have validated p4c1_not-valid", "p4c1_not-valid", - underTest.validatingImportingProcess.directoryName); + assertEquals("p4c1_not-valid", underTest.validatingImportingProcess.directoryName, "should have validated p4c1_not-valid"); ImportingProcess p4c1_notValid = underTest.validatingImportingProcess; - assertFalse("should have validated with error", p4c1_notValid.errors.isEmpty()); + assertFalse(p4c1_notValid.errors.isEmpty(), "should have validated with error"); - assertFalse("p1_valid should not be correct, due to problem in child case", p4_valid_butChildIsNot.isCorrect()); - assertFalse("p1c1_valid should not be correct", p4c1_notValid.isCorrect()); + assertFalse(p4_valid_butChildIsNot.isCorrect(), "p1_valid should not be correct, due to problem in child case"); + assertFalse(p4c1_notValid.isCorrect(), "p1c1_valid should not be correct"); // copy files and create database entry @@ -210,21 +202,19 @@ public void shouldImport() throws Exception { Path metaXml = processPath.resolve("meta.xml"); underTest.run(10); - assertEquals("should have created 1st process,", Long.valueOf(firstProcessId), - ServiceManager.getProcessService().countDatabaseRows()); + assertEquals(Long.valueOf(firstProcessId), ServiceManager.getProcessService().countDatabaseRows(), "should have created 1st process,"); underTest.run(11); - assertTrue("should have created process directory", Files.isDirectory(processPath)); + assertTrue(Files.isDirectory(processPath), "should have created process directory"); underTest.run(12); underTest.run(13); underTest.run(14); underTest.run(15); - assertTrue("should have created images directory", Files.isDirectory(imagesPath)); - assertTrue("should have created media directory", Files.isDirectory(mediaPath)); - assertTrue("should have copied media file", Files.exists(imageOne)); - assertTrue("should have written meta.xml file", Files.exists(metaXml)); - assertTrue("should have added image to meta.xml file", - Files.readString(metaXml, UTF_8).contains("xlink:href=\"images/17_123_0001_media/00000001.jpg\"")); + assertTrue(Files.isDirectory(imagesPath), "should have created images directory"); + assertTrue(Files.isDirectory(mediaPath), "should have created media directory"); + assertTrue(Files.exists(imageOne), "should have copied media file"); + assertTrue(Files.exists(metaXml), "should have written meta.xml file"); + assertTrue(Files.readString(metaXml, UTF_8).contains("xlink:href=\"images/17_123_0001_media/00000001.jpg\""), "should have added image to meta.xml file"); // p1c2_valid (OK) secondProcessId = processesBefore + 2; @@ -237,38 +227,31 @@ public void shouldImport() throws Exception { underTest.run(19); underTest.run(20); underTest.run(21); - assertTrue("should have added image to meta.xml file", - Files.readString(metaXml, UTF_8).contains("xlink:href=\"images/17_123_0002_media/00000001.jpg\"")); + assertTrue(Files.readString(metaXml, UTF_8).contains("xlink:href=\"images/17_123_0002_media/00000001.jpg\""), "should have added image to meta.xml file"); // p2c1_valid (error, broken parent) underTest.run(22); - assertTrue("should have error directory", Files.isDirectory(Paths.get("src/test/resources/errors/p2c1_valid"))); + assertTrue(Files.isDirectory(Paths.get("src/test/resources/errors/p2c1_valid")), "should have error directory"); underTest.run(23); - assertTrue("should have written Errors.txt file", - Files.exists(Paths.get("src/test/resources/errors/p2c1_valid/Errors.txt"))); - assertTrue("should have written error message", - Files.readString(Paths.get("src/test/resources/errors/p2c1_valid/Errors.txt"), UTF_8) - .contains("errors in related process(es): p2_parentMissingAChild")); + assertTrue(Files.exists(Paths.get("src/test/resources/errors/p2c1_valid/Errors.txt")), "should have written Errors.txt file"); + assertTrue(Files.readString(Paths.get("src/test/resources/errors/p2c1_valid/Errors.txt"), UTF_8) + .contains("errors in related process(es): p2_parentMissingAChild"), "should have written error message"); underTest.run(24); - assertTrue("should have copied meta.xml file", - Files.exists(Paths.get("src/test/resources/errors/p2c1_valid/meta.xml"))); + assertTrue(Files.exists(Paths.get("src/test/resources/errors/p2c1_valid/meta.xml")), "should have copied meta.xml file"); // p3c1_valid (error, broken parent) underTest.run(25); underTest.run(26); - assertTrue("should have written error message", - Files.readString(Paths.get("src/test/resources/errors/p3c1_valid/Errors.txt"), UTF_8) - .contains("errors in related process(es): p3_not-valid")); + assertTrue(Files.readString(Paths.get("src/test/resources/errors/p3c1_valid/Errors.txt"), UTF_8) + .contains("errors in related process(es): p3_not-valid"), "should have written error message"); underTest.run(27); - assertTrue("should have copied meta.xml file", - Files.exists(Paths.get("src/test/resources/errors/p3c1_valid/meta.xml"))); + assertTrue(Files.exists(Paths.get("src/test/resources/errors/p3c1_valid/meta.xml")), "should have copied meta.xml file"); // p4c1_not-valid (error, not valid) underTest.run(28); underTest.run(29); - assertTrue("should have written error message", - Files.readString(Paths.get("src/test/resources/errors/p4c1_not-valid/Errors.txt"), UTF_8) - .contains("Validation error")); + assertTrue(Files.readString(Paths.get("src/test/resources/errors/p4c1_not-valid/Errors.txt"), UTF_8) + .contains("Validation error"), "should have written error message"); underTest.run(30); // p1_valid (OK) @@ -277,10 +260,9 @@ public void shouldImport() throws Exception { metaXml = processPath.resolve("meta.xml"); underTest.run(31); - assertEquals("should have created 3rd process,", processesBefore + 3, - (long) ServiceManager.getProcessService().countDatabaseRows()); + assertEquals(processesBefore + 3, (long) ServiceManager.getProcessService().countDatabaseRows(), "should have created 3rd process,"); underTest.run(32); - assertTrue("should have created process directory", Files.isDirectory(processPath)); + assertTrue(Files.isDirectory(processPath), "should have created process directory"); underTest.run(33); String thirdMetaXml = Files.readString(metaXml, UTF_8); assertThat("should have added correct child links to meta.xml file", thirdMetaXml, @@ -289,11 +271,9 @@ public void shouldImport() throws Exception { containsString("xlink:href=\"database://?process.id=" + secondProcessId + "\"")); Process parent = ServiceManager.getProcessService().getById(6); - assertEquals("parent should have 2 children", 2, parent.getChildren().size()); - assertEquals("child (ID " + firstProcessId + ") should have the correct parent", parent, - ServiceManager.getProcessService().getById(firstProcessId).getParent()); - assertEquals("child (ID " + secondProcessId + ") should have the correct parent", parent, - ServiceManager.getProcessService().getById(secondProcessId).getParent()); + assertEquals(2, parent.getChildren().size(), "parent should have 2 children"); + assertEquals(parent, ServiceManager.getProcessService().getById(firstProcessId).getParent(), "child (ID " + firstProcessId + ") should have the correct parent"); + assertEquals(parent, ServiceManager.getProcessService().getById(secondProcessId).getParent(), "child (ID " + secondProcessId + ") should have the correct parent"); // p2_parentMissingAChild (error) underTest.run(34); @@ -311,12 +291,11 @@ public void shouldImport() throws Exception { underTest.run(42); // import results - assertEquals("Should import 3 processes,", processesBefore + 3, - (long) ServiceManager.getProcessService().countDatabaseRows()); - assertEquals("Should not import 6 processes,", 6, ERRORS_DIR_PATH.toFile().list().length); + assertEquals(processesBefore + 3, (long) ServiceManager.getProcessService().countDatabaseRows(), "Should import 3 processes,"); + assertEquals(6, ERRORS_DIR_PATH.toFile().list().length, "Should not import 6 processes,"); } - @After + @AfterEach public void deleteCreatedFiles() throws Exception { ProcessTestUtils.removeTestProcess(firstProcessId); ProcessTestUtils.removeTestProcess(secondProcessId); @@ -324,7 +303,7 @@ public void deleteCreatedFiles() throws Exception { TreeDeleter.deltree(ERRORS_DIR_PATH); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); diff --git a/Kitodo/src/test/java/org/kitodo/production/services/command/KitodoScriptServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/command/KitodoScriptServiceIT.java index eab774a31e9..cbe57dd57ff 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/command/KitodoScriptServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/command/KitodoScriptServiceIT.java @@ -11,9 +11,9 @@ package org.kitodo.production.services.command; -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 java.io.File; import java.io.IOException; @@ -24,12 +24,11 @@ import java.util.Map; import org.apache.commons.lang3.SystemUtils; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.ExecutionPermission; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; @@ -68,7 +67,7 @@ public class KitodoScriptServiceIT { private static final File scriptCreateDirMeta = new File( ConfigCore.getParameter(ParameterCore.SCRIPT_CREATE_DIR_META)); - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -76,7 +75,7 @@ public static void prepareDatabase() throws Exception { SecurityTestUtils.addUserDataToSecurityContext(userOne, clientId); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -85,7 +84,7 @@ public static void cleanDatabase() throws Exception { /** * Add metadata test process and metadata file for KitodoScriptService tests. */ - @Before + @BeforeEach public void prepareFileCopy() throws IOException, DAOException, DataException { kitodoScriptTestProcessId = MockDatabase.insertTestProcess(testProcessTitle, projectId, templateId, rulesetId); ProcessTestUtils.copyTestResources(kitodoScriptTestProcessId, directoryForDerivateGeneration); @@ -95,7 +94,7 @@ public void prepareFileCopy() throws IOException, DAOException, DataException { /** * Remove test process and metadata file for KitodoScriptService tests. */ - @After + @AfterEach public void removeKitodoScriptServiceTestFile() throws IOException, DataException, DAOException { ProcessTestUtils.removeTestProcess(kitodoScriptTestProcessId); kitodoScriptTestProcessId = -1; @@ -122,7 +121,7 @@ public void shouldCreateProcessFolders() throws Exception { processes.add(process); kitodoScript.execute(processes, script); - assertTrue(max + ": There is no such directory!", max.isDirectory()); + assertTrue(max.isDirectory(), max + ": There is no such directory!"); if (!SystemUtils.IS_OS_WINDOWS) { ExecutionPermission.setNoExecutePermission(scriptCreateDirMeta); @@ -144,7 +143,7 @@ public void shouldExecuteAddRoleScript() throws Exception { kitodoScript.execute(processes, script); task = ServiceManager.getTaskService().getById(8); - assertEquals("Role was not correctly added to task!", amountOfRoles + 1, task.getRoles().size()); + assertEquals(amountOfRoles + 1, task.getRoles().size(), "Role was not correctly added to task!"); } @Test @@ -157,7 +156,7 @@ public void shouldExecuteSetTaskStatusScript() throws Exception { kitodoScript.execute(processes, script); Task task = ServiceManager.getTaskService().getById(8); - assertEquals("Processing status was not correctly changed!", TaskStatus.DONE, task.getProcessingStatus()); + assertEquals(TaskStatus.DONE, task.getProcessingStatus(), "Processing status was not correctly changed!"); } @Test @@ -170,8 +169,8 @@ public void shouldExecuteAddShellScriptToTaskScript() throws Exception { kitodoScript.execute(processes, script); Task task = ServiceManager.getTaskService().getById(8); - assertEquals("Script was not added to task - incorrect name!", "script", task.getScriptName()); - assertEquals("Script was not added to task - incorrect path!", "/some/new/path", task.getScriptPath()); + assertEquals("script", task.getScriptName(), "Script was not added to task - incorrect name!"); + assertEquals("/some/new/path", task.getScriptPath(), "Script was not added to task - incorrect path!"); } @Test @@ -184,7 +183,7 @@ public void shouldExecuteSetPropertyTaskScript() throws Exception { kitodoScript.execute(processes, script); Task task = ServiceManager.getTaskService().getById(7); - assertTrue("Task property was not set!", task.isTypeCloseVerify()); + assertTrue(task.isTypeCloseVerify(), "Task property was not set!"); } @Test @@ -197,7 +196,7 @@ public void shouldNotExecuteSetPropertyTaskScript() throws Exception { kitodoScript.execute(processes, script); Task task = ServiceManager.getTaskService().getById(7); - assertFalse("Task property was set - default value is false!", task.isTypeCloseVerify()); + assertFalse(task.isTypeCloseVerify(), "Task property was set - default value is false!"); } @Test @@ -237,7 +236,7 @@ public void shouldAddDataWithValue() throws Exception { metadataSearchMap.put(metadataKey, "PDM1.0"); final List processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("should not contain metadata beforehand", 0, processByMetadata.size() ); + assertEquals(0, processByMetadata.size(), "should not contain metadata beforehand"); String script = "action:addData " + "key:" + metadataKey + " value:PDM1.0"; List processes = new ArrayList<>(); @@ -247,7 +246,7 @@ public void shouldAddDataWithValue() throws Exception { Thread.sleep(2000); final List processByMetadataAfter = ServiceManager.getProcessService() .findByMetadata(metadataSearchMap); - Assert.assertEquals("does not contain metadata", 1, processByMetadataAfter.size() ); + assertEquals(1, processByMetadataAfter.size(), "does not contain metadata"); } @Test @@ -259,7 +258,7 @@ public void shouldAddDataWithType() throws Exception { .readMetadataFile(process); Workpiece workpiece = metadataFile.getWorkpiece(); Collection metadataOfChapter = workpiece.getLogicalStructure().getChildren().get(0).getMetadata(); - Assert.assertEquals("should not contain metadata beforehand", 1, metadataOfChapter.size() ); + assertEquals(1, metadataOfChapter.size(), "should not contain metadata beforehand"); String script = "action:addData " + "key:" + metadataKey + " value:PDM1.0" + " type:Chapter"; List processes = new ArrayList<>(); @@ -271,7 +270,7 @@ public void shouldAddDataWithType() throws Exception { .readMetadataFile(process); workpiece = metadataFile.getWorkpiece(); metadataOfChapter = workpiece.getLogicalStructure().getChildren().get(0).getMetadata(); - Assert.assertEquals("metadata should have been added", 2, metadataOfChapter.size() ); + assertEquals(2, metadataOfChapter.size(), "metadata should have been added"); } @Test @@ -283,7 +282,7 @@ public void shouldDeleteDataWithType() throws Exception { .readMetadataFile(process); Workpiece workpiece = metadataFile.getWorkpiece(); Collection metadataOfChapter = workpiece.getLogicalStructure().getChildren().get(0).getMetadata(); - Assert.assertEquals("should contain metadata beforehand", 1, metadataOfChapter.size() ); + assertEquals(1, metadataOfChapter.size(), "should contain metadata beforehand"); String script = "action:deleteData " + "key:" + metadataKey + " type:Chapter"; List processes = new ArrayList<>(); @@ -295,7 +294,7 @@ public void shouldDeleteDataWithType() throws Exception { .readMetadataFile(process); workpiece = metadataFile.getWorkpiece(); metadataOfChapter = workpiece.getLogicalStructure().getChildren().get(0).getMetadata(); - Assert.assertEquals("metadata should have been deleted", 0, metadataOfChapter.size() ); + assertEquals(0, metadataOfChapter.size(), "metadata should have been deleted"); } @Test @@ -307,7 +306,7 @@ public void shouldNotDeleteDataWithTypeAndWrongValue() throws Exception { .readMetadataFile(process); Workpiece workpiece = metadataFile.getWorkpiece(); Collection metadataOfChapter = workpiece.getLogicalStructure().getChildren().get(0).getMetadata(); - Assert.assertEquals("should contain metadata beforehand", 1, metadataOfChapter.size() ); + assertEquals(1, metadataOfChapter.size(), "should contain metadata beforehand"); String script = "action:deleteData " + "key:" + metadataKey + " value:test" + " type:Chapter"; List processes = new ArrayList<>(); @@ -319,7 +318,7 @@ public void shouldNotDeleteDataWithTypeAndWrongValue() throws Exception { .readMetadataFile(process); workpiece = metadataFile.getWorkpiece(); metadataOfChapter = workpiece.getLogicalStructure().getChildren().get(0).getMetadata(); - Assert.assertEquals("metadata should not have been deleted", 1, metadataOfChapter.size() ); + assertEquals(1, metadataOfChapter.size(), "metadata should not have been deleted"); } @Test @@ -331,7 +330,7 @@ public void shouldNotDeleteDataWithWrongType() throws Exception { .readMetadataFile(process); Workpiece workpiece = metadataFile.getWorkpiece(); Collection metadataOfChapter = workpiece.getLogicalStructure().getChildren().get(0).getMetadata(); - Assert.assertEquals("should contain metadata beforehand", 1, metadataOfChapter.size() ); + assertEquals(1, metadataOfChapter.size(), "should contain metadata beforehand"); String script = "action:deleteData " + "key:" + metadataKey + " type:Chapter"; List processes = new ArrayList<>(); @@ -343,7 +342,7 @@ public void shouldNotDeleteDataWithWrongType() throws Exception { .readMetadataFile(process); workpiece = metadataFile.getWorkpiece(); metadataOfChapter = workpiece.getLogicalStructure().getChildren().get(0).getMetadata(); - Assert.assertEquals("metadata should not have been deleted", 1, metadataOfChapter.size() ); + assertEquals(1, metadataOfChapter.size(), "metadata should not have been deleted"); } @Test @@ -355,7 +354,7 @@ public void shouldCopyMultipleDataToChildren() throws Exception { metadataSearchMap.put(metadataKey, "Kollektion2"); final List processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("should not contain metadata beforehand", 1, processByMetadata.size() ); + assertEquals(1, processByMetadata.size(), "should not contain metadata beforehand"); String script = "action:copyDataToChildren " + "key:" + metadataKey + " source:" + metadataKey; List processes = new ArrayList<>(); @@ -365,7 +364,7 @@ public void shouldCopyMultipleDataToChildren() throws Exception { Thread.sleep(2000); final List processByMetadataAfter = ServiceManager.getProcessService() .findByMetadata(metadataSearchMap); - Assert.assertEquals("does not contain metadata", 3, processByMetadataAfter.size() ); + assertEquals(3, processByMetadataAfter.size(), "does not contain metadata"); ProcessTestUtils.removeTestProcess(testProcessIds.get(MockDatabase.HIERARCHY_PARENT)); } @@ -377,7 +376,7 @@ public void shouldAddDataWithWhitespace() throws Exception { metadataSearchMap.put(metadataKey, "legal note"); final List processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap, true); - Assert.assertEquals("should not contain metadata beforehand", 0, processByMetadata.size() ); + assertEquals(0, processByMetadata.size(), "should not contain metadata beforehand"); String script = "action:addData " + "key:" + metadataKey + " \"value:legal note\""; List processes = new ArrayList<>(); @@ -387,7 +386,7 @@ public void shouldAddDataWithWhitespace() throws Exception { Thread.sleep(2000); final List processByMetadataAfter = ServiceManager.getProcessService() .findByMetadata(metadataSearchMap, true); - Assert.assertEquals("does not contain metadata", 1, processByMetadataAfter.size() ); + assertEquals(1, processByMetadataAfter.size(), "does not contain metadata"); } @Test @@ -400,10 +399,10 @@ public void shouldAddDataWithMultipleScripts() throws Exception { secondMetadataSearchMap.put(metadataKey, "secondNote"); List processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("should not contain metadata beforehand", 0, processByMetadata.size() ); + assertEquals(0, processByMetadata.size(), "should not contain metadata beforehand"); processByMetadata = ServiceManager.getProcessService().findByMetadata(secondMetadataSearchMap); - Assert.assertEquals("should not contain metadata beforehand", 0, processByMetadata.size() ); + assertEquals(0, processByMetadata.size(), "should not contain metadata beforehand"); String script = "action:addData " + "key:" + metadataKey + " value:legal note;" + "key:" + metadataKey + " value:secondNote"; List processes = new ArrayList<>(); @@ -413,9 +412,9 @@ public void shouldAddDataWithMultipleScripts() throws Exception { kitodoScript.execute(processes, script); Thread.sleep(2000); List processByMetadataAfter = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("does not contain metadata", 1, processByMetadataAfter.size()); + assertEquals(1, processByMetadataAfter.size(), "does not contain metadata"); processByMetadataAfter = ServiceManager.getProcessService().findByMetadata(secondMetadataSearchMap); - Assert.assertEquals("does not contain metadata", 1, processByMetadataAfter.size()); + assertEquals(1, processByMetadataAfter.size(), "does not contain metadata"); } @Test @@ -426,7 +425,7 @@ public void shouldCopyDataWithSource() throws Exception { metadataSearchMap.put(metadataKey, "Proc"); List processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("does not contain metadata", 0, processByMetadata.size() ); + assertEquals(0, processByMetadata.size(), "does not contain metadata"); String script = "action:addData " + "key:" + metadataKey + " source:TSL_ATS"; List processes = new ArrayList<>(); @@ -436,7 +435,7 @@ public void shouldCopyDataWithSource() throws Exception { Thread.sleep(2000); processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("does not contain metadata", 1, processByMetadata.size() ); + assertEquals(1, processByMetadata.size(), "does not contain metadata"); } @Test @@ -447,7 +446,7 @@ public void shouldAddDataWithVariable() throws Exception { metadataSearchMap.put(metadataKey, String.valueOf(kitodoScriptTestProcessId)); List processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("does not contain metadata", 0, processByMetadata.size() ); + assertEquals(0, processByMetadata.size(), "does not contain metadata"); String script = "action:addData " + "key:" + metadataKey + " variable:(processid)"; List processes = new ArrayList<>(); @@ -457,7 +456,7 @@ public void shouldAddDataWithVariable() throws Exception { Thread.sleep(2000); processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("does not contain metadata", 1, processByMetadata.size() ); + assertEquals(1, processByMetadata.size(), "does not contain metadata"); } @Test @@ -468,7 +467,7 @@ public void shouldDeleteData() throws Exception { metadataSearchMap.put(metadataKey, "SecondMetaShort"); List processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("should contain metadata", 1, processByMetadata.size() ); + assertEquals(1, processByMetadata.size(), "should contain metadata"); String script = "action:deleteData " + "key:" + metadataKey; List processes = new ArrayList<>(); @@ -478,7 +477,7 @@ public void shouldDeleteData() throws Exception { Thread.sleep(2000); processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("should not contain metadata", 0, processByMetadata.size() ); + assertEquals(0, processByMetadata.size(), "should not contain metadata"); } @Test @@ -489,7 +488,7 @@ public void shouldDeleteDataWithValue() throws Exception { metadataSearchMap.put(metadataKey, "SecondMetaShort"); List processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("should contain metadata", 1, processByMetadata.size() ); + assertEquals(1, processByMetadata.size(), "should contain metadata"); String script = "action:deleteData " + "key:" + metadataKey + " value:SecondMetaShort"; List processes = new ArrayList<>(); @@ -499,7 +498,7 @@ public void shouldDeleteDataWithValue() throws Exception { Thread.sleep(2000); processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("should not contain metadata", 0, processByMetadata.size() ); + assertEquals(0, processByMetadata.size(), "should not contain metadata"); } @Test public void shouldDeleteAllDataWithSameKey() throws Exception { @@ -509,7 +508,7 @@ public void shouldDeleteAllDataWithSameKey() throws Exception { metadataSearchMap.put(metadataKey, "Proc"); List processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("should contain metadata", 1, processByMetadata.size() ); + assertEquals(1, processByMetadata.size(), "should contain metadata"); String script = "action:deleteData " + "key:" + metadataKey; List processes = new ArrayList<>(); @@ -519,7 +518,7 @@ public void shouldDeleteAllDataWithSameKey() throws Exception { Thread.sleep(2000); processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("should not contain metadata", 0, processByMetadata.size() ); + assertEquals(0, processByMetadata.size(), "should not contain metadata"); } @Test @@ -530,7 +529,7 @@ public void shouldDeleteDataWithSource() throws Exception { metadataSearchMap.put(metadataKey, "SecondMetaShort"); List processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("should contain metadata", 1, processByMetadata.size() ); + assertEquals(1, processByMetadata.size(), "should contain metadata"); String script = "action:deleteData " + "key:" + metadataKey + " source:TitleDocMainShort"; List processes = new ArrayList<>(); @@ -540,7 +539,7 @@ public void shouldDeleteDataWithSource() throws Exception { Thread.sleep(2000); processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("should not contain metadata", 0, processByMetadata.size() ); + assertEquals(0, processByMetadata.size(), "should not contain metadata"); } @Test @@ -551,7 +550,7 @@ public void shouldNotDeleteDataWithValue() throws Exception { metadataSearchMap.put(metadataKey, "SecondMetaShort"); List processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("should contain metadata", 1, processByMetadata.size() ); + assertEquals(1, processByMetadata.size(), "should contain metadata"); String script = "action:deleteData" + " key:" + metadataKey + " value:SecondMetaLong"; List processes = new ArrayList<>(); @@ -561,7 +560,7 @@ public void shouldNotDeleteDataWithValue() throws Exception { Thread.sleep(2000); processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); - Assert.assertEquals("should still contain metadata", 1, processByMetadata.size() ); + assertEquals(1, processByMetadata.size(), "should still contain metadata"); } @Test @@ -574,10 +573,10 @@ public void shouldOverwriteDataWithValue() throws Exception { newMetadataSearchMap.put(metadataKey, "Overwritten"); List processByMetadata = ServiceManager.getProcessService().findByMetadata(oldMetadataSearchMap); - Assert.assertEquals("should contain metadata", 1, processByMetadata.size() ); + assertEquals(1, processByMetadata.size(), "should contain metadata"); processByMetadata = ServiceManager.getProcessService().findByMetadata(newMetadataSearchMap); - Assert.assertEquals("should contain new metadata value", 0, processByMetadata.size()); + assertEquals(0, processByMetadata.size(), "should contain new metadata value"); Process process = ServiceManager.getProcessService().getById(kitodoScriptTestProcessId); String script = "action:overwriteData " + "key:" + metadataKey + " value:Overwritten"; @@ -588,10 +587,10 @@ public void shouldOverwriteDataWithValue() throws Exception { Thread.sleep(2000); processByMetadata = ServiceManager.getProcessService().findByMetadata(oldMetadataSearchMap); - Assert.assertEquals("should not contain metadata anymore", 0, processByMetadata.size()); + assertEquals(0, processByMetadata.size(), "should not contain metadata anymore"); processByMetadata = ServiceManager.getProcessService().findByMetadata(newMetadataSearchMap); - Assert.assertEquals("should contain new metadata value", 1, processByMetadata.size()); + assertEquals(1, processByMetadata.size(), "should contain new metadata value"); } @Test @@ -604,10 +603,10 @@ public void shouldOverwriteDataWithSource() throws Exception { newMetadataSearchMap.put(metadataKey, "Second process"); List processByMetadata = ServiceManager.getProcessService().findByMetadata(oldMetadataSearchMap); - Assert.assertEquals("should contain metadata", 1, processByMetadata.size() ); + assertEquals(1, processByMetadata.size(), "should contain metadata"); processByMetadata = ServiceManager.getProcessService().findByMetadata(newMetadataSearchMap); - Assert.assertEquals("should contain new metadata value", 0, processByMetadata.size()); + assertEquals(0, processByMetadata.size(), "should contain new metadata value"); Process process = ServiceManager.getProcessService().getById(kitodoScriptTestProcessId); String script = "action:overwriteData " + "key:" + metadataKey + " source:TitleDocMain"; @@ -618,10 +617,10 @@ public void shouldOverwriteDataWithSource() throws Exception { Thread.sleep(2000); processByMetadata = ServiceManager.getProcessService().findByMetadata(oldMetadataSearchMap); - Assert.assertEquals("should not contain metadata anymore", 0, processByMetadata.size()); + assertEquals(0, processByMetadata.size(), "should not contain metadata anymore"); processByMetadata = ServiceManager.getProcessService().findByMetadata(newMetadataSearchMap); - Assert.assertEquals("should contain new metadata value", 1, processByMetadata.size()); + assertEquals(1, processByMetadata.size(), "should contain new metadata value"); } @Test @@ -634,10 +633,10 @@ public void shouldOverwriteDataWithVariable() throws Exception { newMetadataSearchMap.put(metadataKey, String.valueOf(kitodoScriptTestProcessId)); List processByMetadata = ServiceManager.getProcessService().findByMetadata(oldMetadataSearchMap); - Assert.assertEquals("should contain metadata", 1, processByMetadata.size() ); + assertEquals(1, processByMetadata.size(), "should contain metadata"); processByMetadata = ServiceManager.getProcessService().findByMetadata(newMetadataSearchMap); - Assert.assertEquals("should contain new metadata value", 0, processByMetadata.size()); + assertEquals(0, processByMetadata.size(), "should contain new metadata value"); Process process = ServiceManager.getProcessService().getById(kitodoScriptTestProcessId); String script = "action:overwriteData " + "key:" + metadataKey + " variable:(processid)"; @@ -648,9 +647,9 @@ public void shouldOverwriteDataWithVariable() throws Exception { Thread.sleep(2000); processByMetadata = ServiceManager.getProcessService().findByMetadata(oldMetadataSearchMap); - Assert.assertEquals("should not contain metadata anymore", 0, processByMetadata.size()); + assertEquals(0, processByMetadata.size(), "should not contain metadata anymore"); processByMetadata = ServiceManager.getProcessService().findByMetadata(newMetadataSearchMap); - Assert.assertEquals("should contain new metadata value", 1, processByMetadata.size()); + assertEquals(1, processByMetadata.size(), "should contain new metadata value"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/AuthorityServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/AuthorityServiceIT.java index d9f74204a07..aae27b7f1e2 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/AuthorityServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/AuthorityServiceIT.java @@ -11,15 +11,14 @@ package org.kitodo.production.services.data; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Authority; import org.kitodo.data.database.exceptions.DAOException; @@ -30,58 +29,56 @@ public class AuthorityServiceIT { private static final AuthorityService authorityService = ServiceManager.getAuthorityService(); private static final int EXPECTED_AUTHORITIES_COUNT = 100; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertRolesFull(); MockDatabase.setUpAwaitility(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); } - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void shouldCountAllDatabaseRowsForAuthorities() throws Exception { Long amount = authorityService.countDatabaseRows(); - assertEquals("Authorizations were not counted correctly!", Long.valueOf(EXPECTED_AUTHORITIES_COUNT), amount); + assertEquals(Long.valueOf(EXPECTED_AUTHORITIES_COUNT), amount, "Authorizations were not counted correctly!"); } @Test public void shouldGetAllAuthorities() throws Exception { List authorities = authorityService.getAll(); - assertEquals("Authorizations were not found database!", EXPECTED_AUTHORITIES_COUNT, authorities.size()); + assertEquals(EXPECTED_AUTHORITIES_COUNT, authorities.size(), "Authorizations were not found database!"); } @Test public void shouldGetByTitle() throws Exception { Authority authority = authorityService.getByTitle("viewAllRoles_globalAssignable"); - assertEquals("Authorizations were not found database!", 13, authority.getId().intValue()); + assertEquals(13, authority.getId().intValue(), "Authorizations were not found database!"); } @Test - public void shouldNotGetByTitle() throws Exception { - exception.expect(DAOException.class); - exception.expectMessage("Authority 'viewAllStuff_globalAssignable' cannot be found in database"); - authorityService.getByTitle("viewAllStuff_globalAssignable"); + public void shouldNotGetByTitle() { + Exception exception = assertThrows(DAOException.class, + () -> authorityService.getByTitle("viewAllStuff_globalAssignable")); + + assertEquals("Authority 'viewAllStuff_globalAssignable' cannot be found in database", exception.getMessage()); } @Test - public void shouldNotSaveAlreadyExistingAuthorities() throws Exception { + public void shouldNotSaveAlreadyExistingAuthorities() { Authority adminAuthority = new Authority(); adminAuthority.setTitle("viewAllClients_globalAssignable"); - exception.expect(DAOException.class); - authorityService.saveToDatabase(adminAuthority); + assertThrows(DAOException.class, + () -> authorityService.saveToDatabase(adminAuthority)); } @Test public void shouldGetAllClientAssignableAuthorities() throws DAOException { List authorities = authorityService.getAllAssignableToClients(); - assertEquals("Client assignable authorities were not found database!", 72, authorities.size()); + assertEquals(72, authorities.size(), "Client assignable authorities were not found database!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/BatchServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/BatchServiceIT.java index a209fec6874..25f263f89ee 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/BatchServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/BatchServiceIT.java @@ -13,19 +13,18 @@ import static org.awaitility.Awaitility.given; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; -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; import java.util.List; import java.util.Objects; import org.elasticsearch.index.query.Operator; import org.elasticsearch.index.query.QueryBuilder; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.data.database.beans.Batch; @@ -43,7 +42,7 @@ public class BatchServiceIT { private static final String BATCH_NOT_FOUND = "Batch was not found in index!"; private static final String BATCHES_NOT_FOUND = "Batches were not found in index!"; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -52,51 +51,48 @@ public static void prepareDatabase() throws Exception { given().ignoreExceptions().await().until(() -> Objects.nonNull(batchService.findById(1, true))); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); } - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void shouldCountAllBatches() throws DataException { - assertEquals("Batches were not counted correctly!", Long.valueOf(4), batchService.count()); + assertEquals(Long.valueOf(4), batchService.count(), "Batches were not counted correctly!"); } @Test public void shouldCountAllBatchesAccordingToQuery() throws DataException { QueryBuilder query = matchQuery("title", "First batch").operator(Operator.AND); - assertEquals("Batches were not counted correctly!", Long.valueOf(1), batchService.count(query)); + assertEquals(Long.valueOf(1), batchService.count(query), "Batches were not counted correctly!"); } @Test public void shouldCountAllDatabaseRowsForBatches() throws Exception { Long amount = batchService.countDatabaseRows(); - assertEquals("Batches were not counted correctly!", Long.valueOf(4), amount); + assertEquals(Long.valueOf(4), amount, "Batches were not counted correctly!"); } @Test public void shouldGetBatch() throws Exception { Batch batch = batchService.getById(1); boolean condition = batch.getTitle().equals("First batch"); - assertTrue("Batch was not found in database!", condition); + assertTrue(condition, "Batch was not found in database!"); - assertEquals("Batch was found but processes were not inserted!", 1, batch.getProcesses().size()); + assertEquals(1, batch.getProcesses().size(), "Batch was found but processes were not inserted!"); } @Test public void shouldFindAllBatches() throws Exception { List batches = batchService.getAll(); - assertEquals("Not all batches were found in database!", 4, batches.size()); + assertEquals(4, batches.size(), "Not all batches were found in database!"); } @Test public void shouldGetAllBatchesInGivenRange() throws Exception { List batches = batchService.getAll(2, 10); - assertEquals("Not all batches were found in database!", 2, batches.size()); + assertEquals(2, batches.size(), "Not all batches were found in database!"); } @Test @@ -105,114 +101,108 @@ public void shouldRemoveBatch() throws Exception { batch.setTitle("To Remove"); batchService.save(batch); Batch foundBatch = batchService.getById(5); - assertEquals("Additional batch was not inserted in database!", "To Remove", foundBatch.getTitle()); + assertEquals("To Remove", foundBatch.getTitle(), "Additional batch was not inserted in database!"); batchService.remove(foundBatch); - exception.expect(DAOException.class); - batchService.getById(5); + assertThrows(DAOException.class, () -> batchService.getById(5)); batch = new Batch(); batch.setTitle("To remove"); batchService.save(batch); foundBatch = batchService.getById(6); - assertEquals("Additional batch was not inserted in database!", "To remove", foundBatch.getTitle()); + assertEquals("To remove", foundBatch.getTitle(), "Additional batch was not inserted in database!"); batchService.remove(6); - exception.expect(DAOException.class); - batchService.getById(6); + assertThrows(DAOException.class, () -> batchService.getById(6)); } @Test public void shouldFindById() throws DataException { String expected = "First batch"; - assertEquals(BATCH_NOT_FOUND, expected, batchService.findById(1).getTitle()); + assertEquals(expected, batchService.findById(1).getTitle(), BATCH_NOT_FOUND); } @Test public void shouldFindManyByTitle() throws DataException { - assertEquals(BATCHES_NOT_FOUND, 3, batchService.findByTitle("batch", true).size()); + assertEquals(3, batchService.findByTitle("batch", true).size(), BATCHES_NOT_FOUND); } @Test public void shouldFindOneByTitle() throws DataException { - assertEquals(BATCH_NOT_FOUND, 1, - batchService.findByTitle("First batch", true).size()); + assertEquals(1, batchService.findByTitle("First batch", true).size(), BATCH_NOT_FOUND); } @Test public void shouldNotFindByType() throws DataException { - assertEquals("Batch was found in index!", 0, batchService.findByTitle("noBatch", true).size()); + assertEquals(0, batchService.findByTitle("noBatch", true).size(), "Batch was found in index!"); } @Test public void shouldFindManyByProcessId() throws DataException { - assertEquals(BATCHES_NOT_FOUND, 2, batchService.findByProcessId(1).size()); + assertEquals(2, batchService.findByProcessId(1).size(), BATCHES_NOT_FOUND); } @Test public void shouldFindOneByProcessId() throws DataException { - assertEquals(BATCH_NOT_FOUND, 1, batchService.findByProcessId(2).size()); + assertEquals(1, batchService.findByProcessId(2).size(), BATCH_NOT_FOUND); } @Test public void shouldNotFindByProcessId() throws DataException { - assertEquals("Some batches were found in index!", 0, batchService.findByProcessId(3).size()); + assertEquals(0, batchService.findByProcessId(3).size(), "Some batches were found in index!"); } @Test public void shouldFindManyByProcessTitle() throws DataException { - assertEquals(BATCHES_NOT_FOUND, 2, - batchService.findByProcessTitle("First process").size()); + assertEquals(2, batchService.findByProcessTitle("First process").size(), BATCHES_NOT_FOUND); } @Test public void shouldFindOneByProcessTitle() throws DataException { - assertEquals(BATCH_NOT_FOUND, 1, - batchService.findByProcessTitle("Second process").size()); + assertEquals(1, batchService.findByProcessTitle("Second process").size(), BATCH_NOT_FOUND); } @Test public void shouldNotFindByProcessTitle() throws DataException { - assertEquals("Some batches were found in index!", 0, - batchService.findByProcessTitle("DBConnectionTest").size()); + assertEquals(0, batchService.findByProcessTitle("DBConnectionTest").size(), "Some batches were found in index!"); } @Test public void shouldContainCharSequence() throws Exception { Batch batch = batchService.getById(1); boolean condition = batch.getTitle().contains("bat") == batchService.contains(batch, "bat"); - assertTrue("It doesn't contain given char sequence!", condition); + assertTrue(condition, "It doesn't contain given char sequence!"); } @Test public void shouldGetIdString() throws Exception { Batch batch = batchService.getById(1); boolean condition = batchService.getIdString(batch).equals("1"); - assertTrue("Id's String doesn't match the given plain text!", condition); + assertTrue(condition, "Id's String doesn't match the given plain text!"); } @Test public void shouldGetLabel() throws Exception { Batch firstBatch = batchService.getById(1); boolean firstCondition = batchService.getLabel(firstBatch).equals("First batch"); - assertTrue("It doesn't get given label!", firstCondition); + assertTrue(firstCondition, "It doesn't get given label!"); Batch secondBatch = batchService.getById(4); boolean secondCondition = batchService.getLabel(secondBatch).equals("Batch 4"); - assertTrue("It doesn't get given label!", secondCondition); + assertTrue(secondCondition, "It doesn't get given label!"); } @Test public void shouldGetSizeOfProcesses() throws Exception { Batch batch = batchService.getById(1); int size = batchService.size(batch); - assertEquals("Size of processes is not equal 1!", 1, size); + assertEquals(1, size, "Size of processes is not equal 1!"); } @Test public void shouldCreateLabel() throws Exception { Batch batch = batchService.getById(1); String label = batchService.createLabel(batch); - assertEquals("Created label is incorrect!", "First batch (1 processes)", label); + assertEquals("First batch (1 processes)", label, "Created label is incorrect!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/ClientServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/ClientServiceIT.java index 37e465821cb..e12753382f3 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/ClientServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/ClientServiceIT.java @@ -11,15 +11,13 @@ package org.kitodo.production.services.data; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Client; import org.kitodo.production.services.ServiceManager; @@ -28,25 +26,22 @@ public class ClientServiceIT { private static final ClientService clientService = ServiceManager.getClientService(); - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); MockDatabase.setUpAwaitility(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); } - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void shouldGetAllClients() throws Exception { List clients = clientService.getAll(); - assertEquals("Clients were not found database!", 4, clients.size()); + assertEquals(4, clients.size(), "Clients were not found database!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/CommentServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/CommentServiceIT.java index b8302c563fe..42d87e8f8f7 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/CommentServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/CommentServiceIT.java @@ -11,14 +11,14 @@ package org.kitodo.production.services.data; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Date; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Comment; import org.kitodo.data.database.beans.Process; @@ -36,7 +36,7 @@ public class CommentServiceIT { * @throws Exception * when saving of dummy or test processes fails. */ - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -49,7 +49,7 @@ public static void prepareDatabase() throws Exception { * @throws Exception * when cleaning up database fails. */ - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -73,10 +73,10 @@ public void shouldSaveAndRemoveInfoComment() throws Exception { comment.setType(CommentType.INFO); commentService.saveToDatabase(comment); Comment newComment = commentService.getAll().get(0); - assertEquals("Comment was not found in database!", newComment.getMessage(), "TEST_MESSAGE"); + assertEquals(newComment.getMessage(), "TEST_MESSAGE", "Comment was not found in database!"); commentService.removeComment(newComment); List comments = commentService.getAll(); - assertEquals("Comments were found in database!", comments.size(), 0); + assertEquals(comments.size(), 0, "Comments were found in database!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/DataEditorSettingServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/DataEditorSettingServiceIT.java index 37639693ec1..63e1a5ab66c 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/DataEditorSettingServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/DataEditorSettingServiceIT.java @@ -11,16 +11,13 @@ package org.kitodo.production.services.data; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.DataEditorSetting; import org.kitodo.data.database.exceptions.DAOException; @@ -35,43 +32,40 @@ public class DataEditorSettingServiceIT { * Prepare database for tests. * @throws Exception when preparation fails */ - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertForDataEditorTesting(); MockDatabase.setUpAwaitility(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); } - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void shouldCountAllDatabaseRowsForDataEditorSettings() throws DAOException { Long amount = dataEditorSettingService.countDatabaseRows(); - assertEquals("DataEditorSettings were not counted correctly!", Long.valueOf(3), amount); + assertEquals(Long.valueOf(3), amount, "DataEditorSettings were not counted correctly!"); } @Test public void shouldGetAllDataEditorSettings() throws DAOException { List settings = dataEditorSettingService.getAll(); - assertEquals("DataEditorSettings were not found in database!", EXPECTED_DATAEDITORSETTINGS_COUNT, settings.size()); + assertEquals(EXPECTED_DATAEDITORSETTINGS_COUNT, settings.size(), "DataEditorSettings were not found in database!"); } @Test public void shouldGetById() { DataEditorSetting setting = dataEditorSettingService.loadDataEditorSetting(1, 4); - assertEquals("DataEditorSetting could not be found in database!", 3, setting.getId().intValue()); + assertEquals(3, setting.getId().intValue(), "DataEditorSetting could not be found in database!"); } @Test public void shouldNotGetById() { DataEditorSetting setting = dataEditorSettingService.loadDataEditorSetting(1, 5); - assertNull("No setting should be found for these ids!", setting); + assertEquals(setting, null, "No setting should be found for these ids!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/DocketServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/DocketServiceIT.java index e43505fb034..49a9ed9ae29 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/DocketServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/DocketServiceIT.java @@ -13,19 +13,18 @@ import static org.awaitility.Awaitility.given; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; -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; import java.util.List; import java.util.Objects; import org.elasticsearch.index.query.Operator; import org.elasticsearch.index.query.QueryBuilder; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.data.database.beans.Docket; @@ -48,7 +47,7 @@ public class DocketServiceIT { private static final String none = "none"; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertClients(); @@ -58,112 +57,105 @@ public static void prepareDatabase() throws Exception { given().ignoreExceptions().await().until(() -> Objects.nonNull(docketService.findByTitle(defaultDocket, true))); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); } - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void shouldCountAllDockets() throws DataException { - assertEquals("Dockets were not counted correctly!", Long.valueOf(4), docketService.count()); + assertEquals(Long.valueOf(4), docketService.count(), "Dockets were not counted correctly!"); } @Test public void shouldCountAllDocketsAccordingToQuery() throws DataException { QueryBuilder query = matchQuery("title", defaultDocket).operator(Operator.AND); - assertEquals("Dockets were not counted correctly!", Long.valueOf(1), docketService.count(query)); + assertEquals(Long.valueOf(1), docketService.count(query), "Dockets were not counted correctly!"); } @Test public void shouldCountAllDatabaseRowsForDockets() throws Exception { Long amount = docketService.countDatabaseRows(); - assertEquals("Dockets were not counted correctly!", Long.valueOf(4), amount); + assertEquals(Long.valueOf(4), amount, "Dockets were not counted correctly!"); } @Test public void shouldFindDocket() throws Exception { Docket docket = docketService.getById(1); boolean condition = docket.getTitle().equals(defaultDocket) && docket.getFile().equals(fileName); - assertTrue("Docket was not found in database!", condition); + assertTrue(condition, "Docket was not found in database!"); } @Test public void shouldFindAllDockets() throws Exception { List dockets = docketService.getAll(); - assertEquals("Not all dockets were found in database!", 4, dockets.size()); + assertEquals(4, dockets.size(), "Not all dockets were found in database!"); } @Test public void shouldGetAllDocketsInGivenRange() throws Exception { List dockets = docketService.getAll(1, 10); - assertEquals("Not all dockets were found in database!", 3, dockets.size()); + assertEquals(3, dockets.size(), "Not all dockets were found in database!"); } @Test public void shouldFindById() throws DataException { String expected = defaultDocket; - assertEquals(docketNotFound, expected, docketService.findById(1).getTitle()); + assertEquals(expected, docketService.findById(1).getTitle(), docketNotFound); } @Test public void shouldFindByTitle() throws DataException { - assertEquals(docketNotFound, 1, docketService.findByTitle(defaultDocket, true).size()); + assertEquals(1, docketService.findByTitle(defaultDocket, true).size(), docketNotFound); } @Test public void shouldFindByFile() throws DataException { String expected = fileName; - assertEquals(docketNotFound, expected, - docketService.findByFile(fileName).get(DocketTypeField.FILE.getKey())); + assertEquals(expected, docketService.findByFile(fileName).get(DocketTypeField.FILE.getKey()), docketNotFound); } @Test public void shouldFindManyByClientId() throws DataException { - assertEquals("Dockets were not found in index!", 3, docketService.findByClientId(1).size()); + assertEquals(3, docketService.findByClientId(1).size(), "Dockets were not found in index!"); } @Test public void shouldNotFindByClientId() throws DataException { - assertEquals("Docket was found in index!", 0, docketService.findByClientId(3).size()); + assertEquals(0, docketService.findByClientId(3).size(), "Docket was found in index!"); } @Test public void shouldFindByTitleAndFile() throws DataException { Integer expected = 1; - assertEquals(docketNotFound, expected, - docketService.getIdFromJSONObject(docketService.findByTitleAndFile(defaultDocket, fileName))); + assertEquals(expected, docketService.getIdFromJSONObject(docketService.findByTitleAndFile(defaultDocket, fileName)), docketNotFound); } @Test public void shouldNotFindByTitleAndFile() throws DataException { Integer expected = 0; - assertEquals("Docket was found in index!", expected, - docketService.getIdFromJSONObject(docketService.findByTitleAndFile(defaultDocket, none))); + assertEquals(expected, docketService.getIdFromJSONObject(docketService.findByTitleAndFile(defaultDocket, none)), "Docket was found in index!"); } @Test public void shouldFindManyByTitleOrFile() throws DataException { - assertEquals("Dockets were not found in index!", 2, - docketService.findByTitleOrFile(defaultDocket, fileName).size()); + assertEquals(2, docketService.findByTitleOrFile(defaultDocket, fileName).size(), "Dockets were not found in index!"); } @Test public void shouldFindOneByTitleOrFile() throws DataException { - assertEquals(docketNotFound, 1, docketService.findByTitleOrFile(defaultDocket, none).size()); + assertEquals(1, docketService.findByTitleOrFile(defaultDocket, none).size(), docketNotFound); } @Test public void shouldNotFindByTitleOrFile() throws DataException { - assertEquals("Some dockets were found in index!", 0, docketService.findByTitleOrFile(none, none).size()); + assertEquals(0, docketService.findByTitleOrFile(none, none).size(), "Some dockets were found in index!"); } @Test public void shouldFindAllDocketsDocuments() throws DataException { - assertEquals("Not all dockets were found in index!", 4, docketService.findAllDocuments().size()); + assertEquals(4, docketService.findAllDocuments().size(), "Not all dockets were found in index!"); } @Test @@ -172,20 +164,18 @@ public void shouldRemoveDocket() throws Exception { docket.setTitle("To Remove"); docketService.save(docket); Docket foundDocket = docketService.getById(5); - assertEquals("Additional docket was not inserted in database!", "To Remove", foundDocket.getTitle()); + assertEquals("To Remove", foundDocket.getTitle(), "Additional docket was not inserted in database!"); docketService.remove(foundDocket); - exception.expect(DAOException.class); - docketService.getById(5); + assertThrows(DAOException.class, () -> docketService.getById(5)); docket = new Docket(); docket.setTitle("To remove"); docketService.save(docket); foundDocket = docketService.getById(6); - assertEquals("Additional docket was not inserted in database!", "To remove", foundDocket.getTitle()); + assertEquals("To remove", foundDocket.getTitle(), "Additional docket was not inserted in database!"); docketService.remove(6); - exception.expect(DAOException.class); - docketService.getById(6); + assertThrows(DAOException.class, () -> docketService.getById(6)); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/FilterServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/FilterServiceIT.java index 237a57e478f..8b2feb934bc 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/FilterServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/FilterServiceIT.java @@ -13,8 +13,9 @@ import static org.awaitility.Awaitility.given; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; -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; import java.util.List; import java.util.Objects; @@ -24,11 +25,10 @@ import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.data.database.beans.Filter; @@ -46,7 +46,7 @@ public class FilterServiceIT { private static final String filterValue = "\"id:1\""; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -55,7 +55,7 @@ public static void prepareDatabase() throws Exception { given().ignoreExceptions().await().until(() -> Objects.nonNull(filterService.findByValue(filterValue, true))); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -64,38 +64,38 @@ public static void cleanDatabase() throws Exception { @Test public void shouldCountAllFilters() throws DataException { - assertEquals("Filters were not counted correctly!", Long.valueOf(2), filterService.count()); + assertEquals(Long.valueOf(2), filterService.count(), "Filters were not counted correctly!"); } @Test public void shouldCountAllFiltersAccordingToQuery() throws DataException { QueryBuilder query = matchQuery("value", filterValue).operator(Operator.AND); - assertEquals("Filters were not counted correctly!", Long.valueOf(1), filterService.count(query)); + assertEquals(Long.valueOf(1), filterService.count(query), "Filters were not counted correctly!"); } @Test public void shouldCountAllDatabaseRowsForFilters() throws Exception { Long amount = filterService.countDatabaseRows(); - assertEquals("Filters were not counted correctly!", Long.valueOf(2), amount); + assertEquals(Long.valueOf(2), amount, "Filters were not counted correctly!"); } @Test public void shouldGetFilterById() throws Exception { Filter filter = filterService.getById(1); String actual = filter.getValue(); - assertEquals("Filter was not found in database!", filterValue, actual); + assertEquals(filterValue, actual, "Filter was not found in database!"); } @Test public void shouldGetAllFilters() throws Exception { List filters = filterService.getAll(); - assertEquals("Not all filters were found in database!", 2, filters.size()); + assertEquals(2, filters.size(), "Not all filters were found in database!"); } @Test public void shouldGetAllFiltersInGivenRange() throws Exception { List filters = filterService.getAll(1, 10); - assertEquals("Not all filters were found in database!", 1, filters.size()); + assertEquals(1, filters.size(), "Not all filters were found in database!"); } @Test @@ -103,22 +103,17 @@ public void shouldBuildQueryAndFindByProcessServiceByProcessId() throws Exceptio ProcessService processService = ServiceManager.getProcessService(); QueryBuilder firstQuery = filterService.queryBuilder("\"id:2\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes with id equal 2!", 1, - processService.findByQuery(firstQuery, true).size()); + assertEquals(1, processService.findByQuery(firstQuery, true).size(), "Incorrect amount of processes with id equal 2!"); - assertEquals("Incorrect id for found process!", Integer.valueOf(2), - processService.findByQuery(firstQuery, true).get(0).getId()); + assertEquals(Integer.valueOf(2), processService.findByQuery(firstQuery, true).get(0).getId(), "Incorrect id for found process!"); QueryBuilder secondQuery = filterService.queryBuilder("\"id:1 2\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes with id equal 1 or 2!", 2, - processService.findByQuery(secondQuery, true).size()); + assertEquals(2, processService.findByQuery(secondQuery, true).size(), "Incorrect amount of processes with id equal 1 or 2!"); - assertEquals("Incorrect id for found process!", Integer.valueOf(2), - processService.findByQuery(secondQuery, SortBuilders.fieldSort("id").order(SortOrder.DESC), true).get(0).getId()); + assertEquals(Integer.valueOf(2), processService.findByQuery(secondQuery, SortBuilders.fieldSort("id").order(SortOrder.DESC), true).get(0).getId(), "Incorrect id for found process!"); QueryBuilder thirdQuery = filterService.queryBuilder("\"id:2 3\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes with id equal 2 or 3!", 2, - processService.findByQuery(thirdQuery, true).size()); + assertEquals(2, processService.findByQuery(thirdQuery, true).size(), "Incorrect amount of processes with id equal 2 or 3!"); } @Test @@ -126,27 +121,22 @@ public void shouldBuildQueryAndFindByProcessServiceByProjectTitle() throws Excep ProcessService processService = ServiceManager.getProcessService(); QueryBuilder firstQuery = filterService.queryBuilder("\"project:First\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for project with title containing 'First'!", 2, - processService.findByQuery(firstQuery, true).size()); + assertEquals(2, processService.findByQuery(firstQuery, true).size(), "Incorrect amount of processes for project with title containing 'First'!"); QueryBuilder secondQuery = filterService.queryBuilder("\"project:Second\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for project with title containing 'Second'!", 1, - processService.findByQuery(secondQuery, true).size()); + assertEquals(1, processService.findByQuery(secondQuery, true).size(), "Incorrect amount of processes for project with title containing 'Second'!"); // it has only 2 templates - no processes QueryBuilder thirdQuery = filterService.queryBuilder("\"project:Inactive\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for project with title containing 'Inactive'!", 0, - processService.findByQuery(thirdQuery, true).size()); + assertEquals(0, processService.findByQuery(thirdQuery, true).size(), "Incorrect amount of processes for project with title containing 'Inactive'!"); QueryBuilder fourthQuery = filterService.queryBuilder("\"project:First Inactive\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for project with with title containing 'First Inactive'!", 0, - processService.findByQuery(fourthQuery, true).size()); + assertEquals(0, processService.findByQuery(fourthQuery, true).size(), "Incorrect amount of processes for project with with title containing 'First Inactive'!"); QueryBuilder fifthQuery = filterService.queryBuilder("\"project:First project\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for project with with title containing 'First Project'!", 2, - processService.findByQuery(fifthQuery, true).size()); + assertEquals(2, processService.findByQuery(fifthQuery, true).size(), "Incorrect amount of processes for project with with title containing 'First Project'!"); } @Test @@ -154,12 +144,10 @@ public void shouldBuildQueryAndFindByProcessServiceByProcessTitle() throws Excep ProcessService processService = ServiceManager.getProcessService(); QueryBuilder firstQuery = filterService.queryBuilder("\"process:process\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for title containing 'process'!", 2, - processService.findByQuery(firstQuery, true).size()); + assertEquals(2, processService.findByQuery(firstQuery, true).size(), "Incorrect amount of processes for title containing 'process'!"); QueryBuilder secondQuery = filterService.queryBuilder("\"process:First\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for title containing 'First'!", 1, - processService.findByQuery(secondQuery, true).size()); + assertEquals(1, processService.findByQuery(secondQuery, true).size(), "Incorrect amount of processes for title containing 'First'!"); } @Test @@ -167,12 +155,10 @@ public void shouldBuildQueryAndFindByProcessServiceByTaskTitle() throws Exceptio ProcessService processService = ServiceManager.getProcessService(); QueryBuilder firstQuery = filterService.queryBuilder("\"step:Finished\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for title containing 'Finished'!", 0, - processService.findByQuery(firstQuery, true).size()); + assertEquals(0, processService.findByQuery(firstQuery, true).size(), "Incorrect amount of processes for title containing 'Finished'!"); QueryBuilder secondQuery = filterService.queryBuilder("\"stepopen:Open\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for title containing 'Open'!", 1, - processService.findByQuery(secondQuery, true).size()); + assertEquals(1, processService.findByQuery(secondQuery, true).size(), "Incorrect amount of processes for title containing 'Open'!"); } @Test @@ -180,16 +166,13 @@ public void shouldBuildQueryAndFindByProcessServiceByBatchId() throws Exception ProcessService processService = ServiceManager.getProcessService(); QueryBuilder firstQuery = filterService.queryBuilder("\"batch:1\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for batch with id 1!", 1, - processService.findByQuery(firstQuery, true).size()); + assertEquals(1, processService.findByQuery(firstQuery, true).size(), "Incorrect amount of processes for batch with id 1!"); QueryBuilder secondQuery = filterService.queryBuilder("\"batch:1 2\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for batch with id 1 or 2!", 1, - processService.findByQuery(secondQuery, true).size()); + assertEquals(1, processService.findByQuery(secondQuery, true).size(), "Incorrect amount of processes for batch with id 1 or 2!"); QueryBuilder thirdQuery = filterService.queryBuilder("\"-batch:1 2\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for batch with not id 1 or 2!", 2, - processService.findByQuery(thirdQuery, true).size()); + assertEquals(2, processService.findByQuery(thirdQuery, true).size(), "Incorrect amount of processes for batch with not id 1 or 2!"); } @Test @@ -197,86 +180,70 @@ public void shouldBuildQueryAndFindByTitle() throws DataException { ProcessService processService = ServiceManager.getProcessService(); QueryBuilder query = filterService.queryBuilder("\"DBConnectionTest\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes title 'DBConnectionTest'", 1, - processService.findByQuery(query, true).size()); + assertEquals(1, processService.findByQuery(query, true).size(), "Incorrect amount of processes title 'DBConnectionTest'"); query = filterService.queryBuilder("\"ocess\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes where title contains 'ocess''", 2, - processService.findByQuery(query, true).size()); + assertEquals(2, processService.findByQuery(query, true).size(), "Incorrect amount of processes where title contains 'ocess''"); query = filterService.queryBuilder("\"\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes with empty query'", 3, - processService.findByQuery(query, true).size()); + assertEquals(3, processService.findByQuery(query, true).size(), "Incorrect amount of processes with empty query'"); query = filterService.queryBuilder("\"notAvailable\"", ObjectType.PROCESS, false, false); - assertTrue("Incorrect amount of processes with wrong title", - processService.findByQuery(query, true).isEmpty()); + assertTrue(processService.findByQuery(query, true).isEmpty(), "Incorrect amount of processes with wrong title"); } /** * find by properties. */ - @Ignore + @Disabled @Test public void shouldBuildQueryAndFindByProcessServiceByProperty() throws Exception { ProcessService processService = ServiceManager.getProcessService(); QueryBuilder firstQuery = filterService.queryBuilder("\"processproperty:fix\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for property with value containing 'fix'!", 1, - processService.findByQuery(firstQuery, true).size()); + assertEquals(1, processService.findByQuery(firstQuery, true).size(), "Incorrect amount of processes for property with value containing 'fix'!"); QueryBuilder secondQuery = filterService.queryBuilder("\"processproperty:value\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for property with value containing 'value'!", 1, - processService.findByQuery(secondQuery, true).size()); + assertEquals(1, processService.findByQuery(secondQuery, true).size(), "Incorrect amount of processes for property with value containing 'value'!"); QueryBuilder thirdQuery = filterService.queryBuilder("\"processproperty:Process:value\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for property with title 'Process' and value containing 'value'!", 1, - processService.findByQuery(thirdQuery, true).size()); + assertEquals(1, processService.findByQuery(thirdQuery, true).size(), "Incorrect amount of processes for property with title 'Process' and value containing 'value'!"); QueryBuilder fourthQuery = filterService.queryBuilder("\"processproperty:Korrektur:fix\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for property with title 'Korrektur' and value containing 'fix'!", 1, - processService.findByQuery(fourthQuery, true).size()); + assertEquals(1, processService.findByQuery(fourthQuery, true).size(), "Incorrect amount of processes for property with title 'Korrektur' and value containing 'fix'!"); QueryBuilder fifthQuery = filterService.queryBuilder("\"processproperty:Korrektur notwendig:fix it\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for property with title 'Korrektur' and value containing 'fix'!", 1, - processService.findByQuery(fifthQuery, true).size()); + assertEquals(1, processService.findByQuery(fifthQuery, true).size(), "Incorrect amount of processes for property with title 'Korrektur' and value containing 'fix'!"); QueryBuilder sixthQuery = filterService.queryBuilder("\"-processproperty:fix\"", ObjectType.PROCESS, false, false); - assertEquals("Incorrect amount of processes for property with value not containing 'fix'!", 2, - processService.findByQuery(sixthQuery, true).size()); + assertEquals(2, processService.findByQuery(sixthQuery, true).size(), "Incorrect amount of processes for property with value not containing 'fix'!"); } /** * find by multiple conditions. */ - @Ignore + @Disabled @Test public void shouldBuildQueryAndFindByProcessServiceByMultipleConditions() throws Exception { ProcessService processService = ServiceManager.getProcessService(); QueryBuilder firstQuery = filterService.queryBuilder("\"project:First\" \"processproperty:fix\"", ObjectType.PROCESS, false, false); - assertEquals( - "Incorrect amount of processes for project with title 'First' and property with value containing 'fix'!", 1, - processService.findByQuery(firstQuery, true).size()); + assertEquals(1, processService.findByQuery(firstQuery, true).size(), "Incorrect amount of processes for project with title 'First' and property with value containing 'fix'!"); QueryBuilder secondQuery = filterService.queryBuilder("\"project:First project\" \"processproperty:fix\"", ObjectType.PROCESS, false, false); - assertEquals( - "Incorrect amount of processes for project with title 'First' and property with value containing 'fix'!", 1, - processService.findByQuery(secondQuery, true).size()); + assertEquals(1, processService.findByQuery(secondQuery, true).size(), "Incorrect amount of processes for project with title 'First' and property with value containing 'fix'!"); QueryBuilder thirdQuery = filterService.queryBuilder("\"project:First process\" \"processproperty:fix\"", ObjectType.PROCESS, false, false); - assertEquals( - "Incorrect amount of processes for project with title 'First' and property with value containing 'fix'!", 0, - processService.findByQuery(thirdQuery, true).size()); + assertEquals(0, processService.findByQuery(thirdQuery, true).size(), "Incorrect amount of processes for project with title 'First' and property with value containing 'fix'!"); } @Test @@ -284,16 +251,13 @@ public void shouldBuildQueryAndFindByTaskServiceByProcessId() throws Exception { TaskService taskService = ServiceManager.getTaskService(); QueryBuilder firstQuery = filterService.queryBuilder(filterValue, ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks for process with id equal 1!", 2, - taskService.findByQuery(firstQuery, true).size()); + assertEquals(2, taskService.findByQuery(firstQuery, true).size(), "Incorrect amount of tasks for process with id equal 1!"); QueryBuilder secondQuery = filterService.queryBuilder(filterValue, ObjectType.TASK, true, false); - assertEquals("Incorrect amount of open tasks for process with id equal 1!", 1, - taskService.findByQuery(secondQuery, true).size()); + assertEquals(1, taskService.findByQuery(secondQuery, true).size(), "Incorrect amount of open tasks for process with id equal 1!"); QueryBuilder thirdQuery = filterService.queryBuilder("\"id:1 2\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks for process with id equal to 1 or 2!", 4, - taskService.findByQuery(thirdQuery, true).size()); + assertEquals(4, taskService.findByQuery(thirdQuery, true).size(), "Incorrect amount of tasks for process with id equal to 1 or 2!"); } @Test @@ -301,22 +265,18 @@ public void shouldBuildQueryAndFindByTaskServiceByProjectTitle() throws Exceptio TaskService taskService = ServiceManager.getTaskService(); QueryBuilder firstQuery = filterService.queryBuilder("\"project:First\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks for project with title containing 'First'!", 4, - taskService.findByQuery(firstQuery, true).size()); + assertEquals(4, taskService.findByQuery(firstQuery, true).size(), "Incorrect amount of tasks for project with title containing 'First'!"); QueryBuilder secondQuery = filterService.queryBuilder("\"project:Inactive\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks for project with title containing 'Inactive'!", 0, - taskService.findByQuery(secondQuery, true).size()); + assertEquals(0, taskService.findByQuery(secondQuery, true).size(), "Incorrect amount of tasks for project with title containing 'Inactive'!"); QueryBuilder thirdQuery = filterService.queryBuilder("\"project:First Inactive\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks for project with title containing 'First Inactive'!", 0, - taskService.findByQuery(thirdQuery, true).size()); + assertEquals(0, taskService.findByQuery(thirdQuery, true).size(), "Incorrect amount of tasks for project with title containing 'First Inactive'!"); QueryBuilder fourthQuery = filterService.queryBuilder("\"project:First project\"", ObjectType.TASK, true, false); - assertEquals("Incorrect amount of tasks for project with title containing 'First project'!", 2, - taskService.findByQuery(fourthQuery, true).size()); + assertEquals(2, taskService.findByQuery(fourthQuery, true).size(), "Incorrect amount of tasks for project with title containing 'First project'!"); } @Test @@ -324,22 +284,18 @@ public void shouldBuildQueryAndFindByTaskServiceByProcessTitle() throws Exceptio TaskService taskService = ServiceManager.getTaskService(); QueryBuilder firstQuery = filterService.queryBuilder("\"process:First\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks for process with title containing 'First'!", 2, - taskService.findByQuery(firstQuery, true).size()); + assertEquals(2, taskService.findByQuery(firstQuery, true).size(), "Incorrect amount of tasks for process with title containing 'First'!"); QueryBuilder secondQuery = filterService.queryBuilder("\"process:First\"", ObjectType.TASK, true, false); - assertEquals("Incorrect amount of tasks for process with title containing 'First'!", 1, - taskService.findByQuery(secondQuery, true).size()); + assertEquals(1, taskService.findByQuery(secondQuery, true).size(), "Incorrect amount of tasks for process with title containing 'First'!"); QueryBuilder thirdQuery = filterService.queryBuilder("\"process:Second process\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks for process with title containing 'Second process'!", 2, - taskService.findByQuery(thirdQuery, true).size()); + assertEquals(2, taskService.findByQuery(thirdQuery, true).size(), "Incorrect amount of tasks for process with title containing 'Second process'!"); QueryBuilder fourthQuery = filterService.queryBuilder("\"process:Second process\"", ObjectType.TASK, true, false); - assertEquals("Incorrect amount of tasks for process with title containing 'Second process'!", 1, - taskService.findByQuery(fourthQuery, true).size()); + assertEquals(1, taskService.findByQuery(fourthQuery, true).size(), "Incorrect amount of tasks for process with title containing 'Second process'!"); } @Test @@ -353,52 +309,41 @@ public void shouldBuildQueryAndFindByTaskServiceByTaskTitle() throws Exception { // 'Testing'!", 1, taskDTOS.size()); QueryBuilder firstQuery = filterService.queryBuilder("\"stepopen:Open\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks with title containing 'Open'!", 1, - taskService.findByQuery(firstQuery, true).size()); + assertEquals(1, taskService.findByQuery(firstQuery, true).size(), "Incorrect amount of tasks with title containing 'Open'!"); QueryBuilder secondQuery = filterService.queryBuilder("\"stepopen:Finished\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks with title containing 'Finished'!", 0, - taskService.findByQuery(secondQuery, true).size()); + assertEquals(0, taskService.findByQuery(secondQuery, true).size(), "Incorrect amount of tasks with title containing 'Finished'!"); } /** * find tasks by property. */ - @Ignore + @Disabled @Test public void shouldBuildQueryAndFindByTaskServiceByProperty() throws Exception { TaskService taskService = ServiceManager.getTaskService(); QueryBuilder firstQuery = filterService.queryBuilder("\"processproperty:fix\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks for process property with value containing 'fix'!", 2, - taskService.findByQuery(firstQuery, true).size()); + assertEquals(2, taskService.findByQuery(firstQuery, true).size(), "Incorrect amount of tasks for process property with value containing 'fix'!"); QueryBuilder secondQuery = filterService.queryBuilder("\"processproperty:fix\"", ObjectType.TASK, true, false); - assertEquals("Incorrect amount of tasks for process property with value containing 'fix'!", 1, - taskService.findByQuery(secondQuery, true).size()); + assertEquals(1, taskService.findByQuery(secondQuery, true).size(), "Incorrect amount of tasks for process property with value containing 'fix'!"); QueryBuilder thirdQuery = filterService.queryBuilder("\"processproperty:value\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks for process property with value containing 'value'!", 2, - taskService.findByQuery(thirdQuery, true).size()); + assertEquals(2, taskService.findByQuery(thirdQuery, true).size(), "Incorrect amount of tasks for process property with value containing 'value'!"); QueryBuilder fourthQuery = filterService.queryBuilder("\"processproperty:Process:value\"", ObjectType.TASK, false, false); - assertEquals( - "Incorrect amount of tasks for process property with title 'Process' and value containing 'value'!", 2, - taskService.findByQuery(fourthQuery, true).size()); + assertEquals(2, taskService.findByQuery(fourthQuery, true).size(), "Incorrect amount of tasks for process property with title 'Process' and value containing 'value'!"); QueryBuilder fifthQuery = filterService.queryBuilder("\"processproperty:Korrektur:fix\"", ObjectType.TASK, false, false); - assertEquals( - "Incorrect amount of tasks for process property with title 'Korrektur' and value containing 'fix'!", 2, - taskService.findByQuery(fifthQuery, true).size()); + assertEquals(2, taskService.findByQuery(fifthQuery, true).size(), "Incorrect amount of tasks for process property with title 'Korrektur' and value containing 'fix'!"); QueryBuilder sixthQuery = filterService.queryBuilder("\"processproperty:Korrektur notwendig:fix it\"", ObjectType.TASK, false, false); - assertEquals( - "Incorrect amount of tasks for process property with title 'Korrektur' and value containing 'fix'!", 2, - taskService.findByQuery(sixthQuery, true).size()); + assertEquals(2, taskService.findByQuery(sixthQuery, true).size(), "Incorrect amount of tasks for process property with title 'Korrektur' and value containing 'fix'!"); } @Test @@ -407,18 +352,15 @@ public void shouldBuildQueryAndFindByTaskServiceByClosedTasks() throws Exception // this query will never return anything, since tasks are always filtered for "open" or "inwork" only QueryBuilder firstQuery = filterService.queryBuilder("\"stepdone:1\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of closed tasks with ordering 1!", 0, - taskService.findByQuery(firstQuery, true).size()); + assertEquals(0, taskService.findByQuery(firstQuery, true).size(), "Incorrect amount of closed tasks with ordering 1!"); // this query will never return anything, since tasks are always filtered for "open" or "inwork" only QueryBuilder secondQuery = filterService.queryBuilder("\"stepdone:Closed\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of closed tasks with title 'Closed'!", 0, - taskService.findByQuery(secondQuery, true).size()); + assertEquals(0, taskService.findByQuery(secondQuery, true).size(), "Incorrect amount of closed tasks with title 'Closed'!"); // this query will never exclude anything, because "done" tasks are never listed anyway QueryBuilder thirdQuery = filterService.queryBuilder("\"-stepdone:Closed\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of not closed tasks with title different than 'Closed'!", 4, - taskService.findByQuery(thirdQuery, true).size()); + assertEquals(4, taskService.findByQuery(thirdQuery, true).size(), "Incorrect amount of not closed tasks with title different than 'Closed'!"); } @Test @@ -427,22 +369,18 @@ public void shouldBuildQueryAndFindByTaskServiceByOpenTasks() throws Exception { QueryBuilder allTasksQuery = filterService.queryBuilder("\"\"", ObjectType.TASK, false, false); int numberOfAllTasks = taskService.findByQuery(allTasksQuery, true).size(); - assertEquals("Incorrect number of all tasks!", 4, numberOfAllTasks); + assertEquals(4, numberOfAllTasks, "Incorrect number of all tasks!"); QueryBuilder firstQuery = filterService.queryBuilder("\"stepopen:4\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of open tasks with ordering 4!", 1, - taskService.findByQuery(firstQuery, true).size()); + assertEquals(1, taskService.findByQuery(firstQuery, true).size(), "Incorrect amount of open tasks with ordering 4!"); QueryBuilder secondQuery = filterService.queryBuilder("\"stepopen:Open\"", ObjectType.TASK, false, false); int numberOfOpenTasks = taskService.findByQuery(secondQuery, true).size(); - assertEquals("Incorrect amount of open tasks with title 'Open'!", 1, numberOfOpenTasks); + assertEquals(1, numberOfOpenTasks, "Incorrect amount of open tasks with title 'Open'!"); QueryBuilder thirdQuery = filterService.queryBuilder("\"-stepopen:Open\"", ObjectType.TASK, false, false); int numberOfNotOpenTasks = taskService.findByQuery(thirdQuery, true).size(); - assertEquals( - "Incorrect amount of not open tasks with title different than 'Open'!", - numberOfAllTasks - numberOfOpenTasks, numberOfNotOpenTasks - ); + assertEquals(numberOfAllTasks - numberOfOpenTasks, numberOfNotOpenTasks, "Incorrect amount of not open tasks with title different than 'Open'!"); } @Test @@ -450,34 +388,28 @@ public void shouldBuildQueryAndFindByTaskServiceByInProgressTasks() throws Excep TaskService taskService = ServiceManager.getTaskService(); QueryBuilder firstQuery = filterService.queryBuilder("\"stepinwork:3\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks in progress with ordering 3!", 1, - taskService.findByQuery(firstQuery, true).size()); + assertEquals(1, taskService.findByQuery(firstQuery, true).size(), "Incorrect amount of tasks in progress with ordering 3!"); QueryBuilder secondQuery = filterService.queryBuilder("\"-stepinwork:3\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks not in progress with ordering different than 3!", 3, - taskService.findByQuery(secondQuery, true).size()); + assertEquals(3, taskService.findByQuery(secondQuery, true).size(), "Incorrect amount of tasks not in progress with ordering different than 3!"); QueryBuilder thirdQuery = filterService.queryBuilder("\"-stepinwork:2\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks not in progress with ordering different than 2!", 3, - taskService.findByQuery(thirdQuery, true).size()); + assertEquals(3, taskService.findByQuery(thirdQuery, true).size(), "Incorrect amount of tasks not in progress with ordering different than 2!"); } - @Ignore("problem with steplocked") + @Disabled("problem with steplocked") @Test public void shouldBuildQueryAndFindByTaskServiceByLockedTasks() throws Exception { TaskService taskService = ServiceManager.getTaskService(); QueryBuilder firstQuery = filterService.queryBuilder("\"steplocked:2\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of locked tasks with ordering 2!", 1, - taskService.findByQuery(firstQuery, true).size()); + assertEquals(1, taskService.findByQuery(firstQuery, true).size(), "Incorrect amount of locked tasks with ordering 2!"); QueryBuilder secondQuery = filterService.queryBuilder("\"-steplocked:2\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of not locked tasks with ordering different than 2!", 2, - taskService.findByQuery(secondQuery, true).size()); + assertEquals(2, taskService.findByQuery(secondQuery, true).size(), "Incorrect amount of not locked tasks with ordering different than 2!"); QueryBuilder thirdQuery = filterService.queryBuilder("\"-steplocked:3\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of not locked tasks with ordering different than 3!", 1, - taskService.findByQuery(thirdQuery, true).size()); + assertEquals(1, taskService.findByQuery(thirdQuery, true).size(), "Incorrect amount of not locked tasks with ordering different than 3!"); } @Test @@ -487,26 +419,22 @@ public void shouldBuildQueryAndFindByTaskServiceWithDisjunctions() throws Except // check that two task conditions can be combined by disjunction // returns "Progress" and "Open" tasks associated with any process that are either in state "inwork" or "open", respectively QueryBuilder firstQuery = filterService.queryBuilder("\"stepinwork:Progress | stepopen:Open\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks for disjunction query \"stepinwork:Progress | stepopen:Open\"!", 2, - taskService.findByQuery(firstQuery, true).size()); + assertEquals(2, taskService.findByQuery(firstQuery, true).size(), "Incorrect amount of tasks for disjunction query \"stepinwork:Progress | stepopen:Open\"!"); // check that a task condition can be combined with a process condition by disjunction // returns any tasks associated with process id=1 or "Next Open" tasks that are in state "open" QueryBuilder secondQuery = filterService.queryBuilder("\"stepopen:Next Open | id:1\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks for disjunction query \"stepopen:Next Open | id:1\"!", 3, - taskService.findByQuery(secondQuery, true).size()); + assertEquals(3, taskService.findByQuery(secondQuery, true).size(), "Incorrect amount of tasks for disjunction query \"stepopen:Next Open | id:1\"!"); // check that default queries can be combined with task conditions by disjunction // returns any tasks related to process "First process" or "Second process" but not "Progress" tasks in state "inwork" QueryBuilder thirdQuery = filterService.queryBuilder("\"First | Second\" \"-stepinwork:Progress\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks for disjunction query \"First | Second\"!", 3, - taskService.findByQuery(thirdQuery, true).size()); + assertEquals(3, taskService.findByQuery(thirdQuery, true).size(), "Incorrect amount of tasks for disjunction query \"First | Second\"!"); // check that conditions can be optionally enclosed in parentheses, which masks the vertical line "|" // returns tasks whose process title contains the string "First |" (aka none) or tasks in state "inwork" with title "Progress" QueryBuilder fourthQuery = filterService.queryBuilder("\"(First |) | (stepinwork:Progress)\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks for disjunction query \"(First |) | (stepinwork:Progress)\"!", 1, - taskService.findByQuery(fourthQuery, true).size()); + assertEquals(1, taskService.findByQuery(fourthQuery, true).size(), "Incorrect amount of tasks for disjunction query \"(First |) | (stepinwork:Progress)\"!"); } @Test @@ -514,13 +442,11 @@ public void shouldBuildQueryAndFindByTaskServiceByMultipleConditions() throws Ex TaskService taskService = ServiceManager.getTaskService(); QueryBuilder firstQuery = filterService.queryBuilder("\"id:1\" \"-stepinwork:3\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of not closed tasks with ordering 4 assigned to process with id 1!", 1, - taskService.findByQuery(firstQuery, true).size()); + assertEquals(1, taskService.findByQuery(firstQuery, true).size(), "Incorrect amount of not closed tasks with ordering 4 assigned to process with id 1!"); QueryBuilder secondQuery = filterService.queryBuilder("\"id:1\" \"-stepopen:4\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of not closed tasks with ordering 4 assigned to process with id 1!", 1, - taskService.findByQuery(secondQuery, true).size()); + assertEquals(1, taskService.findByQuery(secondQuery, true).size(), "Incorrect amount of not closed tasks with ordering 4 assigned to process with id 1!"); } @Test @@ -529,20 +455,16 @@ public void shouldBuildQueryForDefaultConditions() throws Exception { TaskService taskService = ServiceManager.getTaskService(); QueryBuilder firstQuery = filterService.queryBuilder("\"First\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks with default condition!", 2, - taskService.findByQuery(firstQuery, true).size()); + assertEquals(2, taskService.findByQuery(firstQuery, true).size(), "Incorrect amount of tasks with default condition!"); QueryBuilder secondQuery = filterService.queryBuilder("\"First\"", ObjectType.TASK, true, false); - assertEquals("Incorrect amount of open tasks with default condition!", 1, - taskService.findByQuery(secondQuery, true).size()); + assertEquals(1, taskService.findByQuery(secondQuery, true).size(), "Incorrect amount of open tasks with default condition!"); QueryBuilder thirdQuery = filterService.queryBuilder("\"Second\"", ObjectType.TASK, false, false); - assertEquals("Incorrect amount of tasks with default condition!", 2, - taskService.findByQuery(thirdQuery, true).size()); + assertEquals(2, taskService.findByQuery(thirdQuery, true).size(), "Incorrect amount of tasks with default condition!"); QueryBuilder fourthQuery = filterService.queryBuilder("\"Second\"", ObjectType.PROCESS, true, false); - assertEquals("Incorrect amount of process with default condition!", 1, - processService.findByQuery(fourthQuery, true).size()); + assertEquals(1, processService.findByQuery(fourthQuery, true).size(), "Incorrect amount of process with default condition!"); } @@ -554,12 +476,12 @@ public void shouldBuildQueryForEmptyConditions() throws Exception { // empty condition is not allowed and returns no results QueryBuilder query = filterService.queryBuilder("\"steplocked:\"", ObjectType.TASK, false, false); List taskDTOS = taskService.findByQuery(query, true); - assertEquals("Incorrect amount of closed tasks with no ordering!", 0, taskDTOS.size()); + assertEquals(0, taskDTOS.size(), "Incorrect amount of closed tasks with no ordering!"); // empty condition is not allowed and throws Exception in ElasticSearch 7 query = filterService.queryBuilder("\"id:\"", ObjectType.PROCESS, false, false); QueryBuilder finalQuery = query; - Assertions.assertThrows(ElasticsearchStatusException.class, + assertThrows(ElasticsearchStatusException.class, () -> processService.findByQuery(finalQuery, true)); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/FolderServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/FolderServiceIT.java index 370788a1c67..e0a1c1f1b3f 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/FolderServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/FolderServiceIT.java @@ -11,15 +11,15 @@ package org.kitodo.production.services.data; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Folder; import org.kitodo.data.database.beans.Project; @@ -30,13 +30,13 @@ */ public class FolderServiceIT { - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -48,7 +48,7 @@ public void shouldFindFolder() throws Exception { Folder folder = folderService.getById(1); boolean condition = folder.getFileGroup().equals("MAX") && folder.getMimeType().equals("image/jpeg"); - assertTrue("Folder was not found in database!", condition); + assertTrue(condition, "Folder was not found in database!"); } @Test @@ -56,16 +56,16 @@ public void shouldGetAllFolders() throws Exception { FolderService folderService = new FolderService(); List folders = folderService.getAll(); - assertEquals("Folder was not found in database!", 6, folders.size()); + assertEquals(6, folders.size(), "Folder was not found in database!"); for (Folder folder : folders) { - assertNotEquals("No project assigned", null, folder.getProject()); + assertNotEquals(null, folder.getProject(), "No project assigned"); } Project project = ServiceManager.getProjectService().getById(1); - assertEquals("No project assigned", 6, project.getFolders().size()); + assertEquals(6, project.getFolders().size(), "No project assigned"); for (Folder folder : project.getFolders()) { - assertNotEquals("No project assigned", null, folder.getProject()); - assertEquals("No project assigned", project.getTitle(), folder.getProject().getTitle()); + assertNotEquals(null, folder.getProject(), "No project assigned"); + assertEquals(project.getTitle(), folder.getProject().getTitle(), "No project assigned"); } } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/ImportConfigurationIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/ImportConfigurationIT.java index 9ca9f6c62d9..ad88ccfc79e 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/ImportConfigurationIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/ImportConfigurationIT.java @@ -11,17 +11,17 @@ package org.kitodo.production.services.data; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.kitodo.test.utils.TestConstants.GBV; import static org.kitodo.test.utils.TestConstants.KALLIOPE; import java.util.List; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.data.database.beans.ImportConfiguration; @@ -34,7 +34,7 @@ public class ImportConfigurationIT { /** * Insert test mapping files and import configurations into database. */ - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertRolesFull(); @@ -52,9 +52,9 @@ public void shouldGetAllImportConfigurationsSortedAlphabetically() throws DAOExc User userOne = ServiceManager.getUserService().getById(1); SecurityTestUtils.addUserDataToSecurityContext(userOne, 1); List configs = ServiceManager.getImportConfigurationService().getAll(); - assertEquals("Wrong number of import configurations", 3, configs.size()); - assertEquals("Wrong first import configuration", GBV, configs.get(0).getTitle()); - assertEquals("Wrong last import configuration", KALLIOPE, configs.get(2).getTitle()); + assertEquals(3, configs.size(), "Wrong number of import configurations"); + assertEquals(GBV, configs.get(0).getTitle(), "Wrong first import configuration"); + assertEquals(KALLIOPE, configs.get(2).getTitle(), "Wrong last import configuration"); } /** @@ -67,12 +67,12 @@ public void shouldNotGetImportConfigurationsOfUnassigedClients() throws DAOExcep User userThree = ServiceManager.getUserService().getById(3); SecurityTestUtils.addUserDataToSecurityContext(userThree, 2); List configs = ServiceManager.getImportConfigurationService().getAll(); - assertEquals("Wrong number of import configurations",2, configs.size()); - assertFalse("User should not have access to import configuration 'Kalliope' of unassigned client", - configs.stream().anyMatch(config -> KALLIOPE.equals(config.getTitle()))); + assertEquals(2, configs.size(), "Wrong number of import configurations"); + assertFalse(configs.stream().anyMatch(config -> KALLIOPE.equals(config.getTitle())), + "User should not have access to import configuration 'Kalliope' of unassigned client"); } - @After + @AfterEach public void cleanupSecurityContext() { SecurityTestUtils.cleanSecurityContext(); } @@ -80,7 +80,7 @@ public void cleanupSecurityContext() { /** * Clean up test database. */ - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/ImportServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/ImportServiceIT.java index 7b56c99309c..862bf8fceab 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/ImportServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/ImportServiceIT.java @@ -12,6 +12,12 @@ package org.kitodo.production.services.data; import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.xebialabs.restito.server.StubServer; @@ -37,10 +43,10 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.SystemUtils; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.ExecutionPermission; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; @@ -122,7 +128,7 @@ public class ImportServiceIT { private static final String EXPECTED_AUTHOR = "HansMeier"; private static final String KITODO_NAMESPACE = "http://meta.kitodo.org/v1/"; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -141,7 +147,7 @@ public static void prepareDatabase() throws Exception { setupServer(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -158,13 +164,13 @@ public static void cleanDatabase() throws Exception { */ @Test public void testImportProcess() throws DAOException, DataException, ImportException, IOException { - Assert.assertEquals("Not the correct amount of processes found", 7, (long) processService.count()); + assertEquals(7, (long) processService.count(), "Not the correct amount of processes found"); Process importedProcess = importProcess(RECORD_ID, MockDatabase.getK10PlusImportConfiguration()); try { - Assert.assertEquals("WrongProcessTitle", "Kitodo_" + RECORD_ID, importedProcess.getTitle()); - Assert.assertEquals("Wrong project used", 1, (long) importedProcess.getProject().getId()); - Assert.assertEquals("Wrong template used", 1, (long) importedProcess.getTemplate().getId()); - Assert.assertEquals("Not the correct amount of processes found", 8, (long) processService.count()); + assertEquals("Kitodo_" + RECORD_ID, importedProcess.getTitle(), "WrongProcessTitle"); + assertEquals(1, (long) importedProcess.getProject().getId(), "Wrong project used"); + assertEquals(1, (long) importedProcess.getTemplate().getId(), "Wrong template used"); + assertEquals(8, (long) processService.count(), "Not the correct amount of processes found"); } finally { ProcessTestUtils.removeTestProcess(importedProcess.getId()); } @@ -188,12 +194,9 @@ public void testImportProcessWithAdditionalMetadata() throws DAOException, Impor .loadWorkpiece(processService.getMetadataFileUri(processWithAdditionalMetadata)); HashSet metadata = workpiece.getLogicalStructure().getMetadata(); try { - Assert.assertTrue("Process does not contain correct metadata", - assertMetadataSetContainsMetadata(metadata, TITLE, "Band 1")); - Assert.assertTrue("Process does not contain correct metadata", - assertMetadataSetContainsMetadata(metadata, PLACE, "Hamburg")); - Assert.assertTrue("Process does not contain correct metadata", - assertMetadataSetContainsMetadata(metadata, PLACE, "Berlin")); + assertTrue(assertMetadataSetContainsMetadata(metadata, TITLE, "Band 1"), "Process does not contain correct metadata"); + assertTrue(assertMetadataSetContainsMetadata(metadata, PLACE, "Hamburg"), "Process does not contain correct metadata"); + assertTrue(assertMetadataSetContainsMetadata(metadata, PLACE, "Berlin"), "Process does not contain correct metadata"); } finally { ProcessTestUtils.removeTestProcess(processWithAdditionalMetadata.getId()); } @@ -210,21 +213,20 @@ private boolean assertMetadataSetContainsMetadata(HashSet metadataSet, public void shouldCreateUrlWithCustomParameters() throws DAOException, ImportException, IOException { Process importedProcess = importProcess(CUSTOM_INTERFACE_RECORD_ID, MockDatabase.getCustomTypeImportConfiguration()); try { - Assert.assertNotNull(importedProcess); + assertNotNull(importedProcess); } finally { ProcessTestUtils.removeTestProcess(importedProcess.getId()); } } - @Test(expected = ImportException.class) - public void shouldFailToImportFromCustomInterfaceWithoutConfiguredUrlParameters() throws DAOException, - ImportException, IOException { + @Test + public void shouldFailToImportFromCustomInterfaceWithoutConfiguredUrlParameters() throws DAOException { ImportConfiguration customConfiguration = MockDatabase.getCustomTypeImportConfiguration(); UrlParameter wrongUrlParameter = new UrlParameter(); wrongUrlParameter.setParameterKey("firstKey"); wrongUrlParameter.setParameterValue("wrongValue"); customConfiguration.setUrlParameters(Collections.singletonList(wrongUrlParameter)); - importProcess(CUSTOM_INTERFACE_RECORD_ID, customConfiguration); + assertThrows(ImportException.class, () -> importProcess(CUSTOM_INTERFACE_RECORD_ID, customConfiguration)); } /** @@ -236,8 +238,7 @@ public void shouldTestWhetherRecordIdentifierMetadataIsConfigured() throws IOExc RulesetManagementInterface rulesetManagement = ServiceManager.getRulesetManagementService() .getRulesetManagement(); rulesetManagement.load(new File(TestConstants.TEST_RULESET)); - Assert.assertTrue("Should determine that recordIdentifier is configured for all document types", - ServiceManager.getImportService().isRecordIdentifierMetadataConfigured(rulesetManagement)); + assertTrue(ServiceManager.getImportService().isRecordIdentifierMetadataConfigured(rulesetManagement), "Should determine that recordIdentifier is configured for all document types"); } /** @@ -252,7 +253,7 @@ public void shouldCreateTempProcessFromDocument() throws Exception { Document xmlDocument = XMLUtils.parseXMLString(fileContent); TempProcess tempProcess = ServiceManager.getImportService().createTempProcessFromDocument(importConfiguration, xmlDocument, TEMPLATE_ID, PROJECT_ID); - Assert.assertNotNull("TempProcess should not be null", tempProcess); + assertNotNull(tempProcess, "TempProcess should not be null"); } } @@ -272,7 +273,7 @@ public void shouldCheckForParent() throws DAOException, ProcessGenerationExcepti try { ProcessTestUtils.updateIdentifier(parentTestId); importService.checkForParent(String.valueOf(parentTestId), ruleset, PROJECT_ID); - Assert.assertNotNull(importService.getParentTempProcess()); + assertNotNull(importService.getParentTempProcess()); } finally { ProcessTestUtils.removeTestProcess(parentTestId); } @@ -286,18 +287,16 @@ public void shouldCheckForParent() throws DAOException, ProcessGenerationExcepti @Test public void shouldGetNumberOfChildren() throws DAOException { int numberOfChildren = importService.getNumberOfChildren(MockDatabase.getK10PlusImportConfiguration(), RECORD_ID); - Assert.assertEquals("Number of children is incorrect", EXPECTED_NR_OF_CHILDREN , numberOfChildren); + assertEquals(EXPECTED_NR_OF_CHILDREN, numberOfChildren, "Number of children is incorrect"); } /** * Tests whether importing child processes via an ImportConfiguration that does not support it fails or not. - * - * @throws Exception when loading ImportConfiguration from test database fails */ - @Test(expected = NoRecordFoundException.class) - public void shouldFailToLoadK1PlusChildProcesses() throws Exception { - importService.getChildProcesses(MockDatabase.getK10PlusImportConfiguration(), RECORD_ID, PROJECT_ID, - TEMPLATE_ID, 1, Collections.emptyList()); + @Test + public void shouldFailToLoadK1PlusChildProcesses() { + assertThrows(NoRecordFoundException.class, + () -> importService.getChildProcesses(MockDatabase.getK10PlusImportConfiguration(), RECORD_ID, PROJECT_ID, TEMPLATE_ID, 1, Collections.emptyList())); } /** @@ -309,7 +308,7 @@ public void shouldFailToLoadK1PlusChildProcesses() throws Exception { public void shouldSucceedToLoadKalliopeChildProcesses() throws Exception { List childRecords = importService.getChildProcesses(MockDatabase.getKalliopeImportConfiguration(), KALLIOPE_RECORD_ID, PROJECT_ID, TEMPLATE_ID, 3, Collections.emptyList()); - Assert.assertEquals("Wrong number of Kalliope child records", 3, childRecords.size()); + assertEquals(3, childRecords.size(), "Wrong number of Kalliope child records"); } /** @@ -329,14 +328,13 @@ public void shouldGetChildProcesses() throws Exception { LinkedList childProcesses = ServiceManager.getImportService().getChildProcesses( MockDatabase.getKalliopeImportConfiguration(), PARENT_RECORD_CATALOG_ID, PROJECT_ID, TEMPLATE_ID, 3, Collections.singletonList(parentTempProcess)); - Assert.assertEquals("Wrong number of imported child processes", 3, childProcesses.size()); + assertEquals(3, childProcesses.size(), "Wrong number of imported child processes"); for (TempProcess childProcess : childProcesses) { String childId = CHILD_RECORD_IDS.get(childProcesses.indexOf(childProcess)); Optional importedChildId = childProcess.getWorkpiece().getLogicalStructure().getMetadata().stream() .filter(metadata -> metadata instanceof MetadataEntry && metadata.getKey().equals("CatalogIDDigital") && ((MetadataEntry) metadata).getValue().equals(childId)).findAny(); - Assert.assertTrue(String.format("Retrieved child records should contain process with CatalogIDDigital '%s'", childId), - importedChildId.isPresent()); + assertTrue(importedChildId.isPresent(), String.format("Retrieved child records should contain process with CatalogIDDigital '%s'", childId)); } } finally { ProcessTestUtils.removeTestProcess(parentProcessId); @@ -366,10 +364,8 @@ public void shouldConvertDataRecordToInternal() throws DAOException, Unsupported dataRecord.setOriginalData(IOUtils.toString(inputStream, Charset.defaultCharset())); Document internalDocument = ServiceManager.getImportService().convertDataRecordToInternal(dataRecord, MockDatabase.getKalliopeImportConfiguration(), false); - Assert.assertEquals("Converted data should contain one 'kitodo' root node", 1, - internalDocument.getElementsByTagNameNS(KITODO_NAMESPACE, KITODO).getLength()); - Assert.assertEquals("Converted data should contain three 'metadata' nodes", 3, - internalDocument.getElementsByTagNameNS(KITODO_NAMESPACE, METADATA).getLength()); + assertEquals(1, internalDocument.getElementsByTagNameNS(KITODO_NAMESPACE, KITODO).getLength(), "Converted data should contain one 'kitodo' root node"); + assertEquals(3, internalDocument.getElementsByTagNameNS(KITODO_NAMESPACE, METADATA).getLength(), "Converted data should contain three 'metadata' nodes"); } } @@ -400,10 +396,8 @@ public void shouldProcessTempProcess() throws DAOException, IOException, Process ImportService.processTempProcess(tempProcess, managementInterface, ImportService.ACQUISITION_STAGE_CREATE, ServiceManager.getUserService() .getCurrentMetadataLanguage(), null); - Assert.assertFalse("Process should have some properties", - tempProcess.getProcess().getProperties().isEmpty()); - Assert.assertTrue("Process title should not be empty", - StringUtils.isNotBlank(tempProcess.getProcess().getTitle())); + assertFalse(tempProcess.getProcess().getProperties().isEmpty(), "Process should have some properties"); + assertTrue(StringUtils.isNotBlank(tempProcess.getProcess().getTitle()), "Process title should not be empty"); } } @@ -415,9 +409,8 @@ public void shouldProcessTempProcess() throws DAOException, IOException, Process @Test public void shouldGetProcessDetailValue() throws Exception { List processDetails = loadProcessDetailsFromTestProcess(TEST_KITODO_METADATA_FILE_PATH); - Assert.assertFalse("List of process details should not be empty", processDetails.isEmpty()); - Assert.assertEquals("Value of first process details should not be empty", - TEST_PROCESS_TITLE, ImportService.getProcessDetailValue(processDetails.get(0))); + assertFalse(processDetails.isEmpty(), "List of process details should not be empty"); + assertEquals(TEST_PROCESS_TITLE, ImportService.getProcessDetailValue(processDetails.get(0)), "Value of first process details should not be empty"); } /** @@ -429,13 +422,11 @@ public void shouldGetProcessDetailValue() throws Exception { public void shouldSetProcessDetailValue() throws Exception { String newProcessTitle = "New process title"; List processDetails = loadProcessDetailsFromTestProcess(TEST_KITODO_METADATA_FILE_PATH); - Assert.assertFalse("Process detail list should not be empty", processDetails.isEmpty()); + assertFalse(processDetails.isEmpty(), "Process detail list should not be empty"); ProcessDetail title = processDetails.get(0); - Assert.assertEquals("Wrong title process detail before setting it", TEST_PROCESS_TITLE, - ImportService.getProcessDetailValue(title)); + assertEquals(TEST_PROCESS_TITLE, ImportService.getProcessDetailValue(title), "Wrong title process detail before setting it"); ImportService.setProcessDetailValue(title, newProcessTitle); - Assert.assertEquals("Wrong title process detail after setting it", newProcessTitle, - ImportService.getProcessDetailValue(title)); + assertEquals(newProcessTitle, ImportService.getProcessDetailValue(title), "Wrong title process detail after setting it"); } /** @@ -446,9 +437,9 @@ public void shouldSetProcessDetailValue() throws Exception { @Test public void shouldGetListOfCreators() throws Exception { List processDetails = loadProcessDetailsFromTestProcess(TEST_METADATA_WITH_AUTHOR_FILE_PATH); - Assert.assertFalse("Process detail list should not be empty", processDetails.isEmpty()); + assertFalse(processDetails.isEmpty(), "Process detail list should not be empty"); String creators = ImportService.getListOfCreators(processDetails); - Assert.assertEquals("Author metadata is not correct", EXPECTED_AUTHOR, creators); + assertEquals(EXPECTED_AUTHOR, creators, "Author metadata is not correct"); } /** @@ -464,14 +455,14 @@ public void shouldSetSelectedExemplarRecord() throws Exception { List processDetails = loadProcessDetailsFromTestProcess(TEST_METADATA_WITH_AUTHOR_FILE_PATH); String exemplarDataOwner = getProcessDetailByMetadataId(importConfiguration.getItemFieldOwnerMetadata(), processDetails); String exemplarDataSignature = getProcessDetailByMetadataId(importConfiguration.getItemFieldSignatureMetadata(), processDetails); - Assert.assertNotEquals("Wrong exemplar data owner BEFORE selecting exemplar", exemplarDataOwner, expectedOwner); - Assert.assertNotEquals("Wrong exemplar data signature BEFORE selecting exemplar", exemplarDataSignature, expectedSignature); + assertNotEquals(exemplarDataOwner, expectedOwner, "Wrong exemplar data owner BEFORE selecting exemplar"); + assertNotEquals(exemplarDataSignature, expectedSignature, "Wrong exemplar data signature BEFORE selecting exemplar"); ExemplarRecord exemplarRecord = new ExemplarRecord(expectedOwner, expectedSignature); ImportService.setSelectedExemplarRecord(exemplarRecord, importConfiguration, processDetails); exemplarDataOwner = getProcessDetailByMetadataId(importConfiguration.getItemFieldOwnerMetadata(), processDetails); exemplarDataSignature = getProcessDetailByMetadataId(importConfiguration.getItemFieldSignatureMetadata(), processDetails); - Assert.assertEquals("Wrong exemplar data owner AFTER selecting exemplar", exemplarDataOwner, expectedOwner); - Assert.assertEquals("Wrong exemplar data signature AFTER selecting exemplar", exemplarDataSignature, expectedSignature); + assertEquals(exemplarDataOwner, expectedOwner, "Wrong exemplar data owner AFTER selecting exemplar"); + assertEquals(exemplarDataSignature, expectedSignature, "Wrong exemplar data signature AFTER selecting exemplar"); } /** @@ -490,12 +481,11 @@ public void shouldEnsureNonEmptyTitles() throws DAOException, DataException, IOE URI metadataFilePath = ServiceManager.getFileService().getMetadataFilePath(parentProcess); Workpiece parentWorkpiece = ServiceManager.getMetsService().loadWorkpiece(metadataFilePath); TempProcess parentTempProcess = new TempProcess(parentProcess, parentWorkpiece); - Assert.assertTrue("Process title should be empty before setting it", - StringUtils.isBlank(parentTempProcess.getProcess().getTitle())); + assertTrue(StringUtils.isBlank(parentTempProcess.getProcess().getTitle()), "Process title should be empty before setting it"); LinkedList tempProcesses = new LinkedList<>(); tempProcesses.add(parentTempProcess); boolean titleChanged = ImportService.ensureNonEmptyTitles(tempProcesses); - Assert.assertTrue("Process titles should have been changed", titleChanged); + assertTrue(titleChanged, "Process titles should have been changed"); } finally { ProcessTestUtils.removeTestProcess(parentProcessId); } @@ -520,11 +510,9 @@ public void shouldAddProperties() throws Exception { Workpiece workpiece = ServiceManager.getMetsService().loadWorkpiece(metadataFilePath); TempProcess tempProcess = new TempProcess(process, workpiece); List processDetails = loadProcessDetailsFromTestProcess(TEST_METADATA_WITH_AUTHOR_FILE_PATH); - Assert.assertFalse("Process should NOT contain 'DocType' property before adding it", - process.getWorkpieces().stream().anyMatch(property -> docType.equals(property.getTitle()))); + assertFalse(process.getWorkpieces().stream().anyMatch(property -> docType.equals(property.getTitle())), "Process should NOT contain 'DocType' property before adding it"); ImportService.addProperties(tempProcess, template, processDetails, monograph, imageDescription); - Assert.assertTrue("Process should contain 'DocType' property after adding it", - process.getWorkpieces().stream().anyMatch(property -> docType.equals(property.getTitle()))); + assertTrue(process.getWorkpieces().stream().anyMatch(property -> docType.equals(property.getTitle())), "Process should contain 'DocType' property after adding it"); } finally { ProcessTestUtils.removeTestProcess(processId); } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/LdapGroupServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/LdapGroupServiceIT.java index 6e0d64f9139..19916e2d196 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/LdapGroupServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/LdapGroupServiceIT.java @@ -11,12 +11,12 @@ package org.kitodo.production.services.data; -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.assertTrue; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.LdapGroup; @@ -25,12 +25,12 @@ */ public class LdapGroupServiceIT { - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.insertLdapGroups(); } - @AfterClass + @AfterAll public static void cleanDatabase() { MockDatabase.cleanDatabase(); } @@ -41,8 +41,8 @@ public void shouldFindLdapGroup() throws Exception { LdapGroup ldapGroup = ldapGroupService.getById(1); boolean condition = ldapGroup.getTitle().equals("LG") && ldapGroup.getDisplayName().equals("Name"); - assertTrue("LDAP group was not found in database!", condition); + assertTrue(condition, "LDAP group was not found in database!"); - assertEquals("Title of Ldap server is not matching", "FirstLdapServer", ldapGroup.getLdapServer().getTitle()); + assertEquals("FirstLdapServer", ldapGroup.getLdapServer().getTitle(), "Title of Ldap server is not matching"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/LdapServerServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/LdapServerServiceIT.java index 8f300e2862a..67314117b68 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/LdapServerServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/LdapServerServiceIT.java @@ -11,12 +11,12 @@ package org.kitodo.production.services.data; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.LdapServer; import org.kitodo.production.services.ServiceManager; @@ -25,12 +25,12 @@ public class LdapServerServiceIT { private static final LdapServerService ldapServerService = ServiceManager.getLdapServerService(); - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.insertLdapGroups(); } - @AfterClass + @AfterAll public static void cleanDatabase() { MockDatabase.cleanDatabase(); } @@ -38,9 +38,8 @@ public static void cleanDatabase() { @Test public void shouldFindLdapServer() throws Exception { LdapServer ldapServer = ldapServerService.getById(1); - assertEquals("LpadServer title is not matching", "FirstLdapServer", ldapServer.getTitle()); - assertFalse("LpadServer useSsl is not matching", ldapServer.isUseSsl()); - assertEquals("LdapServer password encoding is not matching", "SHA", - ldapServer.getPasswordEncryption().getTitle()); + assertEquals("FirstLdapServer", ldapServer.getTitle(), "LpadServer title is not matching"); + assertFalse(ldapServer.isUseSsl(), "LpadServer useSsl is not matching"); + assertEquals("SHA", ldapServer.getPasswordEncryption().getTitle(), "LdapServer password encoding is not matching"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/MassImportServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/MassImportServiceIT.java index 19cf1c8bfe4..7e6fc8b69da 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/MassImportServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/MassImportServiceIT.java @@ -11,10 +11,19 @@ package org.kitodo.production.services.data; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.api.Metadata; import org.kitodo.api.MetadataEntry; @@ -25,13 +34,6 @@ import org.kitodo.production.forms.createprocess.ProcessDetail; import org.kitodo.production.services.ServiceManager; -import java.io.IOException; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.stream.Collectors; - public class MassImportServiceIT { /** @@ -39,7 +41,7 @@ public class MassImportServiceIT { * * @throws Exception when preparing database fails */ - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -50,7 +52,7 @@ public static void prepareDatabase() throws Exception { * * @throws Exception when cleaning up database fails */ - @AfterClass + @AfterAll public static void cleanupDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -68,10 +70,8 @@ public void shouldGetAddableMetadataTable() throws DAOException, IOException { Collection enteredMetadata = createPresetMetadata(); List divisions = retrieveDivisions(); List addableMetadata = ServiceManager.getMassImportService().getAddableMetadataTable(divisions, enteredMetadata); - Assert.assertFalse("List of addable metadata should not be empty", - addableMetadata.isEmpty()); - Assert.assertTrue("List of addable metadata should contain 'TSL/ATS'", - addableMetadata.stream().anyMatch(m -> "TSL/ATS".equals(m.getLabel()))); + assertFalse(addableMetadata.isEmpty(), "List of addable metadata should not be empty"); + assertTrue(addableMetadata.stream().anyMatch(m -> "TSL/ATS".equals(m.getLabel())), "List of addable metadata should contain 'TSL/ATS'"); } private List retrieveDivisions() throws DAOException, IOException { diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceIT.java index ba94294fd75..c220f2579aa 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceIT.java @@ -13,11 +13,12 @@ import static org.awaitility.Awaitility.await; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -34,13 +35,10 @@ import org.apache.commons.lang3.SystemUtils; import org.elasticsearch.index.query.Operator; import org.elasticsearch.index.query.QueryBuilder; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.kitodo.ExecutionPermission; import org.kitodo.FileLoader; import org.kitodo.MockDatabase; @@ -82,7 +80,7 @@ public class ProcessServiceIT { private static final File script = new File(ConfigCore.getParameter(ParameterCore.SCRIPT_CREATE_DIR_META)); private static Map testProcessIds; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { if (!SystemUtils.IS_OS_WINDOWS) { ExecutionPermission.setExecutePermission(script); @@ -101,7 +99,7 @@ public static void prepareDatabase() throws Exception { }); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { ProcessTestUtils.removeTestProcess(testProcessIds.get(MockDatabase.HIERARCHY_PARENT)); MockDatabase.stopNode(); @@ -112,31 +110,27 @@ public static void cleanDatabase() throws Exception { } } - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void shouldCountAllProcesses() throws DataException { - assertEquals("Processes were not counted correctly!", Long.valueOf(7), processService.count()); + assertEquals(Long.valueOf(7), processService.count(), "Processes were not counted correctly!"); } @Test public void shouldCountProcessesAccordingToQuery() throws DataException { QueryBuilder query = matchQuery("title", firstProcess).operator(Operator.AND); - assertEquals("Process was not found!", processService.count(query), - processService.findNumberOfProcessesWithTitle(firstProcess)); + assertEquals(processService.count(query), processService.findNumberOfProcessesWithTitle(firstProcess), "Process was not found!"); } @Test public void shouldCountAllDatabaseRowsForProcesses() throws Exception { Long amount = processService.countDatabaseRows(); - assertEquals("Processes were not counted correctly!", Long.valueOf(7), amount); + assertEquals(Long.valueOf(7), amount, "Processes were not counted correctly!"); } @Test public void shouldFindByInChoiceListShown() throws DataException, DAOException { List byInChoiceListShown = ServiceManager.getProcessService().getTemplateProcesses(); - Assert.assertEquals("wrong amount of processes found", 1, byInChoiceListShown.size()); + assertEquals(1, byInChoiceListShown.size(), "wrong amount of processes found"); } @Test @@ -154,8 +148,8 @@ public void shouldSaveProcess() throws Exception { Process foundProcess = processService.getById(process.getId()); Process foundParent = foundProcess.getParent(); - assertEquals("Child process was not found in database!", "Child", foundProcess.getTitle()); - assertEquals("Parent process was not assigned to child!", "Parent", foundParent.getTitle()); + assertEquals("Child", foundProcess.getTitle(), "Child process was not found in database!"); + assertEquals("Parent", foundParent.getTitle(), "Parent process was not assigned to child!"); foundParent.getChildren().clear(); foundProcess.setParent(null); @@ -168,21 +162,21 @@ public void shouldSaveProcess() throws Exception { public void shouldGetProcess() throws Exception { Process process = processService.getById(1); boolean condition = process.getTitle().equals(firstProcess) && process.getWikiField().equals("field"); - assertTrue("Process was not found in database!", condition); + assertTrue(condition, "Process was not found in database!"); - assertEquals("Process was found but tasks were not inserted!", 5, process.getTasks().size()); + assertEquals(5, process.getTasks().size(), "Process was found but tasks were not inserted!"); } @Test public void shouldGetAllProcesses() throws Exception { List processes = processService.getAll(); - assertEquals("Not all processes were found in database!", 7, processes.size()); + assertEquals(7, processes.size(), "Not all processes were found in database!"); } @Test public void shouldGetAllProcessesInGivenRange() throws Exception { List processes = processService.getAll(1, 10); - assertEquals("Not all processes were found in database!", 6, processes.size()); + assertEquals(6, processes.size(), "Not all processes were found in database!"); } @Test @@ -191,51 +185,48 @@ public void shouldRemoveProcess() throws Exception { process.setTitle("To Remove"); processService.save(process); Process foundProcess = processService.getById(process.getId()); - assertEquals("Additional process was not inserted in database!", "To Remove", foundProcess.getTitle()); + assertEquals("To Remove", foundProcess.getTitle(), "Additional process was not inserted in database!"); processService.remove(foundProcess); - exception.expect(DAOException.class); - processService.getById(10); + assertThrows(DAOException.class, () -> processService.getById(10)); process = new Process(); process.setTitle("To remove"); processService.save(process); - foundProcess = processService.getById(9); - assertEquals("Additional process was not inserted in database!", "To remove", foundProcess.getTitle()); + int processId = process.getId(); + foundProcess = processService.getById(processId); + assertEquals("To remove", foundProcess.getTitle(), "Additional process was not inserted in database!"); - processService.remove(9); - exception.expect(DAOException.class); - processService.getById(9); + processService.remove(processId); + assertThrows(DAOException.class, () -> processService.getById(processId)); } @Test public void shouldFindById() throws DataException { Integer expected = 1; - assertEquals(processNotFound, expected, processService.findById(1).getId()); + assertEquals(expected, processService.findById(1).getId(), processNotFound); } @Test public void shouldFindByTitle() throws DataException { - assertEquals(processNotFound, 1, processService.findByTitle(firstProcess, true).size()); + assertEquals(1, processService.findByTitle(firstProcess, true).size(), processNotFound); } @Test public void shouldFindByMetadata() throws DataException { - assertEquals(processNotFound, 3, - processService.findByMetadata(Collections.singletonMap("TSL_ATS", "Proc")).size()); + assertEquals(3, processService.findByMetadata(Collections.singletonMap("TSL_ATS", "Proc")).size(), processNotFound); } @Test public void shouldNotFindByMetadata() throws DataException { - assertEquals("Process was found in index!", 0, - processService.findByMetadata(Collections.singletonMap("TSL_ATS", "Nope")).size()); + assertEquals(0, processService.findByMetadata(Collections.singletonMap("TSL_ATS", "Nope")).size(), "Process was found in index!"); } @Test public void shouldFindByMetadataContent() throws DataException, DAOException, IOException { int testProcessId = MockDatabase.insertTestProcess(TEST_PROCESS_TITLE, 1, 1, 1); ProcessTestUtils.copyTestMetadataFile(testProcessId, TEST_METADATA_FILE); - assertEquals(processNotFound, 1, processService.findByAnything("SecondMetaShort").size()); + assertEquals(1, processService.findByAnything("SecondMetaShort").size(), processNotFound); ProcessTestUtils.removeTestProcess(testProcessId); } @@ -243,12 +234,12 @@ public void shouldFindByMetadataContent() throws DataException, DAOException, IO public void shouldFindByLongNumberInMetadata() throws DataException, DAOException, IOException { int processId = MockDatabase.insertTestProcess("Test process", 1, 1, 1); ProcessTestUtils.copyTestMetadataFile(processId, ProcessTestUtils.testFileForLongNumbers); - assertEquals(processNotFound, 1, processService - .findByMetadata(Collections.singletonMap("CatalogIDDigital", "999999999999999991")).size()); - assertEquals(processNotFound, 1, processService - .findByMetadata(Collections.singletonMap("CatalogIDDigital", "991022551489706476")).size()); - assertEquals(processNotFound, 1, processService - .findByMetadata(Collections.singletonMap("CatalogIDDigital", "999999999999999999999999991")).size()); + assertEquals(1, processService + .findByMetadata(Collections.singletonMap("CatalogIDDigital", "999999999999999991")).size(), processNotFound); + assertEquals(1, processService + .findByMetadata(Collections.singletonMap("CatalogIDDigital", "991022551489706476")).size(), processNotFound); + assertEquals(1, processService + .findByMetadata(Collections.singletonMap("CatalogIDDigital", "999999999999999999999999991")).size(), processNotFound); ProcessTestUtils.removeTestProcess(processId); } @@ -262,27 +253,27 @@ public void shouldFindProcessWithUnderscore() throws DataException, DAOException ServiceManager.getProcessService().save(process); List byAnything = processService.findByAnything("ith-hyphen_an"); - assertFalse("nothing found", byAnything.isEmpty()); - assertEquals("wrong process found", processTitle, byAnything.get(0).getTitle()); + assertFalse(byAnything.isEmpty(), "nothing found"); + assertEquals(processTitle, byAnything.get(0).getTitle(), "wrong process found"); ServiceManager.getProcessService().remove(process.getId()); } @Test public void shouldFindByProjectTitleWithWildcard() throws DataException { - assertEquals(processNotFound, 6, processService.findByAnything("proj").size()); + assertEquals(6, processService.findByAnything("proj").size(), processNotFound); } @Test public void shouldNotFindByAnything() throws DataException { - assertEquals(processNotFound, 0, processService.findByAnything("Nope").size()); + assertEquals(0, processService.findByAnything("Nope").size(), processNotFound); } @Test public void shouldFindByMetadataGroupContent() throws DataException, DAOException, IOException { int testProcessId = MockDatabase.insertTestProcess("Test process", 1, 1, 1); ProcessTestUtils.copyTestMetadataFile(testProcessId, TEST_METADATA_FILE); - assertEquals(processNotFound, 1, processService.findByAnything("August").size()); + assertEquals(1, processService.findByAnything("August").size(), processNotFound); ProcessTestUtils.removeTestProcess(testProcessId); } @@ -318,22 +309,21 @@ public void shouldNotFindByTokenizedPropertyTitleAndWrongValue() throws DataExce @Test public void shouldFindLinkableParentProcesses() throws DataException, DAOException, IOException { - assertEquals("Processes were not found in index!", 1, - processService.findLinkableParentProcesses(MockDatabase.HIERARCHY_PARENT, 1).size()); + assertEquals(1, processService.findLinkableParentProcesses(MockDatabase.HIERARCHY_PARENT, 1).size(), "Processes were not found in index!"); } - @Ignore("for second process is attached task which is processed by blocked user") + @Disabled("for second process is attached task which is processed by blocked user") @Test public void shouldGetBlockedUser() throws Exception { UserService userService = ServiceManager.getUserService(); Process process = processService.getById(1); boolean condition = MetadataLock.getLockUser(process.getId()) == null; - assertTrue("Process has blocked user but it shouldn't!", condition); + assertTrue(condition, "Process has blocked user but it shouldn't!"); process = processService.getById(2); condition = MetadataLock.getLockUser(process.getId()) == userService.getById(3); - assertTrue("Blocked user doesn't match to given user!", condition); + assertTrue(condition, "Blocked user doesn't match to given user!"); } @Test @@ -342,12 +332,12 @@ public void shouldGetImagesTifDirectory() throws Exception { URI directory = processService.getImagesTifDirectory(true, process.getId(), process.getTitle(), process.getProcessBaseUri()); boolean condition = directory.getRawPath().contains("First__process_tif"); - assertTrue("Images TIF directory doesn't match to given directory!", condition); + assertTrue(condition, "Images TIF directory doesn't match to given directory!"); directory = processService.getImagesTifDirectory(false, process.getId(), process.getTitle(), process.getProcessBaseUri()); condition = directory.getRawPath().contains("First__process_tif"); - assertTrue("Images TIF directory doesn't match to given directory!", condition); + assertTrue(condition, "Images TIF directory doesn't match to given directory!"); // I don't know what changes this useFallback so I'm testing for both // cases } @@ -357,7 +347,7 @@ public void shouldGetImagesOrigDirectory() throws Exception { Process process = processService.getById(1); URI directory = processService.getImagesOriginDirectory(false, process); boolean condition = directory.getRawPath().contains("orig_First__process_tif"); - assertTrue("Images orig directory doesn't match to given directory!", condition); + assertTrue(condition, "Images orig directory doesn't match to given directory!"); } @Test @@ -365,7 +355,7 @@ public void shouldGetImagesDirectory() throws Exception { Process process = processService.getById(1); URI directory = fileService.getImagesDirectory(process); boolean condition = directory.getRawPath().contains("1/images"); - assertTrue("Images directory doesn't match to given directory!", condition); + assertTrue(condition, "Images directory doesn't match to given directory!"); } @Test @@ -373,7 +363,7 @@ public void shouldGetSourceDirectory() throws Exception { Process process = processService.getById(1); URI directory = fileService.getSourceDirectory(process); boolean condition = directory.getRawPath().contains("1/images/First__process_tif"); - assertTrue("Source directory doesn't match to given directory!", condition); + assertTrue(condition, "Source directory doesn't match to given directory!"); } @Test @@ -381,7 +371,7 @@ public void shouldGetProcessDataDirectory() throws Exception { Process process = processService.getById(1); URI directory = processService.getProcessDataDirectory(process); boolean condition = directory.getRawPath().contains("1"); - assertTrue("Process data directory doesn't match to given directory!", condition); + assertTrue(condition, "Process data directory doesn't match to given directory!"); } @Test @@ -389,7 +379,7 @@ public void shouldGetOcrDirectory() throws Exception { Process process = processService.getById(1); URI directory = fileService.getOcrDirectory(process); boolean condition = directory.getRawPath().contains("1/ocr"); - assertTrue("OCR directory doesn't match to given directory!", condition); + assertTrue(condition, "OCR directory doesn't match to given directory!"); } @Test @@ -397,7 +387,7 @@ public void shouldGetTxtDirectory() throws Exception { Process process = processService.getById(1); URI directory = fileService.getTxtDirectory(process); boolean condition = directory.getRawPath().contains("1/ocr/First__process_txt"); - assertTrue("TXT directory doesn't match to given directory!", condition); + assertTrue(condition, "TXT directory doesn't match to given directory!"); } @Test @@ -405,7 +395,7 @@ public void shouldGetWordDirectory() throws Exception { Process process = processService.getById(1); URI directory = fileService.getWordDirectory(process); boolean condition = directory.getRawPath().contains("1/ocr/First__process_wc"); - assertTrue("Word directory doesn't match to given directory!", condition); + assertTrue(condition, "Word directory doesn't match to given directory!"); } @Test @@ -413,7 +403,7 @@ public void shouldGetPdfDirectory() throws Exception { Process process = processService.getById(1); URI directory = fileService.getPdfDirectory(process); boolean condition = directory.getRawPath().contains("1/ocr/First__process_pdf"); - assertTrue("PDF directory doesn't match to given directory!", condition); + assertTrue(condition, "PDF directory doesn't match to given directory!"); } @Test @@ -421,7 +411,7 @@ public void shouldGetAltoDirectory() throws Exception { Process process = processService.getById(1); URI directory = fileService.getAltoDirectory(process); boolean condition = directory.getRawPath().contains("1/ocr/First__process_alto"); - assertTrue("Alto directory doesn't match to given directory!", condition); + assertTrue(condition, "Alto directory doesn't match to given directory!"); } @Test @@ -429,7 +419,7 @@ public void shouldGetImportDirectory() throws Exception { Process process = processService.getById(1); URI directory = fileService.getImportDirectory(process); boolean condition = directory.getRawPath().contains("1/import"); - assertTrue("Import directory doesn't match to given directory!", condition); + assertTrue(condition, "Import directory doesn't match to given directory!"); } @Test @@ -437,14 +427,14 @@ public void shouldGetBatchId() throws Exception { ProcessDTO process = processService.findById(1); String batchId = processService.getBatchID(process); boolean condition = batchId.equals("First batch, Third batch"); - assertTrue("BatchId doesn't match to given plain text!", condition); + assertTrue(condition, "BatchId doesn't match to given plain text!"); } @Test public void shouldGetCurrentTask() throws Exception { Process process = processService.getById(1); Task actual = processService.getCurrentTask(process); - assertEquals("Task doesn't match to given task!", 8, actual.getId().intValue()); + assertEquals(8, actual.getId().intValue(), "Task doesn't match to given task!"); } @Test @@ -452,7 +442,7 @@ public void shouldGetProgress() throws Exception { Process process = processService.getById(1); String progress = ProcessConverter.getCombinedProgressAsString(process, true); - assertEquals("Progress doesn't match given plain text!", "040020020020", progress); + assertEquals("040020020020", progress, "Progress doesn't match given plain text!"); } @Test @@ -460,7 +450,7 @@ public void shouldGetProgressClosed() throws Exception { Process process = processService.getById(1); double condition = ProcessConverter.getTaskProgressPercentageOfProcess(process, true).get(TaskStatus.DONE); - assertEquals("Progress doesn't match given plain text!", 40, condition, 0); + assertEquals(40, condition, 0, "Progress doesn't match given plain text!"); } @Test @@ -468,7 +458,7 @@ public void shouldGetProgressInProcessing() throws Exception { Process process = processService.getById(1); double condition = ProcessConverter.getTaskProgressPercentageOfProcess(process, true).get(TaskStatus.INWORK); - assertEquals("Progress doesn't match given plain text!", 20, condition, 0); + assertEquals(20, condition, 0, "Progress doesn't match given plain text!"); } @Test @@ -482,7 +472,7 @@ public void testGetQueryForClosedProcesses() throws DataException, DAOException QueryBuilder querySortHelperStatusTrue = processService.getQueryForClosedProcesses(); List byQuery = processService.findByQuery(querySortHelperStatusTrue, true); - Assert.assertEquals("Found the wrong amount of Processes", 1 ,byQuery.size()); + assertEquals(1, byQuery.size(), "Found the wrong amount of Processes"); secondProcess.setSortHelperStatus(sortHelperStatusOld); processService.save(secondProcess); } @@ -492,7 +482,7 @@ public void shouldGetProgressOpen() throws Exception { Process process = processService.getById(1); double condition = ProcessConverter.getTaskProgressPercentageOfProcess(process, true).get(TaskStatus.OPEN); - assertEquals("Progress doesn't match given plain text!", 20, condition, 0); + assertEquals(20, condition, 0, "Progress doesn't match given plain text!"); } @Test @@ -500,7 +490,7 @@ public void shouldGetProgressLocked() throws Exception { Process process = processService.getById(1); double condition = ProcessConverter.getTaskProgressPercentageOfProcess(process, true).get(TaskStatus.LOCKED); - assertEquals("Progress doesn't match given plain text!", 20, condition, 0); + assertEquals(20, condition, 0, "Progress doesn't match given plain text!"); } @Test @@ -510,7 +500,7 @@ public void shouldGetMetadataFilePath() throws Exception { Process process = processService.getById(testProcessId); URI directory = fileService.getMetadataFilePath(process); boolean condition = directory.getRawPath().contains(testProcessId + "/meta.xml"); - assertTrue("Metadata file path doesn't match to given file path!", condition); + assertTrue(condition, "Metadata file path doesn't match to given file path!"); ProcessTestUtils.removeTestProcess(testProcessId); } @@ -519,7 +509,7 @@ public void shouldGetTemplateFilePath() throws Exception { Process process = processService.getById(1); URI directory = fileService.getTemplateFile(process); boolean condition = directory.getRawPath().contains("1/template.xml"); - assertTrue("Template file path doesn't match to given file path!", condition); + assertTrue(condition, "Template file path doesn't match to given file path!"); } @Test @@ -532,7 +522,7 @@ public void shouldReadMetadataFile() throws Exception { String processTitle = process.getTitle(); String processTitleFromMetadata = digitalDocument.getLogicalDocStruct().getAllMetadata().get(0).getValue(); - assertEquals("It was not possible to read metadata file!", processTitle, processTitleFromMetadata); + assertEquals(processTitle, processTitleFromMetadata, "It was not possible to read metadata file!"); FileLoader.deleteMetadataFile(); } @@ -543,14 +533,14 @@ public void shouldReadMetadataAsTemplateFile() throws Exception { Process process = processService.getById(1); LegacyMetsModsDigitalDocumentHelper fileFormat = processService.readMetadataAsTemplateFile(process); - assertNotNull("Read template file has incorrect file format!", fileFormat); + assertNotNull(fileFormat, "Read template file has incorrect file format!"); int metadataSize = fileFormat.getDigitalDocument().getLogicalDocStruct().getAllMetadata().size(); - assertEquals("It was not possible to read metadata as template file!", 1, metadataSize); + assertEquals(1, metadataSize, "It was not possible to read metadata as template file!"); FileLoader.deleteMetadataTemplateFile(); } - @Ignore("PreferencesException: Can't obtain DigitalDocument! Maybe wrong preferences file? - METS node") + @Disabled("PreferencesException: Can't obtain DigitalDocument! Maybe wrong preferences file? - METS node") @Test public void shouldWriteMetadataAsTemplateFile() throws Exception { Process process = processService.getById(1); @@ -558,7 +548,7 @@ public void shouldWriteMetadataAsTemplateFile() throws Exception { fileService.writeMetadataAsTemplateFile( new LegacyMetsModsDigitalDocumentHelper(preferences.getRuleset()), process); boolean condition = fileService.fileExist(URI.create("1/template.xml")); - assertTrue("It was not possible to write metadata as template file!", condition); + assertTrue(condition, "It was not possible to write metadata as template file!"); Files.deleteIfExists(Paths.get(ConfigCore.getKitodoDataDirectory() + "1/template.xml")); } @@ -567,11 +557,11 @@ public void shouldWriteMetadataAsTemplateFile() throws Exception { public void shouldCheckIfIsImageFolderInUse() throws Exception { Process process = processService.getById(2); boolean condition = !processService.isImageFolderInUse(process); - assertTrue("Image folder is in use but it shouldn't be!", condition); + assertTrue(condition, "Image folder is in use but it shouldn't be!"); process = processService.getById(1); condition = processService.isImageFolderInUse(process); - assertTrue("Image folder is not in use but it should be!", condition); + assertTrue(condition, "Image folder is not in use but it should be!"); } @Test @@ -581,7 +571,7 @@ public void shouldGetImageFolderInUseUser() throws Exception { Process process = processService.getById(1); User expected = userService.getById(2); User actual = processService.getImageFolderInUseUser(process); - assertEquals("Processing user doesn't match to the given user!", expected, actual); + assertEquals(expected, actual, "Processing user doesn't match to the given user!"); } @Test @@ -589,8 +579,7 @@ public void shouldGetDigitalDocument() throws Exception { FileLoader.createMetadataFile(); LegacyMetsModsDigitalDocumentHelper actual = processService.getDigitalDocument(processService.getById(1)); - assertEquals("Metadata size in digital document is incorrect!", 1, - actual.getLogicalDocStruct().getAllMetadata().size()); + assertEquals(1, actual.getLogicalDocStruct().getAllMetadata().size(), "Metadata size in digital document is incorrect!"); FileLoader.deleteMetadataFile(); } @@ -626,31 +615,30 @@ public void shouldUpdateChildrenFromLogicalStructure() throws Exception { processService.updateChildrenFromLogicalStructure(process, logicalStructure); for (Process child : process.getChildren()) { - assertTrue("Process should have child to keep and child to add as only children", - Arrays.asList("HierarchyChildToKeep", "HierarchyChildToAdd").contains(child.getTitle())); - assertEquals("Child should have parent as parent", process, child.getParent()); + assertTrue(Arrays.asList("HierarchyChildToKeep", "HierarchyChildToAdd").contains(child.getTitle()), "Process should have child to keep and child to add as only children"); + assertEquals(process, child.getParent(), "Child should have parent as parent"); } - assertNull("Process to remove should have no parent", processService.getById(6).getParent()); + assertNull(processService.getById(6).getParent(), "Process to remove should have no parent"); } @Test public void testFindAllIDs() throws DataException { List allIDs = ServiceManager.getProcessService().findAllIDs(); - Assert.assertEquals("Wrong amount of id's in index", 7, allIDs.size()); - Assert.assertTrue("id's contain wrong entries", allIDs.containsAll(Arrays.asList(5, 2, 6, 4, 1, 7, 3))); + assertEquals(7, allIDs.size(), "Wrong amount of id's in index"); + assertTrue(allIDs.containsAll(Arrays.asList(5, 2, 6, 4, 1, 7, 3)), "id's contain wrong entries"); allIDs = ServiceManager.getProcessService().findAllIDs(0L, 5); - Assert.assertEquals("Wrong amount of id's in index", 5, allIDs.size()); - Assert.assertEquals("Duplicate ids in index", allIDs.size(), new HashSet<>(allIDs).size()); + assertEquals(5, allIDs.size(), "Wrong amount of id's in index"); + assertEquals(allIDs.size(), new HashSet<>(allIDs).size(), "Duplicate ids in index"); OptionalInt maxStream = allIDs.stream().mapToInt(Integer::intValue).max(); - assertTrue("Unable to find largest ID in stream of all process IDs!", maxStream.isPresent()); + assertTrue(maxStream.isPresent(), "Unable to find largest ID in stream of all process IDs!"); int maxId = maxStream.getAsInt(); int minId = allIDs.stream().mapToInt(Integer::intValue).min().getAsInt(); - Assert.assertTrue("Ids should all be smaller than 8", maxId < 8); - Assert.assertTrue("Ids should all be larger than 0", minId > 0); + assertTrue(maxId < 8, "Ids should all be smaller than 8"); + assertTrue(minId > 0, "Ids should all be larger than 0"); allIDs = ServiceManager.getProcessService().findAllIDs(5L, 10); - Assert.assertEquals("Wrong amount of id's in index", 2, allIDs.size()); + assertEquals(2, allIDs.size(), "Wrong amount of id's in index"); } @Test @@ -661,7 +649,7 @@ public void testCountMetadata() throws DAOException, IOException, DataException URI metadataFilePath = ServiceManager.getFileService().getMetadataFilePath(process); Workpiece workpiece = ServiceManager.getMetsService().loadWorkpiece(metadataFilePath); long logicalMetadata = MetsService.countLogicalMetadata(workpiece); - Assert.assertEquals("Wrong amount of metadata found!", 4, logicalMetadata); + assertEquals(4, logicalMetadata, "Wrong amount of metadata found!"); ProcessTestUtils.removeTestProcess(testProcessId); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceTest.java b/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceTest.java index 6060c1c6f43..9f1f03cec79 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceTest.java @@ -11,10 +11,11 @@ package org.kitodo.production.services.data; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.net.URI; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kitodo.data.database.beans.Process; import org.kitodo.production.dto.ProcessDTO; import org.kitodo.production.dto.PropertyDTO; @@ -69,11 +70,11 @@ public void testGetMetadataFileUri() { Process process = new Process(); process.setProcessBaseUri(URI.create("relative/path/no/ending/slash")); URI uri = ServiceManager.getProcessService().getMetadataFileUri(process); - Assert.assertEquals(URI.create("relative/path/no/ending/slash/meta.xml"), uri); + assertEquals(URI.create("relative/path/no/ending/slash/meta.xml"), uri); process.setProcessBaseUri(URI.create("relative/path/with/ending/slash/")); uri = ServiceManager.getProcessService().getMetadataFileUri(process); - Assert.assertEquals(URI.create("relative/path/with/ending/slash/meta.xml"), uri); + assertEquals(URI.create("relative/path/with/ending/slash/meta.xml"), uri); } @Test @@ -81,13 +82,13 @@ public void testGetProcessURI() { Process process = new Process(); process.setId(42); URI uri = ServiceManager.getProcessService().getProcessURI(process); - Assert.assertEquals(URI.create("database://?process.id=42"), uri); + assertEquals(URI.create("database://?process.id=42"), uri); } @Test public void testProcessIdFromUri() { URI uri = URI.create("database://?process.id=42"); int processId = ServiceManager.getProcessService().processIdFromUri(uri); - Assert.assertEquals(42, processId); + assertEquals(42, processId); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/ProjectServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/ProjectServiceIT.java index 92db14ecbaf..4683d3c6ea9 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/ProjectServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/ProjectServiceIT.java @@ -13,19 +13,18 @@ import static org.awaitility.Awaitility.await; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; -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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; import org.elasticsearch.index.query.Operator; import org.elasticsearch.index.query.QueryBuilder; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.data.database.beans.Project; @@ -44,7 +43,7 @@ public class ProjectServiceIT { private static final String firstProject = "First project"; private static final String projectNotFound = "Project was not found in index!"; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); @@ -57,61 +56,57 @@ public static void prepareDatabase() throws Exception { }); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); } - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void shouldCountAllProjects() throws DataException { - assertEquals("Projects were not counted correctly!", Long.valueOf(3), projectService.count()); + assertEquals(Long.valueOf(3), projectService.count(), "Projects were not counted correctly!"); } @Test public void shouldCountAllProjectsAccordingToQuery() throws DataException { QueryBuilder query = matchQuery("title", firstProject).operator(Operator.AND); - assertEquals("Projects were not counted correctly!", Long.valueOf(1), projectService.count(query)); + assertEquals(Long.valueOf(1), projectService.count(query), "Projects were not counted correctly!"); } @Test public void shouldCountAllDatabaseRowsForProjects() throws Exception { Long amount = projectService.countDatabaseRows(); - assertEquals("Projects were not counted correctly!", Long.valueOf(3), amount); + assertEquals(Long.valueOf(3), amount, "Projects were not counted correctly!"); } @Test public void shouldFindById() throws DataException { - assertTrue(projectNotFound, - projectService.findById(1).getTitle().equals(firstProject) && projectService.findById(1).getId().equals(1)); - assertTrue(projectNotFound, projectService.findById(1).isActive()); - assertEquals(projectNotFound, 2, projectService.findById(1).getTemplates().size()); + assertTrue(projectService.findById(1).getTitle().equals(firstProject) && projectService.findById(1).getId().equals(1), projectNotFound); + assertTrue(projectService.findById(1).isActive(), projectNotFound); + assertEquals(2, projectService.findById(1).getTemplates().size(), projectNotFound); - assertFalse(projectNotFound, projectService.findById(3).isActive()); + assertFalse(projectService.findById(3).isActive(), projectNotFound); } @Test public void shouldFindAllProjects() throws DataException { - assertEquals("Not all projects were found in index!", 3, projectService.findAll().size()); + assertEquals(3, projectService.findAll().size(), "Not all projects were found in index!"); } @Test public void shouldGetProject() throws Exception { Project project = projectService.getById(1); boolean condition = project.getTitle().equals(firstProject) && project.getId().equals(1); - assertTrue("Project was not found in database!", condition); + assertTrue(condition, "Project was not found in database!"); - assertEquals("Project was found but templates were not inserted!", 2, project.getTemplates().size()); - assertEquals("Project was found but templates were not inserted!", 2, project.getProcesses().size()); + assertEquals(2, project.getTemplates().size(), "Project was found but templates were not inserted!"); + assertEquals(2, project.getProcesses().size(), "Project was found but templates were not inserted!"); } @Test public void shouldGetAllProjects() throws Exception { List projects = projectService.getAll(); - assertEquals("Not all projects were found in database!", 3, projects.size()); + assertEquals(3, projects.size(), "Not all projects were found in database!"); } @Test @@ -124,7 +119,7 @@ public void shouldGetClientProjectsSortedByTitle() { @Test public void shouldGetAllProjectsInGivenRange() throws Exception { List projects = projectService.getAll(2, 10); - assertEquals("Not all projects were found in database!", 1, projects.size()); + assertEquals(1, projects.size(), "Not all projects were found in database!"); } @Test @@ -134,11 +129,10 @@ public void shouldRemoveProjectById() throws Exception { projectService.save(project); Integer projectId = project.getId(); Project foundProject = projectService.getById(projectId); - assertEquals("Additional project was not inserted in database!", "To Remove", foundProject.getTitle()); + assertEquals("To Remove", foundProject.getTitle(), "Additional project was not inserted in database!"); projectService.remove(foundProject); - exception.expect(DAOException.class); - projectService.getById(projectId); + assertThrows(DAOException.class, () -> projectService.getById(projectId)); } @Test @@ -148,30 +142,28 @@ public void shouldRemoveProjectByObject() throws Exception { projectService.save(project); Integer projectId = project.getId(); Project foundProject = projectService.getById(projectId); - assertEquals("Additional project was not inserted in database!", "To remove", foundProject.getTitle()); + assertEquals("To remove", foundProject.getTitle(), "Additional project was not inserted in database!"); projectService.remove(projectId); - exception.expect(DAOException.class); - projectService.getById(projectId); + assertThrows(DAOException.class, () -> projectService.getById(projectId)); } @Test public void shouldFindByTitle() throws DataException { - assertEquals(projectNotFound, 1, projectService.findByTitle(firstProject, true).size()); + assertEquals(1, projectService.findByTitle(firstProject, true).size(), projectNotFound); } @Test - public void shouldNotSaveProjectWithAlreadyExistingTitle() throws DataException { + public void shouldNotSaveProjectWithAlreadyExistingTitle() { Project project = new Project(); project.setTitle(firstProject); - exception.expect(DataException.class); - projectService.save(project); + assertThrows(DataException.class, () -> projectService.save(project)); } @Test public void shouldGetClientOfProject() throws Exception { Project project = projectService.getById(1); - assertEquals("Client names doesnt match", "First client", project.getClient().getName()); + assertEquals("First client", project.getClient().getName(), "Client names doesnt match"); } @Test @@ -179,6 +171,6 @@ public void findByIds() throws DataException { ProjectService projectService = ServiceManager.getProjectService(); QueryBuilder projectsForCurrentUserQuery = projectService.getProjectsForCurrentUserQuery(); List byQuery = projectService.findByQuery(projectsForCurrentUserQuery, true); - assertEquals("Wrong amount of projects found",2,byQuery.size()); + assertEquals(2, byQuery.size(), "Wrong amount of projects found"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/ProjectServiceTest.java b/Kitodo/src/test/java/org/kitodo/production/services/data/ProjectServiceTest.java index fbb4f02b6f5..7305e016746 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/ProjectServiceTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/ProjectServiceTest.java @@ -13,8 +13,10 @@ import java.io.IOException; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; import org.kitodo.config.enums.KitodoConfigFile; import org.kitodo.data.database.beans.Project; import org.kitodo.production.services.ServiceManager; @@ -27,15 +29,15 @@ public void testProjectForCompletness() throws IOException { // A project without dmsExportFormat, internal format or templates Project project = new Project(); - Assert.assertFalse("Project shouldn't be complete", projectService.isProjectComplete(project)); + assertFalse(projectService.isProjectComplete(project), "Project shouldn't be complete"); // Add title, still not complete project.setTitle("testProject"); - Assert.assertFalse("Project shouldn't be complete", projectService.isProjectComplete(project)); + assertFalse(projectService.isProjectComplete(project), "Project shouldn't be complete"); // Add xmls to complete project KitodoConfigFile.PROJECT_CONFIGURATION.getFile().createNewFile(); - Assert.assertTrue("Project should be complete", projectService.isProjectComplete(project)); + assertTrue(projectService.isProjectComplete(project), "Project should be complete"); KitodoConfigFile.PROJECT_CONFIGURATION.getFile().delete(); } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/PropertyServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/PropertyServiceIT.java index 398f20b37ba..e841a419f05 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/PropertyServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/PropertyServiceIT.java @@ -12,15 +12,14 @@ package org.kitodo.production.services.data; import static org.awaitility.Awaitility.await; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Property; import org.kitodo.data.database.exceptions.DAOException; @@ -33,32 +32,29 @@ public class PropertyServiceIT { private static final PropertyService propertyService = ServiceManager.getPropertyService(); - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); MockDatabase.setUpAwaitility(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); } - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void shouldCountAllProperties() { await().untilAsserted( - () -> assertEquals("Properties were not counted correctly!", Long.valueOf(8), propertyService.countDatabaseRows())); + () -> assertEquals(Long.valueOf(8), propertyService.countDatabaseRows(), "Properties were not counted correctly!")); } @Test public void shouldCountAllDatabaseRowsForProperties() throws Exception { Long amount = propertyService.countDatabaseRows(); - assertEquals("Properties were not counted correctly!", Long.valueOf(8), amount); + assertEquals(Long.valueOf(8), amount, "Properties were not counted correctly!"); } @Test @@ -66,11 +62,11 @@ public void shouldGetProcessProperty() throws Exception { Property processProperty = propertyService.getById(1); String actual = processProperty.getTitle(); String expected = "Process Property"; - assertEquals("Process property was not found in database - title doesn't match!", expected, actual); + assertEquals(expected, actual, "Process property was not found in database - title doesn't match!"); actual = processProperty.getValue(); expected = "first value"; - assertEquals("Process property was not found in database - value doesn't match!", expected, actual); + assertEquals(expected, actual, "Process property was not found in database - value doesn't match!"); } @Test @@ -78,11 +74,11 @@ public void shouldGetTemplateProperty() throws Exception { Property templateProperty = propertyService.getById(7); String actual = templateProperty.getTitle(); String expected = "firstTemplate title"; - assertEquals("Template property was not found in database - title doesn't match!", expected, actual); + assertEquals(expected, actual, "Template property was not found in database - title doesn't match!"); actual = templateProperty.getValue(); expected = "first value"; - assertEquals("Template property was not found in database - value doesn't match!", expected, actual); + assertEquals(expected, actual, "Template property was not found in database - value doesn't match!"); } @Test @@ -90,11 +86,11 @@ public void shouldGetWorkpieceProperty() throws Exception { Property workpieceProperty = propertyService.getById(5); String actual = workpieceProperty.getTitle(); String expected = "FirstWorkpiece Property"; - assertEquals("Workpiece property was not found in database - title doesn't match!", expected, actual); + assertEquals(expected, actual, "Workpiece property was not found in database - title doesn't match!"); actual = workpieceProperty.getValue(); expected = "first value"; - assertEquals("Workpiece property was not found in database - value doesn't match!", expected, actual); + assertEquals(expected, actual, "Workpiece property was not found in database - value doesn't match!"); } /** @@ -102,28 +98,27 @@ public void shouldGetWorkpieceProperty() throws Exception { */ @Test public void shouldFindDistinctTitles() { - assertEquals("Incorrect size of distinct titles for process properties!", 6, - propertyService.findDistinctTitles().size()); + assertEquals(6, propertyService.findDistinctTitles().size(), "Incorrect size of distinct titles for process properties!"); List processPropertiesTitlesDistinct = propertyService.findDistinctTitles(); String title = processPropertiesTitlesDistinct.get(0); - assertEquals("Incorrect sorting of distinct titles for process properties!", "FirstWorkpiece Property", title); + assertEquals("FirstWorkpiece Property", title, "Incorrect sorting of distinct titles for process properties!"); title = processPropertiesTitlesDistinct.get(1); - assertEquals("Incorrect sorting of distinct titles for process properties!", "Korrektur notwendig", title); + assertEquals("Korrektur notwendig", title, "Incorrect sorting of distinct titles for process properties!"); } @Test public void shouldGetAllProperties() throws Exception { List properties = propertyService.getAll(); - assertEquals("Not all properties were found in database!", 8, properties.size()); + assertEquals(8, properties.size(), "Not all properties were found in database!"); } @Test public void shouldGetAllPropertiesInGivenRange() throws Exception { List properties = propertyService.getAll(2, 6); - assertEquals("Not all properties were found in database!", 6, properties.size()); + assertEquals(6, properties.size(), "Not all properties were found in database!"); } @Test @@ -131,49 +126,40 @@ public void shouldRemoveProperty() throws Exception { Property property = new Property(); property.setTitle("To Remove"); propertyService.saveToDatabase(property); - Property foundProperty = propertyService.getById(9); - assertEquals("Additional property was not inserted in database!", "To Remove", foundProperty.getTitle()); - - propertyService.saveToDatabase(foundProperty); - exception.expect(DAOException.class); - propertyService.getById(9); + Property foundProperty = propertyService.getById(property.getId()); + assertEquals("To Remove", foundProperty.getTitle(), "Additional property was not inserted in database!"); property = new Property(); property.setTitle("To remove"); propertyService.saveToDatabase(property); foundProperty = propertyService.getById(10); - assertEquals("Additional property was not inserted in database!", "To remove", foundProperty.getTitle()); + assertEquals("To remove", foundProperty.getTitle(), "Additional property was not inserted in database!"); propertyService.removeFromDatabase(10); - exception.expect(DAOException.class); - propertyService.getById(10); + assertThrows(DAOException.class, () -> propertyService.getById(10)); } @Test public void shouldFindById() throws DAOException { Integer expected = 1; - assertEquals("Property was not found in database!", expected, propertyService.getById(1).getId()); + assertEquals(expected, propertyService.getById(1).getId(), "Property was not found in database!"); } @Test public void shouldFindByValue() { - assertEquals("Properties were not found in database!", 2, - propertyService.findByValue("second").size()); + assertEquals(2, propertyService.findByValue("second").size(), "Properties were not found in database!"); - assertEquals("Property was not found in database!", 1, - propertyService.findByValue("second value").size()); + assertEquals(1, propertyService.findByValue("second value").size(), "Property was not found in database!"); } @Test public void shouldFindByTitleAndValue() { - assertEquals("Property was not found in database!", 1, - propertyService.findByTitleAndValue("Korrektur notwendig", "second value").size()); + assertEquals(1, propertyService.findByTitleAndValue("Korrektur notwendig", "second value").size(), "Property was not found in database!"); } @Test public void shouldNotFindByTitleAndValue() { - assertEquals("Property was found in database!", 0, - propertyService.findByTitleAndValue("Korrektur notwendig", "third").size()); + assertEquals(0, propertyService.findByTitleAndValue("Korrektur notwendig", "third").size(), "Property was found in database!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/RoleServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/RoleServiceIT.java index a7385878d32..d88b9b6c97d 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/RoleServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/RoleServiceIT.java @@ -11,16 +11,15 @@ package org.kitodo.production.services.data; -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; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Authority; import org.kitodo.data.database.beans.User; @@ -39,46 +38,42 @@ public class RoleServiceIT { private static final String WRONG_NUMBER_OF_ROLES = "Amount of roles assigned to client is incorrect!"; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertRolesFull(); MockDatabase.setUpAwaitility(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); } - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void shouldCountAllDatabaseRowsForRoles() throws Exception { Long amount = roleService.countDatabaseRows(); - assertEquals("Roles were not counted correctly!", Long.valueOf(EXPECTED_ROLES_COUNT), amount); + assertEquals(Long.valueOf(EXPECTED_ROLES_COUNT), amount, "Roles were not counted correctly!"); } @Test public void shouldGetRole() throws Exception { Role role = roleService.getById(1); - assertEquals("Role title is not matching", "Admin", role.getTitle()); - assertEquals("Role first authorities title is not matching", "viewClient_globalAssignable", - role.getAuthorities().get(1).getTitle()); + assertEquals("Admin", role.getTitle(), "Role title is not matching"); + assertEquals("viewClient_globalAssignable", role.getAuthorities().get(1).getTitle(), "Role first authorities title is not matching"); } @Test public void shouldGetAllRoles() throws Exception { List roles = roleService.getAll(); - assertEquals("Not all user's roles were found in database!", EXPECTED_ROLES_COUNT, roles.size()); + assertEquals(EXPECTED_ROLES_COUNT, roles.size(), "Not all user's roles were found in database!"); } @Test public void shouldGetAllRolesInGivenRange() throws Exception { List roles = roleService.getAll(1, 10); - assertEquals("Not all user's roles were found in database!", 8, roles.size()); + assertEquals(8, roles.size(), "Not all user's roles were found in database!"); } @Test @@ -87,22 +82,19 @@ public void shouldRemoveRole() throws Exception { role.setTitle("To Remove"); roleService.saveToDatabase(role); Role foundRole = roleService.getByQuery("FROM Role WHERE title = 'To Remove'").get(0); - assertEquals("Additional user group was not inserted in database!", "To Remove", foundRole.getTitle()); + assertEquals("To Remove", foundRole.getTitle(), "Additional user group was not inserted in database!"); roleService.removeFromDatabase(foundRole); - exception.expect(DAOException.class); - exception.expectMessage(""); - roleService.getById(foundRole.getId()); + Role finalFoundRole = foundRole; + assertThrows(DAOException.class, () -> roleService.getById(finalFoundRole.getId())); role = new Role(); role.setTitle("To remove"); roleService.saveToDatabase(role); foundRole = roleService.getByQuery("FROM Role WHERE title = 'To remove'").get(0); - assertEquals("Additional user group was not inserted in database!", "To remove", foundRole.getTitle()); + assertEquals("To remove", foundRole.getTitle(), "Additional user group was not inserted in database!"); roleService.removeFromDatabase(foundRole.getId()); - exception.expect(DAOException.class); - exception.expectMessage(""); } @Test @@ -119,14 +111,14 @@ public void shouldRemoveRoleButNotUser() throws Exception { roleService.saveToDatabase(role); Role foundRole = roleService.getByQuery("FROM Role WHERE title = 'Cascados Group'").get(0); - assertEquals("Additional user was not inserted in database!", "Cascados Group", foundRole.getTitle()); + assertEquals("Cascados Group", foundRole.getTitle(), "Additional user was not inserted in database!"); roleService.removeFromDatabase(foundRole); int size = roleService.getByQuery("FROM Role WHERE title = 'Cascados Group'").size(); - assertEquals("Additional user was not removed from database!", 0, size); + assertEquals(0, size, "Additional user was not removed from database!"); size = userService.getByQuery("FROM User WHERE login = 'Cascados'").size(); - assertEquals("User was removed from database!", 1, size); + assertEquals(1, size, "User was removed from database!"); userService.removeFromDatabase(userService.getByQuery("FROM User WHERE login = 'Cascados'").get(0)); } @@ -136,15 +128,14 @@ public void shouldGetAuthorizationsAsString() throws Exception { Role role = roleService.getById(1); int actual = roleService.getAuthorizationsAsString(role).size(); int expected = 34; - assertEquals("Number of authority strings doesn't match!", expected, actual); + assertEquals(expected, actual, "Number of authority strings doesn't match!"); } @Test public void shouldGetAuthorities() throws Exception { Role role = roleService.getById(1); List actual = role.getAuthorities(); - assertEquals("Permission strings doesn't match to given plain text!", "viewClient_globalAssignable", - actual.get(1).getTitle()); + assertEquals("viewClient_globalAssignable", actual.get(1).getTitle(), "Permission strings doesn't match to given plain text!"); } @Test @@ -164,27 +155,26 @@ public void shouldSaveAndRemoveAuthorizationForRole() throws Exception { role = roleService.getById(1); List actual = roleService.getAuthorizationsAsString(role); - assertTrue("Title of Authority was not found in user group authorities!", - actual.contains(authority.getTitle())); + assertTrue(actual.contains(authority.getTitle()), "Title of Authority was not found in user group authorities!"); } @Test public void shouldGetAllRolesByClientIds() { List roles = roleService.getAllRolesByClientId(1); - assertEquals(WRONG_NUMBER_OF_ROLES, 7, roles.size()); + assertEquals(7, roles.size(), WRONG_NUMBER_OF_ROLES); roles = roleService.getAllRolesByClientId(2); - assertEquals(WRONG_NUMBER_OF_ROLES, 2, roles.size()); + assertEquals(2, roles.size(), WRONG_NUMBER_OF_ROLES); } @Test public void shouldGetAllAvailableForAssignToUser() throws Exception { User user = ServiceManager.getUserService().getById(1); List roles = roleService.getAllAvailableForAssignToUser(user); - assertEquals(WRONG_NUMBER_OF_ROLES, 3, roles.size()); + assertEquals(3, roles.size(), WRONG_NUMBER_OF_ROLES); user = ServiceManager.getUserService().getById(2); roles = roleService.getAllAvailableForAssignToUser(user); - assertEquals(WRONG_NUMBER_OF_ROLES, 7, roles.size()); + assertEquals(7, roles.size(), WRONG_NUMBER_OF_ROLES); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/RulesetServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/RulesetServiceIT.java index 96fac99bf0b..4f38ac512b9 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/RulesetServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/RulesetServiceIT.java @@ -13,18 +13,17 @@ import static org.awaitility.Awaitility.await; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; -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; import java.util.List; import org.elasticsearch.index.query.Operator; import org.elasticsearch.index.query.QueryBuilder; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.data.database.beans.Ruleset; @@ -44,7 +43,7 @@ public class RulesetServiceIT { private static final String slubDD = "SLUBDD"; private static final String rulesetNotFound = "Ruleset was not found in index!"; - @Before + @BeforeEach public void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertClients(); @@ -58,117 +57,110 @@ public void prepareDatabase() throws Exception { }); } - @After + @AfterEach public void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); } - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void shouldCountAllRulesets() throws DataException { - assertEquals("Rulesets were not counted correctly!", Long.valueOf(3), rulesetService.count()); + assertEquals(Long.valueOf(3), rulesetService.count(), "Rulesets were not counted correctly!"); } @Test public void shouldCountAllRulesetsAccordingToQuery() throws DataException { QueryBuilder query = matchQuery("title", slubDD).operator(Operator.AND); - assertEquals("Rulesets were not counted correctly!", Long.valueOf(1), rulesetService.count(query)); + assertEquals(Long.valueOf(1), rulesetService.count(query), "Rulesets were not counted correctly!"); } @Test public void shouldCountAllDatabaseRowsForRulesets() throws Exception { Long amount = rulesetService.countDatabaseRows(); - assertEquals("Rulesets were not counted correctly!", Long.valueOf(3), amount); + assertEquals(Long.valueOf(3), amount, "Rulesets were not counted correctly!"); } @Test public void shouldFindRuleset() throws Exception { Ruleset ruleset = rulesetService.getById(1); boolean condition = ruleset.getTitle().equals(slubDD) && ruleset.getFile().equals("ruleset_test.xml"); - assertTrue("Ruleset was not found in database!", condition); + assertTrue(condition, "Ruleset was not found in database!"); } @Test public void shouldFindAllRulesets() throws Exception { List rulesets = rulesetService.getAll(); - assertEquals("Not all rulesets were found in database!", 3, rulesets.size()); + assertEquals(3, rulesets.size(), "Not all rulesets were found in database!"); } @Test public void shouldGetAllRulesetsInGivenRange() throws Exception { List rulesets = rulesetService.getAll(1, 10); - assertEquals("Not all rulesets were found in database!", 2, rulesets.size()); + assertEquals(2, rulesets.size(), "Not all rulesets were found in database!"); } @Test public void shouldFindById() throws DataException { - assertEquals(rulesetNotFound, slubDD, rulesetService.findById(1).getTitle()); + assertEquals(slubDD, rulesetService.findById(1).getTitle(), rulesetNotFound); } @Test public void shouldFindByTitle() throws DataException { - assertEquals(rulesetNotFound, 1, rulesetService.findByTitle(slubDD, true).size()); + assertEquals(1, rulesetService.findByTitle(slubDD, true).size(), rulesetNotFound); } @Test public void shouldFindByFile() throws DataException { String expected = "ruleset_test.xml"; - assertEquals(rulesetNotFound, expected, - rulesetService.findByFile("ruleset_test.xml").get(RulesetTypeField.FILE.getKey())); + assertEquals(expected, rulesetService.findByFile("ruleset_test.xml").get(RulesetTypeField.FILE.getKey()), rulesetNotFound); } @Test public void shouldFindManyByClientId() throws DataException { - assertEquals("Rulesets were not found in index!", 2, rulesetService.findByClientId(1).size()); + assertEquals(2, rulesetService.findByClientId(1).size(), "Rulesets were not found in index!"); } @Test public void shouldFindOneByClientId() throws DataException, DAOException { SecurityTestUtils.addUserDataToSecurityContext(new User(), 2); - assertEquals(rulesetNotFound, 1, rulesetService.findByClientId(2).size()); + assertEquals(1, rulesetService.findByClientId(2).size(), rulesetNotFound); } @Test public void shouldNotFindByClientId() throws DataException { - assertEquals("Ruleset was found in index!", 0, rulesetService.findByClientId(3).size()); + assertEquals(0, rulesetService.findByClientId(3).size(), "Ruleset was found in index!"); } @Test public void shouldFindByTitleAndFile() throws DataException { Integer expected = 2; - assertEquals(rulesetNotFound, expected, - rulesetService.getIdFromJSONObject(rulesetService.findByTitleAndFile("SUBHH", "ruleset_subhh.xml"))); + assertEquals(expected, rulesetService.getIdFromJSONObject(rulesetService.findByTitleAndFile("SUBHH", "ruleset_subhh.xml")), rulesetNotFound); } @Test public void shouldNotFindByTitleAndFile() throws DataException { Integer expected = 0; - assertEquals("Ruleset was found in index!", expected, - rulesetService.getIdFromJSONObject(rulesetService.findByTitleAndFile(slubDD, "none"))); + assertEquals(expected, rulesetService.getIdFromJSONObject(rulesetService.findByTitleAndFile(slubDD, "none")), "Ruleset was found in index!"); } @Test public void shouldFindManyByTitleOrFile() throws DataException { - assertEquals("Rulesets were not found in index!", 2, - rulesetService.findByTitleOrFile(slubDD, "ruleset_subhh.xml").size()); + assertEquals(2, rulesetService.findByTitleOrFile(slubDD, "ruleset_subhh.xml").size(), "Rulesets were not found in index!"); } @Test public void shouldFindOneByTitleOrFile() throws DataException { - assertEquals(rulesetNotFound, 1, rulesetService.findByTitleOrFile("default", "ruleset_subhh.xml").size()); + assertEquals(1, rulesetService.findByTitleOrFile("default", "ruleset_subhh.xml").size(), rulesetNotFound); } @Test public void shouldNotFindByTitleOrFile() throws DataException { - assertEquals("Some rulesets were found in index!", 0, rulesetService.findByTitleOrFile("none", "none").size()); + assertEquals(0, rulesetService.findByTitleOrFile("none", "none").size(), "Some rulesets were found in index!"); } @Test public void shouldFindAllRulesetsDocuments() throws DataException { - assertEquals("Not all rulesets were found in index!", 3, rulesetService.findAllDocuments().size()); + assertEquals(3, rulesetService.findAllDocuments().size(), "Not all rulesets were found in index!"); } @Test @@ -177,20 +169,18 @@ public void shouldRemoveRuleset() throws Exception { ruleset.setTitle("To Remove"); rulesetService.save(ruleset); Ruleset foundRuleset = rulesetService.getById(4); - assertEquals("Additional ruleset was not inserted in database!", "To Remove", foundRuleset.getTitle()); + assertEquals("To Remove", foundRuleset.getTitle(), "Additional ruleset was not inserted in database!"); rulesetService.remove(ruleset); - exception.expect(DAOException.class); - rulesetService.getById(4); + assertThrows(DAOException.class, () -> rulesetService.getById(4)); ruleset = new Ruleset(); ruleset.setTitle("To remove"); rulesetService.save(ruleset); foundRuleset = rulesetService.getById(5); - assertEquals("Additional ruleset was not inserted in database!", "To remove", foundRuleset.getTitle()); + assertEquals("To remove", foundRuleset.getTitle(), "Additional ruleset was not inserted in database!"); rulesetService.remove(5); - exception.expect(DAOException.class); - rulesetService.getById(5); + assertThrows(DAOException.class, () -> rulesetService.getById(5)); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/TaskServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/TaskServiceIT.java index 6b2e2ef6f2a..bebd6aa4d0e 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/TaskServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/TaskServiceIT.java @@ -12,16 +12,15 @@ package org.kitodo.production.services.data; import static org.awaitility.Awaitility.await; -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; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.data.database.beans.Task; import org.kitodo.data.database.enums.TaskStatus; @@ -37,62 +36,58 @@ public class TaskServiceIT { private static final TaskService taskService = ServiceManager.getTaskService(); private static final int AMOUNT_TASKS = 13; - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); MockDatabase.setUpAwaitility(); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); } - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Test public void shouldCountAllTasks() { await().untilAsserted( - () -> assertEquals("Tasks were not counted correctly!", Long.valueOf(AMOUNT_TASKS), taskService.count())); + () -> assertEquals(Long.valueOf(AMOUNT_TASKS), taskService.count(), "Tasks were not counted correctly!")); } @Test public void shouldCountAllDatabaseRowsForTasks() throws Exception { Long amount = taskService.countDatabaseRows(); - assertEquals("Tasks were not counted correctly!", Long.valueOf(AMOUNT_TASKS), amount); + assertEquals(Long.valueOf(AMOUNT_TASKS), amount, "Tasks were not counted correctly!"); } @Test public void shouldFindTask() { - await().untilAsserted(() -> assertEquals("Task was not found in index!", "Finished", - taskService.findById(1).getTitle())); + await().untilAsserted(() -> assertEquals("Finished", taskService.findById(1).getTitle(), "Task was not found in index!")); } @Test public void shouldFindAllTasks() { await().untilAsserted( - () -> assertEquals("Not all tasks were found in index!", AMOUNT_TASKS, taskService.findAll().size())); + () -> assertEquals(AMOUNT_TASKS, taskService.findAll().size(), "Not all tasks were found in index!")); } @Test public void shouldGetTask() throws Exception { Task task = taskService.getById(1); - assertEquals("Task was not found in database!", "Finished", task.getTitle()); + assertEquals("Finished", task.getTitle(), "Task was not found in database!"); } @Test public void shouldGetAllTasks() throws Exception { List tasks = taskService.getAll(); - assertEquals("Not all tasks were found in database!", AMOUNT_TASKS, tasks.size()); + assertEquals(AMOUNT_TASKS, tasks.size(), "Not all tasks were found in database!"); } @Test public void shouldGetAllTasksInGivenRange() throws Exception { List tasks = taskService.getAll(1, 3); - assertEquals("Not all tasks were found in database!", 3, tasks.size()); + assertEquals(3, tasks.size(), "Not all tasks were found in database!"); } @Test @@ -139,22 +134,20 @@ public void shouldRemoveTask() throws Exception { task.setProcessingStatus(TaskStatus.OPEN); taskService.save(task); Task foundTask = taskService.getById(14); - assertEquals("Additional task was not inserted in database!", "To Remove", foundTask.getTitle()); + assertEquals("To Remove", foundTask.getTitle(), "Additional task was not inserted in database!"); taskService.remove(foundTask); - exception.expect(DAOException.class); - taskService.getById(14); + assertThrows(DAOException.class, () -> taskService.getById(14)); task = new Task(); task.setTitle("To remove"); task.setProcessingStatus(TaskStatus.OPEN); taskService.save(task); foundTask = taskService.getById(15); - assertEquals("Additional task was not inserted in database!", "To remove", foundTask.getTitle()); + assertEquals("To remove", foundTask.getTitle(), "Additional task was not inserted in database!"); taskService.remove(15); - exception.expect(DAOException.class); - taskService.getById(14); + assertThrows(DAOException.class, () -> taskService.getById(14)); } @Test @@ -162,7 +155,7 @@ public void shouldGetProcessingBeginAsFormattedString() throws Exception { Task task = taskService.getById(1); String expected = "2016-08-20 00:00:00"; String actual = taskService.getProcessingBeginAsFormattedString(task); - assertEquals("Processing time date is incorrect!", expected, actual); + assertEquals(expected, actual, "Processing time date is incorrect!"); } @Test @@ -170,12 +163,12 @@ public void shouldGetProcessingTimeAsFormattedString() throws Exception { Task task = taskService.getById(1); String expected = "2016-09-24 00:00:00"; String actual = taskService.getProcessingTimeAsFormattedString(task); - assertEquals("Processing time date is incorrect!", expected, actual); + assertEquals(expected, actual, "Processing time date is incorrect!"); task = taskService.getById(2); expected = "-"; actual = taskService.getProcessingTimeAsFormattedString(task); - assertEquals("Processing time date is incorrect!", expected, actual); + assertEquals(expected, actual, "Processing time date is incorrect!"); } @Test @@ -183,13 +176,13 @@ public void shouldGetProcessingEndAsFormattedString() throws Exception { Task task = taskService.getById(1); String expected = "2016-09-24 00:00:00"; String actual = taskService.getProcessingEndAsFormattedString(task); - assertEquals("Processing end date is incorrect!", expected, actual); + assertEquals(expected, actual, "Processing end date is incorrect!"); } @Test public void shouldGetCorrectionStep() throws Exception { Task task = taskService.getById(8); - assertTrue("Task is not a correction task!", task.isRepeatOnCorrection()); + assertTrue(task.isRepeatOnCorrection(), "Task is not a correction task!"); } @Test @@ -197,7 +190,7 @@ public void shouldGetNormalizedTitle() throws Exception { Task task = taskService.getById(12); String expected = "Processed__and__Some"; String actual = Helper.getNormalizedTitle(task.getTitle()); - assertEquals("Normalized title of task doesn't match given plain text!", expected, actual); + assertEquals(expected, actual, "Normalized title of task doesn't match given plain text!"); } @Test @@ -205,12 +198,12 @@ public void shouldGetTitleWithUserName() throws Exception { Task task = taskService.getById(6); String expected = "Finished (Kowalski, Jan)"; String actual = taskService.getTitleWithUserName(task); - assertEquals("Task's title with user name doesn't match given plain text!", expected, actual); + assertEquals(expected, actual, "Task's title with user name doesn't match given plain text!"); task = taskService.getById(3); expected = "Progress"; actual = taskService.getTitleWithUserName(task); - assertEquals("Task's title with user name doesn't match given plain text!", expected, actual); + assertEquals(expected, actual, "Task's title with user name doesn't match given plain text!"); } @Test @@ -223,24 +216,24 @@ public void shouldGetAllTasksInBetween() { List tasks = taskService.getAllTasksInBetween(2, 4, 1); int actual = tasks.size(); int expected = 1; - assertEquals("Task's list size is incorrect!", expected, actual); + assertEquals(expected, actual, "Task's list size is incorrect!"); Task task = tasks.get(0); - assertEquals("",8, task.getId().intValue()); - assertEquals("","Progress", task.getTitle()); - assertEquals("",3, task.getOrdering().intValue()); + assertEquals(8, task.getId().intValue(), ""); + assertEquals("Progress", task.getTitle(), ""); + assertEquals(3, task.getOrdering().intValue(), ""); } @Test public void shouldGetNextTasksForProblemSolution() { List tasks = taskService.getNextTasksForProblemSolution(2, 1); int actual = tasks.size(); - assertEquals("Task's list size is incorrect!", 3, actual); + assertEquals(3, actual, "Task's list size is incorrect!"); Task task = tasks.get(0); - assertEquals("",8, task.getId().intValue()); - assertEquals("","Progress", task.getTitle()); - assertEquals("",3, task.getOrdering().intValue()); + assertEquals(8, task.getId().intValue(), ""); + assertEquals("Progress", task.getTitle(), ""); + assertEquals(3, task.getOrdering().intValue(), ""); } @Test @@ -248,12 +241,12 @@ public void shouldGetPreviousTaskForProblemReporting() { List tasks = taskService.getPreviousTasksForProblemReporting(2, 1); int actual = tasks.size(); int expected = 1; - assertEquals("Task's list size is incorrect!", expected, actual); + assertEquals(expected, actual, "Task's list size is incorrect!"); Task task = tasks.get(0); - assertEquals("",6, task.getId().intValue()); - assertEquals("","Finished", task.getTitle()); - assertEquals("",1, task.getOrdering().intValue()); + assertEquals(6, task.getId().intValue(), ""); + assertEquals("Finished", task.getTitle(), ""); + assertEquals(1, task.getOrdering().intValue(), ""); } /** @@ -268,15 +261,15 @@ public void shouldGetPreviousTaskForProblemReporting() { public void shouldFindDistinctTitles() throws Exception { List taskTitlesDistinct = taskService.findTaskTitlesDistinct(); int size = taskTitlesDistinct.size(); - assertEquals("Incorrect size of distinct titles for tasks!", 9, size); + assertEquals(9, size, "Incorrect size of distinct titles for tasks!"); String title = taskTitlesDistinct.get(0); - assertEquals("Incorrect sorting of distinct titles for tasks!", "additional", title); + assertEquals("additional", title, "Incorrect sorting of distinct titles for tasks!"); title = taskTitlesDistinct.get(1); - assertEquals("Incorrect sorting of distinct titles for tasks!", "blocking", title); + assertEquals("blocking", title, "Incorrect sorting of distinct titles for tasks!"); title = taskTitlesDistinct.get(2); - assertEquals("Incorrect sorting of distinct titles for tasks!", "closed", title); + assertEquals("closed", title, "Incorrect sorting of distinct titles for tasks!"); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/TemplateServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/TemplateServiceIT.java index 5352c717501..57f7f415b89 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/TemplateServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/TemplateServiceIT.java @@ -11,11 +11,17 @@ package org.kitodo.production.services.data; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; import org.kitodo.data.database.beans.Template; @@ -23,22 +29,18 @@ import org.kitodo.production.dto.TemplateDTO; import org.kitodo.production.services.ServiceManager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - public class TemplateServiceIT { private static final TemplateService templateService = ServiceManager.getTemplateService(); - @BeforeClass + @BeforeAll public static void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesFull(); SecurityTestUtils.addUserDataToSecurityContext(ServiceManager.getUserService().getById(1), 1); } - @AfterClass + @AfterAll public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); @@ -47,57 +49,57 @@ public static void cleanDatabase() throws Exception { @Test public void shouldCountAllTemplates() throws Exception { Long amount = templateService.count(); - assertEquals("Templates were not counted correctly!", Long.valueOf(4), amount); + assertEquals(Long.valueOf(4), amount, "Templates were not counted correctly!"); } @Test public void shouldFindAll() throws Exception { List templates = templateService.findAll(); - assertEquals("Found incorrect amount of templates!", 4, templates.size()); + assertEquals(4, templates.size(), "Found incorrect amount of templates!"); } @Test public void shouldGetTemplate() throws Exception { Template template = templateService.getById(1); boolean condition = template.getTitle().equals("First template") && template.getId().equals(1); - assertTrue("Template was not found in database!", condition); + assertTrue(condition, "Template was not found in database!"); - assertEquals("Template was found but processes were not inserted!", 2, template.getProcesses().size()); - assertEquals("Template was found but tasks were not inserted!", 5, template.getTasks().size()); + assertEquals(2, template.getProcesses().size(), "Template was found but processes were not inserted!"); + assertEquals(5, template.getTasks().size(), "Template was found but tasks were not inserted!"); } @Test public void shouldGetTemplates() throws Exception { List