Skip to content

Commit

Permalink
Add tests for newspaper title shortening
Browse files Browse the repository at this point in the history
  • Loading branch information
henning-gerhardt committed Aug 16, 2021
1 parent 0b31134 commit 449f400
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public static void initializeMigration(Integer batchId) throws DAOException {
private void initializeMigrator(Process process, String newspaperIncludedStructalElementDivision)
throws IOException, ConfigurationException {

title = process.getTitle().replaceFirst(INDIVIDUAL_PART, "");
title = generateNewspaperShortTitle(process.getTitle());
logger.trace("Newspaper is: {}", title);
projectId = process.getProject().getId();
logger.trace("Project is: {} (ID {})", process.getProject().getTitle(), projectId);
Expand All @@ -286,6 +286,16 @@ private void initializeMigrator(Process process, String newspaperIncludedStructa
() -> new ConfigurationException(dayDivisionView.getId() + " has no dates metadata configuration!"));
}

/**
* Convert a newspaper like full title into its shorted version.
*
* @param newspaperFullTitle Newspaper like full title
* @return Shorted newspaper like title
*/
public String generateNewspaperShortTitle(String newspaperFullTitle) {
return newspaperFullTitle.replaceFirst(INDIVIDUAL_PART, "");
}

/**
* Converts one newspaper process.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/

package org.kitodo.production.migration;

import java.util.Arrays;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.kitodo.data.database.beans.Batch;


public class NewspaperProcessesMigratorTest {

@Test
public void checkNewspaperShortedTitleGeneration() {
Batch testBatch = new Batch();
testBatch.setTitle("Test Batch for Newspaper Shorted Title Generation");
testBatch.setId(1234);

List<String> listOfNewspaperTitles = Arrays.asList(
"Aben_399196951",
"DresNa_516710338",
"LeipMofT_1679165712",
"StaaHofM_1031939121",
"Zeit_425552225"
);

NewspaperProcessesMigrator migrator = new NewspaperProcessesMigrator(testBatch);
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));
}
}
}

0 comments on commit 449f400

Please sign in to comment.