1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2010 Regents of the University of California and the
|
4
|
* National Center for Ecological Analysis and Synthesis
|
5
|
*
|
6
|
* '$Author: jones $'
|
7
|
* '$Date: 2010-02-03 17:58:12 -0900 (Wed, 03 Feb 2010) $'
|
8
|
* '$Revision: 5211 $'
|
9
|
*
|
10
|
* This program is free software; you can redistribute it and/or modify
|
11
|
* it under the terms of the GNU General Public License as published by
|
12
|
* the Free Software Foundation; either version 2 of the License, or
|
13
|
* (at your option) any later version.
|
14
|
*
|
15
|
* This program is distributed in the hope that it will be useful,
|
16
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
* GNU General Public License for more details.
|
19
|
*
|
20
|
* You should have received a copy of the GNU General Public License
|
21
|
* along with this program; if not, write to the Free Software
|
22
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23
|
*/
|
24
|
|
25
|
package edu.ucsb.nceas.metacattest;
|
26
|
|
27
|
import java.io.ByteArrayInputStream;
|
28
|
import java.io.InputStream;
|
29
|
import java.io.File;
|
30
|
import java.math.BigInteger;
|
31
|
import java.sql.SQLException;
|
32
|
import java.util.*;
|
33
|
|
34
|
import junit.framework.Test;
|
35
|
import junit.framework.TestSuite;
|
36
|
|
37
|
import org.apache.commons.io.FileUtils;
|
38
|
|
39
|
import org.dataone.client.v2.itk.D1Client;
|
40
|
import org.dataone.configuration.Settings;
|
41
|
import org.dataone.service.types.v1.Identifier;
|
42
|
import org.dataone.service.types.v1.NodeReference;
|
43
|
import org.dataone.service.types.v1.NodeType;
|
44
|
import org.dataone.service.types.v1.ObjectFormatIdentifier;
|
45
|
import org.dataone.service.types.v1.ObjectList;
|
46
|
import org.dataone.service.types.v1.Session;
|
47
|
import org.dataone.service.types.v1.Subject;
|
48
|
import org.dataone.service.types.v2.MediaType;
|
49
|
import org.dataone.service.types.v2.MediaTypeProperty;
|
50
|
import org.dataone.service.types.v2.Node;
|
51
|
import org.dataone.service.types.v2.NodeList;
|
52
|
import org.dataone.service.types.v2.SystemMetadata;
|
53
|
|
54
|
import edu.ucsb.nceas.MCTestCase;
|
55
|
import edu.ucsb.nceas.metacat.AccessionNumber;
|
56
|
import edu.ucsb.nceas.metacat.AccessionNumberException;
|
57
|
import edu.ucsb.nceas.metacat.IdentifierManager;
|
58
|
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
|
59
|
import edu.ucsb.nceas.metacat.client.MetacatAuthException;
|
60
|
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
|
61
|
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
|
62
|
import edu.ucsb.nceas.metacat.dataone.CNodeService;
|
63
|
import edu.ucsb.nceas.metacat.dataone.D1NodeServiceTest;
|
64
|
import edu.ucsb.nceas.metacat.dataone.MNodeService;
|
65
|
|
66
|
import org.dataone.service.exceptions.InvalidSystemMetadata;
|
67
|
import org.dataone.service.exceptions.NotFound;
|
68
|
import org.dataone.service.exceptions.ServiceFailure;
|
69
|
|
70
|
public class IdentifierManagerTest extends D1NodeServiceTest {
|
71
|
private String badGuid = "test:testIdThatDoesNotExist";
|
72
|
|
73
|
public IdentifierManagerTest(String name) {
|
74
|
super(name);
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* Create a suite of tests to be run together
|
79
|
*/
|
80
|
public static Test suite() {
|
81
|
TestSuite suite = new TestSuite();
|
82
|
suite.addTest(new IdentifierManagerTest("initialize"));
|
83
|
// Test basic functions
|
84
|
suite.addTest(new IdentifierManagerTest("testGetGUID"));
|
85
|
suite.addTest(new IdentifierManagerTest("testGetAllLocalIds"));
|
86
|
suite.addTest(new IdentifierManagerTest("testGetInstance"));
|
87
|
suite.addTest(new IdentifierManagerTest("testGetLocalId"));
|
88
|
suite.addTest(new IdentifierManagerTest("testGetLocalIdNotFound"));
|
89
|
suite.addTest(new IdentifierManagerTest("testIdentifierExists"));
|
90
|
suite.addTest(new IdentifierManagerTest("testCreateMapping"));
|
91
|
suite.addTest(new IdentifierManagerTest("testGenerateLocalId"));
|
92
|
suite.addTest(new IdentifierManagerTest("testGetHeadPID"));
|
93
|
suite.addTest(new IdentifierManagerTest("testMediaType"));
|
94
|
suite.addTest(new IdentifierManagerTest("testQuerySystemMetadata"));
|
95
|
suite.addTest(new IdentifierManagerTest("testSystemMetadataPIDExists"));
|
96
|
suite.addTest(new IdentifierManagerTest("testSystemMetadataSIDExists"));
|
97
|
suite.addTest(new IdentifierManagerTest("testObjectFileExist"));
|
98
|
suite.addTest(new IdentifierManagerTest("testExistsInXmlRevisionTable"));
|
99
|
|
100
|
return suite;
|
101
|
}
|
102
|
/**
|
103
|
* Initialize the connection to metacat, and insert a document to be
|
104
|
* used for testing with a known docid.
|
105
|
*/
|
106
|
public void setUp() {
|
107
|
|
108
|
metacatConnectionNeeded = true;
|
109
|
try {
|
110
|
DBConnectionPool pool = DBConnectionPool.getInstance();
|
111
|
} catch (SQLException e2) {
|
112
|
fail(e2.getMessage());
|
113
|
}
|
114
|
|
115
|
try {
|
116
|
super.setUp();
|
117
|
} catch (Exception e1) {
|
118
|
fail(e1.getMessage());
|
119
|
}
|
120
|
}
|
121
|
|
122
|
/**
|
123
|
* test getting a guid from the systemmetadata table
|
124
|
*/
|
125
|
public void testGetGUID()
|
126
|
{
|
127
|
ph("testGetGUID");
|
128
|
try
|
129
|
{
|
130
|
IdentifierManager im = IdentifierManager.getInstance();
|
131
|
|
132
|
String docid = insertTestDocument();
|
133
|
docid = docid.substring(0, docid.lastIndexOf("."));
|
134
|
|
135
|
String gotGuid = im.getGUID(docid, 1);
|
136
|
assertNotNull(gotGuid);
|
137
|
}
|
138
|
catch(Exception e)
|
139
|
{
|
140
|
fail("Unexpected exception in testGetGUID: " + e.getMessage());
|
141
|
}
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* test getting a list of all local ids
|
146
|
*/
|
147
|
public void testGetAllLocalIds()
|
148
|
{
|
149
|
ph("testGetAllLocalIds");
|
150
|
try
|
151
|
{
|
152
|
List l = IdentifierManager.getInstance().getAllLocalIds();
|
153
|
for(int i=0; i<l.size(); i++)
|
154
|
{
|
155
|
System.out.println(l.get(i));
|
156
|
}
|
157
|
assertTrue(l.size() > 0);
|
158
|
}
|
159
|
catch(Exception e)
|
160
|
{
|
161
|
fail("Error in testGetAllLocalIds: " + e.getMessage());
|
162
|
}
|
163
|
}
|
164
|
|
165
|
/** Test that IM instances can be created. */
|
166
|
public void testGetInstance() {
|
167
|
ph("testGetInstance");
|
168
|
IdentifierManager im = IdentifierManager.getInstance();
|
169
|
assertNotNull(im);
|
170
|
}
|
171
|
|
172
|
/** Test that known LocalId's can be looked up from GUIDs. */
|
173
|
public void testGetLocalId() {
|
174
|
ph("testGetLocalId");
|
175
|
IdentifierManager im = IdentifierManager.getInstance();
|
176
|
String docidWithRev = insertTestDocument();
|
177
|
String docid = docidWithRev.substring(0, docidWithRev.lastIndexOf("."));
|
178
|
String guid;
|
179
|
String idReturned;
|
180
|
try {
|
181
|
guid = im.getGUID(docid, 1);
|
182
|
idReturned = im.getLocalId(guid);
|
183
|
assertEquals(docidWithRev, idReturned);
|
184
|
|
185
|
} catch (McdbDocNotFoundException e) {
|
186
|
fail(e.getMessage());
|
187
|
} catch (SQLException e) {
|
188
|
fail(e.getMessage());
|
189
|
}
|
190
|
}
|
191
|
|
192
|
/** Test that unknown LocalId's return the proper exception. */
|
193
|
public void testGetLocalIdNotFound() {
|
194
|
ph("testGetLocalIdNotFound");
|
195
|
IdentifierManager im = IdentifierManager.getInstance();
|
196
|
String idReturned;
|
197
|
try {
|
198
|
idReturned = im.getLocalId(badGuid);
|
199
|
fail("Failed: getLocalID() should have returned an document not " +
|
200
|
"found exception but did not.");
|
201
|
} catch (McdbDocNotFoundException e) {
|
202
|
assertNotNull(e);
|
203
|
} catch (SQLException e) {
|
204
|
fail(e.getMessage());
|
205
|
}
|
206
|
}
|
207
|
|
208
|
/**
|
209
|
* Test that an identifier is present in the system when it should
|
210
|
* be, and that it is not present when it shouldn't be.
|
211
|
*/
|
212
|
public void testIdentifierExists() {
|
213
|
ph("testIdentifierExists");
|
214
|
|
215
|
String goodGuid = "";
|
216
|
String accString = "";
|
217
|
String docid = "";
|
218
|
int rev = 0;
|
219
|
|
220
|
try {
|
221
|
IdentifierManager im = IdentifierManager.getInstance();
|
222
|
accString = insertTestDocument();
|
223
|
AccessionNumber accNumber = new AccessionNumber(accString, "NONE");
|
224
|
docid = accNumber.getDocid();
|
225
|
rev = new Integer(accNumber.getRev());
|
226
|
goodGuid = im.getGUID(docid, rev);
|
227
|
assertTrue(im.identifierExists(goodGuid));
|
228
|
assertFalse(im.identifierExists(badGuid));
|
229
|
|
230
|
} catch ( McdbDocNotFoundException dnfe ) {
|
231
|
fail("The document " + docid + "couldn't be found. The error was: " +
|
232
|
dnfe.getMessage());
|
233
|
|
234
|
} catch ( AccessionNumberException ane ) {
|
235
|
fail("The accession number could not be created for docid" +
|
236
|
accString + ". The error was: " + ane.getMessage());
|
237
|
|
238
|
} catch ( NumberFormatException nfe ) {
|
239
|
fail("The revision number could not be created for docid" +
|
240
|
accString + ". The error was: " + nfe.getMessage());
|
241
|
|
242
|
} catch ( SQLException sqle ) {
|
243
|
fail("The accession number could not be created for docid" +
|
244
|
accString + ". The error was: " + sqle.getMessage());
|
245
|
|
246
|
}
|
247
|
}
|
248
|
|
249
|
/**
|
250
|
* Test that we are able to create mappings from guids to localIds, and that
|
251
|
* improperly formatted docids generate the proper exceptions. This also tests
|
252
|
* getLocalId() and getGUID()
|
253
|
*/
|
254
|
public void testCreateMapping() {
|
255
|
ph("testCreateMapping");
|
256
|
try
|
257
|
{
|
258
|
IdentifierManager im = IdentifierManager.getInstance();
|
259
|
String docid = "test." + new Date().getTime() + ".1";
|
260
|
String guid = "guid:" + docid;
|
261
|
im.createMapping(guid, docid);
|
262
|
String guiddocid = docid.substring(0, docid.length() - 2);
|
263
|
System.out.println("guiddocid: " + guiddocid);
|
264
|
String guid2 = im.getGUID(guiddocid, 1);
|
265
|
assertTrue(guid2.equals(guid));
|
266
|
String docid2 = im.getLocalId(guid);
|
267
|
assertTrue(docid.equals(docid2));
|
268
|
} catch (McdbDocNotFoundException e) {
|
269
|
e.printStackTrace();
|
270
|
fail("createMapping failed to create proper localId from guid: " + e.getMessage());
|
271
|
} catch (SQLException e) {
|
272
|
fail(e.getMessage());
|
273
|
}
|
274
|
}
|
275
|
|
276
|
|
277
|
/**
|
278
|
* test the local id creation
|
279
|
*/
|
280
|
public void testGenerateLocalId() {
|
281
|
IdentifierManager im = IdentifierManager.getInstance();
|
282
|
String localid = im.generateLocalId("mynewid." + new Date().getTime(), 1);
|
283
|
System.out.println("localid: " + localid);
|
284
|
assertTrue(localid != null);
|
285
|
}
|
286
|
|
287
|
|
288
|
/**
|
289
|
* Test the method systemMetadataPIDExist
|
290
|
*/
|
291
|
public void testSystemMetadataPIDExists() throws Exception {
|
292
|
Session session = getTestSession();
|
293
|
Identifier guid = new Identifier();
|
294
|
guid.setValue(generateDocumentId());
|
295
|
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
296
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
297
|
MNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
298
|
boolean exist = IdentifierManager.getInstance().systemMetadataPIDExists(guid);
|
299
|
assertTrue(exist);
|
300
|
Thread.sleep(1000);
|
301
|
guid.setValue(generateDocumentId());
|
302
|
exist = IdentifierManager.getInstance().systemMetadataPIDExists(guid);
|
303
|
assertTrue(!exist);
|
304
|
}
|
305
|
|
306
|
/**
|
307
|
* Test the method of systemMetadataSIDExist
|
308
|
* @throws exception
|
309
|
*/
|
310
|
public void testSystemMetadataSIDExists() throws Exception {
|
311
|
Session session = getTestSession();
|
312
|
Identifier guid = new Identifier();
|
313
|
guid.setValue(generateDocumentId());
|
314
|
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
315
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
316
|
String sid1= "sid."+System.nanoTime();
|
317
|
Identifier seriesId = new Identifier();
|
318
|
seriesId.setValue(sid1);
|
319
|
System.out.println("the first sid is "+seriesId.getValue());
|
320
|
sysmeta.setSeriesId(seriesId);
|
321
|
MNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
322
|
boolean exist = IdentifierManager.getInstance().systemMetadataPIDExists(guid);
|
323
|
assertTrue(exist);
|
324
|
exist = IdentifierManager.getInstance().systemMetadataSIDExists(guid);
|
325
|
assertTrue(!exist);
|
326
|
exist = IdentifierManager.getInstance().systemMetadataSIDExists(seriesId);
|
327
|
assertTrue(exist);
|
328
|
exist = IdentifierManager.getInstance().systemMetadataPIDExists(seriesId);
|
329
|
assertTrue(!exist);
|
330
|
Thread.sleep(1000);
|
331
|
sid1= "sid."+System.nanoTime();
|
332
|
seriesId.setValue(sid1);
|
333
|
exist = IdentifierManager.getInstance().systemMetadataSIDExists(seriesId);
|
334
|
assertTrue(!exist);
|
335
|
}
|
336
|
/**
|
337
|
* Test the method - getHeadPID for a speicified SID
|
338
|
*/
|
339
|
public void testGetHeadPID() {
|
340
|
|
341
|
try {
|
342
|
//case-1 P1(S1) <-> P2(S1), S1 = P2 (Type 1)
|
343
|
Session session = getTestSession();
|
344
|
Identifier guid = new Identifier();
|
345
|
guid.setValue(generateDocumentId());
|
346
|
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
347
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
348
|
String sid1= "sid."+System.nanoTime();
|
349
|
Identifier seriesId = new Identifier();
|
350
|
seriesId.setValue(sid1);
|
351
|
System.out.println("the first sid is "+seriesId.getValue());
|
352
|
sysmeta.setSeriesId(seriesId);
|
353
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
354
|
MNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
355
|
System.out.println("the first pid is "+guid.getValue());
|
356
|
Identifier head = IdentifierManager.getInstance().getHeadPID(seriesId);
|
357
|
System.out.println("the head 1 is "+head.getValue());
|
358
|
assertTrue(head.getValue().equals(guid.getValue()));
|
359
|
assertTrue(IdentifierManager.getInstance().systemMetadataSIDExists(seriesId.getValue()));
|
360
|
assertTrue(!IdentifierManager.getInstance().systemMetadataPIDExists(seriesId.getValue()));
|
361
|
assertTrue(IdentifierManager.getInstance().systemMetadataPIDExists(guid.getValue()));
|
362
|
assertTrue(!IdentifierManager.getInstance().systemMetadataSIDExists(guid.getValue()));
|
363
|
|
364
|
//do a update with the same series id
|
365
|
Thread.sleep(1000);
|
366
|
Identifier newPid = new Identifier();
|
367
|
newPid.setValue(generateDocumentId()+"1");
|
368
|
System.out.println("the second pid is "+newPid.getValue());
|
369
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
370
|
SystemMetadata newSysMeta = createSystemMetadata(newPid, session.getSubject(), object);
|
371
|
newSysMeta.setObsoletes(guid);
|
372
|
newSysMeta.setSeriesId(seriesId);
|
373
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
374
|
MNodeService.getInstance(request).update(session, guid, object, newPid, newSysMeta);
|
375
|
|
376
|
//check
|
377
|
SystemMetadata meta = CNodeService.getInstance(request).getSystemMetadata(session, guid);
|
378
|
assertTrue(meta.getObsoletedBy().equals(newPid));
|
379
|
assertTrue(meta.getObsoletes() == null);
|
380
|
|
381
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, newPid);
|
382
|
assertTrue(meta.getObsoletedBy() == null);
|
383
|
assertTrue(meta.getObsoletes().equals(guid));
|
384
|
|
385
|
System.out.println("case 1: =======");
|
386
|
// the pid should be the newPid when we try to get the sid1
|
387
|
head = IdentifierManager.getInstance().getHeadPID(seriesId);
|
388
|
assertTrue(head.getValue().equals(newPid.getValue()));
|
389
|
|
390
|
|
391
|
// the pid should be null when we try to get a no-exist sid
|
392
|
Identifier non_exist_sid = new Identifier();
|
393
|
non_exist_sid.setValue("no-sid-exist-123qwe");
|
394
|
assertTrue(IdentifierManager.getInstance().getHeadPID(non_exist_sid) == null);
|
395
|
|
396
|
//case-2 P1(S1) ? P2(S1), S1 = P2
|
397
|
// http://jenkins-1.dataone.org/documentation/unstable/API-Documentation-development/design/ContentMutability.html
|
398
|
System.out.println("case 2======= ");
|
399
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
400
|
Identifier pid1_case2 = new Identifier();
|
401
|
pid1_case2.setValue(generateDocumentId());
|
402
|
String sid_case2_str= "sid."+System.nanoTime();
|
403
|
Identifier sid_case2 = new Identifier();
|
404
|
sid_case2.setValue(sid_case2_str);
|
405
|
SystemMetadata sysmeta_case2 = createSystemMetadata(pid1_case2, session.getSubject(), object);
|
406
|
sysmeta_case2.setSeriesId(sid_case2);
|
407
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
408
|
CNodeService.getInstance(request).create(session, pid1_case2, object, sysmeta_case2);
|
409
|
|
410
|
Thread.sleep(1000);
|
411
|
Identifier pid2_case2 = new Identifier();
|
412
|
pid2_case2.setValue(generateDocumentId());
|
413
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
414
|
sysmeta = createSystemMetadata(pid2_case2, session.getSubject(), object);
|
415
|
sysmeta.setSeriesId(sid_case2);
|
416
|
//try {
|
417
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
418
|
CNodeService.getInstance(request).create(session, pid2_case2, object, sysmeta);
|
419
|
//fail("we shouldn't get here and an InvalidSystemMetacat exception should be thrown.");
|
420
|
head = IdentifierManager.getInstance().getHeadPID(sid_case2);
|
421
|
assertTrue(head.getValue().equals(pid2_case2.getValue()));
|
422
|
|
423
|
//} catch (Exception e) {
|
424
|
/*System.out.println("case 2======= Invalid system metadata to insert the second object");
|
425
|
//check
|
426
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case2);
|
427
|
assertTrue(meta.getObsoletedBy() == null);
|
428
|
assertTrue(meta.getObsoletes() == null);
|
429
|
// the pid should be the newPid when we try to get the sid1
|
430
|
head = IdentifierManager.getInstance().getHeadPID(sid_case2);
|
431
|
assertTrue(head.getValue().equals(pid1_case2.getValue()));*/
|
432
|
//}
|
433
|
|
434
|
|
435
|
//case-3 P1(S1) <- P2(S1), S1 = P2, Discouraged, but not error condition, S1 = P2 (P1 and P2 are type 1 ends, not an ideal chain )
|
436
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
437
|
Identifier pid1_case3 = new Identifier();
|
438
|
pid1_case3.setValue(generateDocumentId());
|
439
|
String sid_case3_str= "sid."+System.nanoTime();
|
440
|
Identifier sid_case3 = new Identifier();
|
441
|
sid_case3.setValue(sid_case3_str);
|
442
|
SystemMetadata sysmeta_case3 = createSystemMetadata(pid1_case3, session.getSubject(), object);
|
443
|
sysmeta_case3.setSeriesId(sid_case3);
|
444
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
445
|
CNodeService.getInstance(request).create(session, pid1_case3, object, sysmeta_case3);
|
446
|
|
447
|
Thread.sleep(1000);
|
448
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
449
|
Identifier pid2_case3 = new Identifier();
|
450
|
pid2_case3.setValue(generateDocumentId());
|
451
|
SystemMetadata sysmeta2_case3 = createSystemMetadata(pid2_case3, session.getSubject(), object);
|
452
|
sysmeta2_case3.setSeriesId(sid_case3);
|
453
|
sysmeta2_case3.setObsoletes(pid1_case3);
|
454
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
455
|
CNodeService.getInstance(request).create(session, pid2_case3, object, sysmeta2_case3);
|
456
|
|
457
|
//check
|
458
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case3);
|
459
|
assertTrue(meta.getObsoletedBy() == null);
|
460
|
assertTrue(meta.getObsoletes() == null);
|
461
|
|
462
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case3);
|
463
|
assertTrue(meta.getObsoletedBy() == null);
|
464
|
assertTrue(meta.getObsoletes().equals(pid1_case3));
|
465
|
|
466
|
System.out.println("case 3: =======");
|
467
|
head = IdentifierManager.getInstance().getHeadPID(sid_case3);
|
468
|
assertTrue(head.equals(pid2_case3));
|
469
|
|
470
|
//case-4 P1(S1) <-> P2(S1) <-> P3(S2), S1 = P2 (Type 2), S2 = P3 (Type 1)
|
471
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
472
|
Identifier pid1_case4 = new Identifier();
|
473
|
pid1_case4.setValue(generateDocumentId());
|
474
|
Identifier sid_case4 = new Identifier();
|
475
|
sid_case4.setValue("sid."+System.nanoTime());
|
476
|
SystemMetadata sysmeta_case4 = createSystemMetadata(pid1_case4, session.getSubject(), object);
|
477
|
sysmeta_case4.setSeriesId(sid_case4);
|
478
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
479
|
CNodeService.getInstance(request).create(session, pid1_case4, object, sysmeta_case4);
|
480
|
|
481
|
Thread.sleep(1000);
|
482
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
483
|
Identifier pid2_case4 = new Identifier();
|
484
|
pid2_case4.setValue(generateDocumentId());
|
485
|
SystemMetadata sysmeta2_case4 = createSystemMetadata(pid2_case4, session.getSubject(), object);
|
486
|
sysmeta2_case4.setSeriesId(sid_case4);
|
487
|
sysmeta2_case4.setObsoletes(pid1_case4);
|
488
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
489
|
CNodeService.getInstance(request).create(session, pid2_case4, object, sysmeta2_case4);
|
490
|
|
491
|
sysmeta_case4.setObsoletedBy(pid2_case4);
|
492
|
BigInteger version = BigInteger.ONE.add(BigInteger.ONE);
|
493
|
sysmeta_case4.setSerialVersion(version);
|
494
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid1_case4, sysmeta_case4);
|
495
|
|
496
|
Thread.sleep(1000);
|
497
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
498
|
Identifier pid3_case4 = new Identifier();
|
499
|
pid3_case4.setValue(generateDocumentId());
|
500
|
Identifier sid2_case4 = new Identifier();
|
501
|
sid2_case4.setValue("sid."+System.nanoTime());
|
502
|
SystemMetadata sysmeta3_case4 = createSystemMetadata(pid3_case4, session.getSubject(), object);
|
503
|
sysmeta3_case4.setSeriesId(sid2_case4);
|
504
|
sysmeta3_case4.setObsoletes(pid2_case4);
|
505
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
506
|
CNodeService.getInstance(request).create(session, pid3_case4, object, sysmeta3_case4);
|
507
|
|
508
|
sysmeta2_case4.setObsoletedBy(pid3_case4);
|
509
|
version = version.add(BigInteger.ONE);
|
510
|
sysmeta2_case4.setSerialVersion(version);
|
511
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid2_case4, sysmeta2_case4);
|
512
|
|
513
|
//check
|
514
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case4);
|
515
|
assertTrue(meta.getObsoletedBy().equals(pid2_case4));
|
516
|
assertTrue(meta.getObsoletes() == null);
|
517
|
|
518
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case4);
|
519
|
assertTrue(meta.getObsoletedBy().equals(pid3_case4));
|
520
|
assertTrue(meta.getObsoletes().equals(pid1_case4));
|
521
|
|
522
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid3_case4);
|
523
|
assertTrue(meta.getObsoletedBy() == null);
|
524
|
assertTrue(meta.getObsoletes().equals(pid2_case4));
|
525
|
|
526
|
System.out.println("case 4: =======");
|
527
|
head = IdentifierManager.getInstance().getHeadPID(sid_case4);
|
528
|
assertTrue(head.equals(pid2_case4));
|
529
|
head = IdentifierManager.getInstance().getHeadPID(sid2_case4);
|
530
|
assertTrue(head.equals(pid3_case4));
|
531
|
|
532
|
|
533
|
//case-5 P1(S1) <- P2(S1) <- P3(S2), S1 = P2 (P1 and P2 are type 1 ends, not an ideal chain), S2 = P3 (Type 1)
|
534
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
535
|
Identifier pid1_case5 = new Identifier();
|
536
|
pid1_case5.setValue(generateDocumentId());
|
537
|
Identifier sid_case5 = new Identifier();
|
538
|
sid_case5.setValue("sid."+System.nanoTime());
|
539
|
SystemMetadata sysmeta1_case5 = createSystemMetadata(pid1_case5, session.getSubject(), object);
|
540
|
sysmeta1_case5.setSeriesId(sid_case5);
|
541
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
542
|
CNodeService.getInstance(request).create(session, pid1_case5, object, sysmeta1_case5);
|
543
|
|
544
|
Thread.sleep(1000);
|
545
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
546
|
Identifier pid2_case5 = new Identifier();
|
547
|
pid2_case5.setValue(generateDocumentId());
|
548
|
SystemMetadata sysmeta2_case5 = createSystemMetadata(pid2_case5, session.getSubject(), object);
|
549
|
sysmeta2_case5.setSeriesId(sid_case5);
|
550
|
sysmeta2_case5.setObsoletes(pid1_case5);
|
551
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
552
|
CNodeService.getInstance(request).create(session, pid2_case5, object, sysmeta2_case5);
|
553
|
|
554
|
Thread.sleep(1000);
|
555
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
556
|
Identifier pid3_case5 = new Identifier();
|
557
|
pid3_case5.setValue(generateDocumentId());
|
558
|
Identifier sid2_case5 = new Identifier();
|
559
|
sid2_case5.setValue("sid."+System.nanoTime());
|
560
|
SystemMetadata sysmeta3_case5 = createSystemMetadata(pid3_case5, session.getSubject(), object);
|
561
|
sysmeta3_case5.setSeriesId(sid2_case5);
|
562
|
sysmeta3_case5.setObsoletes(pid2_case5);
|
563
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
564
|
CNodeService.getInstance(request).create(session, pid3_case5, object, sysmeta3_case5);
|
565
|
|
566
|
//check
|
567
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case5);
|
568
|
assertTrue(meta.getObsoletedBy() == null);
|
569
|
assertTrue(meta.getObsoletes() == null);
|
570
|
|
571
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case5);
|
572
|
assertTrue(meta.getObsoletedBy() == null );
|
573
|
assertTrue(meta.getObsoletes().equals(pid1_case5));
|
574
|
|
575
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid3_case5);
|
576
|
assertTrue(meta.getObsoletedBy() == null);
|
577
|
assertTrue(meta.getObsoletes().equals(pid2_case5));
|
578
|
|
579
|
System.out.println("case 5: =======");
|
580
|
head = IdentifierManager.getInstance().getHeadPID(sid_case5);
|
581
|
assertTrue(head.equals(pid2_case5));
|
582
|
head = IdentifierManager.getInstance().getHeadPID(sid2_case5);
|
583
|
assertTrue(head.equals(pid3_case5));
|
584
|
|
585
|
|
586
|
//case-6 P1(S1) <-> P2(S1) <-> P3(), S1 = P2 (Type 2)
|
587
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
588
|
Identifier pid1_case6 = new Identifier();
|
589
|
pid1_case6.setValue(generateDocumentId());
|
590
|
Identifier sid_case6 = new Identifier();
|
591
|
sid_case6.setValue("sid."+System.nanoTime());
|
592
|
SystemMetadata sysmeta_case6 = createSystemMetadata(pid1_case6, session.getSubject(), object);
|
593
|
sysmeta_case6.setSeriesId(sid_case6);
|
594
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
595
|
CNodeService.getInstance(request).create(session, pid1_case6, object, sysmeta_case6);
|
596
|
|
597
|
Thread.sleep(1000);
|
598
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
599
|
Identifier pid2_case6 = new Identifier();
|
600
|
pid2_case6.setValue(generateDocumentId());
|
601
|
SystemMetadata sysmeta2_case6 = createSystemMetadata(pid2_case6, session.getSubject(), object);
|
602
|
sysmeta2_case6.setSeriesId(sid_case6);
|
603
|
sysmeta2_case6.setObsoletes(pid1_case6);
|
604
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
605
|
CNodeService.getInstance(request).create(session, pid2_case6, object, sysmeta2_case6);
|
606
|
|
607
|
sysmeta_case6.setObsoletedBy(pid2_case6);
|
608
|
version = BigInteger.ONE.add(BigInteger.ONE);
|
609
|
sysmeta_case6.setSerialVersion(version);
|
610
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid1_case6, sysmeta_case6);
|
611
|
|
612
|
Thread.sleep(1000);
|
613
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
614
|
Identifier pid3_case6 = new Identifier();
|
615
|
pid3_case6.setValue(generateDocumentId());
|
616
|
SystemMetadata sysmeta3_case6 = createSystemMetadata(pid3_case6, session.getSubject(), object);
|
617
|
sysmeta3_case6.setObsoletes(pid2_case6);
|
618
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
619
|
CNodeService.getInstance(request).create(session, pid3_case6, object, sysmeta3_case6);
|
620
|
|
621
|
sysmeta2_case6.setObsoletedBy(pid3_case6);
|
622
|
version = version.add(BigInteger.ONE);
|
623
|
sysmeta2_case6.setSerialVersion(version);
|
624
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid2_case6, sysmeta2_case6);
|
625
|
|
626
|
//check
|
627
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case6);
|
628
|
assertTrue(meta.getObsoletedBy().equals(pid2_case6));
|
629
|
assertTrue(meta.getObsoletes() == null);
|
630
|
|
631
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case6);
|
632
|
assertTrue(meta.getObsoletedBy().equals(pid3_case6));
|
633
|
assertTrue(meta.getObsoletes().equals(pid1_case6));
|
634
|
|
635
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid3_case6);
|
636
|
assertTrue(meta.getObsoletedBy() == null);
|
637
|
assertTrue(meta.getObsoletes().equals(pid2_case6));
|
638
|
|
639
|
System.out.println("case 6: =======");
|
640
|
head = IdentifierManager.getInstance().getHeadPID(sid_case6);
|
641
|
assertTrue(head.equals(pid2_case6));
|
642
|
|
643
|
|
644
|
//case-7 P1(S1) <-> P2(S1) <-> P3() <-> P4(S2), S1 = P2 (Type 2), S2 = P4 (Type 1)
|
645
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
646
|
Identifier pid1_case7 = new Identifier();
|
647
|
pid1_case7.setValue(generateDocumentId());
|
648
|
Identifier sid_case7 = new Identifier();
|
649
|
sid_case7.setValue("sid."+System.nanoTime());
|
650
|
SystemMetadata sysmeta_case7 = createSystemMetadata(pid1_case7, session.getSubject(), object);
|
651
|
sysmeta_case7.setSeriesId(sid_case7);
|
652
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
653
|
CNodeService.getInstance(request).create(session, pid1_case7, object, sysmeta_case7);
|
654
|
|
655
|
Thread.sleep(1000);
|
656
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
657
|
Identifier pid2_case7 = new Identifier();
|
658
|
pid2_case7.setValue(generateDocumentId());
|
659
|
SystemMetadata sysmeta2_case7 = createSystemMetadata(pid2_case7, session.getSubject(), object);
|
660
|
sysmeta2_case7.setSeriesId(sid_case7);
|
661
|
sysmeta2_case7.setObsoletes(pid1_case7);
|
662
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
663
|
CNodeService.getInstance(request).create(session, pid2_case7, object, sysmeta2_case7);
|
664
|
|
665
|
sysmeta_case7.setObsoletedBy(pid2_case7);
|
666
|
version = version.add(BigInteger.ONE);
|
667
|
sysmeta_case7.setSerialVersion(version);
|
668
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid1_case7, sysmeta_case7);
|
669
|
|
670
|
Thread.sleep(1000);
|
671
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
672
|
Identifier pid3_case7 = new Identifier();
|
673
|
pid3_case7.setValue(generateDocumentId());
|
674
|
SystemMetadata sysmeta3_case7 = createSystemMetadata(pid3_case7, session.getSubject(), object);
|
675
|
sysmeta3_case7.setObsoletes(pid2_case7);
|
676
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
677
|
CNodeService.getInstance(request).create(session, pid3_case7, object, sysmeta3_case7);
|
678
|
|
679
|
sysmeta2_case7.setObsoletedBy(pid3_case7);
|
680
|
version = version.add(BigInteger.ONE);
|
681
|
sysmeta2_case7.setSerialVersion(version);
|
682
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid2_case7, sysmeta2_case7);
|
683
|
|
684
|
Thread.sleep(1000);
|
685
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
686
|
Identifier pid4_case7 = new Identifier();
|
687
|
pid4_case7.setValue(generateDocumentId());
|
688
|
Identifier sid2_case7 = new Identifier();
|
689
|
sid2_case7.setValue("sid."+System.nanoTime());
|
690
|
SystemMetadata sysmeta4_case7 = createSystemMetadata(pid4_case7, session.getSubject(), object);
|
691
|
sysmeta4_case7.setObsoletes(pid3_case7);
|
692
|
sysmeta4_case7.setSeriesId(sid2_case7);
|
693
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
694
|
CNodeService.getInstance(request).create(session, pid4_case7, object, sysmeta4_case7);
|
695
|
|
696
|
sysmeta3_case7.setObsoletedBy(pid4_case7);
|
697
|
version = version.add(BigInteger.ONE);
|
698
|
sysmeta3_case7.setSerialVersion(version);
|
699
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid3_case7, sysmeta3_case7);
|
700
|
|
701
|
//check
|
702
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case7);
|
703
|
assertTrue(meta.getObsoletedBy().equals(pid2_case7));
|
704
|
assertTrue(meta.getObsoletes() == null);
|
705
|
|
706
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case7);
|
707
|
assertTrue(meta.getObsoletedBy().equals(pid3_case7));
|
708
|
assertTrue(meta.getObsoletes().equals(pid1_case7));
|
709
|
|
710
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid3_case7);
|
711
|
assertTrue(meta.getObsoletedBy().equals(pid4_case7));
|
712
|
assertTrue(meta.getObsoletes().equals(pid2_case7));
|
713
|
|
714
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid4_case7);
|
715
|
assertTrue(meta.getObsoletedBy() == null);
|
716
|
assertTrue(meta.getObsoletes().equals(pid3_case7));
|
717
|
|
718
|
System.out.println("case 7: =======");
|
719
|
head = IdentifierManager.getInstance().getHeadPID(sid_case7);
|
720
|
assertTrue(head.equals(pid2_case7));
|
721
|
head = IdentifierManager.getInstance().getHeadPID(sid2_case7);
|
722
|
assertTrue(head.equals(pid4_case7));
|
723
|
|
724
|
|
725
|
//case-8 P1(S1) <-> P2(S1) -> ?? <- P4(S1), S1 = P4, (Type 1) (Error, but will happen)
|
726
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
727
|
Identifier pid1_case8 = new Identifier();
|
728
|
pid1_case8.setValue(generateDocumentId());
|
729
|
Identifier sid_case8 = new Identifier();
|
730
|
sid_case8.setValue("sid."+System.nanoTime());
|
731
|
SystemMetadata sysmeta_case8 = createSystemMetadata(pid1_case8, session.getSubject(), object);
|
732
|
sysmeta_case8.setSeriesId(sid_case8);
|
733
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
734
|
CNodeService.getInstance(request).create(session, pid1_case8, object, sysmeta_case8);
|
735
|
|
736
|
Thread.sleep(1000);
|
737
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
738
|
Identifier pid2_case8 = new Identifier();
|
739
|
pid2_case8.setValue(generateDocumentId());
|
740
|
SystemMetadata sysmeta2_case8 = createSystemMetadata(pid2_case8, session.getSubject(), object);
|
741
|
sysmeta2_case8.setSeriesId(sid_case8);
|
742
|
sysmeta2_case8.setObsoletes(pid1_case8);
|
743
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
744
|
CNodeService.getInstance(request).create(session, pid2_case8, object, sysmeta2_case8);
|
745
|
|
746
|
sysmeta_case8.setObsoletedBy(pid2_case8);
|
747
|
version = version.add(BigInteger.ONE);
|
748
|
sysmeta_case8.setSerialVersion(version);
|
749
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid1_case8, sysmeta_case8);
|
750
|
|
751
|
Thread.sleep(1000);
|
752
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
753
|
Identifier pid3_case8 = new Identifier();
|
754
|
pid3_case8.setValue(generateDocumentId());
|
755
|
SystemMetadata sysmeta3_case8 = createSystemMetadata(pid3_case8, session.getSubject(), object);
|
756
|
sysmeta3_case8.setObsoletes(pid2_case8);
|
757
|
sysmeta3_case8.setSeriesId(sid_case8);
|
758
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
759
|
CNodeService.getInstance(request).create(session, pid3_case8, object, sysmeta3_case8);
|
760
|
|
761
|
sysmeta2_case8.setObsoletedBy(pid3_case8);
|
762
|
version = version.add(BigInteger.ONE);
|
763
|
sysmeta2_case8.setSerialVersion(version);
|
764
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid2_case8, sysmeta2_case8);
|
765
|
|
766
|
Thread.sleep(1000);
|
767
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
768
|
Identifier pid4_case8 = new Identifier();
|
769
|
pid4_case8.setValue(generateDocumentId());
|
770
|
//Identifier sid2_case7 = new Identifier();
|
771
|
//sid2_case7.setValue("sid."+System.nanoTime());
|
772
|
SystemMetadata sysmeta4_case8 = createSystemMetadata(pid4_case8, session.getSubject(), object);
|
773
|
sysmeta4_case8.setObsoletes(pid3_case8);
|
774
|
sysmeta4_case8.setSeriesId(sid_case8);
|
775
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
776
|
CNodeService.getInstance(request).create(session, pid4_case8, object, sysmeta4_case8);
|
777
|
|
778
|
//delete pid3_case8
|
779
|
CNodeService.getInstance(request).delete(session, pid3_case8);
|
780
|
try {
|
781
|
CNodeService.getInstance(request).getSystemMetadata(session, pid3_case8);
|
782
|
fail("The pid "+pid3_case8.getValue()+" should be deleted.");
|
783
|
} catch (NotFound e) {
|
784
|
//e.printStackTrace();
|
785
|
assertTrue(true);
|
786
|
}
|
787
|
|
788
|
//check
|
789
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case8);
|
790
|
assertTrue(meta.getObsoletedBy().equals(pid2_case8));
|
791
|
assertTrue(meta.getObsoletes() == null);
|
792
|
|
793
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case8);
|
794
|
assertTrue(meta.getObsoletedBy().equals(pid3_case8));
|
795
|
assertTrue(meta.getObsoletes().equals(pid1_case8));
|
796
|
|
797
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid4_case8);
|
798
|
assertTrue(meta.getObsoletedBy() == null);
|
799
|
assertTrue(meta.getObsoletes().equals(pid3_case8));
|
800
|
|
801
|
System.out.println("case 8: =======");
|
802
|
head = IdentifierManager.getInstance().getHeadPID(sid_case8);
|
803
|
assertTrue(head.equals(pid4_case8));
|
804
|
|
805
|
|
806
|
//case-9 P1(S1) <-> P2(S1) ?? <- P4(S1), S1 = P4 (P2 and P4 are type 1 ends, not an ideal chain)
|
807
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
808
|
Identifier pid1_case9 = new Identifier();
|
809
|
pid1_case9.setValue(generateDocumentId());
|
810
|
Identifier sid_case9 = new Identifier();
|
811
|
sid_case9.setValue("sid."+System.nanoTime());
|
812
|
SystemMetadata sysmeta_case9 = createSystemMetadata(pid1_case9, session.getSubject(), object);
|
813
|
sysmeta_case9.setSeriesId(sid_case9);
|
814
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
815
|
CNodeService.getInstance(request).create(session, pid1_case9, object, sysmeta_case9);
|
816
|
|
817
|
Thread.sleep(1000);
|
818
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
819
|
Identifier pid2_case9 = new Identifier();
|
820
|
pid2_case9.setValue(generateDocumentId());
|
821
|
SystemMetadata sysmeta2_case9 = createSystemMetadata(pid2_case9, session.getSubject(), object);
|
822
|
sysmeta2_case9.setSeriesId(sid_case9);
|
823
|
sysmeta2_case9.setObsoletes(pid1_case9);
|
824
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
825
|
CNodeService.getInstance(request).create(session, pid2_case9, object, sysmeta2_case9);
|
826
|
|
827
|
sysmeta_case9.setObsoletedBy(pid2_case9);
|
828
|
version = version.add(BigInteger.ONE);
|
829
|
sysmeta_case9.setSerialVersion(version);
|
830
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid1_case9, sysmeta_case9);
|
831
|
//check
|
832
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case9);
|
833
|
assertTrue(meta.getObsoletedBy().equals(pid2_case9));
|
834
|
|
835
|
Thread.sleep(1000);
|
836
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
837
|
Identifier pid3_case9 = new Identifier();
|
838
|
pid3_case9.setValue(generateDocumentId());
|
839
|
SystemMetadata sysmeta3_case9 = createSystemMetadata(pid3_case9, session.getSubject(), object);
|
840
|
sysmeta3_case9.setObsoletes(pid2_case9);
|
841
|
sysmeta3_case9.setSeriesId(sid_case9);
|
842
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
843
|
CNodeService.getInstance(request).create(session, pid3_case9, object, sysmeta3_case9);
|
844
|
|
845
|
//sysmeta2_case8.setObsoletedBy(pid3_case8);
|
846
|
//CNodeService.getInstance(request).updateSystemMetadata(session, pid2_case8, sysmeta2_case8);
|
847
|
|
848
|
Thread.sleep(1000);
|
849
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
850
|
Identifier pid4_case9 = new Identifier();
|
851
|
pid4_case9.setValue(generateDocumentId());
|
852
|
//Identifier sid2_case7 = new Identifier();
|
853
|
//sid2_case7.setValue("sid."+System.nanoTime());
|
854
|
SystemMetadata sysmeta4_case9 = createSystemMetadata(pid4_case9, session.getSubject(), object);
|
855
|
sysmeta4_case9.setObsoletes(pid3_case9);
|
856
|
sysmeta4_case9.setSeriesId(sid_case9);
|
857
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
858
|
CNodeService.getInstance(request).create(session, pid4_case9, object, sysmeta4_case9);
|
859
|
|
860
|
//delete pid3_case8
|
861
|
CNodeService.getInstance(request).delete(session, pid3_case9);
|
862
|
try {
|
863
|
CNodeService.getInstance(request).getSystemMetadata(session, pid3_case9);
|
864
|
fail("The pid "+pid3_case9.getValue()+" should be deleted.");
|
865
|
} catch (NotFound e) {
|
866
|
//e.printStackTrace();
|
867
|
assertTrue(true);
|
868
|
}
|
869
|
|
870
|
//check
|
871
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case9);
|
872
|
assertTrue(meta.getObsoletedBy().equals(pid2_case9));
|
873
|
assertTrue(meta.getObsoletes() == null);
|
874
|
|
875
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case9);
|
876
|
assertTrue(meta.getObsoletedBy() == null);
|
877
|
assertTrue(meta.getObsoletes().equals(pid1_case9));
|
878
|
|
879
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid4_case9);
|
880
|
assertTrue(meta.getObsoletedBy() == null);
|
881
|
assertTrue(meta.getObsoletes().equals(pid3_case9));
|
882
|
|
883
|
System.out.println("case 9: =======");
|
884
|
head = IdentifierManager.getInstance().getHeadPID(sid_case9);
|
885
|
assertTrue(head.equals(pid4_case9));
|
886
|
|
887
|
|
888
|
//case-10 P1(S1) <-> P2(S1) -> XX <- P4(S1), S1 = P4, (Type 1)
|
889
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
890
|
Identifier pid1_case10 = new Identifier();
|
891
|
pid1_case10.setValue(generateDocumentId());
|
892
|
Identifier sid_case10 = new Identifier();
|
893
|
sid_case10.setValue("sid."+System.nanoTime());
|
894
|
SystemMetadata sysmeta_case10 = createSystemMetadata(pid1_case10, session.getSubject(), object);
|
895
|
sysmeta_case10.setSeriesId(sid_case10);
|
896
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
897
|
CNodeService.getInstance(request).create(session, pid1_case10, object, sysmeta_case10);
|
898
|
|
899
|
Thread.sleep(1000);
|
900
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
901
|
Identifier pid2_case10 = new Identifier();
|
902
|
pid2_case10.setValue(generateDocumentId());
|
903
|
SystemMetadata sysmeta2_case10 = createSystemMetadata(pid2_case10, session.getSubject(), object);
|
904
|
sysmeta2_case10.setSeriesId(sid_case10);
|
905
|
sysmeta2_case10.setObsoletes(pid1_case10);
|
906
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
907
|
CNodeService.getInstance(request).create(session, pid2_case10, object, sysmeta2_case10);
|
908
|
|
909
|
sysmeta_case10.setObsoletedBy(pid2_case10);
|
910
|
version = version.add(BigInteger.ONE);
|
911
|
sysmeta_case10.setSerialVersion(version);
|
912
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid1_case10, sysmeta_case10);
|
913
|
//check
|
914
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case10);
|
915
|
assertTrue(meta.getObsoletedBy().equals(pid2_case10));
|
916
|
|
917
|
Thread.sleep(1000);
|
918
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
919
|
Identifier pid3_case10 = new Identifier();
|
920
|
pid3_case10.setValue(generateDocumentId());
|
921
|
SystemMetadata sysmeta3_case10 = createSystemMetadata(pid3_case10, session.getSubject(), object);
|
922
|
sysmeta3_case10.setObsoletes(pid2_case10);
|
923
|
sysmeta3_case10.setSeriesId(sid_case10);
|
924
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
925
|
CNodeService.getInstance(request).create(session, pid3_case10, object, sysmeta3_case10);
|
926
|
|
927
|
sysmeta2_case10.setObsoletedBy(pid3_case10);
|
928
|
version = version.add(BigInteger.ONE);
|
929
|
sysmeta2_case10.setSerialVersion(version);
|
930
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid2_case10, sysmeta2_case10);
|
931
|
|
932
|
Thread.sleep(1000);
|
933
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
934
|
Identifier pid4_case10 = new Identifier();
|
935
|
pid4_case10.setValue(generateDocumentId());
|
936
|
//Identifier sid2_case7 = new Identifier();
|
937
|
//sid2_case7.setValue("sid."+System.nanoTime());
|
938
|
SystemMetadata sysmeta4_case10 = createSystemMetadata(pid4_case10, session.getSubject(), object);
|
939
|
sysmeta4_case10.setObsoletes(pid3_case10);
|
940
|
sysmeta4_case10.setSeriesId(sid_case10);
|
941
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
942
|
CNodeService.getInstance(request).create(session, pid4_case10, object, sysmeta4_case10);
|
943
|
|
944
|
//delete pid3_case10
|
945
|
CNodeService.getInstance(request).delete(session, pid3_case10);
|
946
|
try {
|
947
|
CNodeService.getInstance(request).getSystemMetadata(session, pid3_case10);
|
948
|
fail("The pid "+pid3_case10.getValue()+" should be deleted.");
|
949
|
} catch (NotFound e) {
|
950
|
//e.printStackTrace();
|
951
|
assertTrue(true);
|
952
|
}
|
953
|
|
954
|
//check
|
955
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case10);
|
956
|
assertTrue(meta.getObsoletedBy().equals(pid2_case10));
|
957
|
assertTrue(meta.getObsoletes() == null);
|
958
|
|
959
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case10);
|
960
|
assertTrue(meta.getObsoletedBy().equals(pid3_case10));
|
961
|
assertTrue(meta.getObsoletes().equals(pid1_case10));
|
962
|
|
963
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid4_case10);
|
964
|
assertTrue(meta.getObsoletedBy() == null);
|
965
|
assertTrue(meta.getObsoletes().equals(pid3_case10));
|
966
|
|
967
|
System.out.println("case 10: =======");
|
968
|
head = IdentifierManager.getInstance().getHeadPID(sid_case10);
|
969
|
assertTrue(head.equals(pid4_case10));
|
970
|
|
971
|
|
972
|
//case-11 P1(S1) <-> P2(S1) <-> [archived:P3(S1)], S1 = P3, (Type 1)
|
973
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
974
|
Identifier pid1_case11 = new Identifier();
|
975
|
pid1_case11.setValue(generateDocumentId());
|
976
|
Identifier sid_case11 = new Identifier();
|
977
|
sid_case11.setValue("sid."+System.nanoTime());
|
978
|
SystemMetadata sysmeta_case11 = createSystemMetadata(pid1_case11, session.getSubject(), object);
|
979
|
sysmeta_case11.setSeriesId(sid_case11);
|
980
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
981
|
CNodeService.getInstance(request).create(session, pid1_case11, object, sysmeta_case11);
|
982
|
|
983
|
Thread.sleep(1000);
|
984
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
985
|
Identifier pid2_case11 = new Identifier();
|
986
|
pid2_case11.setValue(generateDocumentId());
|
987
|
SystemMetadata sysmeta2_case11 = createSystemMetadata(pid2_case11, session.getSubject(), object);
|
988
|
sysmeta2_case11.setSeriesId(sid_case11);
|
989
|
sysmeta2_case11.setObsoletes(pid1_case11);
|
990
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
991
|
CNodeService.getInstance(request).create(session, pid2_case11, object, sysmeta2_case11);
|
992
|
|
993
|
sysmeta_case11.setObsoletedBy(pid2_case11);
|
994
|
version = version.add(BigInteger.ONE);
|
995
|
sysmeta_case11.setSerialVersion(version);
|
996
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid1_case11, sysmeta_case11);
|
997
|
//check
|
998
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case11);
|
999
|
assertTrue(meta.getObsoletedBy().equals(pid2_case11));
|
1000
|
|
1001
|
Thread.sleep(1000);
|
1002
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1003
|
Identifier pid3_case11 = new Identifier();
|
1004
|
pid3_case11.setValue(generateDocumentId());
|
1005
|
SystemMetadata sysmeta3_case11 = createSystemMetadata(pid3_case11, session.getSubject(), object);
|
1006
|
sysmeta3_case11.setObsoletes(pid2_case11);
|
1007
|
sysmeta3_case11.setSeriesId(sid_case11);
|
1008
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1009
|
CNodeService.getInstance(request).create(session, pid3_case11, object, sysmeta3_case11);
|
1010
|
|
1011
|
sysmeta2_case11.setObsoletedBy(pid3_case11);
|
1012
|
version = version.add(BigInteger.ONE);
|
1013
|
sysmeta2_case11.setSerialVersion(version);
|
1014
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid2_case11, sysmeta2_case11);
|
1015
|
|
1016
|
//archive pid3_case11
|
1017
|
sysmeta3_case11.setArchived(true);
|
1018
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid3_case11, sysmeta3_case11);
|
1019
|
//CNodeService.getInstance(request).archive(session, pid3_case11);
|
1020
|
|
1021
|
//check
|
1022
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case11);
|
1023
|
assertTrue(meta.getObsoletedBy().equals(pid2_case11));
|
1024
|
assertTrue(meta.getObsoletes() == null);
|
1025
|
|
1026
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case11);
|
1027
|
assertTrue(meta.getObsoletedBy().equals(pid3_case11));
|
1028
|
assertTrue(meta.getObsoletes().equals(pid1_case11));
|
1029
|
|
1030
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid3_case11);
|
1031
|
assertTrue(meta.getArchived());
|
1032
|
assertTrue(meta.getObsoletedBy() == null);
|
1033
|
assertTrue(meta.getObsoletes().equals(pid2_case11));
|
1034
|
|
1035
|
System.out.println("case 11: =======");
|
1036
|
head = IdentifierManager.getInstance().getHeadPID(sid_case11);
|
1037
|
assertTrue(head.equals(pid3_case11));
|
1038
|
|
1039
|
|
1040
|
//case-12 P1(S1) <-> P2(S1) -> ??, S1 = P2, (Type 2) (Error, but will happen)
|
1041
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1042
|
Identifier pid1_case12 = new Identifier();
|
1043
|
pid1_case12.setValue(generateDocumentId());
|
1044
|
Identifier sid_case12 = new Identifier();
|
1045
|
sid_case12.setValue("sid."+System.nanoTime());
|
1046
|
SystemMetadata sysmeta_case12 = createSystemMetadata(pid1_case12, session.getSubject(), object);
|
1047
|
sysmeta_case12.setSeriesId(sid_case12);
|
1048
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1049
|
CNodeService.getInstance(request).create(session, pid1_case12, object, sysmeta_case12);
|
1050
|
|
1051
|
Thread.sleep(1000);
|
1052
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1053
|
Identifier pid2_case12 = new Identifier();
|
1054
|
pid2_case12.setValue(generateDocumentId());
|
1055
|
SystemMetadata sysmeta2_case12 = createSystemMetadata(pid2_case12, session.getSubject(), object);
|
1056
|
sysmeta2_case12.setSeriesId(sid_case12);
|
1057
|
sysmeta2_case12.setObsoletes(pid1_case12);
|
1058
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1059
|
CNodeService.getInstance(request).create(session, pid2_case12, object, sysmeta2_case12);
|
1060
|
|
1061
|
sysmeta_case12.setObsoletedBy(pid2_case12);
|
1062
|
version = version.add(BigInteger.ONE);
|
1063
|
sysmeta_case12.setSerialVersion(version);
|
1064
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid1_case12, sysmeta_case12);
|
1065
|
//check
|
1066
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case12);
|
1067
|
assertTrue(meta.getObsoletedBy().equals(pid2_case12));
|
1068
|
|
1069
|
Thread.sleep(1000);
|
1070
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1071
|
Identifier pid3_case12 = new Identifier();
|
1072
|
pid3_case12.setValue(generateDocumentId());
|
1073
|
SystemMetadata sysmeta3_case12 = createSystemMetadata(pid3_case12, session.getSubject(), object);
|
1074
|
sysmeta3_case12.setObsoletes(pid2_case12);
|
1075
|
sysmeta3_case12.setSeriesId(sid_case12);
|
1076
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1077
|
CNodeService.getInstance(request).create(session, pid3_case12, object, sysmeta3_case12);
|
1078
|
|
1079
|
sysmeta2_case12.setObsoletedBy(pid3_case12);
|
1080
|
version = version.add(BigInteger.ONE);
|
1081
|
sysmeta2_case12.setSerialVersion(version);
|
1082
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid2_case12, sysmeta2_case12);
|
1083
|
|
1084
|
//archive pid3_case12
|
1085
|
MNodeService.getInstance(request).delete(session, pid3_case12);
|
1086
|
try {
|
1087
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid3_case12);
|
1088
|
fail("The pid "+pid3_case12.getValue()+" should be deleted.");
|
1089
|
} catch (NotFound ee) {
|
1090
|
assertTrue(true);
|
1091
|
}
|
1092
|
|
1093
|
//check
|
1094
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case12);
|
1095
|
assertTrue(meta.getObsoletedBy().equals(pid2_case12));
|
1096
|
assertTrue(meta.getObsoletes() == null);
|
1097
|
|
1098
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case12);
|
1099
|
assertTrue(meta.getObsoletedBy().equals(pid3_case12));
|
1100
|
assertTrue(meta.getObsoletes().equals(pid1_case12));
|
1101
|
|
1102
|
System.out.println("case 12: =======");
|
1103
|
head = IdentifierManager.getInstance().getHeadPID(sid_case12);
|
1104
|
assertTrue(head.equals(pid2_case12));
|
1105
|
|
1106
|
|
1107
|
|
1108
|
//case-13 P1(S1) <- P2(S1) -> ??, S1 = P2 (P1 is a type 1 end and P2 is a type 2 end, not an ideal chain)
|
1109
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1110
|
Identifier pid1_case13 = new Identifier();
|
1111
|
pid1_case13.setValue(generateDocumentId());
|
1112
|
Identifier sid_case13 = new Identifier();
|
1113
|
sid_case13.setValue("sid."+System.nanoTime());
|
1114
|
SystemMetadata sysmeta_case13 = createSystemMetadata(pid1_case13, session.getSubject(), object);
|
1115
|
sysmeta_case13.setSeriesId(sid_case13);
|
1116
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1117
|
CNodeService.getInstance(request).create(session, pid1_case13, object, sysmeta_case13);
|
1118
|
|
1119
|
Thread.sleep(1000);
|
1120
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1121
|
Identifier pid2_case13 = new Identifier();
|
1122
|
pid2_case13.setValue(generateDocumentId());
|
1123
|
Thread.sleep(1000);
|
1124
|
Identifier pid3_case13 = new Identifier();
|
1125
|
pid3_case13.setValue(generateDocumentId());
|
1126
|
SystemMetadata sysmeta2_case13 = createSystemMetadata(pid2_case13, session.getSubject(), object);
|
1127
|
sysmeta2_case13.setSeriesId(sid_case13);
|
1128
|
sysmeta2_case13.setObsoletes(pid1_case13);
|
1129
|
sysmeta2_case13.setObsoletedBy(pid3_case13);
|
1130
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1131
|
CNodeService.getInstance(request).create(session, pid2_case13, object, sysmeta2_case13);
|
1132
|
|
1133
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case13);
|
1134
|
assertTrue(meta.getObsoletedBy().equals(pid3_case13));
|
1135
|
assertTrue(meta.getObsoletes().equals(pid1_case13));
|
1136
|
|
1137
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case13);
|
1138
|
assertTrue(meta.getObsoletedBy() == null);
|
1139
|
assertTrue(meta.getObsoletes() == null);
|
1140
|
|
1141
|
System.out.println("case 13: =======");
|
1142
|
head = IdentifierManager.getInstance().getHeadPID(sid_case13);
|
1143
|
assertTrue(head.equals(pid2_case13));
|
1144
|
|
1145
|
|
1146
|
|
1147
|
//case-14 P1(S1) <- P2(S1) -> P3(S2), S1 = P2 (P1 is a type one end and P2 is a type 2 end, not an ideal chain)
|
1148
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1149
|
Identifier pid1_case14 = new Identifier();
|
1150
|
pid1_case14.setValue(generateDocumentId());
|
1151
|
Identifier sid_case14 = new Identifier();
|
1152
|
sid_case14.setValue("sid."+System.nanoTime());
|
1153
|
SystemMetadata sysmeta_case14 = createSystemMetadata(pid1_case14, session.getSubject(), object);
|
1154
|
sysmeta_case14.setSeriesId(sid_case14);
|
1155
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1156
|
CNodeService.getInstance(request).create(session, pid1_case14, object, sysmeta_case14);
|
1157
|
|
1158
|
Thread.sleep(1000);
|
1159
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1160
|
Identifier pid2_case14 = new Identifier();
|
1161
|
pid2_case14.setValue(generateDocumentId());
|
1162
|
SystemMetadata sysmeta2_case14 = createSystemMetadata(pid2_case14, session.getSubject(), object);
|
1163
|
sysmeta2_case14.setSeriesId(sid_case14);
|
1164
|
sysmeta2_case14.setObsoletes(pid1_case14);
|
1165
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1166
|
CNodeService.getInstance(request).create(session, pid2_case14, object, sysmeta2_case14);
|
1167
|
|
1168
|
Thread.sleep(1000);
|
1169
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1170
|
Identifier pid3_case14 = new Identifier();
|
1171
|
pid3_case14.setValue(generateDocumentId());
|
1172
|
Identifier sid2_case14 = new Identifier();
|
1173
|
sid2_case14.setValue("sid."+System.nanoTime());
|
1174
|
SystemMetadata sysmeta3_case14 = createSystemMetadata(pid3_case14, session.getSubject(), object);
|
1175
|
sysmeta3_case14.setSeriesId(sid2_case14);
|
1176
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1177
|
CNodeService.getInstance(request).create(session, pid3_case14, object, sysmeta3_case14);
|
1178
|
|
1179
|
sysmeta2_case14.setObsoletedBy(pid3_case14);
|
1180
|
version = version.add(BigInteger.ONE);
|
1181
|
sysmeta2_case14.setSerialVersion(version);
|
1182
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid2_case14, sysmeta2_case14);
|
1183
|
|
1184
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case14);
|
1185
|
assertTrue(meta.getObsoletedBy().equals(pid3_case14));
|
1186
|
assertTrue(meta.getObsoletes().equals(pid1_case14));
|
1187
|
|
1188
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case14);
|
1189
|
assertTrue(meta.getObsoletedBy() == null);
|
1190
|
assertTrue(meta.getObsoletes() == null);
|
1191
|
|
1192
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid3_case14);
|
1193
|
assertTrue(meta.getObsoletedBy() == null);
|
1194
|
assertTrue(meta.getObsoletes() == null);
|
1195
|
|
1196
|
System.out.println("case 14: =======");
|
1197
|
head = IdentifierManager.getInstance().getHeadPID(sid_case14);
|
1198
|
assertTrue(head.equals(pid2_case14));
|
1199
|
head = IdentifierManager.getInstance().getHeadPID(sid2_case14);
|
1200
|
assertTrue(head.equals(pid3_case14));
|
1201
|
|
1202
|
|
1203
|
//case-15 P1(S1) <-> P2(S1) ?? <- P4(S1) <-> P5(S2), S1 = P4 (P2 is a type 1 end and P4 is a type 2 end, not an ideal chain)
|
1204
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1205
|
Identifier pid1_case15 = new Identifier();
|
1206
|
pid1_case15.setValue(generateDocumentId());
|
1207
|
Identifier sid_case15 = new Identifier();
|
1208
|
sid_case15.setValue("sid."+System.nanoTime());
|
1209
|
SystemMetadata sysmeta_case15 = createSystemMetadata(pid1_case15, session.getSubject(), object);
|
1210
|
sysmeta_case15.setSeriesId(sid_case15);
|
1211
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1212
|
CNodeService.getInstance(request).create(session, pid1_case15, object, sysmeta_case15);
|
1213
|
|
1214
|
Thread.sleep(1000);
|
1215
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1216
|
Identifier pid2_case15 = new Identifier();
|
1217
|
pid2_case15.setValue(generateDocumentId());
|
1218
|
SystemMetadata sysmeta2_case15 = createSystemMetadata(pid2_case15, session.getSubject(), object);
|
1219
|
sysmeta2_case15.setSeriesId(sid_case15);
|
1220
|
sysmeta2_case15.setObsoletes(pid1_case15);
|
1221
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1222
|
CNodeService.getInstance(request).create(session, pid2_case15, object, sysmeta2_case15);
|
1223
|
|
1224
|
sysmeta_case15.setObsoletedBy(pid2_case15);
|
1225
|
version = version.add(BigInteger.ONE);
|
1226
|
sysmeta_case15.setSerialVersion(version);
|
1227
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid1_case15, sysmeta_case15);
|
1228
|
//check
|
1229
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case15);
|
1230
|
assertTrue(meta.getObsoletedBy().equals(pid2_case15));
|
1231
|
|
1232
|
Thread.sleep(1000);
|
1233
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1234
|
Identifier pid3_case15 = new Identifier();
|
1235
|
pid3_case15.setValue(generateDocumentId());
|
1236
|
SystemMetadata sysmeta3_case15 = createSystemMetadata(pid3_case15, session.getSubject(), object);
|
1237
|
sysmeta3_case15.setSeriesId(sid_case15);
|
1238
|
sysmeta3_case15.setObsoletes(pid2_case15);
|
1239
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1240
|
CNodeService.getInstance(request).create(session, pid3_case15, object, sysmeta3_case15);
|
1241
|
|
1242
|
Thread.sleep(1000);
|
1243
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1244
|
Identifier pid4_case15 = new Identifier();
|
1245
|
pid4_case15.setValue(generateDocumentId());
|
1246
|
SystemMetadata sysmeta4_case15 = createSystemMetadata(pid4_case15, session.getSubject(), object);
|
1247
|
sysmeta4_case15.setSeriesId(sid_case15);
|
1248
|
sysmeta4_case15.setObsoletes(pid3_case15);
|
1249
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1250
|
CNodeService.getInstance(request).create(session, pid4_case15, object, sysmeta4_case15);
|
1251
|
|
1252
|
Thread.sleep(1000);
|
1253
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1254
|
Identifier pid5_case15 = new Identifier();
|
1255
|
pid5_case15.setValue(generateDocumentId());
|
1256
|
Identifier sid2_case15 = new Identifier();
|
1257
|
sid2_case15.setValue("sid."+System.nanoTime());
|
1258
|
SystemMetadata sysmeta5_case15 = createSystemMetadata(pid5_case15, session.getSubject(), object);
|
1259
|
sysmeta5_case15.setSeriesId(sid2_case15);
|
1260
|
sysmeta5_case15.setObsoletes(pid4_case15);
|
1261
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1262
|
CNodeService.getInstance(request).create(session, pid5_case15, object, sysmeta5_case15);
|
1263
|
|
1264
|
sysmeta4_case15.setObsoletedBy(pid5_case15);
|
1265
|
version = version.add(BigInteger.ONE);
|
1266
|
sysmeta4_case15.setSerialVersion(version);
|
1267
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid4_case15, sysmeta4_case15);
|
1268
|
|
1269
|
CNodeService.getInstance(request).delete(session, pid3_case15);
|
1270
|
try {
|
1271
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid3_case15);
|
1272
|
fail("The pid "+pid3_case15.getValue()+" should be deleted.");
|
1273
|
} catch (NotFound ee) {
|
1274
|
assertTrue(true);
|
1275
|
}
|
1276
|
//check
|
1277
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case15);
|
1278
|
assertTrue(meta.getObsoletedBy().equals(pid2_case15));
|
1279
|
assertTrue(meta.getObsoletes() == null);
|
1280
|
|
1281
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case15);
|
1282
|
assertTrue(meta.getObsoletedBy() == null);
|
1283
|
assertTrue(meta.getObsoletes().equals(pid1_case15));
|
1284
|
|
1285
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid4_case15);
|
1286
|
assertTrue(meta.getObsoletedBy().equals(pid5_case15));
|
1287
|
assertTrue(meta.getObsoletes().equals(pid3_case15));
|
1288
|
|
1289
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid5_case15);
|
1290
|
assertTrue(meta.getObsoletedBy() == null);
|
1291
|
assertTrue(meta.getObsoletes().equals(pid4_case15));
|
1292
|
|
1293
|
System.out.println("case 15: =======");
|
1294
|
head = IdentifierManager.getInstance().getHeadPID(sid_case15);
|
1295
|
assertTrue(head.equals(pid4_case15));
|
1296
|
head = IdentifierManager.getInstance().getHeadPID(sid2_case15);
|
1297
|
assertTrue(head.equals(pid5_case15));
|
1298
|
|
1299
|
|
1300
|
|
1301
|
|
1302
|
//case-16 P1(S1) <- P2(S1) -> ?? <-P4(S2) S1 = P2 (P1 is a type 1 end and P2 is a type 2 ends, not an ideal chain), S2=P4 (rule1)
|
1303
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1304
|
Identifier pid1_case16 = new Identifier();
|
1305
|
pid1_case16.setValue(generateDocumentId());
|
1306
|
Identifier sid_case16 = new Identifier();
|
1307
|
sid_case16.setValue("sid."+System.nanoTime());
|
1308
|
SystemMetadata sysmeta_case16 = createSystemMetadata(pid1_case16, session.getSubject(), object);
|
1309
|
sysmeta_case16.setSeriesId(sid_case16);
|
1310
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1311
|
CNodeService.getInstance(request).create(session, pid1_case16, object, sysmeta_case16);
|
1312
|
|
1313
|
Thread.sleep(1000);
|
1314
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1315
|
Identifier pid2_case16 = new Identifier();
|
1316
|
pid2_case16.setValue(generateDocumentId());
|
1317
|
SystemMetadata sysmeta2_case16 = createSystemMetadata(pid2_case16, session.getSubject(), object);
|
1318
|
sysmeta2_case16.setSeriesId(sid_case16);
|
1319
|
sysmeta2_case16.setObsoletes(pid1_case16);
|
1320
|
CNodeService.getInstance(request).create(session, pid2_case16, object, sysmeta2_case16);
|
1321
|
|
1322
|
Thread.sleep(1000);
|
1323
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1324
|
Identifier pid3_case16 = new Identifier();
|
1325
|
pid3_case16.setValue(generateDocumentId());
|
1326
|
SystemMetadata sysmeta3_case16 = createSystemMetadata(pid3_case16, session.getSubject(), object);
|
1327
|
sysmeta3_case16.setSeriesId(sid_case16);
|
1328
|
sysmeta3_case16.setObsoletes(pid2_case16);
|
1329
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1330
|
CNodeService.getInstance(request).create(session, pid3_case16, object, sysmeta3_case16);
|
1331
|
|
1332
|
sysmeta2_case16.setObsoletedBy(pid3_case16);
|
1333
|
version = version.add(BigInteger.ONE);
|
1334
|
sysmeta2_case16.setSerialVersion(version);
|
1335
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid2_case16, sysmeta2_case16);
|
1336
|
|
1337
|
Thread.sleep(1000);
|
1338
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1339
|
Identifier pid4_case16 = new Identifier();
|
1340
|
pid4_case16.setValue(generateDocumentId());
|
1341
|
Identifier sid2_case16 = new Identifier();
|
1342
|
sid2_case16.setValue("sid."+System.nanoTime());
|
1343
|
SystemMetadata sysmeta4_case16 = createSystemMetadata(pid4_case16, session.getSubject(), object);
|
1344
|
sysmeta4_case16.setSeriesId(sid2_case16);
|
1345
|
sysmeta4_case16.setObsoletes(pid3_case16);
|
1346
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1347
|
CNodeService.getInstance(request).create(session, pid4_case16, object, sysmeta4_case16);
|
1348
|
|
1349
|
CNodeService.getInstance(request).delete(session, pid3_case16);
|
1350
|
try {
|
1351
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid3_case16);
|
1352
|
fail("The pid "+pid3_case16.getValue()+" should be deleted.");
|
1353
|
} catch (NotFound ee) {
|
1354
|
assertTrue(true);
|
1355
|
}
|
1356
|
//check
|
1357
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case16);
|
1358
|
assertTrue(meta.getObsoletedBy() == null);
|
1359
|
assertTrue(meta.getObsoletes() == null);
|
1360
|
|
1361
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case16);
|
1362
|
assertTrue(meta.getObsoletedBy().equals(pid3_case16));
|
1363
|
assertTrue(meta.getObsoletes().equals(pid1_case16));
|
1364
|
|
1365
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid4_case16);
|
1366
|
assertTrue(meta.getObsoletedBy() == null);
|
1367
|
assertTrue(meta.getObsoletes().equals(pid3_case16));
|
1368
|
|
1369
|
System.out.println("case 16: =======");
|
1370
|
head = IdentifierManager.getInstance().getHeadPID(sid_case16);
|
1371
|
assertTrue(head.equals(pid2_case16));
|
1372
|
head = IdentifierManager.getInstance().getHeadPID(sid2_case16);
|
1373
|
assertTrue(head.equals(pid4_case16));
|
1374
|
|
1375
|
|
1376
|
//case-17 P1(S1) <- P2(S1) -> ?? <-P4(S1) S1 = P4 (P1 and P4 are type 1 ends, not an ideal chain)
|
1377
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1378
|
Identifier pid1_case17 = new Identifier();
|
1379
|
pid1_case17.setValue(generateDocumentId());
|
1380
|
Identifier sid_case17 = new Identifier();
|
1381
|
sid_case17.setValue("sid."+System.nanoTime());
|
1382
|
SystemMetadata sysmeta_case17 = createSystemMetadata(pid1_case17, session.getSubject(), object);
|
1383
|
sysmeta_case17.setSeriesId(sid_case17);
|
1384
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1385
|
CNodeService.getInstance(request).create(session, pid1_case17, object, sysmeta_case17);
|
1386
|
|
1387
|
Thread.sleep(1000);
|
1388
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1389
|
Identifier pid2_case17 = new Identifier();
|
1390
|
pid2_case17.setValue(generateDocumentId());
|
1391
|
SystemMetadata sysmeta2_case17 = createSystemMetadata(pid2_case17, session.getSubject(), object);
|
1392
|
sysmeta2_case17.setSeriesId(sid_case17);
|
1393
|
sysmeta2_case17.setObsoletes(pid1_case17);
|
1394
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1395
|
CNodeService.getInstance(request).create(session, pid2_case17, object, sysmeta2_case17);
|
1396
|
|
1397
|
Thread.sleep(1000);
|
1398
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1399
|
Identifier pid3_case17 = new Identifier();
|
1400
|
pid3_case17.setValue(generateDocumentId());
|
1401
|
SystemMetadata sysmeta3_case17 = createSystemMetadata(pid3_case17, session.getSubject(), object);
|
1402
|
sysmeta3_case17.setSeriesId(sid_case17);
|
1403
|
sysmeta3_case17.setObsoletes(pid2_case17);
|
1404
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1405
|
CNodeService.getInstance(request).create(session, pid3_case17, object, sysmeta3_case17);
|
1406
|
|
1407
|
sysmeta2_case17.setObsoletedBy(pid3_case17);
|
1408
|
version = version.add(BigInteger.ONE);
|
1409
|
sysmeta2_case17.setSerialVersion(version);
|
1410
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid2_case17, sysmeta2_case17);
|
1411
|
|
1412
|
Thread.sleep(1000);
|
1413
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1414
|
Identifier pid4_case17 = new Identifier();
|
1415
|
pid4_case17.setValue(generateDocumentId());
|
1416
|
SystemMetadata sysmeta4_case17 = createSystemMetadata(pid4_case17, session.getSubject(), object);
|
1417
|
sysmeta4_case17.setSeriesId(sid_case17);
|
1418
|
sysmeta4_case17.setObsoletes(pid3_case17);
|
1419
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1420
|
CNodeService.getInstance(request).create(session, pid4_case17, object, sysmeta4_case17);
|
1421
|
|
1422
|
CNodeService.getInstance(request).delete(session, pid3_case17);
|
1423
|
try {
|
1424
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid3_case17);
|
1425
|
fail("The pid "+pid3_case17.getValue()+" should be deleted.");
|
1426
|
} catch (NotFound ee) {
|
1427
|
assertTrue(true);
|
1428
|
}
|
1429
|
//check
|
1430
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case17);
|
1431
|
assertTrue(meta.getObsoletedBy() == null);
|
1432
|
assertTrue(meta.getObsoletes() == null);
|
1433
|
|
1434
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case17);
|
1435
|
assertTrue(meta.getObsoletedBy().equals(pid3_case17));
|
1436
|
assertTrue(meta.getObsoletes().equals(pid1_case17));
|
1437
|
|
1438
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid4_case17);
|
1439
|
assertTrue(meta.getObsoletedBy() == null);
|
1440
|
assertTrue(meta.getObsoletes().equals(pid3_case17));
|
1441
|
|
1442
|
System.out.println("case 17: =======");
|
1443
|
head = IdentifierManager.getInstance().getHeadPID(sid_case17);
|
1444
|
assertTrue(head.equals(pid4_case17));
|
1445
|
|
1446
|
|
1447
|
|
1448
|
//case-18 P1(S1) <->P2(S1) -> ?? ???<-P5(S1) S1 = P5 (P2 is a type 2 end and P4 is a type 1 end, not an ideal chain)
|
1449
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1450
|
Identifier pid1_case18 = new Identifier();
|
1451
|
pid1_case18.setValue(generateDocumentId());
|
1452
|
Identifier sid_case18 = new Identifier();
|
1453
|
sid_case18.setValue("sid."+System.nanoTime());
|
1454
|
SystemMetadata sysmeta_case18 = createSystemMetadata(pid1_case18, session.getSubject(), object);
|
1455
|
sysmeta_case18.setSeriesId(sid_case18);
|
1456
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1457
|
CNodeService.getInstance(request).create(session, pid1_case18, object, sysmeta_case18);
|
1458
|
|
1459
|
Thread.sleep(1000);
|
1460
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1461
|
Identifier pid2_case18 = new Identifier();
|
1462
|
pid2_case18.setValue(generateDocumentId());
|
1463
|
SystemMetadata sysmeta2_case18 = createSystemMetadata(pid2_case18, session.getSubject(), object);
|
1464
|
sysmeta2_case18.setSeriesId(sid_case18);
|
1465
|
sysmeta2_case18.setObsoletes(pid1_case18);
|
1466
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1467
|
CNodeService.getInstance(request).create(session, pid2_case18, object, sysmeta2_case18);
|
1468
|
|
1469
|
sysmeta_case18.setObsoletedBy(pid2_case18);
|
1470
|
version = version.add(BigInteger.ONE);
|
1471
|
sysmeta_case18.setSerialVersion(version);
|
1472
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid1_case18, sysmeta_case18);
|
1473
|
|
1474
|
Thread.sleep(1000);
|
1475
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1476
|
Identifier pid3_case18 = new Identifier();
|
1477
|
pid3_case18.setValue(generateDocumentId());
|
1478
|
SystemMetadata sysmeta3_case18 = createSystemMetadata(pid3_case18, session.getSubject(), object);
|
1479
|
sysmeta3_case18.setSeriesId(sid_case18);
|
1480
|
sysmeta3_case18.setObsoletes(pid2_case18);
|
1481
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1482
|
CNodeService.getInstance(request).create(session, pid3_case18, object, sysmeta3_case18);
|
1483
|
|
1484
|
sysmeta2_case18.setObsoletedBy(pid3_case18);
|
1485
|
version = version.add(BigInteger.ONE);
|
1486
|
sysmeta2_case18.setSerialVersion(version);
|
1487
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid2_case18, sysmeta2_case18);
|
1488
|
|
1489
|
Thread.sleep(1000);
|
1490
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1491
|
Identifier pid4_case18 = new Identifier();
|
1492
|
pid4_case18.setValue(generateDocumentId());
|
1493
|
SystemMetadata sysmeta4_case18 = createSystemMetadata(pid4_case18, session.getSubject(), object);
|
1494
|
sysmeta4_case18.setSeriesId(sid_case18);
|
1495
|
sysmeta4_case18.setObsoletes(pid3_case18);
|
1496
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1497
|
CNodeService.getInstance(request).create(session, pid4_case18, object, sysmeta4_case18);
|
1498
|
|
1499
|
Thread.sleep(1000);
|
1500
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1501
|
Identifier pid5_case18 = new Identifier();
|
1502
|
pid5_case18.setValue(generateDocumentId());
|
1503
|
SystemMetadata sysmeta5_case18 = createSystemMetadata(pid5_case18, session.getSubject(), object);
|
1504
|
sysmeta5_case18.setSeriesId(sid_case18);
|
1505
|
sysmeta5_case18.setObsoletes(pid4_case18);
|
1506
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1507
|
CNodeService.getInstance(request).create(session, pid5_case18, object, sysmeta5_case18);
|
1508
|
|
1509
|
sysmeta4_case18.setObsoletedBy(pid5_case18);
|
1510
|
version = version.add(BigInteger.ONE);
|
1511
|
sysmeta4_case18.setSerialVersion(version);
|
1512
|
MNodeService.getInstance(request).updateSystemMetadata(session, pid4_case18, sysmeta4_case18);
|
1513
|
|
1514
|
CNodeService.getInstance(request).delete(session, pid3_case18);
|
1515
|
try {
|
1516
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid3_case18);
|
1517
|
fail("The pid "+pid3_case18.getValue()+" should be deleted.");
|
1518
|
} catch (NotFound ee) {
|
1519
|
assertTrue(true);
|
1520
|
}
|
1521
|
|
1522
|
CNodeService.getInstance(request).delete(session, pid4_case18);
|
1523
|
try {
|
1524
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid4_case18);
|
1525
|
fail("The pid "+pid4_case18.getValue()+" should be deleted.");
|
1526
|
} catch (NotFound ee) {
|
1527
|
assertTrue(true);
|
1528
|
}
|
1529
|
//check
|
1530
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case18);
|
1531
|
assertTrue(meta.getObsoletedBy().equals(pid2_case18));
|
1532
|
assertTrue(meta.getObsoletes() == null);
|
1533
|
|
1534
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case18);
|
1535
|
assertTrue(meta.getObsoletedBy().equals(pid3_case18));
|
1536
|
assertTrue(meta.getObsoletes().equals(pid1_case18));
|
1537
|
|
1538
|
meta = CNodeService.getInstance(request).getSystemMetadata(session, pid5_case18);
|
1539
|
assertTrue(meta.getObsoletedBy() == null);
|
1540
|
assertTrue(meta.getObsoletes().equals(pid4_case18));
|
1541
|
|
1542
|
System.out.println("case 18: =======");
|
1543
|
head = IdentifierManager.getInstance().getHeadPID(sid_case18);
|
1544
|
assertTrue(head.equals(pid5_case18));
|
1545
|
|
1546
|
//case-19 This is about the time stamps messing up.
|
1547
|
//P1(S1,t1) <-P2(S1,t2) <-P3(S1, t3) S1 = P3 (t1, t2 and t3 are the time stamp while t1 >t2 > t3. P1, P2 and P3 are a type 1 end, not an ideal chain.
|
1548
|
//So we will pick up P1 as the head since t1 is the lastest one. However, if we also consider the obsoletes chain, we will pick up P3)
|
1549
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1550
|
Identifier pid3_case19 = new Identifier();
|
1551
|
pid3_case19.setValue(generateDocumentId());
|
1552
|
System.out.println("pid3 is "+pid3_case19.getValue());
|
1553
|
Thread.sleep(1000);
|
1554
|
Identifier pid2_case19 = new Identifier();
|
1555
|
pid2_case19.setValue(generateDocumentId());
|
1556
|
System.out.println("pid2 is "+pid2_case19.getValue());
|
1557
|
Thread.sleep(1000);
|
1558
|
Identifier pid1_case19 = new Identifier();
|
1559
|
pid1_case19.setValue(generateDocumentId());
|
1560
|
System.out.println("pid1 is "+pid1_case19.getValue());
|
1561
|
|
1562
|
Identifier sid_case19 = new Identifier();
|
1563
|
sid_case19.setValue("sid."+System.nanoTime());
|
1564
|
SystemMetadata sysmeta3_case19 = createSystemMetadata(pid3_case19, session.getSubject(), object);
|
1565
|
sysmeta3_case19.setSeriesId(sid_case19);
|
1566
|
sysmeta3_case19.setObsoletes(pid2_case19);
|
1567
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1568
|
CNodeService.getInstance(request).create(session, pid3_case19, object, sysmeta3_case19);
|
1569
|
SystemMetadata sys3 = CNodeService.getInstance(request).getSystemMetadata(session, pid3_case19);
|
1570
|
Date time3 = sys3.getDateUploaded();
|
1571
|
|
1572
|
Thread.sleep(1000);
|
1573
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1574
|
SystemMetadata sysmeta2_case19 = createSystemMetadata(pid2_case19, session.getSubject(), object);
|
1575
|
sysmeta2_case19.setSeriesId(sid_case19);
|
1576
|
sysmeta2_case19.setObsoletes(pid1_case19);
|
1577
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1578
|
CNodeService.getInstance(request).create(session, pid2_case19, object, sysmeta2_case19);
|
1579
|
SystemMetadata sys2 = CNodeService.getInstance(request).getSystemMetadata(session, pid2_case19);
|
1580
|
Date time2 = sys2.getDateUploaded();
|
1581
|
|
1582
|
Thread.sleep(1000);
|
1583
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1584
|
SystemMetadata sysmeta1_case19 = createSystemMetadata(pid1_case19, session.getSubject(), object);
|
1585
|
sysmeta1_case19.setSeriesId(sid_case19);
|
1586
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1587
|
CNodeService.getInstance(request).create(session, pid1_case19, object, sysmeta1_case19);
|
1588
|
SystemMetadata sys1 = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case19);
|
1589
|
Date time1 = sys1.getDateUploaded();
|
1590
|
|
1591
|
//time1 > time2 > time3
|
1592
|
assertTrue(time1.getTime()>time2.getTime());
|
1593
|
assertTrue(time2.getTime()>time3.getTime());
|
1594
|
|
1595
|
System.out.println("case 19: =======");
|
1596
|
Identifier head2 = IdentifierManager.getInstance().getHeadPID(sid_case19);
|
1597
|
assertTrue(head2.equals(pid3_case19));
|
1598
|
|
1599
|
|
1600
|
} catch (Exception e) {
|
1601
|
e.printStackTrace();
|
1602
|
fail(e.getMessage());
|
1603
|
}
|
1604
|
|
1605
|
}
|
1606
|
|
1607
|
/**
|
1608
|
* Insert a test document, returning the docid that was used.
|
1609
|
*/
|
1610
|
private String insertTestDocument() {
|
1611
|
String accessBlock = getAccessBlock("public", true, true,
|
1612
|
false, false, false);
|
1613
|
String emldoc = getTestEmlDoc("Test identifier manager", EML2_1_0, null,
|
1614
|
null, "http://fake.example.com/somedata", null,
|
1615
|
accessBlock, null, null,
|
1616
|
null, null);
|
1617
|
System.out.println("inserting doc: " + emldoc);
|
1618
|
String docid = generateDocumentId() + ".1";
|
1619
|
try {
|
1620
|
m.login(username, password);
|
1621
|
String response = insertDocumentId(docid, emldoc, true, false);
|
1622
|
} catch (MetacatAuthException e) {
|
1623
|
fail(e.getMessage());
|
1624
|
} catch (MetacatInaccessibleException e) {
|
1625
|
fail(e.getMessage());
|
1626
|
}
|
1627
|
return docid;
|
1628
|
}
|
1629
|
|
1630
|
/**
|
1631
|
* Method to test new system metadata field such as media type and file name.
|
1632
|
*/
|
1633
|
public void testMediaType() throws Exception {
|
1634
|
String fileName = "new file name";
|
1635
|
String name = "text/plain";
|
1636
|
String p1Name = "charset";
|
1637
|
String p1Value = "UTF8";
|
1638
|
String p2Name = "n2";
|
1639
|
String p2Value = "v2";
|
1640
|
IdentifierManager im = IdentifierManager.getInstance();
|
1641
|
|
1642
|
//test system metadata write/read without mediatype and file name.
|
1643
|
String docid = "test." + new Date().getTime() + ".1";
|
1644
|
String guid = "guid:" + docid;
|
1645
|
//create a mapping (identifier-docid)
|
1646
|
im.createMapping(guid, docid);
|
1647
|
Session session = getTestSession();
|
1648
|
Identifier id = new Identifier();
|
1649
|
id.setValue(guid);
|
1650
|
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1651
|
SystemMetadata sysmeta = createSystemMetadata(id, session.getSubject(), object);
|
1652
|
//sysmeta.setFileName(fileName);
|
1653
|
im.insertOrUpdateSystemMetadata(sysmeta);
|
1654
|
SystemMetadata read = im.getSystemMetadata(guid);
|
1655
|
assertTrue(read.getIdentifier().equals(id));
|
1656
|
assertTrue(read.getFileName() == null);
|
1657
|
assertTrue(read.getMediaType() == null);
|
1658
|
//remove the system metadata
|
1659
|
im.deleteSystemMetadata(guid);
|
1660
|
//remove the mapping
|
1661
|
im.removeMapping(guid, docid);
|
1662
|
|
1663
|
|
1664
|
//test system metadata write/read with mediatype and file name.
|
1665
|
Thread.sleep(1000);
|
1666
|
docid = "test." + new Date().getTime() + ".1";
|
1667
|
guid = "guid:" + docid;
|
1668
|
//create a mapping (identifier-docid)
|
1669
|
im.createMapping(guid, docid);
|
1670
|
id = new Identifier();
|
1671
|
id.setValue(guid);
|
1672
|
object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1673
|
sysmeta = createSystemMetadata(id, session.getSubject(), object);
|
1674
|
sysmeta.setFileName(fileName);
|
1675
|
MediaType media = new MediaType();
|
1676
|
media.setName(name);
|
1677
|
MediaTypeProperty p1 = new MediaTypeProperty();
|
1678
|
p1.setName(p1Name);
|
1679
|
p1.setValue(p1Value);
|
1680
|
media.addProperty(p1);
|
1681
|
MediaTypeProperty p2 = new MediaTypeProperty();
|
1682
|
p2.setName(p2Name);
|
1683
|
p2.setValue(p2Value);
|
1684
|
media.addProperty(p2);
|
1685
|
sysmeta.setMediaType(media);
|
1686
|
im.insertOrUpdateSystemMetadata(sysmeta);
|
1687
|
read = im.getSystemMetadata(guid);
|
1688
|
assertTrue(read.getIdentifier().equals(id));
|
1689
|
assertTrue(read.getFileName().equals(fileName));
|
1690
|
MediaType type = read.getMediaType();
|
1691
|
assertTrue(type.getName().equals(name));
|
1692
|
List<MediaTypeProperty> list = type.getPropertyList();
|
1693
|
assertTrue(list.size() == 2);
|
1694
|
MediaTypeProperty item1 = list.get(0);
|
1695
|
assertTrue(item1.getName().equals(p1Name));
|
1696
|
assertTrue(item1.getValue().equals(p1Value));
|
1697
|
MediaTypeProperty item2 = list.get(1);
|
1698
|
assertTrue(item2.getName().equals(p2Name));
|
1699
|
assertTrue(item2.getValue().equals(p2Value));
|
1700
|
|
1701
|
//Thread.sleep(100000);
|
1702
|
//remove the system metadata
|
1703
|
im.deleteSystemMetadata(guid);
|
1704
|
//remove the mapping
|
1705
|
im.removeMapping(guid, docid);
|
1706
|
|
1707
|
|
1708
|
}
|
1709
|
|
1710
|
private void ph(String s)
|
1711
|
{
|
1712
|
System.out.println("*********************** " + s + " ****************************");
|
1713
|
}
|
1714
|
|
1715
|
public void testQuerySystemMetadata() throws Exception {
|
1716
|
String nodeIdStr="rtgf:test:ert";
|
1717
|
Date startTime = null;
|
1718
|
Date endTime = null;
|
1719
|
ObjectFormatIdentifier objectFormatId = null;
|
1720
|
NodeReference nodeId = null;
|
1721
|
int start = 0;
|
1722
|
int count =1000;
|
1723
|
Identifier identifier = null;
|
1724
|
boolean isSID = false;
|
1725
|
ObjectList list = IdentifierManager.getInstance().querySystemMetadata(startTime, endTime,
|
1726
|
objectFormatId, nodeId, start, count, identifier, isSID);
|
1727
|
int size1= list.sizeObjectInfoList();
|
1728
|
assertTrue( size1>0);
|
1729
|
nodeId = new NodeReference();
|
1730
|
String currentNodeId = Settings.getConfiguration().getString("dataone.nodeId");
|
1731
|
nodeId.setValue(currentNodeId);
|
1732
|
list = IdentifierManager.getInstance().querySystemMetadata(startTime, endTime,
|
1733
|
objectFormatId, nodeId, start, count, identifier, isSID);
|
1734
|
int size2= list.sizeObjectInfoList();
|
1735
|
assertTrue( size2 > 0);
|
1736
|
assertTrue( size1 >= size2);
|
1737
|
nodeId.setValue("there_bei_we12");
|
1738
|
list = IdentifierManager.getInstance().querySystemMetadata(startTime, endTime,
|
1739
|
objectFormatId, nodeId, start, count, identifier, isSID);
|
1740
|
int size3 = list.sizeObjectInfoList();
|
1741
|
assertTrue(size3==0);
|
1742
|
|
1743
|
Session session = getTestSession();
|
1744
|
Identifier guid = new Identifier();
|
1745
|
guid.setValue(generateDocumentId());
|
1746
|
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1747
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
1748
|
nodeId.setValue(nodeIdStr);
|
1749
|
sysmeta.setAuthoritativeMemberNode(nodeId);
|
1750
|
String sid1= "sid."+System.nanoTime();
|
1751
|
Identifier seriesId = new Identifier();
|
1752
|
seriesId.setValue(sid1);
|
1753
|
System.out.println("the first sid is "+seriesId.getValue());
|
1754
|
sysmeta.setSeriesId(seriesId);
|
1755
|
MNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
1756
|
Thread.sleep(5000);
|
1757
|
list = IdentifierManager.getInstance().querySystemMetadata(startTime, endTime,
|
1758
|
objectFormatId, nodeId, start, count, identifier, isSID);
|
1759
|
int size4 = list.sizeObjectInfoList();
|
1760
|
assertTrue(size4 > 0);
|
1761
|
}
|
1762
|
|
1763
|
public void testObjectFileExist() throws Exception {
|
1764
|
//test the data object
|
1765
|
Session session = getTestSession();
|
1766
|
Identifier guid = new Identifier();
|
1767
|
guid.setValue(generateDocumentId());
|
1768
|
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
|
1769
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
1770
|
MNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
1771
|
String localId = IdentifierManager.getInstance().getLocalId(guid.getValue());
|
1772
|
boolean isScienceMetadata = false;
|
1773
|
assertTrue("The data file "+localId+" should exists.", IdentifierManager.getInstance().objectFileExists(localId, isScienceMetadata));
|
1774
|
|
1775
|
localId = "boo.foo.12w3d";
|
1776
|
assertTrue("The data file "+localId+" should exists.", !IdentifierManager.getInstance().objectFileExists(localId, isScienceMetadata));
|
1777
|
|
1778
|
Thread.sleep(500);
|
1779
|
//test the medata object
|
1780
|
guid = new Identifier();
|
1781
|
guid.setValue(generateDocumentId());
|
1782
|
object = new ByteArrayInputStream(FileUtils.readFileToByteArray(new File("./test/eml-sample.xml")));
|
1783
|
sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
1784
|
ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
|
1785
|
formatId.setValue("eml://ecoinformatics.org/eml-2.0.1");
|
1786
|
sysmeta.setFormatId(formatId);
|
1787
|
MNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
1788
|
localId = IdentifierManager.getInstance().getLocalId(guid.getValue());
|
1789
|
isScienceMetadata = true;
|
1790
|
assertTrue("The science data file "+localId+" should exists.", IdentifierManager.getInstance().objectFileExists(localId, isScienceMetadata));
|
1791
|
|
1792
|
localId = "boo.foo.12w3d";
|
1793
|
assertTrue("The science data file "+localId+" should exists.", !IdentifierManager.getInstance().objectFileExists(localId, isScienceMetadata));
|
1794
|
|
1795
|
Thread.sleep(500);
|
1796
|
//test the medata object
|
1797
|
guid = new Identifier();
|
1798
|
guid.setValue(generateDocumentId());
|
1799
|
object = new ByteArrayInputStream(FileUtils.readFileToByteArray(new File("./test/resourcemap.xml")));
|
1800
|
sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
1801
|
formatId = new ObjectFormatIdentifier();
|
1802
|
formatId.setValue("http://www.openarchives.org/ore/terms");
|
1803
|
sysmeta.setFormatId(formatId);
|
1804
|
MNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
1805
|
localId = IdentifierManager.getInstance().getLocalId(guid.getValue());
|
1806
|
System.out.println("The local id for resource map ================================= is "+localId);
|
1807
|
isScienceMetadata = false;
|
1808
|
assertTrue("The science data file "+localId+" should exists.", IdentifierManager.getInstance().objectFileExists(localId, isScienceMetadata));
|
1809
|
|
1810
|
|
1811
|
|
1812
|
}
|
1813
|
|
1814
|
public void testExistsInXmlRevisionTable() {
|
1815
|
try {
|
1816
|
String localId = "test.12";
|
1817
|
int rev =1;
|
1818
|
assertTrue("The object "+localId+" should not exists in the xml_revisions table.", !IdentifierManager.getInstance().existsInXmlLRevisionTable(localId, rev));
|
1819
|
} catch (Exception e) {
|
1820
|
e.printStackTrace();
|
1821
|
fail("testExistsInXmlRevisiontable failed since" +e.getMessage());
|
1822
|
}
|
1823
|
|
1824
|
}
|
1825
|
/**
|
1826
|
* We want to act as the CN itself
|
1827
|
* @throws ServiceFailure
|
1828
|
* @throws Exception
|
1829
|
*/
|
1830
|
@Override
|
1831
|
public Session getTestSession() throws Exception {
|
1832
|
Session session = super.getTestSession();
|
1833
|
|
1834
|
// use the first CN we find in the nodelist
|
1835
|
NodeList nodeList = D1Client.getCN().listNodes();
|
1836
|
for (Node node : nodeList.getNodeList()) {
|
1837
|
if ( node.getType().equals(NodeType.CN) ) {
|
1838
|
|
1839
|
List<Subject> subjects = node.getSubjectList();
|
1840
|
for (Subject subject : subjects) {
|
1841
|
session.setSubject(subject);
|
1842
|
// we are done here
|
1843
|
return session;
|
1844
|
}
|
1845
|
}
|
1846
|
}
|
1847
|
// in case we didn't find it
|
1848
|
return session;
|
1849
|
}
|
1850
|
|
1851
|
}
|