Revision 8952
Added by Jing Tao about 10 years ago
test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java | ||
---|---|---|
51 | 51 |
import junit.framework.Test; |
52 | 52 |
import junit.framework.TestSuite; |
53 | 53 |
|
54 |
import org.apache.commons.io.FileUtils; |
|
54 | 55 |
import org.apache.commons.io.IOUtils; |
55 | 56 |
import org.dataone.client.v2.formats.ObjectFormatCache; |
56 | 57 |
import org.dataone.configuration.Settings; |
... | ... | |
83 | 84 |
import org.dataone.service.types.v1.Session; |
84 | 85 |
import org.dataone.service.types.v1.Subject; |
85 | 86 |
import org.dataone.service.types.v1.SubjectInfo; |
87 |
import org.dataone.service.types.v1.util.ChecksumUtil; |
|
86 | 88 |
import org.dataone.service.types.v2.SystemMetadata; |
87 | 89 |
import org.dspace.foresite.ResourceMap; |
88 | 90 |
import org.jibx.runtime.JiBXException; |
... | ... | |
98 | 100 |
*/ |
99 | 101 |
public class MNodeServiceTest extends D1NodeServiceTest { |
100 | 102 |
|
103 |
private static String unmatchingEncodingFilePath = "test/incorrect-encoding-declaration.xml"; |
|
101 | 104 |
/** |
102 | 105 |
* Set up the test fixtures |
103 | 106 |
* |
... | ... | |
156 | 159 |
suite.addTest(new MNodeServiceTest("testGetPackage")); |
157 | 160 |
suite.addTest(new MNodeServiceTest("testGetOREPackage")); |
158 | 161 |
suite.addTest(new MNodeServiceTest("testReadDeletedObject")); |
159 |
|
|
162 |
suite.addTest(new MNodeServiceTest("testCreateAndUpdateXMLWithUnmatchingEncoding")); |
|
160 | 163 |
return suite; |
161 | 164 |
|
162 | 165 |
} |
... | ... | |
1342 | 1345 |
|
1343 | 1346 |
} |
1344 | 1347 |
} |
1348 |
|
|
1349 |
/** |
|
1350 |
* Test to create and update a metadata which xml declaration is ASCII, but actually |
|
1351 |
* has some special charaters. The saved document should has the same bytes as the origianl. |
|
1352 |
*/ |
|
1353 |
public void testCreateAndUpdateXMLWithUnmatchingEncoding() throws Exception { |
|
1354 |
String algorithm = "md5"; |
|
1355 |
Session session = getTestSession(); |
|
1356 |
Identifier guid = new Identifier(); |
|
1357 |
guid.setValue("testCreateAndUpdate." + System.currentTimeMillis()); |
|
1358 |
InputStream object = new ByteArrayInputStream(FileUtils.readFileToByteArray(new File(unmatchingEncodingFilePath))); |
|
1359 |
Checksum orgChecksum = ChecksumUtil.checksum(object, algorithm); |
|
1360 |
//System.out.println("the original checksum is "+orgChecksum.getValue()); |
|
1361 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object); |
|
1362 |
Identifier pid = |
|
1363 |
MNodeService.getInstance(request).create(session, guid, object, sysmeta); |
|
1364 |
InputStream readResult = MNodeService.getInstance(request).get(session, pid); |
|
1365 |
byte[] readBytes = IOUtils.toByteArray(readResult); |
|
1366 |
Checksum checksum1 = ChecksumUtil.checksum(readBytes, algorithm); |
|
1367 |
//System.out.println("the read checksum1 is "+checksum1.getValue()); |
|
1368 |
assertEquals(orgChecksum.getValue(), checksum1.getValue()); |
|
1369 |
|
|
1370 |
Identifier newPid = new Identifier(); |
|
1371 |
newPid.setValue("testCreateAndUpdate." + (System.currentTimeMillis() + 1)); // ensure it is different from original |
|
1372 |
SystemMetadata newSysMeta = createSystemMetadata(newPid, session.getSubject(), object); |
|
1373 |
|
|
1374 |
// do the update |
|
1375 |
Identifier updatedPid = |
|
1376 |
MNodeService.getInstance(request).update(session, pid, object, newPid, newSysMeta); |
|
1377 |
InputStream readResult2 = MNodeService.getInstance(request).get(session, updatedPid); |
|
1378 |
byte[] readBytes2 = IOUtils.toByteArray(readResult2); |
|
1379 |
Checksum checksum2 = ChecksumUtil.checksum(readBytes2, algorithm); |
|
1380 |
assertEquals(orgChecksum.getValue(), checksum2.getValue()); |
|
1381 |
//System.out.println("the read checksum2 is "+checksum2.getValue()); |
|
1382 |
|
|
1383 |
|
|
1384 |
} |
|
1345 | 1385 |
|
1346 | 1386 |
} |
Also available in: Unified diff
Add junit test method for saving a metadata document with unmatched xml encoding declaration.