forked from kitodo/kitodo-production
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test media partial form validation, code improvements
- Loading branch information
1 parent
56e25e1
commit 62f06bd
Showing
5 changed files
with
195 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
Kitodo/src/test/java/org/kitodo/production/forms/dataeditor/MediaPartialFormTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* (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.forms.dataeditor; | ||
|
||
import org.apache.commons.lang3.tuple.ImmutablePair; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.kitodo.api.dataformat.LogicalDivision; | ||
import org.kitodo.api.dataformat.MediaPartialView; | ||
import org.kitodo.api.dataformat.PhysicalDivision; | ||
import org.kitodo.api.dataformat.View; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class MediaPartialFormTest { | ||
|
||
@Test | ||
public void testValidation() throws NoSuchFieldException, IllegalAccessException { | ||
DataEditorForm dataEditorForm = mock(DataEditorForm.class); | ||
GalleryPanel galleryPanel = mock(GalleryPanel.class); | ||
MediaPartialsPanel mediaPartialsPanel = spy(new MediaPartialsPanel(dataEditorForm)); | ||
when(dataEditorForm.getGalleryPanel()).thenReturn(galleryPanel); | ||
when(galleryPanel.getMediaPartialsPanel()).thenReturn(mediaPartialsPanel); | ||
|
||
MediaPartialForm mediaPartialForm = spy(new MediaPartialForm(dataEditorForm)); | ||
|
||
Assert.assertFalse(mediaPartialForm.valid()); | ||
Assert.assertEquals("mediaPartialFormNoMedium", getValidationError(mediaPartialForm)); | ||
|
||
View view = mock(View.class); | ||
PhysicalDivision physicalDivision = spy(PhysicalDivision.class); | ||
String existingMediaPartialBegin = "00:00:30"; | ||
physicalDivision.setMediaPartialView(new MediaPartialView(existingMediaPartialBegin)); | ||
when(view.getPhysicalDivision()).thenReturn(physicalDivision); | ||
|
||
LogicalDivision childLogicalDivision = spy(LogicalDivision.class); | ||
childLogicalDivision.getViews().add(view); | ||
LogicalDivision logicalDivision = new LogicalDivision(); | ||
logicalDivision.getChildren().add(childLogicalDivision); | ||
|
||
when(mediaPartialForm.getMediaSelection()).thenReturn(new ImmutablePair<>(null, logicalDivision)); | ||
Assert.assertFalse(mediaPartialForm.valid()); | ||
Assert.assertEquals("mediaPartialFormMediaDurationEmpty", getValidationError(mediaPartialForm)); | ||
|
||
when(mediaPartialsPanel.getMediaDuration()).thenReturn("12345"); | ||
Assert.assertFalse(mediaPartialForm.valid()); | ||
Assert.assertEquals("mediaPartialFormMediaDurationWrongTimeFormat", getValidationError(mediaPartialForm)); | ||
|
||
when(mediaPartialsPanel.getMediaDuration()).thenReturn("00:01:00"); | ||
Assert.assertFalse(mediaPartialForm.valid()); | ||
Assert.assertEquals("mediaPartialFormStartEmpty", getValidationError(mediaPartialForm)); | ||
|
||
when(mediaPartialForm.getBegin()).thenReturn("12345"); | ||
Assert.assertFalse(mediaPartialForm.valid()); | ||
Assert.assertEquals("mediaPartialFormStartWrongTimeFormat", getValidationError(mediaPartialForm)); | ||
|
||
when(mediaPartialForm.getBegin()).thenReturn("00:02:00"); | ||
Assert.assertFalse(mediaPartialForm.valid()); | ||
Assert.assertEquals("mediaPartialFormStartLessThanMediaDuration", getValidationError(mediaPartialForm)); | ||
|
||
when(mediaPartialForm.getBegin()).thenReturn(existingMediaPartialBegin); | ||
Assert.assertFalse(mediaPartialForm.valid()); | ||
Assert.assertEquals("mediaPartialFormStartExists", getValidationError(mediaPartialForm)); | ||
|
||
when(mediaPartialForm.getBegin()).thenReturn("00:00:45"); | ||
Assert.assertTrue(mediaPartialForm.valid()); | ||
} | ||
|
||
private static String getValidationError(MediaPartialForm mediaPartialForm) | ||
throws NoSuchFieldException, IllegalAccessException { | ||
Field validationErrorField = mediaPartialForm.getClass().getDeclaredField("validationError"); | ||
validationErrorField.setAccessible(true); | ||
String validationError = (String) validationErrorField.get(mediaPartialForm); | ||
return validationError; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
Kitodo/src/test/java/org/kitodo/production/forms/dataeditor/MediaPartialPanelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* (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.forms.dataeditor; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.kitodo.DummyRulesetManagement; | ||
import org.kitodo.api.dataformat.LogicalDivision; | ||
import org.kitodo.api.dataformat.mets.LinkedMetsResource; | ||
import org.kitodo.data.database.beans.Process; | ||
import org.kitodo.data.database.beans.Template; | ||
import org.kitodo.data.database.beans.Workflow; | ||
import org.primefaces.model.DefaultTreeNode; | ||
import org.primefaces.model.TreeNode; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
import java.net.URI; | ||
|
||
public class MediaPartialPanelTest { | ||
|
||
@Test | ||
public void testBuildStructureTreeRecursively() throws Exception { | ||
DataEditorForm dummyDataEditorForm = new DataEditorForm(); | ||
Process process = new Process(); | ||
Template template = new Template(); | ||
template.setWorkflow(new Workflow()); | ||
process.setTemplate(template); | ||
dummyDataEditorForm.setProcess(process); | ||
Field ruleset = DataEditorForm.class.getDeclaredField("ruleset"); | ||
ruleset.setAccessible(true); | ||
ruleset.set(dummyDataEditorForm, new DummyRulesetManagement()); | ||
final StructurePanel underTest = new StructurePanel(dummyDataEditorForm); | ||
|
||
LogicalDivision structure = new LogicalDivision(); | ||
LinkedMetsResource link = new LinkedMetsResource(); | ||
link.setUri(URI.create("database://?process.id=42")); | ||
structure.setLink(link); | ||
TreeNode result = new DefaultTreeNode(); | ||
|
||
Method buildStructureTreeRecursively = StructurePanel.class.getDeclaredMethod("buildStructureTreeRecursively", | ||
LogicalDivision.class, TreeNode.class); | ||
buildStructureTreeRecursively.setAccessible(true); | ||
buildStructureTreeRecursively.invoke(underTest, structure, result); | ||
|
||
Assert.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()); | ||
} | ||
} |