Revision 9286
Added by Jing Tao over 9 years ago
test/edu/ucsb/nceas/metacat/dataone/CNodeServiceTest.java | ||
---|---|---|
833 | 833 |
CNodeService.getInstance(request).create(session, newPid, object2, newSysMeta); |
834 | 834 |
//update the system metadata of previous version. |
835 | 835 |
sysmeta.setObsoletedBy(newPid); |
836 |
SystemMetadata read = CNodeService.getInstance(request).getSystemMetadata(session, guid); |
|
837 |
BigInteger version = read.getSerialVersion(); |
|
838 |
version = version.add(BigInteger.ONE); |
|
839 |
sysmeta.setSerialVersion(version); |
|
836 | 840 |
CNodeService.getInstance(request).updateSystemMetadata(session, guid, sysmeta); |
837 | 841 |
InputStream result4 = CNodeService.getInstance(request).get(session, guid); |
838 | 842 |
// go back to beginning of original stream |
... | ... | |
918 | 922 |
CNodeService.getInstance(request).create(session, newPid2, object3, sysmeta3); |
919 | 923 |
//update the system metadata of the previous version |
920 | 924 |
newSysMeta.setObsoletedBy(newPid2); |
925 |
SystemMetadata read2 = CNodeService.getInstance(request).getSystemMetadata(session, newPid); |
|
926 |
BigInteger version2= read2.getSerialVersion(); |
|
927 |
version2 = version2.add(BigInteger.ONE); |
|
928 |
newSysMeta.setSerialVersion(version2); |
|
921 | 929 |
CNodeService.getInstance(request).updateSystemMetadata(session, newPid, newSysMeta); |
922 | 930 |
|
923 | 931 |
InputStream result9 = CNodeService.getInstance(request).get(session, guid); |
... | ... | |
1207 | 1215 |
|
1208 | 1216 |
//test to fail to update system metadata by a non-cn subject |
1209 | 1217 |
Session testSession = getTestSession(); |
1210 |
metadata.setArchived(true); |
|
1218 |
SystemMetadata sysmeta1 = CNodeService.getInstance(request).getSystemMetadata(session, guid); |
|
1219 |
BigInteger version = sysmeta.getSerialVersion(); |
|
1220 |
version = version.add(BigInteger.ONE); |
|
1221 |
sysmeta1.setSerialVersion(version); |
|
1222 |
sysmeta1.setArchived(true); |
|
1211 | 1223 |
try { |
1212 |
CNodeService.getInstance(request).updateSystemMetadata(testSession, guid, metadata);
|
|
1224 |
CNodeService.getInstance(request).updateSystemMetadata(testSession, guid, sysmeta1);
|
|
1213 | 1225 |
fail("It shouldn't get there since the test session can't update system metadata"); |
1214 | 1226 |
} catch (NotAuthorized e) { |
1215 | 1227 |
|
... | ... | |
1217 | 1229 |
|
1218 | 1230 |
|
1219 | 1231 |
//update system metadata sucessfully |
1220 |
metadata.setArchived(true);
|
|
1221 |
CNodeService.getInstance(request).updateSystemMetadata(session, guid, metadata);
|
|
1232 |
sysmeta1.setArchived(true);
|
|
1233 |
CNodeService.getInstance(request).updateSystemMetadata(session, guid, sysmeta1);
|
|
1222 | 1234 |
SystemMetadata metadata2 = CNodeService.getInstance(request).getSystemMetadata(session, seriesId); |
1223 | 1235 |
assertTrue(metadata2.getIdentifier().equals(guid)); |
1224 | 1236 |
assertTrue(metadata2.getSeriesId().equals(seriesId)); |
1225 | 1237 |
assertTrue(metadata2.getArchived().equals(true)); |
1226 | 1238 |
assertTrue(metadata2.getChecksum().getValue().equals(metadata.getChecksum().getValue())); |
1227 | 1239 |
|
1240 |
SystemMetadata sysmeta2 = CNodeService.getInstance(request).getSystemMetadata(session, seriesId); |
|
1241 |
version = sysmeta2.getSerialVersion(); |
|
1242 |
version = version.add(BigInteger.ONE); |
|
1243 |
sysmeta2.setSerialVersion(version); |
|
1228 | 1244 |
Identifier newId = new Identifier(); |
1229 | 1245 |
newId.setValue("newValue"); |
1230 |
metadata.setIdentifier(newId);
|
|
1246 |
sysmeta2.setIdentifier(newId);
|
|
1231 | 1247 |
try { |
1232 |
CNodeService.getInstance(request).updateSystemMetadata(session, guid, metadata);
|
|
1248 |
CNodeService.getInstance(request).updateSystemMetadata(session, guid, sysmeta2);
|
|
1233 | 1249 |
fail("We shouldn't get there"); |
1234 | 1250 |
} catch (Exception e) { |
1235 | 1251 |
assertTrue(e instanceof InvalidRequest); |
1236 | 1252 |
} |
1237 | 1253 |
|
1238 | 1254 |
newId.setValue("newValue"); |
1239 |
metadata.setSeriesId(newId);
|
|
1255 |
sysmeta2.setSeriesId(newId);
|
|
1240 | 1256 |
try { |
1241 |
CNodeService.getInstance(request).updateSystemMetadata(session, guid, metadata);
|
|
1257 |
CNodeService.getInstance(request).updateSystemMetadata(session, guid, sysmeta2);
|
|
1242 | 1258 |
fail("We shouldn't get there"); |
1243 | 1259 |
} catch (Exception e) { |
1244 | 1260 |
assertTrue(e instanceof InvalidRequest); |
1245 | 1261 |
} |
1246 | 1262 |
|
1247 | 1263 |
Date newDate = new Date(); |
1248 |
metadata.setDateUploaded(newDate);
|
|
1264 |
sysmeta2.setDateUploaded(newDate);
|
|
1249 | 1265 |
try { |
1250 |
CNodeService.getInstance(request).updateSystemMetadata(session, guid, metadata);
|
|
1266 |
CNodeService.getInstance(request).updateSystemMetadata(session, guid, sysmeta2);
|
|
1251 | 1267 |
fail("We shouldn't get there"); |
1252 | 1268 |
} catch (Exception e) { |
1253 | 1269 |
assertTrue(e instanceof InvalidRequest); |
... | ... | |
1255 | 1271 |
|
1256 | 1272 |
Checksum checkSum = new Checksum(); |
1257 | 1273 |
checkSum.setValue("12345"); |
1258 |
metadata.setChecksum(checkSum);
|
|
1274 |
sysmeta2.setChecksum(checkSum);
|
|
1259 | 1275 |
try { |
1260 |
CNodeService.getInstance(request).updateSystemMetadata(session, guid, metadata);
|
|
1276 |
CNodeService.getInstance(request).updateSystemMetadata(session, guid, sysmeta2);
|
|
1261 | 1277 |
fail("We shouldn't get there"); |
1262 | 1278 |
} catch (Exception e) { |
1263 | 1279 |
assertTrue(e instanceof InvalidRequest); |
1264 | 1280 |
} |
1265 | 1281 |
|
1266 | 1282 |
BigInteger size = new BigInteger("4000"); |
1267 |
metadata.setSize(size);
|
|
1283 |
sysmeta2.setSize(size);
|
|
1268 | 1284 |
try { |
1269 |
CNodeService.getInstance(request).updateSystemMetadata(session, guid, metadata);
|
|
1285 |
CNodeService.getInstance(request).updateSystemMetadata(session, guid, sysmeta2);
|
|
1270 | 1286 |
fail("We shouldn't get there"); |
1271 | 1287 |
} catch (Exception e) { |
1272 | 1288 |
assertTrue(e instanceof InvalidRequest); |
Also available in: Unified diff
Increased the serial version number before updating the system metadata.