Skip to content

Commit

Permalink
Merge pull request kitodo#5977 from slub/add_clone_to_course
Browse files Browse the repository at this point in the history
Add missing clone method to Course class
  • Loading branch information
solth authored May 14, 2024
2 parents 47619d8 + adbbb28 commit c3af9a5
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* (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.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());
}
}
133 changes: 133 additions & 0 deletions Kitodo/src/test/resources/newspaper-course.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
*
* (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.
*
-->
<course>
<description>Die Zeitung erschien vom 1. Januar 2024 bis zum 31. Januar 2024 regelmäßig an allen Montagen, Dienstagen, Mittwochen, Donnerstagen und Freitagen.</description>
<processes>
<process>
<title index="1">
<appeared date="2024-01-01"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-02"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-03"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-04"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-05"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-08"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-09"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-10"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-11"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-12"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-15"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-16"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-17"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-18"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-19"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-22"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-23"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-24"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-25"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-26"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-29"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-30"/>
</title>
</process>
<process>
<title index="1">
<appeared date="2024-01-31"/>
</title>
</process>
</processes>
</course>

0 comments on commit c3af9a5

Please sign in to comment.