Adjust two tests slightly

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1745370 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2016-05-24 14:48:57 +00:00
parent a7df6604a4
commit 10ce4e23a6
2 changed files with 9 additions and 15 deletions

View File

@ -111,7 +111,9 @@ public final class TestOPCComplianceCoreProperties extends TestCase {
try { try {
extractInvalidFormatMessage("OnlyOneCorePropertiesPartFAIL.docx"); extractInvalidFormatMessage("OnlyOneCorePropertiesPartFAIL.docx");
fail("M4.1 should be being relaxed"); fail("M4.1 should be being relaxed");
} catch (AssertionFailedError e) {} } catch (AssertionFailedError e) {
// expected here
}
// We will use the first core properties, and ignore the others // We will use the first core properties, and ignore the others
InputStream is = OpenXML4JTestDataSamples.openSampleStream("MultipleCoreProperties.docx"); InputStream is = OpenXML4JTestDataSamples.openSampleStream("MultipleCoreProperties.docx");
@ -167,14 +169,9 @@ public final class TestOPCComplianceCoreProperties extends TestCase {
/** /**
* Test M4.1 rule. * Test M4.1 rule.
*/ */
public void testOnlyOneCorePropertiesPart_AddPart() { public void testOnlyOneCorePropertiesPart_AddPart() throws InvalidFormatException {
String sampleFileName = "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx"; String sampleFileName = "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx";
OPCPackage pkg = null; OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
try {
pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
} catch (Exception e) {
throw new RuntimeException(e);
}
URI partUri = createURI("/docProps/core2.xml"); URI partUri = createURI("/docProps/core2.xml");
try { try {
@ -182,8 +179,6 @@ public final class TestOPCComplianceCoreProperties extends TestCase {
ContentTypes.CORE_PROPERTIES_PART); ContentTypes.CORE_PROPERTIES_PART);
// no longer fail on compliance error // no longer fail on compliance error
//fail("expected OPC compliance exception was not thrown"); //fail("expected OPC compliance exception was not thrown");
} catch (InvalidFormatException e) {
throw new RuntimeException(e);
} catch (InvalidOperationException e) { } catch (InvalidOperationException e) {
// expected during successful test // expected during successful test
assertEquals("OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !", e.getMessage()); assertEquals("OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !", e.getMessage());
@ -318,6 +313,6 @@ public final class TestOPCComplianceCoreProperties extends TestCase {
// Finish and tidy // Finish and tidy
pkg.revert(); pkg.revert();
tmp.delete(); assertTrue(tmp.delete());
} }
} }

View File

@ -208,7 +208,6 @@ public class TestEncryptor {
byte keySalt[] = infoExpected.getHeader().getKeySalt(); byte keySalt[] = infoExpected.getHeader().getKeySalt();
POIFSFileSystem fs = new POIFSFileSystem();
EncryptionInfo infoActual = new EncryptionInfo( EncryptionInfo infoActual = new EncryptionInfo(
EncryptionMode.standard EncryptionMode.standard
, infoExpected.getVerifier().getCipherAlgorithm() , infoExpected.getVerifier().getCipherAlgorithm()
@ -227,7 +226,6 @@ public class TestEncryptor {
// now we use a newly generated salt/verifier and check // now we use a newly generated salt/verifier and check
// if the file content is still the same // if the file content is still the same
fs = new POIFSFileSystem();
infoActual = new EncryptionInfo( infoActual = new EncryptionInfo(
EncryptionMode.standard EncryptionMode.standard
, infoExpected.getVerifier().getCipherAlgorithm() , infoExpected.getVerifier().getCipherAlgorithm()
@ -240,6 +238,7 @@ public class TestEncryptor {
e = Encryptor.getInstance(infoActual); e = Encryptor.getInstance(infoActual);
e.confirmPassword(pass); e.confirmPassword(pass);
POIFSFileSystem fs = new POIFSFileSystem();
OutputStream os = e.getDataStream(fs); OutputStream os = e.getDataStream(fs);
IOUtils.copy(new ByteArrayInputStream(payloadExpected), os); IOUtils.copy(new ByteArrayInputStream(payloadExpected), os);
os.close(); os.close();