Revision 9081
Added by Jing Tao almost 10 years ago
test/edu/ucsb/nceas/metacat/dataone/SIDTest.java | ||
---|---|---|
118 | 118 |
} |
119 | 119 |
|
120 | 120 |
public void testCases() throws Exception { |
121 |
testCase1(); |
|
121 | 122 |
testCase14(); |
122 | 123 |
} |
123 | 124 |
|
124 | 125 |
/** |
126 |
* case 1. P1(S1) <-> P2(S1), S1 = P2 (Rule 1) |
|
127 |
*/ |
|
128 |
private void testCase1() throws Exception { |
|
129 |
Identifier s1 = new Identifier(); |
|
130 |
s1.setValue("S1"); |
|
131 |
Identifier s2 = new Identifier(); |
|
132 |
s2.setValue("S2"); |
|
133 |
Identifier p1 = new Identifier(); |
|
134 |
p1.setValue("P1"); |
|
135 |
Identifier p2 = new Identifier(); |
|
136 |
p2.setValue("P2"); |
|
137 |
|
|
138 |
|
|
139 |
SystemMetadata p1Sys = new SystemMetadata(); |
|
140 |
p1Sys.setIdentifier(p1); |
|
141 |
p1Sys.setSeriesId(s1); |
|
142 |
p1Sys.setObsoletedBy(p2); |
|
143 |
p1Sys.setDateUploaded(new Date(100)); |
|
144 |
|
|
145 |
SystemMetadata p2Sys = new SystemMetadata(); |
|
146 |
p2Sys.setIdentifier(p2); |
|
147 |
p2Sys.setSeriesId(s1); |
|
148 |
p2Sys.setObsoletes(p1); |
|
149 |
p2Sys.setDateUploaded(new Date(200)); |
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
Vector<SystemMetadata> chain = new Vector<SystemMetadata>(); |
|
154 |
chain.add(p1Sys); |
|
155 |
chain.add(p2Sys); |
|
156 |
|
|
157 |
System.out.println("Case 1:"); |
|
158 |
Identifier head = getHeadVersion(s1, chain); |
|
159 |
//System.out.println("The head is "+head.getValue()); |
|
160 |
assertTrue(head.equals(p2)); |
|
161 |
} |
|
162 |
|
|
163 |
/** |
|
125 | 164 |
* Case 14: P1(S1) <- P2(S1) -> P3(S2). |
126 |
* After decorating sysmeta, it changed to P1(S1) <-> P2(S1) <-> P3(S2). |
|
127 |
* S1 = P2 (Rule 3) |
|
165 |
* It has a missing obsoletedBy fields, we use the uploadedDate field.S1 = P2 |
|
128 | 166 |
* @throws Exception |
129 | 167 |
*/ |
130 | 168 |
private void testCase14() throws Exception { |
... | ... | |
160 | 198 |
chain.add(p2Sys); |
161 | 199 |
chain.add(p3Sys); |
162 | 200 |
|
201 |
System.out.println("Case 14:"); |
|
163 | 202 |
Identifier head = getHeadVersion(s1, chain); |
164 | 203 |
//System.out.println("The head is "+head.getValue()); |
165 | 204 |
assertTrue(head.equals(p2)); |
... | ... | |
231 | 270 |
boolean has = false; |
232 | 271 |
if(targetSysmeta != null) { |
233 | 272 |
if (targetSysmeta.getObsoletes() == null && targetSysmeta.getObsoletedBy() == null) { |
234 |
Identifier obsoletes = getRelatedIdentifier(targetSysmeta.getIdentifier(), OBSOLETES, chain); |
|
235 |
if(obsoletes != null) { |
|
273 |
if(foundIdentifierInAnotherSystemMetadata(targetSysmeta.getIdentifier(), OBSOLETEDBY, chain)) { |
|
236 | 274 |
has = true; |
237 |
|
|
238 | 275 |
} else { |
239 |
Identifier obsoleted = getRelatedIdentifier(targetSysmeta.getIdentifier(), OBSOLETEDBY, chain); |
|
240 |
if(obsoleted != null) { |
|
276 |
if(foundIdentifierInAnotherSystemMetadata(targetSysmeta.getIdentifier(), OBSOLETES, chain)) { |
|
241 | 277 |
has = true; |
242 | 278 |
} |
243 | 279 |
} |
244 | 280 |
|
245 | 281 |
} else if (targetSysmeta.getObsoletes() != null && targetSysmeta.getObsoletedBy() == null) { |
246 |
Identifier obsoleted = getRelatedIdentifier(targetSysmeta.getIdentifier(), OBSOLETEDBY, chain); |
|
247 |
if(obsoleted != null) { |
|
282 |
if(foundIdentifierInAnotherSystemMetadata(targetSysmeta.getIdentifier(), OBSOLETES, chain)) { |
|
248 | 283 |
has = true; |
249 | 284 |
} |
250 | 285 |
|
251 | 286 |
} else if (targetSysmeta.getObsoletes() == null && targetSysmeta.getObsoletedBy() != null) { |
252 |
Identifier obsoletes = getRelatedIdentifier(targetSysmeta.getIdentifier(), OBSOLETES, chain); |
|
253 |
if(obsoletes != null) { |
|
287 |
if(foundIdentifierInAnotherSystemMetadata(targetSysmeta.getIdentifier(), OBSOLETEDBY, chain)) { |
|
254 | 288 |
has = true; |
255 | 289 |
} |
256 | 290 |
} |
... | ... | |
259 | 293 |
} |
260 | 294 |
|
261 | 295 |
/** |
296 |
* Determine if the sepcified identifier exists in the sepcified field in another system metadata object. |
|
297 |
* @param target |
|
298 |
* @param fieldName |
|
299 |
* @param chain |
|
300 |
* @return true if we found it; false otherwise. |
|
301 |
*/ |
|
302 |
private boolean foundIdentifierInAnotherSystemMetadata(Identifier target, String fieldName, Vector<SystemMetadata> chain) { |
|
303 |
boolean found = false; |
|
304 |
if(fieldName.equals(OBSOLETES)) { |
|
305 |
for(SystemMetadata sysmeta :chain) { |
|
306 |
Identifier obsoletes = sysmeta.getObsoletes(); |
|
307 |
if(obsoletes != null && obsoletes.equals(target)) { |
|
308 |
System.out.println("missing obsoletedBy"); |
|
309 |
found = true; |
|
310 |
} |
|
311 |
} |
|
312 |
} else if(fieldName.equals(OBSOLETEDBY)) { |
|
313 |
for(SystemMetadata sysmeta :chain) { |
|
314 |
Identifier obsoletedBy = sysmeta.getObsoletedBy(); |
|
315 |
if(obsoletedBy != null && obsoletedBy.equals(target)) { |
|
316 |
System.out.println("missing obsoleteds"); |
|
317 |
found = true; |
|
318 |
} |
|
319 |
} |
|
320 |
|
|
321 |
} |
|
322 |
return found; |
|
323 |
} |
|
324 |
|
|
325 |
/** |
|
262 | 326 |
* Get the head version of the chain |
263 | 327 |
* @param sid |
264 | 328 |
* @return |
... | ... | |
299 | 363 |
} |
300 | 364 |
|
301 | 365 |
if(hasMissingObsolescenceFields) { |
302 |
System.out.println("It has an object whose system metadata has missing obsoletes or obsoletedBy field."); |
|
366 |
System.out.println("It has an object whose system metadata has a missing obsoletes or obsoletedBy field.");
|
|
303 | 367 |
Collections.sort(sidChain, new SystemMetadataDateUploadedComparator()); |
304 | 368 |
pid =sidChain.lastElement().getIdentifier(); |
305 | 369 |
} else { |
Also available in: Unified diff
Added a test case and fixed a bug.