diff --git a/Kitodo/src/main/java/org/kitodo/production/model/bibliography/course/Course.java b/Kitodo/src/main/java/org/kitodo/production/model/bibliography/course/Course.java index fd78a4f4a10..6bab6583e4c 100644 --- a/Kitodo/src/main/java/org/kitodo/production/model/bibliography/course/Course.java +++ b/Kitodo/src/main/java/org/kitodo/production/model/bibliography/course/Course.java @@ -927,4 +927,14 @@ public void setYearName(String yearName) { public void setYearStart(MonthDay yearStart) { this.yearStart = yearStart; } + + /** + * Returns a shallow copy of this Course instance. + * + * @return a clone of this Course instance + */ + @Override + public Course clone() { + return (Course) super.clone(); + } } diff --git a/Kitodo/src/test/java/org/kitodo/production/model/bibliography/course/CourseTest.java b/Kitodo/src/test/java/org/kitodo/production/model/bibliography/course/CourseTest.java new file mode 100644 index 00000000000..4efe59f686e --- /dev/null +++ b/Kitodo/src/test/java/org/kitodo/production/model/bibliography/course/CourseTest.java @@ -0,0 +1,54 @@ +/* + * (c) Kitodo. Key to digital objects e. V. + * + * 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.model.bibliography.course; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; + +import javax.xml.parsers.ParserConfigurationException; + +import org.junit.jupiter.api.Test; +import org.kitodo.production.helper.XMLUtils; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +public class CourseTest { + + @Test + public void testCloneMethod() throws IOException, ParserConfigurationException, SAXException { + String xmlString = new String(Files.readAllBytes(new File("src/test/resources/newspaper-course.xml").toPath())); + Document xmlDocument = XMLUtils.parseXMLString(xmlString); + Course course = new Course(xmlDocument); + + // assert / check some data from the xml file + assertEquals(23L, course.getIndividualIssues().size()); + assertEquals(23, course.countIndividualIssues()); + assertEquals("", course.getYearName()); + + // clone course + Course clonedCourse = course.clone(); + // courses should have same data + assertEquals(course.countIndividualIssues(), clonedCourse.countIndividualIssues()); + assertEquals(course.getNumberOfProcesses(), clonedCourse.getNumberOfProcesses()); + assertEquals(course.getYearName(), clonedCourse.getYearName()); + + // change year name of not cloned course + course.setYearName("Year 2024"); + // year name should now differ + assertEquals("", clonedCourse.getYearName()); + assertNotEquals(course.getYearName(), clonedCourse.getYearName()); + } +} diff --git a/Kitodo/src/test/resources/newspaper-course.xml b/Kitodo/src/test/resources/newspaper-course.xml new file mode 100644 index 00000000000..7ea2b05baec --- /dev/null +++ b/Kitodo/src/test/resources/newspaper-course.xml @@ -0,0 +1,133 @@ + + + + Die Zeitung erschien vom 1. Januar 2024 bis zum 31. Januar 2024 regelmäßig an allen Montagen, Dienstagen, Mittwochen, Donnerstagen und Freitagen. + + + + <appeared date="2024-01-01"/> + + + + + <appeared date="2024-01-02"/> + + + + + <appeared date="2024-01-03"/> + + + + + <appeared date="2024-01-04"/> + + + + + <appeared date="2024-01-05"/> + + + + + <appeared date="2024-01-08"/> + + + + + <appeared date="2024-01-09"/> + + + + + <appeared date="2024-01-10"/> + + + + + <appeared date="2024-01-11"/> + + + + + <appeared date="2024-01-12"/> + + + + + <appeared date="2024-01-15"/> + + + + + <appeared date="2024-01-16"/> + + + + + <appeared date="2024-01-17"/> + + + + + <appeared date="2024-01-18"/> + + + + + <appeared date="2024-01-19"/> + + + + + <appeared date="2024-01-22"/> + + + + + <appeared date="2024-01-23"/> + + + + + <appeared date="2024-01-24"/> + + + + + <appeared date="2024-01-25"/> + + + + + <appeared date="2024-01-26"/> + + + + + <appeared date="2024-01-29"/> + + + + + <appeared date="2024-01-30"/> + + + + + <appeared date="2024-01-31"/> + + + +