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