19
19
import java .util .ArrayList ;
20
20
import java .util .List ;
21
21
import java .util .Locale ;
22
+ import java .util .Map ;
22
23
23
24
import org .apache .commons .io .FileUtils ;
24
25
import org .junit .AfterClass ;
39
40
import org .kitodo .data .database .beans .User ;
40
41
import org .kitodo .production .services .ServiceManager ;
41
42
import org .kitodo .production .services .data .ProcessService ;
43
+ import org .kitodo .utils .ProcessTestUtils ;
42
44
43
45
44
46
public class MetadataEditorIT {
45
47
private static final ProcessService processService = ServiceManager .getProcessService ();
46
-
47
48
private static final String firstProcess = "First process" ;
49
+ private static Map <String , Integer > testProcessIds ;
50
+ private static final String TEST_METADATA_CHILD_PROCESS_TO_ADD = "testMetadataForNonBlockingParallelTasksTest.xml" ;
51
+ private static final String TEST_METADATA_FILE = "testMetadataFileServiceTest.xml" ;
52
+ private static final String TEST_PROCESS_TITLE = "Test process" ;
48
53
49
54
/**
50
55
* Is running before the class runs.
@@ -53,7 +58,9 @@ public class MetadataEditorIT {
53
58
public static void prepareDatabase () throws Exception {
54
59
MockDatabase .startNode ();
55
60
MockDatabase .insertProcessesFull ();
56
- MockDatabase .insertProcessesForHierarchyTests ();
61
+ testProcessIds = MockDatabase .insertProcessesForHierarchyTests ();
62
+ ProcessTestUtils .copyHierarchyTestFiles (testProcessIds );
63
+ ProcessTestUtils .copyTestFiles (testProcessIds .get (MockDatabase .HIERARCHY_CHILD_TO_ADD ), TEST_METADATA_CHILD_PROCESS_TO_ADD );
57
64
MockDatabase .setUpAwaitility ();
58
65
User userOne = ServiceManager .getUserService ().getById (1 );
59
66
SecurityTestUtils .addUserDataToSecurityContext (userOne , 1 );
@@ -68,6 +75,8 @@ public static void prepareDatabase() throws Exception {
68
75
*/
69
76
@ AfterClass
70
77
public static void cleanDatabase () throws Exception {
78
+ ProcessTestUtils .removeTestProcess (testProcessIds .get (MockDatabase .HIERARCHY_PARENT ));
79
+ ProcessTestUtils .removeTestProcess (testProcessIds .get (MockDatabase .HIERARCHY_CHILD_TO_ADD ));
71
80
MockDatabase .stopNode ();
72
81
MockDatabase .cleanDatabase ();
73
82
}
@@ -77,22 +86,25 @@ public static void cleanDatabase() throws Exception {
77
86
78
87
@ Test
79
88
public void shouldAddLink () throws Exception {
80
- File metaXmlFile = new File ("src/test/resources/metadata/4/meta.xml" );
89
+ int parentId = testProcessIds .get (MockDatabase .HIERARCHY_PARENT );
90
+ int childId = testProcessIds .get (MockDatabase .HIERARCHY_CHILD_TO_ADD );
91
+ File metaXmlFile = new File ("src/test/resources/metadata/" + parentId + "/meta.xml" );
81
92
List <String > metaXmlContentBefore = FileUtils .readLines (metaXmlFile , StandardCharsets .UTF_8 );
82
93
83
- MetadataEditor .addLink (ServiceManager .getProcessService ().getById (4 ), "0" , 7 );
94
+ MetadataEditor .addLink (ServiceManager .getProcessService ().getById (parentId ), "0" , childId );
84
95
85
96
assertTrue ("The link was not added correctly!" ,
86
- isInternalMetsLink (FileUtils .readLines (metaXmlFile , StandardCharsets .UTF_8 ).get (36 ), 7 ));
97
+ isInternalMetsLink (FileUtils .readLines (metaXmlFile , StandardCharsets .UTF_8 ).get (36 ), childId ));
87
98
88
99
FileUtils .writeLines (metaXmlFile , StandardCharsets .UTF_8 .toString (), metaXmlContentBefore );
89
- FileUtils .deleteQuietly (new File ("src/test/resources/metadata/4 /meta.xml.1" ));
100
+ FileUtils .deleteQuietly (new File ("src/test/resources/metadata/" + parentId + " /meta.xml.1" ));
90
101
}
91
102
92
103
@ Test
93
104
public void shouldAddMultipleStructuresWithoutMetadata () throws Exception {
94
-
95
- File metaXmlFile = new File ("src/test/resources/metadata/2/meta.xml" );
105
+ int testProcessId = MockDatabase .insertTestProcess (TEST_PROCESS_TITLE , 1 , 1 , 1 );
106
+ ProcessTestUtils .copyTestMetadataFile (testProcessId , TEST_METADATA_FILE );
107
+ File metaXmlFile = new File ("src/test/resources/metadata/" + testProcessId + "/meta.xml" );
96
108
Workpiece workpiece = ServiceManager .getMetsService ().loadWorkpiece (metaXmlFile .toURI ());
97
109
98
110
int oldNrLogicalDivisions = workpiece .getAllLogicalDivisions ().size ();
@@ -104,6 +116,7 @@ public void shouldAddMultipleStructuresWithoutMetadata() throws Exception {
104
116
105
117
List <LogicalDivision > logicalDivisions = workpiece .getAllLogicalDivisions ();
106
118
assertTrue ("Metadata should be empty" , logicalDivisions .get (newNrDivisions - 1 ).getMetadata ().isEmpty ());
119
+ ProcessTestUtils .removeTestProcess (testProcessId );
107
120
}
108
121
109
122
@ Test
@@ -115,7 +128,9 @@ public void shouldAddMultipleStructuresWithMetadataGroup() throws Exception {
115
128
Locale .LanguageRange .parse ("en" ));
116
129
String metadataKey = "TitleDocMain" ;
117
130
118
- File metaXmlFile = new File ("src/test/resources/metadata/2/meta.xml" );
131
+ int testProcessId = MockDatabase .insertTestProcess (TEST_PROCESS_TITLE , 1 , 1 , 1 );
132
+ ProcessTestUtils .copyTestMetadataFile (testProcessId , TEST_METADATA_FILE );
133
+ File metaXmlFile = new File ("src/test/resources/metadata/" + testProcessId + "/meta.xml" );
119
134
Workpiece workpiece = ServiceManager .getMetsService ().loadWorkpiece (metaXmlFile .toURI ());
120
135
121
136
int oldNrLogicalDivisions = workpiece .getAllLogicalDivisions ().size ();
@@ -128,15 +143,16 @@ public void shouldAddMultipleStructuresWithMetadataGroup() throws Exception {
128
143
MetadataEditor .addMultipleStructuresWithMetadata (addedDivisions , "Monograph" , workpiece ,
129
144
workpiece .getLogicalStructure (), InsertionPosition .FIRST_CHILD_OF_CURRENT_ELEMENT , mvi , "value" );
130
145
LogicalDivision newSectionOne = workpiece .getAllLogicalDivisions ().get (newNrDivisions - 2 );
131
- List <Metadata > metadataListOne = new ArrayList <Metadata >(newSectionOne .getMetadata ());
146
+ List <Metadata > metadataListOne = new ArrayList <>(newSectionOne .getMetadata ());
132
147
LogicalDivision newSectionTwo = workpiece .getAllLogicalDivisions ().get (newNrDivisions - 1 );
133
- List <Metadata > metadataListTwo = new ArrayList <Metadata >(newSectionTwo .getMetadata ());
148
+ List <Metadata > metadataListTwo = new ArrayList <>(newSectionTwo .getMetadata ());
134
149
Metadata metadatumOne = metadataListOne .get (0 );
135
150
Metadata metadatumTwo = metadataListTwo .get (0 );
136
151
137
152
assertTrue ("Metadata should be of type MetadataEntry" , metadatumOne instanceof MetadataEntry );
138
153
assertTrue ("Metadata value was incorrectly added" , ((MetadataEntry ) metadatumOne ).getValue ().equals ("value 1" )
139
154
&& ((MetadataEntry ) metadatumTwo ).getValue ().equals ("value 2" ));
155
+ ProcessTestUtils .removeTestProcess (testProcessId );
140
156
}
141
157
142
158
@ Test
@@ -147,7 +163,9 @@ public void shouldAddMultipleStructuresWithMetadataEntry() throws Exception {
147
163
Locale .LanguageRange .parse ("en" ));
148
164
String metadataKey = "Person" ;
149
165
150
- File metaXmlFile = new File ("src/test/resources/metadata/2/meta.xml" );
166
+ int testProcessId = MockDatabase .insertTestProcess (TEST_PROCESS_TITLE , 1 , 1 , 1 );
167
+ ProcessTestUtils .copyTestMetadataFile (testProcessId , TEST_METADATA_FILE );
168
+ File metaXmlFile = new File ("src/test/resources/metadata/" + testProcessId + "/meta.xml" );
151
169
Workpiece workpiece = ServiceManager .getMetsService ().loadWorkpiece (metaXmlFile .toURI ());
152
170
153
171
int oldNrLogicalDivisions = workpiece .getAllLogicalDivisions ().size ();
@@ -170,6 +188,7 @@ public void shouldAddMultipleStructuresWithMetadataEntry() throws Exception {
170
188
metadatumOne instanceof MetadataGroup && metadatumTwo instanceof MetadataGroup );
171
189
assertTrue ("Metadata value was incorrectly added" ,
172
190
metadatumOne .getKey ().equals ("Person" ) && metadatumTwo .getKey ().equals ("Person" ));
191
+ ProcessTestUtils .removeTestProcess (testProcessId );
173
192
}
174
193
175
194
private boolean isInternalMetsLink (String lineOfMets , int recordNumber ) {
0 commit comments